-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauxiliary.cpp
More file actions
55 lines (49 loc) · 1.23 KB
/
auxiliary.cpp
File metadata and controls
55 lines (49 loc) · 1.23 KB
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
#include "auxiliary.h"
namespace violet {
GLFWwindow* window;
double getTime() {
return glfwGetTime() - 0;
}
namespace math {
float length(const glm::vec3&v) {
return sqrtf(v.x * v.x + v.y * v.y + v.z * v.z);
}
glm::vec3 normalize(const glm::vec3&v) {
float inverse = 1 / length(v);
return glm::vec3{ v.x * inverse,v.y * inverse,v.z * inverse };
}
glm::mat4 rotatex(float Degree) {
float cost = cosf(glm::radians(Degree));
float sint = sinf(glm::radians(Degree));
return glm::mat4(
1.f, 0.f, 0.f, 0.f,
0.f, cost, -sint, 0.f,
0.f, sint, cost, 0.f,
0.f, 0.f, 0.f, 1.f
);
}
glm::mat4 rotatey(float Degree) {
float cost = cosf(glm::radians(Degree));
float sint = sinf(glm::radians(Degree));
return glm::mat4(
cost, 0.f, -sint, 0.f,
0.f, 1.f, 0, 0.f,
sint, 0.f, cost, 0.f,
0.f, 0.f, 0.f, 1.f
);
}
glm::mat4 rotatez(float Degree) {
float cost = cosf(glm::radians(Degree));
float sint = sinf(glm::radians(Degree));
return glm::mat4(
cost, -sint, 0.f, 0.f,
sint, cost, 0.f, 0.f,
0.f, 0.f, 1.f, 0.f,
0.f, 0.f, 0.f, 1.f
);
}
glm::mat4 rotate(const glm::vec3&euler) {
return rotatez(euler.z) * rotatey(euler.y) * rotatex(euler.x);
}
}
}