2 Copyright (C) 1999-2007 id Software, Inc. and contributors.
\r
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
\r
5 This file is part of GtkRadiant.
\r
7 GtkRadiant is free software; you can redistribute it and/or modify
\r
8 it under the terms of the GNU General Public License as published by
\r
9 the Free Software Foundation; either version 2 of the License, or
\r
10 (at your option) any later version.
\r
12 GtkRadiant is distributed in the hope that it will be useful,
\r
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
15 GNU General Public License for more details.
\r
17 You should have received a copy of the GNU General Public License
\r
18 along with GtkRadiant; if not, write to the Free Software
\r
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
\r
22 #include "math_vector.h"
\r
32 #define M_PI 3.14159265358979323846 // matches value in gcc v2 math.h
\r
34 #define LERP_DELTA 1e-6
\r
36 idVec3 vec_zero( 0.0f, 0.0f, 0.0f );
\r
40 float idVec3::toYaw( void ) {
\r
43 if ( ( y == 0 ) && ( x == 0 ) ) {
\r
46 yaw = atan2( y, x ) * 180 / M_PI;
\r
55 float idVec3::toPitch( void ) {
\r
59 if ( ( x == 0 ) && ( y == 0 ) ) {
\r
66 forward = ( float )idSqrt( x * x + y * y );
\r
67 pitch = atan2( z, forward ) * 180 / M_PI;
\r
77 angles_t idVec3::toAngles( void ) {
\r
82 if ( ( x == 0 ) && ( y == 0 ) ) {
\r
90 yaw = atan2( y, x ) * 180 / M_PI;
\r
95 forward = ( float )idSqrt( x * x + y * y );
\r
96 pitch = atan2( z, forward ) * 180 / M_PI;
\r
102 return angles_t( -pitch, yaw, 0 );
\r
106 idVec3 LerpVector( idVec3 &w1, idVec3 &w2, const float t ) {
\r
107 float omega, cosom, sinom, scale0, scale1;
\r
110 if ( ( 1.0 - cosom ) > LERP_DELTA ) {
\r
111 omega = acos( cosom );
\r
112 sinom = sin( omega );
\r
113 scale0 = sin( ( 1.0 - t ) * omega ) / sinom;
\r
114 scale1 = sin( t * omega ) / sinom;
\r
120 return ( w1 * scale0 + w2 * scale1 );
\r
127 This is just a convenience function
\r
128 for printing vectors
\r
131 char *idVec3::string( void ) {
\r
132 static int index = 0;
\r
133 static char str[ 8 ][ 36 ];
\r
136 // use an array so that multiple toString's won't collide
\r
138 index = (index + 1)&7;
\r
140 sprintf( s, "%.2f %.2f %.2f", x, y, z );
\r