-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquaternion.h
111 lines (93 loc) · 2.99 KB
/
quaternion.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
#ifndef QUATERNION_H
#define QUATERNION_H
// Declaration of quaternion structure
typedef struct { double W, X, Y, Z; } quat;
typedef struct { double X, Y, Z; } vec3;
////////////////////////////////////////////////////
/// Constructors
////////////////////////////////////////////////////
/**
* @desc Constructs qauternion from three angles
* @param Pointer to array of angles
* @return Pointer to newly created quat
*/
quat *quat_fromAngles(double angles[3]);
/**
* @desc Constructs qauternion from vector and angle
* @param angle of rotation
* @param vector of rotation
* @return Pointer to newly created quat
*/
quat *quat_fromVectorAndAngle(double angle, double vector[3]);
/**
* @desc Constructs qauternion from gravity vector
* @param vector that as to be as similar to gravity vector, as possible
* @return Pointer to newly created quat
*/
quat *quat_fromGravityVector(double vector[3]);
////////////////////////////////////////////////////
/// Operations with quaternions
////////////////////////////////////////////////////
/**
* @desc Adds quaternion rhs to quaternion lhs
* @param Quat value to be added to
* @param Quat value to be added
* @return lhs after adding rhs
*/
quat *quat_add(quat *lhs, quat *rhs);
/**
* @desc Divides quaternion rhs from quaternion lhs
* @param Quat value to be divided from
* @param Quat value to be divided
* @return lhs after dividing rhs
*/
quat *quat_substract(quat *lhs, quat *rhs);
/**
* @desc Multiplies quaternion lhs by quaternion rhs
* @param Quat value to be multiplied
* @param Quat value to be multiplied by
* @return lhs after multiplying by rhs
*/
quat *quat_multiply(quat *lhs, quat *rhs);
/**
* @desc Divides quaternion lhs by quaternion rhs
* @param Quat value to be divided
* @param Quat value to be divided by
* @return lhs after dividing by rhs
*/
quat *quat_divide(quat *lhs, quat *rhs);
////////////////////////////////////////////////////
/// Other functions
////////////////////////////////////////////////////
/**
* @desc Rotates vector using quaternion
* @param quat of rotation
* @param vector to be rotated
* @return rotated vector
*/
vec3 quat_rotateVector(quat *lhs, double vector[3]);
/**
* @desc Calculates angles using quaternion
* @param quat - source of data
* @return rotation angles
*/
vec3 quat_get3EulerAngles(quat *rhs);
/**
* @desc Gives copy of current inverted quat
* @param Quat to be inverted
* @return Inverted copy of rhs
*/
quat quat_inverted(quat *rhs);
/**
* @desc Calculates modulus of quat
* @param Quat which modulus is supposed to be calculated
* @return Modulus of quat
*/
double quat_modulus(quat *rhs);
/**
* @desc Normalizes quaternion
* @param Pointer to quat to be normalized
* @return Pointer to normalized rhs
*/
quat *quat_normalize(quat *rhs);
#endif