MercuryMath.h

Go to the documentation of this file.
00001 #ifndef _MERCURYMATH_H
00002 #define _MERCURYMATH_H
00003 
00004 #include <math.h>
00005 
00006 #define DEGRAD  0.01745329251994329576f     //degree to radian
00007 #define RADDEG  57.2957795130823208767f     //radian to degree
00008 #define Q_PI    3.14159265358979323846f
00009 
00010 #if defined(WIN32)
00011 //In win32, sin works faster than sinf and similar functions
00012 #define SIN( x )        float( sin ( x ) )
00013 #define COS( x )        float( cos ( x ) )
00014 #define ATAN2( x, y )   float( atan2( x, y ) )
00015 #define ASIN( x )       float( asin ( x ) )
00016 #define ACOS( x )       float( acos ( x ) )
00017 #define SQRT( x )       float( sqrt ( x ) )
00018 #define TAN( x )        float( tan ( x ) )
00019 #define ABS( x )        float( ((x<0)?(-x):(x)) )
00020 #else
00021 //On other OSes in general, sinf works faster than floating a sin
00022 #define SIN( x )        sinf( x )
00023 #define COS( x )        cosf( x )
00024 #define ATAN2( x, y )   atan2f( x, y )
00025 #define ASIN( x )       asinf ( x )
00026 #define ACOS( x )       acosf ( x )
00027 #define SQRT( x )       sqrtf( x )
00028 #define TAN( x )        tanf( x )
00029 #define ABS( x )        ((x<0)?(-x):(x))
00030 #endif
00031 
00032 #define SQ(x) ((x)*(x));
00033 
00034 #define DotProduct(x,y) ((x)[0]*(y)[0]+(x)[1]*(y)[1]+(x)[2]*(y)[2])
00035 
00036 #if !defined( _MSC_VER ) || defined( SLOW_CODE )
00037 
00038 void Mul4f(const float* first, const float* second, float* out);
00039 void Div4f(const float* first, const float* second, float* out);
00040 void Add4f(const float* first, const float* second, float* out);
00041 void Sub4f(const float* first, const float* second, float* out);
00042 void Copy4f( void * dest, const void * source );
00043 void Copy8f( void * dest, const void * source );
00044 void Copy16f( void * dest, const void * source );
00045 void R_ConcatTransforms4 ( const float* in1, const float* in2, float* out );
00046 #else
00047 //http://www.digitalmars.com/ctg/ctgAsm.html
00048 extern "C" void Mul4f(const float* first, const float* second, float* out);
00049 extern "C" void Div4f(const float* first, const float* second, float* out);
00050 extern "C" void Add4f(const float* first, const float* second, float* out);
00051 extern "C" void Sub4f(const float* first, const float* second, float* out);
00052 extern "C" void __fastcall Copy4f( void * dest, const void * source );
00053 extern "C" void __fastcall Copy8f( void * dest, const void * source );
00054 extern "C" void __fastcall Copy16f( void * dest, const void * source );
00055 extern "C" void R_ConcatTransforms4 ( const float* in1, const float* in2, float* out );
00056 #endif
00057 
00058 void VectorMultiply4f(const float *m, float *p, float *out );
00059 
00060 #endif
00061 
00062 /*
00063  * (c) 2006 Joshua Allen
00064  * All rights reserved.
00065  * 
00066  * Permission is hereby granted, free of charge, to any person obtaining a
00067  * copy of this software and associated documentation files (the
00068  * "Software"), to deal in the Software without restriction, including
00069  * without limitation the rights to use, copy, modify, merge, publish,
00070  * distribute, and/or sell copies of the Software, and to permit persons to
00071  * whom the Software is furnished to do so, provided that the above
00072  * copyright notice(s) and this permission notice appear in all copies of
00073  * the Software and that both the above copyright notice(s) and this
00074  * permission notice appear in supporting documentation.
00075  * 
00076  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00077  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00078  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
00079  * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
00080  * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
00081  * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
00082  * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
00083  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00084  * PERFORMANCE OF THIS SOFTWARE.
00085  */
00086 

Hosted by SourceForge.net Logo