doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JointTransform.h
Go to the documentation of this file.
1 /*
2 ===========================================================================
3 
4 Doom 3 GPL Source Code
5 Copyright (C) 1999-2011 id Software LLC, a ZeniMax Media company.
6 
7 This file is part of the Doom 3 GPL Source Code (?Doom 3 Source Code?).
8 
9 Doom 3 Source Code is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13 
14 Doom 3 Source Code is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with Doom 3 Source Code. If not, see <http://www.gnu.org/licenses/>.
21 
22 In addition, the Doom 3 Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 Source Code. If not, please request a copy in writing from id Software at the address below.
23 
24 If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
25 
26 ===========================================================================
27 */
28 
29 #ifndef __JOINTTRANSFORM_H__
30 #define __JOINTTRANSFORM_H__
31 
32 /*
33 ===============================================================================
34 
35  Joint Quaternion
36 
37 ===============================================================================
38 */
39 
40 class idJointQuat {
41 public:
42 
45 };
46 
47 
48 /*
49 ===============================================================================
50 
51  Joint Matrix
52 
53  idMat3 m;
54  idVec3 t;
55 
56  m[0][0], m[1][0], m[2][0], t[0]
57  m[0][1], m[1][1], m[2][1], t[1]
58  m[0][2], m[1][2], m[2][2], t[2]
59 
60 ===============================================================================
61 */
62 
63 class idJointMat {
64 public:
65 
66  void SetRotation( const idMat3 &m );
67  void SetTranslation( const idVec3 &t );
68 
69  idVec3 operator*( const idVec3 &v ) const; // only rotate
70  idVec3 operator*( const idVec4 &v ) const; // rotate and translate
71 
72  idJointMat & operator*=( const idJointMat &a ); // transform
73  idJointMat & operator/=( const idJointMat &a ); // untransform
74 
75  bool Compare( const idJointMat &a ) const; // exact compare, no epsilon
76  bool Compare( const idJointMat &a, const float epsilon ) const; // compare with epsilon
77  bool operator==( const idJointMat &a ) const; // exact compare, no epsilon
78  bool operator!=( const idJointMat &a ) const; // exact compare, no epsilon
79 
80  idMat3 ToMat3( void ) const;
81  idVec3 ToVec3( void ) const;
82  idJointQuat ToJointQuat( void ) const;
83  const float * ToFloatPtr( void ) const;
84  float * ToFloatPtr( void );
85 
86 private:
87  float mat[3*4];
88 };
89 
90 ID_INLINE void idJointMat::SetRotation( const idMat3 &m ) {
91  // NOTE: idMat3 is transposed because it is column-major
92  mat[0 * 4 + 0] = m[0][0];
93  mat[0 * 4 + 1] = m[1][0];
94  mat[0 * 4 + 2] = m[2][0];
95  mat[1 * 4 + 0] = m[0][1];
96  mat[1 * 4 + 1] = m[1][1];
97  mat[1 * 4 + 2] = m[2][1];
98  mat[2 * 4 + 0] = m[0][2];
99  mat[2 * 4 + 1] = m[1][2];
100  mat[2 * 4 + 2] = m[2][2];
101 }
102 
103 ID_INLINE void idJointMat::SetTranslation( const idVec3 &t ) {
104  mat[0 * 4 + 3] = t[0];
105  mat[1 * 4 + 3] = t[1];
106  mat[2 * 4 + 3] = t[2];
107 }
108 
109 ID_INLINE idVec3 idJointMat::operator*( const idVec3 &v ) const {
110  return idVec3( mat[0 * 4 + 0] * v[0] + mat[0 * 4 + 1] * v[1] + mat[0 * 4 + 2] * v[2],
111  mat[1 * 4 + 0] * v[0] + mat[1 * 4 + 1] * v[1] + mat[1 * 4 + 2] * v[2],
112  mat[2 * 4 + 0] * v[0] + mat[2 * 4 + 1] * v[1] + mat[2 * 4 + 2] * v[2] );
113 }
114 
115 ID_INLINE idVec3 idJointMat::operator*( const idVec4 &v ) const {
116  return idVec3( mat[0 * 4 + 0] * v[0] + mat[0 * 4 + 1] * v[1] + mat[0 * 4 + 2] * v[2] + mat[0 * 4 + 3] * v[3],
117  mat[1 * 4 + 0] * v[0] + mat[1 * 4 + 1] * v[1] + mat[1 * 4 + 2] * v[2] + mat[1 * 4 + 3] * v[3],
118  mat[2 * 4 + 0] * v[0] + mat[2 * 4 + 1] * v[1] + mat[2 * 4 + 2] * v[2] + mat[2 * 4 + 3] * v[3] );
119 }
120 
122  float dst[3];
123 
124  dst[0] = mat[0 * 4 + 0] * a.mat[0 * 4 + 0] + mat[1 * 4 + 0] * a.mat[0 * 4 + 1] + mat[2 * 4 + 0] * a.mat[0 * 4 + 2];
125  dst[1] = mat[0 * 4 + 0] * a.mat[1 * 4 + 0] + mat[1 * 4 + 0] * a.mat[1 * 4 + 1] + mat[2 * 4 + 0] * a.mat[1 * 4 + 2];
126  dst[2] = mat[0 * 4 + 0] * a.mat[2 * 4 + 0] + mat[1 * 4 + 0] * a.mat[2 * 4 + 1] + mat[2 * 4 + 0] * a.mat[2 * 4 + 2];
127  mat[0 * 4 + 0] = dst[0];
128  mat[1 * 4 + 0] = dst[1];
129  mat[2 * 4 + 0] = dst[2];
130 
131  dst[0] = mat[0 * 4 + 1] * a.mat[0 * 4 + 0] + mat[1 * 4 + 1] * a.mat[0 * 4 + 1] + mat[2 * 4 + 1] * a.mat[0 * 4 + 2];
132  dst[1] = mat[0 * 4 + 1] * a.mat[1 * 4 + 0] + mat[1 * 4 + 1] * a.mat[1 * 4 + 1] + mat[2 * 4 + 1] * a.mat[1 * 4 + 2];
133  dst[2] = mat[0 * 4 + 1] * a.mat[2 * 4 + 0] + mat[1 * 4 + 1] * a.mat[2 * 4 + 1] + mat[2 * 4 + 1] * a.mat[2 * 4 + 2];
134  mat[0 * 4 + 1] = dst[0];
135  mat[1 * 4 + 1] = dst[1];
136  mat[2 * 4 + 1] = dst[2];
137 
138  dst[0] = mat[0 * 4 + 2] * a.mat[0 * 4 + 0] + mat[1 * 4 + 2] * a.mat[0 * 4 + 1] + mat[2 * 4 + 2] * a.mat[0 * 4 + 2];
139  dst[1] = mat[0 * 4 + 2] * a.mat[1 * 4 + 0] + mat[1 * 4 + 2] * a.mat[1 * 4 + 1] + mat[2 * 4 + 2] * a.mat[1 * 4 + 2];
140  dst[2] = mat[0 * 4 + 2] * a.mat[2 * 4 + 0] + mat[1 * 4 + 2] * a.mat[2 * 4 + 1] + mat[2 * 4 + 2] * a.mat[2 * 4 + 2];
141  mat[0 * 4 + 2] = dst[0];
142  mat[1 * 4 + 2] = dst[1];
143  mat[2 * 4 + 2] = dst[2];
144 
145  dst[0] = mat[0 * 4 + 3] * a.mat[0 * 4 + 0] + mat[1 * 4 + 3] * a.mat[0 * 4 + 1] + mat[2 * 4 + 3] * a.mat[0 * 4 + 2];
146  dst[1] = mat[0 * 4 + 3] * a.mat[1 * 4 + 0] + mat[1 * 4 + 3] * a.mat[1 * 4 + 1] + mat[2 * 4 + 3] * a.mat[1 * 4 + 2];
147  dst[2] = mat[0 * 4 + 3] * a.mat[2 * 4 + 0] + mat[1 * 4 + 3] * a.mat[2 * 4 + 1] + mat[2 * 4 + 3] * a.mat[2 * 4 + 2];
148  mat[0 * 4 + 3] = dst[0];
149  mat[1 * 4 + 3] = dst[1];
150  mat[2 * 4 + 3] = dst[2];
151 
152  mat[0 * 4 + 3] += a.mat[0 * 4 + 3];
153  mat[1 * 4 + 3] += a.mat[1 * 4 + 3];
154  mat[2 * 4 + 3] += a.mat[2 * 4 + 3];
155 
156  return *this;
157 }
158 
160  float dst[3];
161 
162  mat[0 * 4 + 3] -= a.mat[0 * 4 + 3];
163  mat[1 * 4 + 3] -= a.mat[1 * 4 + 3];
164  mat[2 * 4 + 3] -= a.mat[2 * 4 + 3];
165 
166  dst[0] = mat[0 * 4 + 0] * a.mat[0 * 4 + 0] + mat[1 * 4 + 0] * a.mat[1 * 4 + 0] + mat[2 * 4 + 0] * a.mat[2 * 4 + 0];
167  dst[1] = mat[0 * 4 + 0] * a.mat[0 * 4 + 1] + mat[1 * 4 + 0] * a.mat[1 * 4 + 1] + mat[2 * 4 + 0] * a.mat[2 * 4 + 1];
168  dst[2] = mat[0 * 4 + 0] * a.mat[0 * 4 + 2] + mat[1 * 4 + 0] * a.mat[1 * 4 + 2] + mat[2 * 4 + 0] * a.mat[2 * 4 + 2];
169  mat[0 * 4 + 0] = dst[0];
170  mat[1 * 4 + 0] = dst[1];
171  mat[2 * 4 + 0] = dst[2];
172 
173  dst[0] = mat[0 * 4 + 1] * a.mat[0 * 4 + 0] + mat[1 * 4 + 1] * a.mat[1 * 4 + 0] + mat[2 * 4 + 1] * a.mat[2 * 4 + 0];
174  dst[1] = mat[0 * 4 + 1] * a.mat[0 * 4 + 1] + mat[1 * 4 + 1] * a.mat[1 * 4 + 1] + mat[2 * 4 + 1] * a.mat[2 * 4 + 1];
175  dst[2] = mat[0 * 4 + 1] * a.mat[0 * 4 + 2] + mat[1 * 4 + 1] * a.mat[1 * 4 + 2] + mat[2 * 4 + 1] * a.mat[2 * 4 + 2];
176  mat[0 * 4 + 1] = dst[0];
177  mat[1 * 4 + 1] = dst[1];
178  mat[2 * 4 + 1] = dst[2];
179 
180  dst[0] = mat[0 * 4 + 2] * a.mat[0 * 4 + 0] + mat[1 * 4 + 2] * a.mat[1 * 4 + 0] + mat[2 * 4 + 2] * a.mat[2 * 4 + 0];
181  dst[1] = mat[0 * 4 + 2] * a.mat[0 * 4 + 1] + mat[1 * 4 + 2] * a.mat[1 * 4 + 1] + mat[2 * 4 + 2] * a.mat[2 * 4 + 1];
182  dst[2] = mat[0 * 4 + 2] * a.mat[0 * 4 + 2] + mat[1 * 4 + 2] * a.mat[1 * 4 + 2] + mat[2 * 4 + 2] * a.mat[2 * 4 + 2];
183  mat[0 * 4 + 2] = dst[0];
184  mat[1 * 4 + 2] = dst[1];
185  mat[2 * 4 + 2] = dst[2];
186 
187  dst[0] = mat[0 * 4 + 3] * a.mat[0 * 4 + 0] + mat[1 * 4 + 3] * a.mat[1 * 4 + 0] + mat[2 * 4 + 3] * a.mat[2 * 4 + 0];
188  dst[1] = mat[0 * 4 + 3] * a.mat[0 * 4 + 1] + mat[1 * 4 + 3] * a.mat[1 * 4 + 1] + mat[2 * 4 + 3] * a.mat[2 * 4 + 1];
189  dst[2] = mat[0 * 4 + 3] * a.mat[0 * 4 + 2] + mat[1 * 4 + 3] * a.mat[1 * 4 + 2] + mat[2 * 4 + 3] * a.mat[2 * 4 + 2];
190  mat[0 * 4 + 3] = dst[0];
191  mat[1 * 4 + 3] = dst[1];
192  mat[2 * 4 + 3] = dst[2];
193 
194  return *this;
195 }
196 
197 ID_INLINE bool idJointMat::Compare( const idJointMat &a ) const {
198  int i;
199 
200  for ( i = 0; i < 12; i++ ) {
201  if ( mat[i] != a.mat[i] ) {
202  return false;
203  }
204  }
205  return true;
206 }
207 
208 ID_INLINE bool idJointMat::Compare( const idJointMat &a, const float epsilon ) const {
209  int i;
210 
211  for ( i = 0; i < 12; i++ ) {
212  if ( idMath::Fabs( mat[i] - a.mat[i] ) > epsilon ) {
213  return false;
214  }
215  }
216  return true;
217 }
218 
219 ID_INLINE bool idJointMat::operator==( const idJointMat &a ) const {
220  return Compare( a );
221 }
222 
223 ID_INLINE bool idJointMat::operator!=( const idJointMat &a ) const {
224  return !Compare( a );
225 }
226 
227 ID_INLINE idMat3 idJointMat::ToMat3( void ) const {
228  return idMat3( mat[0 * 4 + 0], mat[1 * 4 + 0], mat[2 * 4 + 0],
229  mat[0 * 4 + 1], mat[1 * 4 + 1], mat[2 * 4 + 1],
230  mat[0 * 4 + 2], mat[1 * 4 + 2], mat[2 * 4 + 2] );
231 }
232 
233 ID_INLINE idVec3 idJointMat::ToVec3( void ) const {
234  return idVec3( mat[0 * 4 + 3], mat[1 * 4 + 3], mat[2 * 4 + 3] );
235 }
236 
237 ID_INLINE const float *idJointMat::ToFloatPtr( void ) const {
238  return mat;
239 }
240 
241 ID_INLINE float *idJointMat::ToFloatPtr( void ) {
242  return mat;
243 }
244 
245 #endif /* !__JOINTTRANSFORM_H__ */
idJointMat & operator/=(const idJointMat &a)
bool operator==(const idJointMat &a) const
const GLdouble * v
Definition: glext.h:2936
bool Compare(const idJointMat &a) const
Definition: Vector.h:316
int i
Definition: process.py:33
void SetTranslation(const idVec3 &t)
void SetRotation(const idMat3 &m)
GLuint dst
Definition: glext.h:5285
float mat[3 *4]
Definition: Vector.h:808
idVec3 ToVec3(void) const
static float Fabs(float f)
Definition: Math.h:779
const float * ToFloatPtr(void) const
idJointQuat ToJointQuat(void) const
GLubyte GLubyte GLubyte a
Definition: glext.h:4662
Definition: Quat.h:48
idMat3 ToMat3(void) const
Definition: Matrix.h:333
idVec3 operator*(const idVec3 &v) const
bool operator!=(const idJointMat &a) const
GLdouble GLdouble t
Definition: glext.h:2943
idJointMat & operator*=(const idJointMat &a)