--- /dev/null
+/*\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 "q_shared.h"\r
+\r
+mat3_t mat3_default( idVec3( 1, 0, 0 ), idVec3( 0, 1, 0 ), idVec3( 0, 0, 1 ) );\r
+\r
+void toMatrix( quat_t const &src, mat3_t &dst ) {\r
+ float wx, wy, wz;\r
+ float xx, yy, yz;\r
+ float xy, xz, zz;\r
+ float x2, y2, z2;\r
+\r
+ x2 = src.x + src.x;\r
+ y2 = src.y + src.y;\r
+ z2 = src.z + src.z;\r
+\r
+ xx = src.x * x2;\r
+ xy = src.x * y2;\r
+ xz = src.x * z2;\r
+\r
+ yy = src.y * y2;\r
+ yz = src.y * z2;\r
+ zz = src.z * z2;\r
+\r
+ wx = src.w * x2;\r
+ wy = src.w * y2;\r
+ wz = src.w * z2;\r
+\r
+ dst[ 0 ][ 0 ] = 1.0f - ( yy + zz );\r
+ dst[ 0 ][ 1 ] = xy - wz;\r
+ dst[ 0 ][ 2 ] = xz + wy;\r
+\r
+ dst[ 1 ][ 0 ] = xy + wz;\r
+ dst[ 1 ][ 1 ] = 1.0f - ( xx + zz );\r
+ dst[ 1 ][ 2 ] = yz - wx;\r
+\r
+ dst[ 2 ][ 0 ] = xz - wy;\r
+ dst[ 2 ][ 1 ] = yz + wx;\r
+ dst[ 2 ][ 2 ] = 1.0f - ( xx + yy );\r
+}\r
+\r
+void toMatrix( angles_t const &src, mat3_t &dst ) {\r
+ float angle;\r
+ static float sr, sp, sy, cr, cp, cy; // static to help MS compiler fp bugs\r
+ \r
+ angle = src.yaw * ( M_PI * 2.0f / 360.0f );\r
+ sy = sin( angle );\r
+ cy = cos( angle );\r
+\r
+ angle = src.pitch * ( M_PI * 2.0f / 360.0f );\r
+ sp = sin( angle );\r
+ cp = cos( angle );\r
+\r
+ angle = src.roll * ( M_PI * 2.0f / 360.0f );\r
+ sr = sin( angle );\r
+ cr = cos( angle );\r
+\r
+ dst[ 0 ].set( cp * cy, cp * sy, -sp );\r
+ dst[ 1 ].set( sr * sp * cy + cr * -sy, sr * sp * sy + cr * cy, sr * cp );\r
+ dst[ 2 ].set( cr * sp * cy + -sr * -sy, cr * sp * sy + -sr * cy, cr * cp );\r
+}\r
+\r
+void toMatrix( idVec3 const &src, mat3_t &dst ) {\r
+ angles_t sup = src;\r
+ toMatrix(sup, dst);\r
+}\r
+\r
+void mat3_t::ProjectVector( const idVec3 &src, idVec3 &dst ) const {\r
+ dst.x = src * mat[ 0 ];\r
+ dst.y = src * mat[ 1 ];\r
+ dst.z = src * mat[ 2 ];\r
+}\r
+\r
+void mat3_t::UnprojectVector( const idVec3 &src, idVec3 &dst ) const {\r
+ dst = mat[ 0 ] * src.x + mat[ 1 ] * src.y + mat[ 2 ] * src.z;\r
+}\r
+\r
+void mat3_t::Transpose( mat3_t &matrix ) {\r
+ int i;\r
+ int j;\r
+ \r
+ for( i = 0; i < 3; i++ ) {\r
+ for( j = 0; j < 3; j++ ) {\r
+ matrix[ i ][ j ] = mat[ j ][ i ];\r
+ }\r
+ }\r
+}\r
+\r
+void mat3_t::Transpose( void ) {\r
+ float temp;\r
+ int i;\r
+ int j;\r
+ \r
+ for( i = 0; i < 3; i++ ) {\r
+ for( j = i + 1; j < 3; j++ ) {\r
+ temp = mat[ i ][ j ];\r
+ mat[ i ][ j ] = mat[ j ][ i ];\r
+ mat[ j ][ i ] = temp;\r
+ }\r
+ }\r
+}\r
+\r
+mat3_t mat3_t::Inverse( void ) const {\r
+ mat3_t inv( *this );\r
+\r
+ inv.Transpose();\r
+\r
+ return inv;\r
+}\r
+\r
+void mat3_t::Clear( void ) {\r
+ mat[0].set( 1, 0, 0 );\r
+ mat[1].set( 0, 1, 0 );\r
+ mat[2].set( 0, 0, 1 );\r
+}\r