From: <axl...@us...> - 2009-01-04 19:10:57
|
Revision: 147 http://hgengine.svn.sourceforge.net/hgengine/?rev=147&view=rev Author: axlecrusher Date: 2009-01-04 19:10:52 +0000 (Sun, 04 Jan 2009) Log Message: ----------- move the transpose function out into math Modified Paths: -------------- Mercury2/src/MercuryMath.cpp Mercury2/src/MercuryMath.h Mercury2/src/MercuryMatrix.cpp Mercury2/src/MercuryMatrix.h Modified: Mercury2/src/MercuryMath.cpp =================================================================== --- Mercury2/src/MercuryMath.cpp 2009-01-04 18:32:00 UTC (rev 146) +++ Mercury2/src/MercuryMath.cpp 2009-01-04 19:10:52 UTC (rev 147) @@ -1,5 +1,34 @@ #include "MercuryMath.h" +//the SSE version of this was really slow, this is quicker +void TransposeMatrix( FloatRow* m ) +{ + float tmp; + float *_m = (float*)m; + + tmp = _m[1]; + _m[1] = _m[4]; + _m[4] = tmp; + + tmp = _m[2]; + _m[2] = _m[8]; + _m[8] = tmp; + tmp = _m[3]; + _m[3] = _m[12]; + _m[12] = tmp; + + tmp = _m[6]; + _m[6] = _m[9]; + _m[9] = tmp; + tmp = _m[7]; + _m[7] = _m[13]; + _m[13] = tmp; + + tmp = _m[11]; + _m[11] = _m[14]; + _m[14] = tmp; +} + #ifndef USE_SSE //Generic Math functions. Compile these if you can not use optimized functions. Modified: Mercury2/src/MercuryMath.h =================================================================== --- Mercury2/src/MercuryMath.h 2009-01-04 18:32:00 UTC (rev 146) +++ Mercury2/src/MercuryMath.h 2009-01-04 19:10:52 UTC (rev 147) @@ -53,6 +53,7 @@ void Copy16f( void * dest, const void * source ); void MatrixMultiply4f ( const FloatRow* in1, const FloatRow* in2, FloatRow* out ); void VectorMultiply4f(const FloatRow* matrix, const FloatRow* p, FloatRow* out ); +void TransposeMatrix( FloatRow* m ); #endif Modified: Mercury2/src/MercuryMatrix.cpp =================================================================== --- Mercury2/src/MercuryMatrix.cpp 2009-01-04 18:32:00 UTC (rev 146) +++ Mercury2/src/MercuryMatrix.cpp 2009-01-04 19:10:52 UTC (rev 147) @@ -214,40 +214,6 @@ printf("\n"); } -void TransposeMatrix( const MercuryMatrix &in, MercuryMatrix &out ) -{ - float tmp; - const float* _in = (const float*)in.Ptr(); - float* _out = out.Ptr(); - - //unchanging - _out[0] = _in[0]; - _out[5] = _in[5]; - _out[10] = _in[10]; - _out[15] = _in[15]; - - tmp = _in[1]; - _out[1] = _in[4]; - _out[4] = tmp; - tmp = _in[2]; - _out[2] = _in[8]; - _out[8] = tmp; - tmp = _in[3]; - _out[3] = _in[12]; - _out[12] = tmp; - - tmp = _in[6]; - _out[6] = _in[9]; - _out[9] = tmp; - tmp = _in[7]; - _out[7] = _in[13]; - _out[13] = tmp; - - tmp = _in[11]; - _out[11] = _in[14]; - _out[14] = tmp; -} - /* * Copyright (c) 2006 Joshua Allen * All rights reserved. Modified: Mercury2/src/MercuryMatrix.h =================================================================== --- Mercury2/src/MercuryMatrix.h 2009-01-04 18:32:00 UTC (rev 146) +++ Mercury2/src/MercuryMatrix.h 2009-01-04 19:10:52 UTC (rev 147) @@ -7,9 +7,6 @@ class MercuryMatrix; -//Matrix in1 will be copied, n2 will not. n2 better never be the same as out -void TransposeMatrix( const MercuryMatrix& in, MercuryMatrix &out ); - ///General Purpose 4x4 row-major matrix class MercuryMatrix { @@ -38,7 +35,7 @@ void RotateAngAxis( float fAngle, float x, float y, float z ); void Scale(float x, float y, float z); void Transotale( float tX, float tY, float tZ, float rX, float rY, float rZ, float sX, float sY, float sZ ); - inline void Transpose() { TransposeMatrix(*this, *this); } + inline void Transpose() { TransposeMatrix( m_matrix ); } void Zero(); void Identity(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |