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
25 angles_t ang_zero( 0.0f, 0.0f, 0.0f );
27 void toAngles( mat3_t &src, angles_t &dst ) {
34 // cap off our sin value so that we don't get any NANs
38 else if ( sp < -1.0 ) {
45 if ( cp > 8192 * FLT_EPSILON ) {
46 dst.pitch = theta * 180 / M_PI;
47 dst.yaw = atan2( src[ 0 ][ 1 ], src[ 0 ][ 0 ] ) * 180 / M_PI;
48 dst.roll = atan2( src[ 1 ][ 2 ], src[ 2 ][ 2 ] ) * 180 / M_PI;
51 dst.pitch = theta * 180 / M_PI;
52 dst.yaw = -atan2( src[ 1 ][ 0 ], src[ 1 ][ 1 ] ) * 180 / M_PI;
57 void toAngles( quat_t &src, angles_t &dst ) {
60 toMatrix( src, temp );
61 toAngles( temp, dst );
64 void toAngles( idVec3 &src, angles_t &dst ) {
70 void angles_t::toVectors( idVec3 *forward, idVec3 *right, idVec3 *up ) {
72 static float sr, sp, sy, cr, cp, cy; // static to help MS compiler fp bugs
74 angle = yaw * ( M_PI * 2 / 360 );
78 angle = pitch * ( M_PI * 2 / 360 );
82 angle = roll * ( M_PI * 2 / 360 );
87 forward->set( cp * cy, cp * sy, -sp );
91 right->set( -sr * sp * cy + cr * sy, -sr * sp * sy + -cr * cy, -sr * cp );
95 up->set( cr * sp * cy + -sr * -sy, cr * sp * sy + -sr * cy, cr * cp );
99 idVec3 angles_t::toForward( void ) {
101 static float sp, sy, cp, cy; // static to help MS compiler fp bugs
103 angle = yaw * ( M_PI * 2 / 360 );
107 angle = pitch * ( M_PI * 2 / 360 );
111 return idVec3( cp * cy, cp * sy, -sp );
118 returns angles normalized to the range [0 <= angle < 360]
121 angles_t& angles_t::Normalize360( void ) {
122 pitch = ( 360.0 / 65536 ) * ( ( int )( pitch * ( 65536 / 360.0 ) ) & 65535 );
123 yaw = ( 360.0 / 65536 ) * ( ( int )( yaw * ( 65536 / 360.0 ) ) & 65535 );
124 roll = ( 360.0 / 65536 ) * ( ( int )( roll * ( 65536 / 360.0 ) ) & 65535 );
134 returns angles normalized to the range [-180 < angle <= 180]
137 angles_t& angles_t::Normalize180( void ) {
140 if ( pitch > 180.0 ) {
148 if ( roll > 180.0 ) {