-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCameraMan.cpp
More file actions
130 lines (124 loc) · 2.87 KB
/
Copy pathCameraMan.cpp
File metadata and controls
130 lines (124 loc) · 2.87 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
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
129
130
#include "CameraMan.h"
void CrossProduct(float* A, float* B, float* result)
{
result[0] = (A[1] * B[2]) - (A[2] * B[1]);
result[1] = (A[2] * B[0]) - (A[0] * B[2]);
result[2] = (A[0] * B[1]) - (A[1] * B[0]);
}
CameraMan::CameraMan()
{
this->viewMatrix = glm::mat4(1.0f);
position.x = 0.0f;
position.y = 0.0f;
position.z = 0.0f;
rotation.x = 0.0f;
rotation.y = 0.0f;
rotation.z = 0.0f;
actualizeCamera();
}
CameraMan::CameraMan(glm::vec3 pos, glm::vec3 rot)
{
this->viewMatrix = glm::mat4(1.0f);
position.x = pos.x;
position.y = pos.y;
position.z = pos.z;
rotation.x = rot.x;
rotation.y = rot.y;
rotation.z = rot.z;
actualizeCamera();
}
CameraMan::~CameraMan()
{
}
void CameraMan::updateCamera(glm::vec3 pos, glm::vec3 rot)
{
position.x += pos.x;
position.y += pos.y;
position.z += pos.z;
rotation.x += rot.x;
rotation.y += rot.y;
rotation.z += rot.z;
}
void CameraMan::updateCamera_pos(glm::vec3 pos)
{
position.x = pos.x;
position.y = pos.y;
position.z = pos.z;
}
void CameraMan::updateCamera_rot(glm::vec3 rot)
{
rotation.x = rot.x;
rotation.y = rot.y;
rotation.z = rot.z;
}
void CameraMan::setCamera(glm::vec3 pos, glm::vec3 rot)
{
position.x = pos.x;
position.y = pos.y;
position.z = pos.z;
rotation.x = rot.x;
rotation.y = rot.y;
rotation.z = rot.z;
}
glm::vec3 CameraMan::actualizeCamera()
{
float a = sinf(degtorad * this->rotation.x),
b = sinf(degtorad * this->rotation.y),
c = sinf(degtorad * this->rotation.z),
d = cosf(degtorad * this->rotation.x),
e = cosf(degtorad * this->rotation.y),
h = cosf(degtorad * this->rotation.z);
//gluLookAt(x, 1.0f, z, x + lx, 1.0f, z + lz, 0.0f, 1.0f, 0.0f);
/*
gluLookAt( position[0],
position[1],
position[2],
position[0] + (h * b - c * a * e),
position[1] + (b * d * c - a * e),
position[2] - (-a * c * b + d * e) ,
-e * c * d - a * b,
a * b * c + d * h,
b * d * c - a * h
);
gluLookAt(
position[0],
position[1],
position[2],
position[0] + (h * b - c * a * e),
position[1] + (d * c * b - a * h),
position[2] + (a * c * b - d * e),
a * b + e * c * d,
a * b * c + d * h,
b * d * c - a * e
gluLookAt(
position[0],
position[1],
position[2],
position[0] + (h * b - c * a * e),
position[1] + (d * c * b - a * h),
position[2] + (a * c * b - d * e),
-c * d + a * h * b,
a * b * c + d * h,
b * d * c - a * e
*/
// float tVec[3] = { 0,1,0};
glm::vec3 tVec = { 0.0f,a * b * c + d * h,0.0f };
glm::vec3 forward = { d * h * b + a * c, d * b * c - h * a, d * e + b * c * a };
glm::vec3 right = glm::normalize(glm::cross(forward, tVec));
glm::vec3 up = glm::normalize(glm::cross(right, forward));
CameraPosition = position;
viewMatrix = glm::lookAt(position, position + forward, up);
/*
gluLookAt(
position.x,
position.y,
position.z,
position.x + forward[0],
position.y + forward[1],
position.z + forward[2],
up[0],
up[1],
up[2]
); */
return forward;
}