]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - libs/splines/math_angles.h
transfer from internal tree r5311 branches/1.4-gpl
[xonotic/netradiant.git] / libs / splines / math_angles.h
1 /*\r
2 Copyright (C) 1999-2007 id Software, Inc. and contributors.\r
3 For a list of contributors, see the accompanying CONTRIBUTORS file.\r
4 \r
5 This file is part of GtkRadiant.\r
6 \r
7 GtkRadiant is free software; you can redistribute it and/or modify\r
8 it under the terms of the GNU General Public License as published by\r
9 the Free Software Foundation; either version 2 of the License, or\r
10 (at your option) any later version.\r
11 \r
12 GtkRadiant is distributed in the hope that it will be useful,\r
13 but WITHOUT ANY WARRANTY; without even the implied warranty of\r
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
15 GNU General Public License for more details.\r
16 \r
17 You should have received a copy of the GNU General Public License\r
18 along with GtkRadiant; if not, write to the Free Software\r
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA\r
20 */\r
21 \r
22 #ifndef __MATH_ANGLES_H__\r
23 #define __MATH_ANGLES_H__\r
24 \r
25 #include <stdlib.h>\r
26 #include <assert.h>\r
27 \r
28 #include "math_vector.h"\r
29 \r
30 class mat3_t;\r
31 class quat_t;\r
32 class idVec3;\r
33 typedef idVec3 &vec3_p;\r
34 \r
35 class angles_t {\r
36 public:\r
37         float                   pitch;\r
38         float                   yaw;\r
39         float                   roll;\r
40 \r
41                                         angles_t();\r
42                                         angles_t( float pitch, float yaw, float roll );\r
43                                         angles_t( const idVec3 &vec );\r
44 \r
45         friend void             toAngles( idVec3 &src, angles_t &dst );\r
46         friend void             toAngles( quat_t &src, angles_t &dst );\r
47         friend void             toAngles( mat3_t &src, angles_t &dst );\r
48 \r
49                                         operator vec3_p();\r
50 \r
51         float                   operator[]( int index ) const;\r
52         float&                  operator[]( int index );\r
53 \r
54         void                    set( float pitch, float yaw, float roll );\r
55 \r
56         void                    operator=( angles_t const &a );\r
57         void                    operator=( idVec3 const &a );\r
58 \r
59         friend angles_t operator+( const angles_t &a, const angles_t &b );\r
60         angles_t                &operator+=( angles_t const &a );\r
61         angles_t                &operator+=( idVec3 const &a );\r
62 \r
63         friend angles_t operator-( angles_t &a, angles_t &b );\r
64         angles_t                &operator-=( angles_t &a );\r
65 \r
66         friend angles_t operator*( const angles_t &a, float b );\r
67         friend angles_t operator*( float a, const angles_t &b );\r
68         angles_t                &operator*=( float a );\r
69 \r
70         friend int              operator==(     angles_t &a, angles_t &b );\r
71                                         \r
72         friend int              operator!=(     angles_t &a, angles_t &b );\r
73 \r
74         void                    toVectors( idVec3 *forward, idVec3 *right = NULL, idVec3 *up = NULL );\r
75         idVec3                  toForward( void );\r
76 \r
77         angles_t                &Zero( void );\r
78 \r
79         angles_t                &Normalize360( void );\r
80         angles_t                &Normalize180( void );\r
81 };\r
82 \r
83 extern angles_t ang_zero;\r
84 \r
85 inline angles_t::angles_t() {}\r
86 \r
87 inline angles_t::angles_t( float pitch, float yaw, float roll ) {\r
88         this->pitch = pitch;\r
89         this->yaw       = yaw;\r
90         this->roll      = roll;\r
91 }\r
92 \r
93 inline angles_t::angles_t( const idVec3 &vec ) {\r
94         this->pitch = vec.x;\r
95         this->yaw       = vec.y;\r
96         this->roll      = vec.z;\r
97 }\r
98 \r
99 inline float angles_t::operator[]( int index ) const {\r
100         assert( ( index >= 0 ) && ( index < 3 ) );\r
101         return ( &pitch )[ index ];\r
102 }\r
103 \r
104 inline float& angles_t::operator[]( int index ) {\r
105         assert( ( index >= 0 ) && ( index < 3 ) );\r
106         return ( &pitch )[ index ];\r
107 }\r
108 \r
109 inline angles_t::operator vec3_p( void ) {\r
110         return *( idVec3 * )&pitch;\r
111 }\r
112 \r
113 inline void angles_t::set( float pitch, float yaw, float roll ) {\r
114         this->pitch = pitch;\r
115         this->yaw       = yaw;\r
116         this->roll      = roll;\r
117 }\r
118 \r
119 inline void angles_t::operator=( angles_t const &a ) {\r
120         pitch   = a.pitch;\r
121         yaw             = a.yaw;\r
122         roll    = a.roll;\r
123 }\r
124 \r
125 inline void angles_t::operator=( idVec3 const &a ) {\r
126         pitch   = a[ 0 ];\r
127         yaw             = a[ 1 ];\r
128         roll    = a[ 2 ];\r
129 }\r
130 \r
131 inline angles_t operator+( const angles_t &a, const angles_t &b ) {\r
132         return angles_t( a.pitch + b.pitch, a.yaw + b.yaw, a.roll + b.roll );\r
133 }\r
134 \r
135 inline angles_t& angles_t::operator+=( angles_t const &a ) {\r
136         pitch   += a.pitch;\r
137         yaw             += a.yaw;\r
138         roll    += a.roll;\r
139 \r
140         return *this;\r
141 }\r
142 \r
143 inline angles_t& angles_t::operator+=( idVec3 const &a ) {\r
144         pitch   += a.x;\r
145         yaw     += a.y;\r
146         roll    += a.z;\r
147 \r
148         return *this;\r
149 }\r
150 \r
151 inline angles_t operator-( angles_t &a, angles_t &b ) {\r
152         return angles_t( a.pitch - b.pitch, a.yaw - b.yaw, a.roll - b.roll );\r
153 }\r
154 \r
155 inline angles_t& angles_t::operator-=( angles_t &a ) {\r
156         pitch   -= a.pitch;\r
157         yaw             -= a.yaw;\r
158         roll    -= a.roll;\r
159 \r
160         return *this;\r
161 }\r
162 \r
163 inline angles_t operator*( const angles_t &a, float b ) {\r
164         return angles_t( a.pitch * b, a.yaw * b, a.roll * b );\r
165 }\r
166 \r
167 inline angles_t operator*( float a, const angles_t &b ) {\r
168         return angles_t( a * b.pitch, a * b.yaw, a * b.roll );\r
169 }\r
170 \r
171 inline angles_t& angles_t::operator*=( float a ) {\r
172         pitch   *= a;\r
173         yaw             *= a;\r
174         roll    *= a;\r
175 \r
176         return *this;\r
177 }\r
178 \r
179 inline int operator==( angles_t &a, angles_t &b ) {\r
180         return ( ( a.pitch == b.pitch ) && ( a.yaw == b.yaw ) && ( a.roll == b.roll ) );\r
181 }\r
182 \r
183 inline int operator!=( angles_t &a, angles_t &b ) {\r
184         return ( ( a.pitch != b.pitch ) || ( a.yaw != b.yaw ) || ( a.roll != b.roll ) );\r
185 }\r
186 \r
187 inline angles_t& angles_t::Zero( void ) {\r
188         pitch   = 0.0f;\r
189         yaw             = 0.0f;\r
190         roll    = 0.0f;\r
191 \r
192         return *this;\r
193 }\r
194 \r
195 #endif /* !__MATH_ANGLES_H__ */\r