-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rotation.h
200 lines (168 loc) · 6.46 KB
/
Rotation.h
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#ifndef FAGL_ROTATION_H
#define FAGL_ROTATION_H
#include "FAGL.h"
#include <glm/gtc/quaternion.hpp>
#include <glm/gtx/quaternion.hpp>
#include "BasicTypes.h"
namespace fagl {
/// <summary>
/// Create a rotation quaternion around an axis.
/// </summary>
/// <param name="axis"> Axis.</param>
/// <param name="angle"> Turn angle in degrees.</param>
/// <returns> Rotation quaternion.</returns>
glm::quat Turn(const glm::vec3 axis, const float angle);
/// <summary>
/// Modify an axis using a rotation quaternion and create a rotation quaternion around that axis.
/// </summary>
/// <param name="baseAxis"> Original axis.</param>
/// <param name="angle"> Turn angle in degrees.</param>
/// <param name="currentRotation"> Starting rotation quaternion.</param>
/// <returns> Rotation quaternion.</returns>
glm::quat Turn(const glm::vec3 baseAxis, const float angle, const glm::quat currentRotation);
/// <summary>
/// Rotate a point around an axis.
/// </summary>
/// <param name="point"> Original point.</param>
/// <param name="axis"> Axis.</param>
/// <param name="angle"> Turn angle in degrees.</param>
/// <returns> The rotated point.</returns>
glm::vec3 TurnPoint(const glm::vec3 point, const glm::vec3 axis, const float angle);
/// <summary>
/// Modify an axis using a rotation quaternion and rotate a point around that axis.
/// </summary>
/// <param name="point"> Original point.</param>
/// <param name="baseAxis"> Original axis.</param>
/// <param name="angle"> Turn angle in degrees.</param>
/// <param name="currentRotation"> Starting rotation quaternion.</param>
/// <returns> The rotated point.</returns>
glm::vec3 TurnPoint(const glm::vec3 point, const glm::vec3 baseAxis, const float angle, const glm::quat currentRotation);
class Rotation_Manager {
protected:
glm::vec3 BaseUpVec;
glm::vec3 BaseGazeVec;
glm::vec3 BaseRightVec;
glm::quat currentRotation;
public:
/// <summary>
/// Turn around the unmodified axis.
/// </summary>
/// <param name="baseAxis"> Axis</param>
/// <param name="angle"> Turn angle in degrees.</param>
void TurnBase(const glm::vec3 baseAxis, const float angle);
/// <summary>
/// Turn around the unmodified axis.
/// </summary>
/// <param name="baseAxis"> Axis</param>
/// <param name="angle"> Turn angle in degrees.</param>
void TurnBase(const CAMERA_VECTOR baseAxis, const float angle);
/// <summary>
/// Turn around the axis after it modified according to current rotation.
/// </summary>
/// <param name="axis"> Axis</param>
/// <param name="angle"> Turn angle in degrees.</param>
void Turn(const glm::vec3 axis, const float angle);
/// <summary>
/// Turn around the axis after it modified according to current rotation.
/// </summary>
/// <param name="axis"> Axis</param>
/// <param name="angle"> Turn angle in degrees.</param>
void Turn(const CAMERA_VECTOR axis, const float angle);
/// <summary>
/// Roll around the original gaze vector.
/// </summary>
/// <param name="angle"> Turn angle in degrees.</param>
void RollBase(const float angle);
/// <summary>
/// Roll around the original right vector.
/// </summary>
/// <param name="angle"> Turn angle in degrees.</param>
void PitchBase(const float angle);
/// <summary>
/// Roll around the original up vector.
/// </summary>
/// <param name="angle"> Turn angle in degrees.</param>
void YawBase(const float angle);
/// <summary>
/// Roll around the current gaze vector.
/// </summary>
/// <param name="angle"> Turn angle in degrees.</param>
void Roll(const float angle);
/// <summary>
/// Roll around the current right vector.
/// </summary>
/// <param name="angle"> Turn angle in degrees.</param>
void Pitch(const float angle);
/// <summary>
/// Roll around the current up vector.
/// </summary>
/// <param name="angle"> Turn angle in degrees.</param>
void Yaw(const float angle);
/// <summary>
/// Get current rotation quaternion.
/// </summary>
/// <returns> Current rotation quaternion.</returns>
glm::quat GetCurrentRotation() const;
/// <summary>
/// Get current up vector.
/// </summary>
/// <returns> Current up vector.</returns>
glm::vec3 GetUpAxis() const;
/// <summary>
/// Get current gaze vector.
/// </summary>
/// <returns> Current gaze vector.</returns>
glm::vec3 GetGazeAxis() const;
/// <summary>
/// Get current right vector.
/// </summary>
/// <returns> Current right vector.</returns>
glm::vec3 GetRightAxis() const;
/// <summary>
/// Get original up vector.
/// </summary>
/// <returns> Original up vector.</returns>
glm::vec3 GetBaseUpAxis() const;
/// <summary>
/// Get original gaze vector.
/// </summary>
/// <returns> Original gaze vector.</returns>
glm::vec3 GetBaseGazeAxis() const;
/// <summary>
/// Get original right vector.
/// </summary>
/// <returns> Original right vector.</returns>
glm::vec3 GetBaseRightAxis() const;
/// <summary>
/// Get the current value of the axis.
/// </summary>
/// <param name="axis"> Axis.</param>
/// <returns> Its current value.</returns>
glm::vec3 GetAxis(const CAMERA_VECTOR axis) const;
/// <summary>
/// Get the original value of the axis.
/// </summary>
/// <param name="axis"> Axis.</param>
/// <returns> Its original value.</returns>
glm::vec3 GetBaseAxis(const CAMERA_VECTOR axis) const;
/// <summary>
/// Rotate a point according to current rotation.
/// </summary>
/// <param name="point"> The original point.</param>
/// <returns> Its new value.</returns>
glm::vec3 Rotate(const glm::vec3 point) const;
/// <summary>
/// Returns the rotation matrix that is equivalent to current rotation.
/// </summary>
/// <returns> Rotation matrix.</returns>
glm::mat4 GetRotationMatrix() const;
Rotation_Manager(const glm::vec3 up, const glm::vec3 gaze);
Rotation_Manager(const glm::vec3 up, const glm::vec3 gaze, const glm::vec3 right);
Rotation_Manager(const glm::vec3 up, const glm::vec3 gaze, const glm::quat rotation);
Rotation_Manager(const glm::vec3 up, const glm::vec3 gaze, const glm::vec3 right, const glm::quat rotation);
Rotation_Manager(const glm::vec3 up, const glm::vec3 gaze, const float xRot, const float yRot, const float zRot);
Rotation_Manager(const glm::vec3 up, const glm::vec3 gaze, const glm::vec3 right, const float xRot, const float yRot, const float zRot);
};
}
#include "Rotation.inl"
#endif