forked from SaschaWillems/Vulkan
-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathcommon.hpp
128 lines (110 loc) · 2.83 KB
/
common.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#pragma once
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstdint>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <array>
#include <chrono>
#include <fstream>
#include <functional>
#include <initializer_list>
#include <iostream>
#include <iomanip>
#include <list>
#include <memory>
#include <mutex>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <fstream>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <thread>
#include <vector>
#if defined(__ANDROID__)
#include <android/native_activity.h>
#include <android/asset_manager.h>
#include <android_native_app_glue.h>
#endif
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/matrix_inverse.hpp>
#include <glm/gtc/noise.hpp>
#include <glm/gtc/quaternion.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <glm/gtx/rotate_vector.hpp>
#include <glm/gtx/transform.hpp>
#include <glm/gtx/quaternion.hpp>
// Image loading
#include <gli/gli.hpp>
// Vulkan!
#include <vulkan/vulkan.hpp>
#include "keycodes.hpp"
#if defined(__ANDROID__)
#include "android.hpp"
#else
#include "gl.hpp"
// Cross platform window management (except android)
#include "glfw/glfw.hpp"
#endif
using glm::ivec2;
using glm::mat3;
using glm::mat4;
using glm::quat;
using glm::uvec2;
using glm::vec2;
using glm::vec3;
using glm::vec4;
class Rotations {
public:
static const quat IDENTITY;
static const quat Y_180;
// Helper function returns the positive angle (in radians) between two 3D vectors
static inline float angleBetween(const glm::vec3& v1, const glm::vec3& v2) { return acosf((glm::dot(v1, v2)) / (glm::length(v1) * glm::length(v2))); }
};
class Vectors {
public:
static const vec3 UNIT_X;
static const vec3 UNIT_Y;
static const vec3 UNIT_Z;
static const vec3 UNIT_NEG_X;
static const vec3 UNIT_NEG_Y;
static const vec3 UNIT_NEG_Z;
static const vec3 UNIT_XY;
static const vec3 UNIT_XZ;
static const vec3 UNIT_YZ;
static const vec3 UNIT_XYZ;
static const vec3 MAX;
static const vec3 MIN;
static const vec3 ZERO;
static const vec3 ONE;
static const vec3 TWO;
static const vec3 HALF;
static const vec3& RIGHT;
static const vec3& UP;
static const vec3& FRONT;
static const vec3 ZERO4;
};
// Boilerplate for running an example
#if defined(__ANDROID__)
#define ENTRY_POINT_START \
void android_main(android_app* state) { \
vkx::android::androidApp = state;
#define ENTRY_POINT_END }
#else
#define ENTRY_POINT_START int main(const int argc, const char* argv[]) {
#define ENTRY_POINT_END \
return 0; \
}
#endif
#define RUN_EXAMPLE(ExampleType) \
ENTRY_POINT_START \
ExampleType().run(); \
ENTRY_POINT_END
#define VULKAN_EXAMPLE_MAIN() RUN_EXAMPLE(VulkanExample)