doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Rotation.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 __MATH_ROTATION_H__
30 #define __MATH_ROTATION_H__
31 
32 /*
33 ===============================================================================
34 
35  Describes a complete rotation in degrees about an abritray axis.
36  A local rotation matrix is stored for fast rotation of multiple points.
37 
38 ===============================================================================
39 */
40 
41 
42 class idAngles;
43 class idQuat;
44 class idMat3;
45 
46 class idRotation {
47 
48  friend class idAngles;
49  friend class idQuat;
50  friend class idMat3;
51 
52 public:
53  idRotation( void );
54  idRotation( const idVec3 &rotationOrigin, const idVec3 &rotationVec, const float rotationAngle );
55 
56  void Set( const idVec3 &rotationOrigin, const idVec3 &rotationVec, const float rotationAngle );
57  void SetOrigin( const idVec3 &rotationOrigin );
58  void SetVec( const idVec3 &rotationVec ); // has to be normalized
59  void SetVec( const float x, const float y, const float z ); // has to be normalized
60  void SetAngle( const float rotationAngle );
61  void Scale( const float s );
62  void ReCalculateMatrix( void );
63  const idVec3 & GetOrigin( void ) const;
64  const idVec3 & GetVec( void ) const;
65  float GetAngle( void ) const;
66 
67  idRotation operator-() const; // flips rotation
68  idRotation operator*( const float s ) const; // scale rotation
69  idRotation operator/( const float s ) const; // scale rotation
70  idRotation & operator*=( const float s ); // scale rotation
71  idRotation & operator/=( const float s ); // scale rotation
72  idVec3 operator*( const idVec3 &v ) const; // rotate vector
73 
74  friend idRotation operator*( const float s, const idRotation &r ); // scale rotation
75  friend idVec3 operator*( const idVec3 &v, const idRotation &r ); // rotate vector
76  friend idVec3 & operator*=( idVec3 &v, const idRotation &r ); // rotate vector
77 
78  idAngles ToAngles( void ) const;
79  idQuat ToQuat( void ) const;
80  const idMat3 & ToMat3( void ) const;
81  idMat4 ToMat4( void ) const;
82  idVec3 ToAngularVelocity( void ) const;
83 
84  void RotatePoint( idVec3 &point ) const;
85 
86  void Normalize180( void );
87  void Normalize360( void );
88 
89 private:
90  idVec3 origin; // origin of rotation
91  idVec3 vec; // normalized vector to rotate around
92  float angle; // angle of rotation in degrees
93  mutable idMat3 axis; // rotation axis
94  mutable bool axisValid; // true if rotation axis is valid
95 };
96 
97 
98 ID_INLINE idRotation::idRotation( void ) {
99 }
100 
101 ID_INLINE idRotation::idRotation( const idVec3 &rotationOrigin, const idVec3 &rotationVec, const float rotationAngle ) {
102  origin = rotationOrigin;
103  vec = rotationVec;
104  angle = rotationAngle;
105  axisValid = false;
106 }
107 
108 ID_INLINE void idRotation::Set( const idVec3 &rotationOrigin, const idVec3 &rotationVec, const float rotationAngle ) {
109  origin = rotationOrigin;
110  vec = rotationVec;
111  angle = rotationAngle;
112  axisValid = false;
113 }
114 
115 ID_INLINE void idRotation::SetOrigin( const idVec3 &rotationOrigin ) {
116  origin = rotationOrigin;
117 }
118 
119 ID_INLINE void idRotation::SetVec( const idVec3 &rotationVec ) {
120  vec = rotationVec;
121  axisValid = false;
122 }
123 
124 ID_INLINE void idRotation::SetVec( float x, float y, float z ) {
125  vec[0] = x;
126  vec[1] = y;
127  vec[2] = z;
128  axisValid = false;
129 }
130 
131 ID_INLINE void idRotation::SetAngle( const float rotationAngle ) {
132  angle = rotationAngle;
133  axisValid = false;
134 }
135 
136 ID_INLINE void idRotation::Scale( const float s ) {
137  angle *= s;
138  axisValid = false;
139 }
140 
141 ID_INLINE void idRotation::ReCalculateMatrix( void ) {
142  axisValid = false;
143  ToMat3();
144 }
145 
146 ID_INLINE const idVec3 &idRotation::GetOrigin( void ) const {
147  return origin;
148 }
149 
150 ID_INLINE const idVec3 &idRotation::GetVec( void ) const {
151  return vec;
152 }
153 
154 ID_INLINE float idRotation::GetAngle( void ) const {
155  return angle;
156 }
157 
159  return idRotation( origin, vec, -angle );
160 }
161 
162 ID_INLINE idRotation idRotation::operator*( const float s ) const {
163  return idRotation( origin, vec, angle * s );
164 }
165 
166 ID_INLINE idRotation idRotation::operator/( const float s ) const {
167  assert( s != 0.0f );
168  return idRotation( origin, vec, angle / s );
169 }
170 
171 ID_INLINE idRotation &idRotation::operator*=( const float s ) {
172  angle *= s;
173  axisValid = false;
174  return *this;
175 }
176 
177 ID_INLINE idRotation &idRotation::operator/=( const float s ) {
178  assert( s != 0.0f );
179  angle /= s;
180  axisValid = false;
181  return *this;
182 }
183 
184 ID_INLINE idVec3 idRotation::operator*( const idVec3 &v ) const {
185  if ( !axisValid ) {
186  ToMat3();
187  }
188  return ((v - origin) * axis + origin);
189 }
190 
191 ID_INLINE idRotation operator*( const float s, const idRotation &r ) {
192  return r * s;
193 }
194 
195 ID_INLINE idVec3 operator*( const idVec3 &v, const idRotation &r ) {
196  return r * v;
197 }
198 
199 ID_INLINE idVec3 &operator*=( idVec3 &v, const idRotation &r ) {
200  v = r * v;
201  return v;
202 }
203 
204 ID_INLINE void idRotation::RotatePoint( idVec3 &point ) const {
205  if ( !axisValid ) {
206  ToMat3();
207  }
208  point = ((point - origin) * axis + origin);
209 }
210 
211 #endif /* !__MATH_ROTATION_H__ */
ID_INLINE idRotation operator*(const float s, const idRotation &r)
Definition: Rotation.h:191
assert(prefInfo.fullscreenBtn)
const GLdouble * v
Definition: glext.h:2936
void SetVec(const idVec3 &rotationVec)
Definition: Rotation.h:119
GLenum GLint GLint y
Definition: glext.h:2849
void Normalize360(void)
Definition: Rotation.cpp:149
Definition: Vector.h:316
void Scale(const float s)
Definition: Rotation.h:136
GLdouble s
Definition: glext.h:2935
GLenum GLint x
Definition: glext.h:2849
void Normalize180(void)
Definition: Rotation.cpp:134
float angle
Definition: Rotation.h:92
idVec3 vec
Definition: Rotation.h:91
bool axisValid
Definition: Rotation.h:94
ID_INLINE idVec3 & operator*=(idVec3 &v, const idRotation &r)
Definition: Rotation.h:199
idVec3 origin
Definition: Rotation.h:90
float GetAngle(void) const
Definition: Rotation.h:154
idMat3 axis
Definition: Rotation.h:93
idVec3 ToAngularVelocity(void) const
Definition: Rotation.cpp:125
void Set(const idVec3 &rotationOrigin, const idVec3 &rotationVec, const float rotationAngle)
Definition: Rotation.h:108
const idVec3 & GetVec(void) const
Definition: Rotation.h:150
Definition: Quat.h:48
idRotation(void)
Definition: Rotation.h:98
GLdouble GLdouble GLdouble r
Definition: glext.h:2951
Definition: Matrix.h:333
idRotation & operator*=(const float s)
Definition: Rotation.h:171
idRotation operator/(const float s) const
Definition: Rotation.h:166
void SetOrigin(const idVec3 &rotationOrigin)
Definition: Rotation.h:115
tuple f
Definition: idal.py:89
const idMat3 & ToMat3(void) const
Definition: Rotation.cpp:60
idRotation & operator/=(const float s)
Definition: Rotation.h:177
void ReCalculateMatrix(void)
Definition: Rotation.h:141
const idVec3 & GetOrigin(void) const
Definition: Rotation.h:146
idRotation operator-() const
Definition: Rotation.h:158
idAngles ToAngles(void) const
Definition: Rotation.cpp:38
idQuat ToQuat(void) const
Definition: Rotation.cpp:47
Definition: Matrix.h:764
GLdouble GLdouble z
Definition: glext.h:3067
void RotatePoint(idVec3 &point) const
Definition: Rotation.h:204
idRotation operator*(const float s) const
Definition: Rotation.h:162
idMat4 ToMat4(void) const
Definition: Rotation.cpp:116
void SetAngle(const float rotationAngle)
Definition: Rotation.h:131