]> de.git.xonotic.org Git - xonotic/netradiant.git/blobdiff - libs/splines/math_vector.cpp
more eol-style
[xonotic/netradiant.git] / libs / splines / math_vector.cpp
index 7237de5252778f8d6192687092be8309bc058a3f..dfbcfc6bd6256d25ed05ece411a6c64982e4529f 100644 (file)
-/*\r
-Copyright (C) 1999-2007 id Software, Inc. and contributors.\r
-For a list of contributors, see the accompanying CONTRIBUTORS file.\r
-\r
-This file is part of GtkRadiant.\r
-\r
-GtkRadiant is free software; you can redistribute it and/or modify\r
-it under the terms of the GNU General Public License as published by\r
-the Free Software Foundation; either version 2 of the License, or\r
-(at your option) any later version.\r
-\r
-GtkRadiant is distributed in the hope that it will be useful,\r
-but WITHOUT ANY WARRANTY; without even the implied warranty of\r
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
-GNU General Public License for more details.\r
-\r
-You should have received a copy of the GNU General Public License\r
-along with GtkRadiant; if not, write to the Free Software\r
-Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA\r
-*/\r
-\r
-#include "math_vector.h"\r
-#include <assert.h>\r
-#include <math.h>\r
-#include <stdio.h>\r
-#include <stdarg.h>\r
-#include <string.h>\r
-#include <stdlib.h>\r
-#include <time.h>\r
-#include <ctype.h>\r
-\r
-#define M_PI           3.14159265358979323846  // matches value in gcc v2 math.h\r
-\r
-#define LERP_DELTA 1e-6\r
-\r
-idVec3 vec_zero( 0.0f, 0.0f, 0.0f );\r
-\r
-Bounds boundsZero;\r
-\r
-float idVec3::toYaw( void ) {\r
-       float yaw;\r
-       \r
-       if ( ( y == 0 ) && ( x == 0 ) ) {\r
-               yaw = 0;\r
-       } else {\r
-               yaw = atan2( y, x ) * 180 / M_PI;\r
-               if ( yaw < 0 ) {\r
-                       yaw += 360;\r
-               }\r
-       }\r
-\r
-       return yaw;\r
-}\r
-\r
-float idVec3::toPitch( void ) {\r
-       float   forward;\r
-       float   pitch;\r
-       \r
-       if ( ( x == 0 ) && ( y == 0 ) ) {\r
-               if ( z > 0 ) {\r
-                       pitch = 90;\r
-               } else {\r
-                       pitch = 270;\r
-               }\r
-       } else {\r
-               forward = ( float )idSqrt( x * x + y * y );\r
-               pitch = atan2( z, forward ) * 180 / M_PI;\r
-               if ( pitch < 0 ) {\r
-                       pitch += 360;\r
-               }\r
-       }\r
-\r
-       return pitch;\r
-}\r
-\r
-/*\r
-angles_t idVec3::toAngles( void ) {\r
-       float forward;\r
-       float yaw;\r
-       float pitch;\r
-       \r
-       if ( ( x == 0 ) && ( y == 0 ) ) {\r
-               yaw = 0;\r
-               if ( z > 0 ) {\r
-                       pitch = 90;\r
-               } else {\r
-                       pitch = 270;\r
-               }\r
-       } else {\r
-               yaw = atan2( y, x ) * 180 / M_PI;\r
-               if ( yaw < 0 ) {\r
-                       yaw += 360;\r
-               }\r
-\r
-               forward = ( float )idSqrt( x * x + y * y );\r
-               pitch = atan2( z, forward ) * 180 / M_PI;\r
-               if ( pitch < 0 ) {\r
-                       pitch += 360;\r
-               }\r
-       }\r
-\r
-       return angles_t( -pitch, yaw, 0 );\r
-}\r
-*/\r
-\r
-idVec3 LerpVector( idVec3 &w1, idVec3 &w2, const float t ) {\r
-       float omega, cosom, sinom, scale0, scale1;\r
-\r
-       cosom = w1 * w2;\r
-       if ( ( 1.0 - cosom ) > LERP_DELTA ) {\r
-               omega = acos( cosom );\r
-               sinom = sin( omega );\r
-               scale0 = sin( ( 1.0 - t ) * omega ) / sinom;\r
-               scale1 = sin( t * omega ) / sinom;\r
-       } else {\r
-               scale0 = 1.0 - t;\r
-               scale1 = t;\r
-       }\r
-\r
-       return ( w1 * scale0 + w2 * scale1 );\r
-}\r
-\r
-/*\r
-=============\r
-idVec3::string\r
-\r
-This is just a convenience function\r
-for printing vectors\r
-=============\r
-*/\r
-char *idVec3::string( void ) {\r
-       static  int             index = 0;\r
-       static  char    str[ 8 ][ 36 ];\r
-       char    *s;\r
-\r
-       // use an array so that multiple toString's won't collide\r
-       s = str[ index ];\r
-       index = (index + 1)&7;\r
-\r
-       sprintf( s, "%.2f %.2f %.2f", x, y, z );\r
-\r
-       return s;\r
-}\r
+/*
+Copyright (C) 1999-2007 id Software, Inc. and contributors.
+For a list of contributors, see the accompanying CONTRIBUTORS file.
+
+This file is part of GtkRadiant.
+
+GtkRadiant is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+GtkRadiant is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GtkRadiant; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#include "math_vector.h"
+#include <assert.h>
+#include <math.h>
+#include <stdio.h>
+#include <stdarg.h>
+#include <string.h>
+#include <stdlib.h>
+#include <time.h>
+#include <ctype.h>
+
+#define M_PI           3.14159265358979323846  // matches value in gcc v2 math.h
+
+#define LERP_DELTA 1e-6
+
+idVec3 vec_zero( 0.0f, 0.0f, 0.0f );
+
+Bounds boundsZero;
+
+float idVec3::toYaw( void ) {
+       float yaw;
+       
+       if ( ( y == 0 ) && ( x == 0 ) ) {
+               yaw = 0;
+       } else {
+               yaw = atan2( y, x ) * 180 / M_PI;
+               if ( yaw < 0 ) {
+                       yaw += 360;
+               }
+       }
+
+       return yaw;
+}
+
+float idVec3::toPitch( void ) {
+       float   forward;
+       float   pitch;
+       
+       if ( ( x == 0 ) && ( y == 0 ) ) {
+               if ( z > 0 ) {
+                       pitch = 90;
+               } else {
+                       pitch = 270;
+               }
+       } else {
+               forward = ( float )idSqrt( x * x + y * y );
+               pitch = atan2( z, forward ) * 180 / M_PI;
+               if ( pitch < 0 ) {
+                       pitch += 360;
+               }
+       }
+
+       return pitch;
+}
+
+/*
+angles_t idVec3::toAngles( void ) {
+       float forward;
+       float yaw;
+       float pitch;
+       
+       if ( ( x == 0 ) && ( y == 0 ) ) {
+               yaw = 0;
+               if ( z > 0 ) {
+                       pitch = 90;
+               } else {
+                       pitch = 270;
+               }
+       } else {
+               yaw = atan2( y, x ) * 180 / M_PI;
+               if ( yaw < 0 ) {
+                       yaw += 360;
+               }
+
+               forward = ( float )idSqrt( x * x + y * y );
+               pitch = atan2( z, forward ) * 180 / M_PI;
+               if ( pitch < 0 ) {
+                       pitch += 360;
+               }
+       }
+
+       return angles_t( -pitch, yaw, 0 );
+}
+*/
+
+idVec3 LerpVector( idVec3 &w1, idVec3 &w2, const float t ) {
+       float omega, cosom, sinom, scale0, scale1;
+
+       cosom = w1 * w2;
+       if ( ( 1.0 - cosom ) > LERP_DELTA ) {
+               omega = acos( cosom );
+               sinom = sin( omega );
+               scale0 = sin( ( 1.0 - t ) * omega ) / sinom;
+               scale1 = sin( t * omega ) / sinom;
+       } else {
+               scale0 = 1.0 - t;
+               scale1 = t;
+       }
+
+       return ( w1 * scale0 + w2 * scale1 );
+}
+
+/*
+=============
+idVec3::string
+
+This is just a convenience function
+for printing vectors
+=============
+*/
+char *idVec3::string( void ) {
+       static  int             index = 0;
+       static  char    str[ 8 ][ 36 ];
+       char    *s;
+
+       // use an array so that multiple toString's won't collide
+       s = str[ index ];
+       index = (index + 1)&7;
+
+       sprintf( s, "%.2f %.2f %.2f", x, y, z );
+
+       return s;
+}