1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2 * Mupen64plus - VectorMath.cpp *
3 * Mupen64Plus homepage: http://code.google.com/p/mupen64plus/ *
4 * Copyright (C) 2002 Rice1964 *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 2 of the License, or *
9 * (at your option) any later version. *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program; if not, write to the *
18 * Free Software Foundation, Inc., *
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
20 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
24 #include "VectorMath.h"
32 XMATRIX::XMATRIX( const float *pIn )
37 XMATRIX::XMATRIX( const MATRIX &pIn )
39 memcpy(m, pIn.m, 16*4);
42 XMATRIX::XMATRIX( float _11, float _12, float _13, float _14,
43 float _21, float _22, float _23, float _24,
44 float _31, float _32, float _33, float _34,
45 float _41, float _42, float _43, float _44 )
65 float& XMATRIX::operator () ( unsigned int Row, unsigned int Col )
70 float XMATRIX::operator () ( unsigned int Row, unsigned int Col ) const
75 XMATRIX::operator float* ()
80 XMATRIX::operator const float* () const
85 XMATRIX& XMATRIX::operator *= ( const XMATRIX &pIn )
92 XMATRIX& XMATRIX::operator += ( const XMATRIX &pIn )
99 XMATRIX& XMATRIX::operator -= ( const XMATRIX &pIn )
101 XMATRIX mTemp(*this);
106 XMATRIX& XMATRIX::operator *= ( float f)
108 for (int i=0; i<16; i++)
116 XMATRIX& XMATRIX::operator /= ( float f)
118 for (int i=0; i<16; i++)
126 XMATRIX XMATRIX::operator + () const
131 XMATRIX XMATRIX::operator - () const
135 for (int i=0; i<16; i++)
137 ((float*)mTemp.m)[i] = -((float*)m)[i];
143 XMATRIX XMATRIX::operator * ( const XMATRIX &pIn ) const
147 for (int i=0; i<4; i++)
149 for (int j=0; j<4; j++)
151 mTemp.m[i][j] = m[i][0]*pIn.m[0][j] +
152 m[i][1]*pIn.m[1][j] +
153 m[i][2]*pIn.m[2][j] +
161 XMATRIX XMATRIX::operator + ( const XMATRIX &pIn ) const
165 for (int i=0; i<16; i++)
167 ((float*)mTemp.m)[i] = ((float*)m)[i] + ((float*)pIn.m)[i];
173 XMATRIX XMATRIX::operator - ( const XMATRIX &pIn ) const
177 for (int i=0; i<16; i++)
179 ((float*)mTemp.m)[i] = ((float*)m)[i] - ((float*)pIn.m)[i];
186 XMATRIX operator * ( float ) const;
187 XMATRIX operator / ( float ) const;
188 friend XMATRIX operator * ( float, const XMATRIX & );
189 bool operator == ( const XMATRIX & ) const;
190 bool operator != ( const XMATRIX & ) const;
199 XVECTOR3::XVECTOR3( const float *f )
206 XVECTOR3::XVECTOR3( const VECTOR3 &v )
213 XVECTOR3::XVECTOR3( float _x, float _y, float _z )
222 inline operator float* ();
223 inline operator const float* () const;
225 // assignment operators
226 inline XVECTOR3& operator += ( const XVECTOR3 &op );
227 inline XVECTOR3& operator -= ( const XVECTOR3 &op );
228 inline XVECTOR3& operator *= ( float op );
229 inline XVECTOR3& operator /= ( float op );
232 inline XVECTOR3 operator + () const;
233 inline XVECTOR3 operator - () const;
236 inline XVECTOR3 operator + ( const XVECTOR3 &op ) const;
237 inline XVECTOR3 operator - ( const XVECTOR3 &op ) const;
238 inline XVECTOR3 operator * ( float op ) const;
239 inline XVECTOR3 operator / ( float op ) const;
242 friend XVECTOR3 operator * ( float, const XVECTOR3& );
244 inline bool operator == ( const XVECTOR3 &op ) const;
245 inline bool operator != ( const XVECTOR3 &op ) const;
248 //---------- XVECTOR4
255 XVECTOR4( const float *f );
256 XVECTOR4( const VECTOR4 &v );
257 XVECTOR4( float _x, float _y, float _z, float _w );
260 inline operator float* ();
261 inline operator const float* () const;
263 // assignment operators
264 inline XVECTOR4& operator += ( const XVECTOR4 &op );
265 inline XVECTOR4& operator -= ( const XVECTOR4 &op );
266 inline XVECTOR4& operator *= ( float op );
267 inline XVECTOR4& operator /= ( float op );
270 inline XVECTOR4 operator + () const;
271 inline XVECTOR4 operator - () const;
274 inline XVECTOR4 operator + ( const XVECTOR4 &op ) const;
275 inline XVECTOR4 operator - ( const XVECTOR4 &op ) const;
276 inline XVECTOR4 operator * ( float op ) const;
277 inline XVECTOR4 operator / ( float op ) const;
279 friend XVECTOR4 operator * ( float, const XVECTOR4& );
281 inline bool operator == ( const XVECTOR4 &op ) const;
282 inline bool operator != ( const XVECTOR4 &op ) const;
287 XMATRIX* MatrixTranspose( XMATRIX* pOut, const XMATRIX* pM )
308 XVECTOR4 Vec3Transform( XVECTOR4 *pOut, const XVECTOR3 *pV, const XMATRIX *pM )
310 pOut->x = pV->x*pM->_11 + pV->y*pM->_21 + pV->z*pM->_31 + pM->_41;
311 pOut->y = pV->x*pM->_12 + pV->y*pM->_22 + pV->z*pM->_32 + pM->_42;
312 pOut->z = pV->x*pM->_13 + pV->y*pM->_23 + pV->z*pM->_33 + pM->_43;
313 pOut->w = pV->x*pM->_14 + pV->y*pM->_24 + pV->z*pM->_34 + pM->_44;