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_QUATERNION_H__
23 #define __MATH_QUATERNION_H__
40 quat_t( float x, float y, float z, float w );
42 friend void toQuat( idVec3_t &src, quat_t &dst );
43 friend void toQuat( angles_t &src, quat_t &dst );
44 friend void toQuat( mat3_t &src, quat_t &dst );
48 float operator[]( int index ) const;
49 float &operator[]( int index );
51 void set( float x, float y, float z, float w );
53 void operator=( quat_t a );
55 friend quat_t operator+( quat_t a, quat_t b );
56 quat_t &operator+=( quat_t a );
58 friend quat_t operator-( quat_t a, quat_t b );
59 quat_t &operator-=( quat_t a );
61 friend quat_t operator*( quat_t a, float b );
62 friend quat_t operator*( float a, quat_t b );
63 quat_t &operator*=( float a );
65 friend int operator==( quat_t a, quat_t b );
66 friend int operator!=( quat_t a, quat_t b );
69 quat_t &Normalize( void );
74 inline quat_t::quat_t() {
77 inline quat_t::quat_t( float x, float y, float z, float w ) {
84 inline float *quat_t::vec4( void ) {
88 inline float quat_t::operator[]( int index ) const {
89 assert( ( index >= 0 ) && ( index < 4 ) );
90 return ( &x )[ index ];
93 inline float& quat_t::operator[]( int index ) {
94 assert( ( index >= 0 ) && ( index < 4 ) );
95 return ( &x )[ index ];
98 inline void quat_t::set( float x, float y, float z, float w ) {
105 inline void quat_t::operator=( quat_t a ) {
112 inline quat_t operator+( quat_t a, quat_t b ) {
113 return quat_t( a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w );
116 inline quat_t& quat_t::operator+=( quat_t a ) {
125 inline quat_t operator-( quat_t a, quat_t b ) {
126 return quat_t( a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w );
129 inline quat_t& quat_t::operator-=( quat_t a ) {
138 inline quat_t operator*( quat_t a, float b ) {
139 return quat_t( a.x * b, a.y * b, a.z * b, a.w * b );
142 inline quat_t operator*( float a, quat_t b ) {
146 inline quat_t& quat_t::operator*=( float a ) {
155 inline int operator==( quat_t a, quat_t b ) {
156 return ( ( a.x == b.x ) && ( a.y == b.y ) && ( a.z == b.z ) && ( a.w == b.w ) );
159 inline int operator!=( quat_t a, quat_t b ) {
160 return ( ( a.x != b.x ) || ( a.y != b.y ) || ( a.z != b.z ) && ( a.w != b.w ) );
163 inline float quat_t::Length( void ) {
166 length = x * x + y * y + z * z + w * w;
167 return ( float )sqrt( length );
170 inline quat_t& quat_t::Normalize( void ) {
174 length = this->Length();
176 ilength = 1 / length;
186 inline quat_t quat_t::operator-() {
187 return quat_t( -x, -y, -z, -w );
190 #endif /* !__MATH_QUATERNION_H__ */