FreeWRL/FreeX3D  3.0.0
quaternion.h
1 /*
2 
3 
4 Quaternion ???
5 
6 */
7 
8 /****************************************************************************
9  This file is part of the FreeWRL/FreeX3D Distribution.
10 
11  Copyright 2009 CRC Canada. (http://www.crc.gc.ca)
12 
13  FreeWRL/FreeX3D is free software: you can redistribute it and/or modify
14  it under the terms of the GNU Lesser Public License as published by
15  the Free Software Foundation, either version 3 of the License, or
16  (at your option) any later version.
17 
18  FreeWRL/FreeX3D is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  GNU General Public License for more details.
22 
23  You should have received a copy of the GNU General Public License
24  along with FreeWRL/FreeX3D. If not, see <http://www.gnu.org/licenses/>.
25 ****************************************************************************/
26 
27 
28 #ifndef __FREEWRL_QUATERNION_H__
29 #define __FREEWRL_QUATERNION_H__
30 
31 
32 #define DELTA 0.0001
33 
34 /* definitions for mapping matrix in OpenGL format to standard math */
35 #define MAT00 mat[0]
36 #define MAT01 mat[1]
37 #define MAT02 mat[2]
38 #define MAT03 mat[3]
39 #define MAT10 mat[4]
40 #define MAT11 mat[5]
41 #define MAT12 mat[6]
42 #define MAT13 mat[7]
43 #define MAT20 mat[8]
44 #define MAT21 mat[9]
45 #define MAT22 mat[10]
46 #define MAT23 mat[11]
47 #define MAT30 mat[12]
48 #define MAT31 mat[13]
49 #define MAT32 mat[14]
50 #define MAT33 mat[15]
51 
52 /* definitions for "standard" matrix representation to map to OpenGL */
53 #define MATHEMATICS_MAT00 mat[0]
54 #define MATHEMATICS_MAT01 mat[4]
55 #define MATHEMATICS_MAT02 mat[8]
56 #define MATHEMATICS_MAT03 mat[12]
57 #define MATHEMATICS_MAT10 mat[1]
58 #define MATHEMATICS_MAT11 mat[5]
59 #define MATHEMATICS_MAT12 mat[9]
60 #define MATHEMATICS_MAT13 mat[13]
61 #define MATHEMATICS_MAT20 mat[2]
62 #define MATHEMATICS_MAT21 mat[6]
63 #define MATHEMATICS_MAT22 mat[10]
64 #define MATHEMATICS_MAT23 mat[14]
65 #define MATHEMATICS_MAT30 mat[3]
66 #define MATHEMATICS_MAT31 mat[7]
67 #define MATHEMATICS_MAT32 mat[11]
68 #define MATHEMATICS_MAT33 mat[15]
69 
70 typedef struct quaternion {
71  double w;
72  double x;
73  double y;
74  double z;
75 } Quaternion;
76 void
77 matrix_to_quaternion (Quaternion *quat, double *mat) ;
78 void
79 quaternion_to_matrix (double *mat, Quaternion *quat) ;
80 
81 void scale_to_matrix (double *mat, struct point_XYZ *scale);
82 
83 void
84 vrmlrot_to_quaternion(Quaternion *quat,
85  const double x,
86  const double y,
87  const double z,
88  const double a);
89 
90 void
91 quaternion_to_vrmlrot(const Quaternion *quat,
92  double *x,
93  double *y,
94  double *z,
95  double *a);
96 
97 void
98 quaternion_conjugate(Quaternion *quat);
99 
100 void
101 quaternion_inverse(Quaternion *ret,
102  const Quaternion *quat);
103 
104 double
105 quaternion_norm(const Quaternion *quat);
106 
107 void
108 quaternion_normalize(Quaternion *quat);
109 
110 void
111 quaternion_add(Quaternion *ret,
112  const Quaternion *q1,
113  const Quaternion *q2);
114 
115 void
116 quaternion_multiply(Quaternion *ret,
117  const Quaternion *q1,
118  const Quaternion *q2);
119 
120 void
121 quaternion_scalar_multiply(Quaternion *quat,
122  const double s);
123 
124 void
125 quaternion_rotation(struct point_XYZ *ret,
126  const Quaternion *quat,
127  const struct point_XYZ *v);
128 void
129 quaternion_rotationd(double *ret, Quaternion *quat, double *v);
130 
131 void
132 quaternion_togl(Quaternion *quat);
133 
134 void
135 quaternion_set(Quaternion *ret,
136  const Quaternion *quat);
137 
138 void
139 quaternion_slerp(Quaternion *ret,
140  const Quaternion *q1,
141  const Quaternion *q2,
142  const double t);
143 void quaternion_print(const Quaternion *quat, char* description );
144 void double2quat(Quaternion *quat, double *quat4);
145 void quat2double(double *quat4,Quaternion *quat);
146 void quat2euler(double *rxyz, int iaxis_halfcircle, Quaternion *q);
147 void quat2yawpitch(double *ypr, Quaternion *q);
148 void euler2quat1(Quaternion *qout, double *axyz);
149 void euler2quat(Quaternion *qout, double heading, double attitude, double bank);
150 
151 double rad2deg(double rad);
152 void loadIdentityMatrix (double *);
153 void vrmlrot_multiply(float* ret, float *a, float *b);
154 void vrmlrot_normalize(float *ret);
155 
156 #endif /* __FREEWRL_QUATERNION_H__ */