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++) ((float*)m)[i] *= f;
112
XMATRIX& XMATRIX::operator /= ( float f)
114
for (int i=0; i<16; i++) ((float*)m)[i] /= f;
118
XMATRIX XMATRIX::operator + () const
123
XMATRIX XMATRIX::operator - () const
126
for (int i=0; i<16; i++) ((float*)mTemp.m)[i] = -((float*)m)[i];
130
XMATRIX XMATRIX::operator * ( const XMATRIX &pIn ) const
133
for (int i=0; i<4; i++)
134
for (int j=0; j<4; j++)
135
mTemp.m[i][j] = m[i][0]*pIn.m[0][j] +
136
m[i][1]*pIn.m[1][j] +
137
m[i][2]*pIn.m[2][j] +
142
XMATRIX XMATRIX::operator + ( const XMATRIX &pIn ) const
145
for (int i=0; i<16; i++)
146
((float*)mTemp.m)[i] = ((float*)m)[i] + ((float*)pIn.m)[i];
150
XMATRIX XMATRIX::operator - ( const XMATRIX &pIn ) const
153
for (int i=0; i<16; i++)
154
((float*)mTemp.m)[i] = ((float*)m)[i] - ((float*)pIn.m)[i];
159
XMATRIX operator * ( float ) const;
160
XMATRIX operator / ( float ) const;
161
friend XMATRIX operator * ( float, const XMATRIX & );
162
bool operator == ( const XMATRIX & ) const;
163
bool operator != ( const XMATRIX & ) const;
172
XVECTOR3::XVECTOR3( const float *f )
179
XVECTOR3::XVECTOR3( const VECTOR3 &v )
186
XVECTOR3::XVECTOR3( float _x, float _y, float _z )
195
inline operator float* ();
196
inline operator const float* () const;
198
// assignment operators
199
inline XVECTOR3& operator += ( const XVECTOR3 &op );
200
inline XVECTOR3& operator -= ( const XVECTOR3 &op );
201
inline XVECTOR3& operator *= ( float op );
202
inline XVECTOR3& operator /= ( float op );
205
inline XVECTOR3 operator + () const;
206
inline XVECTOR3 operator - () const;
209
inline XVECTOR3 operator + ( const XVECTOR3 &op ) const;
210
inline XVECTOR3 operator - ( const XVECTOR3 &op ) const;
211
inline XVECTOR3 operator * ( float op ) const;
212
inline XVECTOR3 operator / ( float op ) const;
215
friend XVECTOR3 operator * ( float, const XVECTOR3& );
217
inline bool operator == ( const XVECTOR3 &op ) const;
218
inline bool operator != ( const XVECTOR3 &op ) const;
221
//---------- XVECTOR4
228
XVECTOR4( const float *f );
229
XVECTOR4( const VECTOR4 &v );
230
XVECTOR4( float _x, float _y, float _z, float _w );
233
inline operator float* ();
234
inline operator const float* () const;
236
// assignment operators
237
inline XVECTOR4& operator += ( const XVECTOR4 &op );
238
inline XVECTOR4& operator -= ( const XVECTOR4 &op );
239
inline XVECTOR4& operator *= ( float op );
240
inline XVECTOR4& operator /= ( float op );
243
inline XVECTOR4 operator + () const;
244
inline XVECTOR4 operator - () const;
247
inline XVECTOR4 operator + ( const XVECTOR4 &op ) const;
248
inline XVECTOR4 operator - ( const XVECTOR4 &op ) const;
249
inline XVECTOR4 operator * ( float op ) const;
250
inline XVECTOR4 operator / ( float op ) const;
252
friend XVECTOR4 operator * ( float, const XVECTOR4& );
254
inline bool operator == ( const XVECTOR4 &op ) const;
255
inline bool operator != ( const XVECTOR4 &op ) const;
260
XMATRIX* MatrixTranspose(
284
XVECTOR4 Vec3Transform(XVECTOR4 *pOut, const XVECTOR3 *pV, const XMATRIX *pM)
286
pOut->x = pV->x*pM->_11 + pV->y*pM->_21 + pV->z*pM->_31 + pM->_41;
287
pOut->y = pV->x*pM->_12 + pV->y*pM->_22 + pV->z*pM->_32 + pM->_42;
288
pOut->z = pV->x*pM->_13 + pV->y*pM->_23 + pV->z*pM->_33 + pM->_43;
289
pOut->w = pV->x*pM->_14 + pV->y*pM->_24 + pV->z*pM->_34 + pM->_44;