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 );
41 quat_t( const quat_t & ) = default;
43 friend void toQuat( idVec3_t &src, quat_t &dst );
44 friend void toQuat( angles_t &src, quat_t &dst );
45 friend void toQuat( mat3_t &src, quat_t &dst );
49 float operator[]( int index ) const;
50 float &operator[]( int index );
52 void set( float x, float y, float z, float w );
54 quat_t &operator=( const quat_t &a ) = default;
56 friend quat_t operator+( quat_t a, quat_t b );
57 quat_t &operator+=( quat_t a );
59 friend quat_t operator-( quat_t a, quat_t b );
60 quat_t &operator-=( quat_t a );
62 friend quat_t operator*( quat_t a, float b );
63 friend quat_t operator*( float a, quat_t b );
64 quat_t &operator*=( float a );
66 friend int operator==( quat_t a, quat_t b );
67 friend int operator!=( quat_t a, quat_t b );
70 quat_t &Normalize( void );
75 inline quat_t::quat_t() {
78 inline quat_t::quat_t( float x, float y, float z, float w ) {
85 inline float *quat_t::vec4( void ) {
89 inline float quat_t::operator[]( int index ) const {
90 assert( ( index >= 0 ) && ( index < 4 ) );
91 return ( &x )[ index ];
94 inline float& quat_t::operator[]( int index ) {
95 assert( ( index >= 0 ) && ( index < 4 ) );
96 return ( &x )[ index ];
99 inline void quat_t::set( float x, float y, float z, float w ) {
106 inline quat_t operator+( quat_t a, quat_t b ) {
107 return quat_t( a.x + b.x, a.y + b.y, a.z + b.z, a.w + b.w );
110 inline quat_t& quat_t::operator+=( quat_t a ) {
119 inline quat_t operator-( quat_t a, quat_t b ) {
120 return quat_t( a.x - b.x, a.y - b.y, a.z - b.z, a.w - b.w );
123 inline quat_t& quat_t::operator-=( quat_t a ) {
132 inline quat_t operator*( quat_t a, float b ) {
133 return quat_t( a.x * b, a.y * b, a.z * b, a.w * b );
136 inline quat_t operator*( float a, quat_t b ) {
140 inline quat_t& quat_t::operator*=( float a ) {
149 inline int operator==( quat_t a, quat_t b ) {
150 return ( ( a.x == b.x ) && ( a.y == b.y ) && ( a.z == b.z ) && ( a.w == b.w ) );
153 inline int operator!=( quat_t a, quat_t b ) {
154 return ( ( a.x != b.x ) || ( a.y != b.y ) || (( a.z != b.z ) && ( a.w != b.w )) );
157 inline float quat_t::Length( void ) {
160 length = x * x + y * y + z * z + w * w;
161 return ( float )sqrt( length );
164 inline quat_t& quat_t::Normalize( void ) {
168 length = this->Length();
170 ilength = 1 / length;
180 inline quat_t quat_t::operator-() {
181 return quat_t( -x, -y, -z, -w );
184 #endif /* !__MATH_QUATERNION_H__ */