doom3-gpl
Doom 3 GPL source release
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Rotation.cpp
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 #include "../precompiled.h"
30 #pragma hdrstop
31 
32 
33 /*
34 ============
35 idRotation::ToAngles
36 ============
37 */
39  return ToMat3().ToAngles();
40 }
41 
42 /*
43 ============
44 idRotation::ToQuat
45 ============
46 */
47 idQuat idRotation::ToQuat( void ) const {
48  float a, s, c;
49 
50  a = angle * ( idMath::M_DEG2RAD * 0.5f );
51  idMath::SinCos( a, s, c );
52  return idQuat( vec.x * s, vec.y * s, vec.z * s, c );
53 }
54 
55 /*
56 ============
57 idRotation::toMat3
58 ============
59 */
60 const idMat3 &idRotation::ToMat3( void ) const {
61  float wx, wy, wz;
62  float xx, yy, yz;
63  float xy, xz, zz;
64  float x2, y2, z2;
65  float a, c, s, x, y, z;
66 
67  if ( axisValid ) {
68  return axis;
69  }
70 
71  a = angle * ( idMath::M_DEG2RAD * 0.5f );
72  idMath::SinCos( a, s, c );
73 
74  x = vec[0] * s;
75  y = vec[1] * s;
76  z = vec[2] * s;
77 
78  x2 = x + x;
79  y2 = y + y;
80  z2 = z + z;
81 
82  xx = x * x2;
83  xy = x * y2;
84  xz = x * z2;
85 
86  yy = y * y2;
87  yz = y * z2;
88  zz = z * z2;
89 
90  wx = c * x2;
91  wy = c * y2;
92  wz = c * z2;
93 
94  axis[ 0 ][ 0 ] = 1.0f - ( yy + zz );
95  axis[ 0 ][ 1 ] = xy - wz;
96  axis[ 0 ][ 2 ] = xz + wy;
97 
98  axis[ 1 ][ 0 ] = xy + wz;
99  axis[ 1 ][ 1 ] = 1.0f - ( xx + zz );
100  axis[ 1 ][ 2 ] = yz - wx;
101 
102  axis[ 2 ][ 0 ] = xz - wy;
103  axis[ 2 ][ 1 ] = yz + wx;
104  axis[ 2 ][ 2 ] = 1.0f - ( xx + yy );
105 
106  axisValid = true;
107 
108  return axis;
109 }
110 
111 /*
112 ============
113 idRotation::ToMat4
114 ============
115 */
116 idMat4 idRotation::ToMat4( void ) const {
117  return ToMat3().ToMat4();
118 }
119 
120 /*
121 ============
122 idRotation::ToAngularVelocity
123 ============
124 */
126  return vec * DEG2RAD( angle );
127 }
128 
129 /*
130 ============
131 idRotation::Normalize180
132 ============
133 */
135  angle -= floor( angle / 360.0f ) * 360.0f;
136  if ( angle > 180.0f ) {
137  angle -= 360.0f;
138  }
139  else if ( angle < -180.0f ) {
140  angle += 360.0f;
141  }
142 }
143 
144 /*
145 ============
146 idRotation::Normalize360
147 ============
148 */
150  angle -= floor( angle / 360.0f ) * 360.0f;
151  if ( angle > 360.0f ) {
152  angle -= 360.0f;
153  }
154  else if ( angle < 0.0f ) {
155  angle += 360.0f;
156  }
157 }
GLdouble GLdouble x2
Definition: qgl.h:415
GLenum GLint GLint y
Definition: glext.h:2849
float z
Definition: Vector.h:320
void Normalize360(void)
Definition: Rotation.cpp:149
Definition: Vector.h:316
static const float M_DEG2RAD
Definition: Math.h:214
GLdouble s
Definition: glext.h:2935
float x
Definition: Vector.h:318
GLenum GLint x
Definition: glext.h:2849
void Normalize180(void)
Definition: Rotation.cpp:134
static void SinCos(float a, float &s, float &c)
Definition: Math.h:390
float angle
Definition: Rotation.h:92
idVec3 vec
Definition: Rotation.h:91
bool axisValid
Definition: Rotation.h:94
friend class idQuat
Definition: Rotation.h:49
const GLubyte * c
Definition: glext.h:4677
float y
Definition: Vector.h:319
idMat3 axis
Definition: Rotation.h:93
idVec3 ToAngularVelocity(void) const
Definition: Rotation.cpp:125
GLubyte GLubyte GLubyte a
Definition: glext.h:4662
#define DEG2RAD(a)
Definition: Math.h:56
GLdouble GLdouble GLdouble y2
Definition: qgl.h:415
Definition: Quat.h:48
Definition: Matrix.h:333
tuple f
Definition: idal.py:89
const idMat3 & ToMat3(void) const
Definition: Rotation.cpp:60
idAngles ToAngles(void) const
Definition: Matrix.cpp:147
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
idMat4 ToMat4(void) const
Definition: Matrix.h:1125
idMat4 ToMat4(void) const
Definition: Rotation.cpp:116