2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
5 This file is part of GtkRadiant.
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 mat3_t mat3_default( idVec3( 1, 0, 0 ), idVec3( 0, 1, 0 ), idVec3( 0, 0, 1 ) );
26 void toMatrix( quat_t const &src, mat3_t &dst ) {
48 dst[ 0 ][ 0 ] = 1.0f - ( yy + zz );
49 dst[ 0 ][ 1 ] = xy - wz;
50 dst[ 0 ][ 2 ] = xz + wy;
52 dst[ 1 ][ 0 ] = xy + wz;
53 dst[ 1 ][ 1 ] = 1.0f - ( xx + zz );
54 dst[ 1 ][ 2 ] = yz - wx;
56 dst[ 2 ][ 0 ] = xz - wy;
57 dst[ 2 ][ 1 ] = yz + wx;
58 dst[ 2 ][ 2 ] = 1.0f - ( xx + yy );
61 void toMatrix( angles_t const &src, mat3_t &dst ) {
63 static float sr, sp, sy, cr, cp, cy; // static to help MS compiler fp bugs
65 angle = src.yaw * ( M_PI * 2.0f / 360.0f );
69 angle = src.pitch * ( M_PI * 2.0f / 360.0f );
73 angle = src.roll * ( M_PI * 2.0f / 360.0f );
77 dst[ 0 ].set( cp * cy, cp * sy, -sp );
78 dst[ 1 ].set( sr * sp * cy + cr * -sy, sr * sp * sy + cr * cy, sr * cp );
79 dst[ 2 ].set( cr * sp * cy + -sr * -sy, cr * sp * sy + -sr * cy, cr * cp );
82 void toMatrix( idVec3 const &src, mat3_t &dst ) {
87 void mat3_t::ProjectVector( const idVec3 &src, idVec3 &dst ) const {
88 dst.x = src * mat[ 0 ];
89 dst.y = src * mat[ 1 ];
90 dst.z = src * mat[ 2 ];
93 void mat3_t::UnprojectVector( const idVec3 &src, idVec3 &dst ) const {
94 dst = mat[ 0 ] * src.x + mat[ 1 ] * src.y + mat[ 2 ] * src.z;
97 void mat3_t::Transpose( mat3_t &matrix ) {
101 for( i = 0; i < 3; i++ ) {
102 for( j = 0; j < 3; j++ ) {
103 matrix[ i ][ j ] = mat[ j ][ i ];
108 void mat3_t::Transpose( void ) {
113 for( i = 0; i < 3; i++ ) {
114 for( j = i + 1; j < 3; j++ ) {
115 temp = mat[ i ][ j ];
116 mat[ i ][ j ] = mat[ j ][ i ];
117 mat[ j ][ i ] = temp;
122 mat3_t mat3_t::Inverse( void ) const {
130 void mat3_t::Clear( void ) {
131 mat[0].set( 1, 0, 0 );
132 mat[1].set( 0, 1, 0 );
133 mat[2].set( 0, 0, 1 );