2 Copyright (C) 1999-2007 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 #include "math_vector.h"
32 #define M_PI 3.14159265358979323846 // matches value in gcc v2 math.h
34 #define LERP_DELTA 1e-6
36 idVec3 vec_zero( 0.0f, 0.0f, 0.0f );
40 float idVec3::toYaw( void ) {
43 if ( ( y == 0 ) && ( x == 0 ) ) {
46 yaw = atan2( y, x ) * 180 / M_PI;
55 float idVec3::toPitch( void ) {
59 if ( ( x == 0 ) && ( y == 0 ) ) {
66 forward = ( float )idSqrt( x * x + y * y );
67 pitch = atan2( z, forward ) * 180 / M_PI;
77 angles_t idVec3::toAngles( void ) {
82 if ( ( x == 0 ) && ( y == 0 ) ) {
90 yaw = atan2( y, x ) * 180 / M_PI;
95 forward = ( float )idSqrt( x * x + y * y );
96 pitch = atan2( z, forward ) * 180 / M_PI;
102 return angles_t( -pitch, yaw, 0 );
106 idVec3 LerpVector( idVec3 &w1, idVec3 &w2, const float t ) {
107 float omega, cosom, sinom, scale0, scale1;
110 if ( ( 1.0 - cosom ) > LERP_DELTA ) {
111 omega = acos( cosom );
112 sinom = sin( omega );
113 scale0 = sin( ( 1.0 - t ) * omega ) / sinom;
114 scale1 = sin( t * omega ) / sinom;
120 return ( w1 * scale0 + w2 * scale1 );
127 This is just a convenience function
131 char *idVec3::string( void ) {
132 static int index = 0;
133 static char str[ 8 ][ 36 ];
136 // use an array so that multiple toString's won't collide
138 index = (index + 1)&7;
140 sprintf( s, "%.2f %.2f %.2f", x, y, z );