2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 #ifndef __MATH_ANGLES_H__
23 #define __MATH_ANGLES_H__
28 #include "math_vector.h"
33 typedef idVec3 &vec3_p;
42 angles_t( float pitch, float yaw, float roll );
43 angles_t( const idVec3 &vec );
45 friend void toAngles( idVec3 &src, angles_t &dst );
46 friend void toAngles( quat_t &src, angles_t &dst );
47 friend void toAngles( mat3_t &src, angles_t &dst );
51 float operator[]( int index ) const;
52 float& operator[]( int index );
54 void set( float pitch, float yaw, float roll );
56 angles_t &operator=( angles_t const &a ) = default;
57 angles_t &operator=( idVec3 const &a );
59 friend angles_t operator+( const angles_t &a, const angles_t &b );
60 angles_t &operator+=( angles_t const &a );
61 angles_t &operator+=( idVec3 const &a );
63 friend angles_t operator-( angles_t &a, angles_t &b );
64 angles_t &operator-=( angles_t &a );
66 friend angles_t operator*( const angles_t &a, float b );
67 friend angles_t operator*( float a, const angles_t &b );
68 angles_t &operator*=( float a );
70 friend int operator==( angles_t &a, angles_t &b );
71 friend int operator!=( angles_t &a, angles_t &b );
73 void toVectors( idVec3 *forward, idVec3 *right = NULL, idVec3 *up = NULL );
74 idVec3 toForward( void );
76 angles_t &Zero( void );
78 angles_t &Normalize360( void );
79 angles_t &Normalize180( void );
82 extern angles_t ang_zero;
84 inline angles_t::angles_t() {}
86 inline angles_t::angles_t( float pitch, float yaw, float roll ) {
92 inline angles_t::angles_t( const idVec3 &vec ) {
98 inline float angles_t::operator[]( int index ) const {
99 assert( ( index >= 0 ) && ( index < 3 ) );
100 return ( &pitch )[ index ];
103 inline float& angles_t::operator[]( int index ) {
104 assert( ( index >= 0 ) && ( index < 3 ) );
105 return ( &pitch )[ index ];
108 inline angles_t::operator vec3_p( void ) {
109 return *( idVec3 * )&pitch;
112 inline void angles_t::set( float pitch, float yaw, float roll ) {
118 inline angles_t &angles_t::operator=( idVec3 const &a ) {
125 inline angles_t operator+( const angles_t &a, const angles_t &b ) {
126 return angles_t( a.pitch + b.pitch, a.yaw + b.yaw, a.roll + b.roll );
129 inline angles_t& angles_t::operator+=( angles_t const &a ) {
137 inline angles_t& angles_t::operator+=( idVec3 const &a ) {
145 inline angles_t operator-( angles_t &a, angles_t &b ) {
146 return angles_t( a.pitch - b.pitch, a.yaw - b.yaw, a.roll - b.roll );
149 inline angles_t& angles_t::operator-=( angles_t &a ) {
157 inline angles_t operator*( const angles_t &a, float b ) {
158 return angles_t( a.pitch * b, a.yaw * b, a.roll * b );
161 inline angles_t operator*( float a, const angles_t &b ) {
162 return angles_t( a * b.pitch, a * b.yaw, a * b.roll );
165 inline angles_t& angles_t::operator*=( float a ) {
173 inline int operator==( angles_t &a, angles_t &b ) {
174 return ( ( a.pitch == b.pitch ) && ( a.yaw == b.yaw ) && ( a.roll == b.roll ) );
177 inline int operator!=( angles_t &a, angles_t &b ) {
178 return ( ( a.pitch != b.pitch ) || ( a.yaw != b.yaw ) || ( a.roll != b.roll ) );
181 inline angles_t& angles_t::Zero( void ) {
189 #endif /* !__MATH_ANGLES_H__ */