Rice Video Plugin for GLES1.1
[mupen64plus-pandora.git] / source / rice_gles / src / VectorMath.h
CommitLineData
d07c171f 1/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2 * Mupen64plus - VectorMath.h *
3 * Mupen64Plus homepage: http://code.google.com/p/mupen64plus/ *
4 * Copyright (C) 2002 Rice1964 *
5 * *
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. *
10 * *
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. *
15 * *
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 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
21
22#ifndef VECTORMATH_H
23#define VECTORMATH_H
24
25/******************************************************************************
26 * 4x4 matrix
27 ******************************************************************************/
28
29typedef struct _MATRIX {
30 union {
31 struct {
32 float _11, _12, _13, _14;
33 float _21, _22, _23, _24;
34 float _31, _32, _33, _34;
35 float _41, _42, _43, _44;
36 };
37 float m[4][4];
38 };
39} MATRIX;
40
41typedef struct XMATRIX : public MATRIX {
42public:
43 XMATRIX();
44 XMATRIX( const float * );
45 XMATRIX( const MATRIX & );
46 XMATRIX( float _11, float _12, float _13, float _14,
47 float _21, float _22, float _23, float _24,
48 float _31, float _32, float _33, float _34,
49 float _41, float _42, float _43, float _44 );
50
51 float& operator () ( unsigned int Row, unsigned int Col );
52 float operator () ( unsigned int Row, unsigned int Col ) const;
53
54 operator float* ();
55 operator const float* () const;
56
57 // assignment operators
58 XMATRIX& operator *= ( const XMATRIX & );
59 XMATRIX& operator += ( const XMATRIX & );
60 XMATRIX& operator -= ( const XMATRIX & );
61 XMATRIX& operator *= ( float );
62 XMATRIX& operator /= ( float );
63
64 // unary operators
65 XMATRIX operator + () const;
66 XMATRIX operator - () const;
67
68 // binary operators
69 XMATRIX operator * ( const XMATRIX & ) const;
70 XMATRIX operator + ( const XMATRIX & ) const;
71 XMATRIX operator - ( const XMATRIX & ) const;
72 XMATRIX operator * ( float ) const;
73 XMATRIX operator / ( float ) const;
74 friend XMATRIX operator * ( float, const XMATRIX & );
75 bool operator == ( const XMATRIX & ) const;
76 bool operator != ( const XMATRIX & ) const;
77} XMATRIX, *LPXMATRIX;
78
79/******************************************************************************
80 * 3d vector
81 ******************************************************************************/
82
83typedef struct _VECTOR3
84{
85 float x;
86 float y;
87 float z;
88} VECTOR3;
89
90class XVECTOR3 : public VECTOR3
91{
92public:
93 XVECTOR3();
94 XVECTOR3( const float *f );
95 XVECTOR3( const VECTOR3 &v );
96 XVECTOR3( float _x, float _y, float _z );
97
98 // casting
99 inline operator float* ();
100 inline operator const float* () const;
101
102 // assignment operators
103 inline XVECTOR3& operator += ( const XVECTOR3 &op );
104 inline XVECTOR3& operator -= ( const XVECTOR3 &op );
105 inline XVECTOR3& operator *= ( float op );
106 inline XVECTOR3& operator /= ( float op );
107
108 // unary operators
109 inline XVECTOR3 operator + () const;
110 inline XVECTOR3 operator - () const;
111
112 // binary operators
113 inline XVECTOR3 operator + ( const XVECTOR3 &op ) const;
114 inline XVECTOR3 operator - ( const XVECTOR3 &op ) const;
115 inline XVECTOR3 operator * ( float op ) const;
116 inline XVECTOR3 operator / ( float op ) const;
117
118
119 friend XVECTOR3 operator * ( float, const XVECTOR3& );
120
121 inline bool operator == ( const XVECTOR3 &op ) const;
122 inline bool operator != ( const XVECTOR3 &op ) const;
123};
124
125/******************************************************************************
126 * 4d vector
127 ******************************************************************************/
128
129typedef struct _VECTOR4
130{
131 float x;
132 float y;
133 float z;
134 float w;
135} VECTOR4;
136
137class XVECTOR4 : public VECTOR4
138{
139public:
140 XVECTOR4();
141 XVECTOR4( const float *f );
142 XVECTOR4( const VECTOR4 &v );
143 XVECTOR4( float _x, float _y, float _z, float _w );
144
145 // casting
146 inline operator float* ();
147 inline operator const float* () const;
148
149 // assignment operators
150 inline XVECTOR4& operator += ( const XVECTOR4 &op );
151 inline XVECTOR4& operator -= ( const XVECTOR4 &op );
152 inline XVECTOR4& operator *= ( float op );
153 inline XVECTOR4& operator /= ( float op );
154
155 // unary operators
156 inline XVECTOR4 operator + () const;
157 inline XVECTOR4 operator - () const;
158
159 // binary operators
160 inline XVECTOR4 operator + ( const XVECTOR4 &op ) const;
161 inline XVECTOR4 operator - ( const XVECTOR4 &op ) const;
162 inline XVECTOR4 operator * ( float op ) const;
163 inline XVECTOR4 operator / ( float op ) const;
164
165 friend XVECTOR4 operator * ( float, const XVECTOR4& );
166
167 inline bool operator == ( const XVECTOR4 &op ) const;
168 inline bool operator != ( const XVECTOR4 &op ) const;
169};
170
171XVECTOR4 Vec3Transform(XVECTOR4 *pOut, const XVECTOR3 *pV, const XMATRIX *pM);
172
173XMATRIX* MatrixTranspose(XMATRIX* pOut, const XMATRIX* pM);
174
175#endif
176