MercuryMath.cpp

Go to the documentation of this file.
00001 #include "MercuryMath.h"
00002 
00003 #if !defined( _MSC_VER ) || defined( SLOW_CODE )
00004 
00005 //Generic Math functions. Compile these if you can not use optimized functions.
00006 
00007 void Mul4f(const float* first, const float* second, float* out)
00008 {
00009     out[0] = first[0] * second[0];
00010     out[1] = first[1] * second[1];
00011     out[2] = first[2] * second[2];
00012     out[3] = first[3] * second[3];
00013 }
00014 
00015 void Div4f(const float* first, const float* second, float* out)
00016 {
00017     out[0] = first[0] / second[0];
00018     out[1] = first[1] / second[1];
00019     out[2] = first[2] / second[2];
00020     out[3] = first[3] / second[3];
00021 }
00022 
00023 void Add4f(const float* first, const float* second, float* out)
00024 {
00025     out[0] = first[0] + second[0];
00026     out[1] = first[1] + second[1];
00027     out[2] = first[2] + second[2];
00028     out[3] = first[3] + second[3];
00029 }
00030 
00031 void Sub4f(const float* first, const float* second, float* out)
00032 {
00033     out[0] = first[0] - second[0];
00034     out[1] = first[1] - second[1];
00035     out[2] = first[2] - second[2];
00036     out[3] = first[3] - second[3];
00037 }
00038 
00039 void Copy4f( void * dest, const void * source )
00040 {
00041     ((float*)dest)[0] = ((float*)source)[0];
00042     ((float*)dest)[1] = ((float*)source)[1];
00043     ((float*)dest)[2] = ((float*)source)[2];
00044     ((float*)dest)[3] = ((float*)source)[3];
00045 }
00046 
00047 void Copy8f( void * dest, const void * source )
00048 {
00049     ((float*)dest)[0] = ((float*)source)[0];
00050     ((float*)dest)[1] = ((float*)source)[1];
00051     ((float*)dest)[2] = ((float*)source)[2];
00052     ((float*)dest)[3] = ((float*)source)[3];
00053 
00054     ((float*)dest)[4] = ((float*)source)[4];
00055     ((float*)dest)[5] = ((float*)source)[5];
00056     ((float*)dest)[6] = ((float*)source)[6];
00057     ((float*)dest)[7] = ((float*)source)[7];
00058 }
00059 
00060 void Copy16f( void * dest, const void * source )
00061 {
00062     ((float*)dest)[0] = ((float*)source)[0];
00063     ((float*)dest)[1] = ((float*)source)[1];
00064     ((float*)dest)[2] = ((float*)source)[2];
00065     ((float*)dest)[3] = ((float*)source)[3];
00066 
00067     ((float*)dest)[4] = ((float*)source)[4];
00068     ((float*)dest)[5] = ((float*)source)[5];
00069     ((float*)dest)[6] = ((float*)source)[6];
00070     ((float*)dest)[7] = ((float*)source)[7];
00071 
00072     ((float*)dest)[8] = ((float*)source)[8];
00073     ((float*)dest)[9] = ((float*)source)[9];
00074     ((float*)dest)[10] = ((float*)source)[10];
00075     ((float*)dest)[11] = ((float*)source)[11];
00076 
00077     ((float*)dest)[12] = ((float*)source)[12];
00078     ((float*)dest)[13] = ((float*)source)[13];
00079     ((float*)dest)[14] = ((float*)source)[14];
00080     ((float*)dest)[15] = ((float*)source)[15];
00081 }
00082 
00083 void R_ConcatTransforms4 ( const float* in1, const float* in2, float* out)
00084 {
00085     out[0] = in1[0] * in2[0] + in1[1] * in2[4] +
00086                 in1[2] * in2[8] + in1[3] * in2[12];
00087     out[1] = in1[0] * in2[1] + in1[1] * in2[5] +
00088                 in1[2] * in2[9] + in1[3] * in2[13];
00089     out[2] = in1[0] * in2[2] + in1[1] * in2[6] +
00090                 in1[2] * in2[10] + in1[3] * in2[14];
00091     out[3] = in1[0] * in2[3] + in1[1] * in2[7] +
00092                 in1[2] * in2[11] + in1[3] * in2[15];
00093 
00094     out[4] = in1[4] * in2[0] + in1[5] * in2[4] +
00095                 in1[6] * in2[8] + in1[7] * in2[12];
00096     out[5] = in1[4] * in2[1] + in1[5] * in2[5] +
00097                 in1[6] * in2[9] + in1[7] * in2[13];
00098     out[6] = in1[4] * in2[2] + in1[5] * in2[6] +
00099                 in1[6] * in2[10] + in1[7] * in2[14];
00100     out[7] = in1[4] * in2[3] + in1[5] * in2[7] +
00101                 in1[6] * in2[11] + in1[7] * in2[15];
00102 
00103     out[8] = in1[8] * in2[0] + in1[9] * in2[4] +
00104                 in1[10] * in2[8] + in1[11] * in2[12];
00105     out[9] = in1[8] * in2[1] + in1[9] * in2[5] +
00106                 in1[10] * in2[9] + in1[11] * in2[13];
00107     out[10] = in1[8] * in2[2] + in1[9] * in2[6] +
00108                 in1[10] * in2[10] + in1[11] * in2[14];
00109     out[11] = in1[8] * in2[3] + in1[9] * in2[7] +
00110                 in1[10] * in2[11] + in1[11] * in2[15];
00111 
00112     out[12] = in1[12] * in2[0] + in1[13] * in2[4] +
00113                 in1[14] * in2[8] + in1[15] * in2[12];
00114     out[13] = in1[12] * in2[1] + in1[13] * in2[5] +
00115                 in1[14] * in2[9] + in1[15] * in2[13];
00116     out[14] = in1[12] * in2[2] + in1[13] * in2[6] +
00117                 in1[14] * in2[10] + in1[15] * in2[14];
00118     out[15] = in1[12] * in2[3] + in1[13] * in2[7] +
00119                 in1[14] * in2[11] + in1[15] * in2[15];
00120 }
00121 
00122 #endif
00123 
00124 void VectorMultiply4f( const float * m, float *p, float *out )
00125 {
00126     out[0] = p[0] * m[0] + p[1] * m[1] + p[2] * m[2] + p[3] * m[3];
00127     out[1] = p[0] * m[4] + p[1] * m[5] + p[2] * m[6] + p[3] * m[7];
00128     out[2] = p[0] * m[8] + p[1] * m[9] + p[2] * m[10] + p[3] * m[11];
00129     out[3] = p[0] * m[12] + p[1] * m[13] + p[2] * m[14] + p[3] * m[15];
00130 }
00131 
00132 /*
00133  * (c) 2006 Joshua Allen, Charles Lohr
00134  * All rights reserved.
00135  * 
00136  * Permission is hereby granted, free of charge, to any person obtaining a
00137  * copy of this software and associated documentation files (the
00138  * "Software"), to deal in the Software without restriction, including
00139  * without limitation the rights to use, copy, modify, merge, publish,
00140  * distribute, and/or sell copies of the Software, and to permit persons to
00141  * whom the Software is furnished to do so, provided that the above
00142  * copyright notice(s) and this permission notice appear in all copies of
00143  * the Software and that both the above copyright notice(s) and this
00144  * permission notice appear in supporting documentation.
00145  * 
00146  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00147  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00148  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF
00149  * THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS
00150  * INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT
00151  * OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
00152  * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
00153  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
00154  * PERFORMANCE OF THIS SOFTWARE.
00155  */

Hosted by SourceForge.net Logo