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
37 } else if ( sp < -1.0 ) {
44 if ( cp > 8192 * FLT_EPSILON ) {
45 dst.pitch = theta * 180 / M_PI;
46 dst.yaw = atan2( src[ 0 ][ 1 ], src[ 0 ][ 0 ] ) * 180 / M_PI;
47 dst.roll = atan2( src[ 1 ][ 2 ], src[ 2 ][ 2 ] ) * 180 / M_PI;
49 dst.pitch = theta * 180 / M_PI;
50 dst.yaw = -atan2( src[ 1 ][ 0 ], src[ 1 ][ 1 ] ) * 180 / M_PI;
55 void toAngles( quat_t &src, angles_t &dst ) {
58 toMatrix( src, temp );
59 toAngles( temp, dst );
62 void toAngles( idVec3 &src, angles_t &dst ) {
68 void angles_t::toVectors( idVec3 *forward, idVec3 *right, idVec3 *up ) {
70 static float sr, sp, sy, cr, cp, cy; // static to help MS compiler fp bugs
72 angle = yaw * ( M_PI * 2 / 360 );
76 angle = pitch * ( M_PI * 2 / 360 );
80 angle = roll * ( M_PI * 2 / 360 );
85 forward->set( cp * cy, cp * sy, -sp );
89 right->set( -sr * sp * cy + cr * sy, -sr * sp * sy + -cr * cy, -sr * cp );
93 up->set( cr * sp * cy + -sr * -sy, cr * sp * sy + -sr * cy, cr * cp );
97 idVec3 angles_t::toForward( void ) {
99 static float sp, sy, cp, cy; // static to help MS compiler fp bugs
101 angle = yaw * ( M_PI * 2 / 360 );
105 angle = pitch * ( M_PI * 2 / 360 );
109 return idVec3( cp * cy, cp * sy, -sp );
116 returns angles normalized to the range [0 <= angle < 360]
119 angles_t& angles_t::Normalize360( void ) {
120 pitch = (360.0 / 65536) * ( ( int )( pitch * ( 65536 / 360.0 ) ) & 65535 );
121 yaw = (360.0 / 65536) * ( ( int )( yaw * ( 65536 / 360.0 ) ) & 65535 );
122 roll = (360.0 / 65536) * ( ( int )( roll * ( 65536 / 360.0 ) ) & 65535 );
132 returns angles normalized to the range [-180 < angle <= 180]
135 angles_t& angles_t::Normalize180( void ) {
138 if ( pitch > 180.0 ) {
146 if ( roll > 180.0 ) {