File: FXMat4f.h

package info (click to toggle)
gogglesmm 1.2.5-6
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 16,812 kB
  • sloc: cpp: 231,960; ansic: 893; xml: 222; makefile: 33
file content (251 lines) | stat: -rw-r--r-- 8,341 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
/********************************************************************************
*                                                                               *
*            S i n g l e - P r e c i s i o n   4 x 4   M a t r i x              *
*                                                                               *
*********************************************************************************
* Copyright (C) 1994,2022 by Jeroen van der Zijp.   All Rights Reserved.        *
*********************************************************************************
* This library is free software; you can redistribute it and/or modify          *
* it under the terms of the GNU Lesser General Public License as published by   *
* the Free Software Foundation; either version 3 of the License, or             *
* (at your option) any later version.                                           *
*                                                                               *
* This library is distributed in the hope that it will be useful,               *
* but WITHOUT ANY WARRANTY; without even the implied warranty of                *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                 *
* GNU Lesser General Public License for more details.                           *
*                                                                               *
* You should have received a copy of the GNU Lesser General Public License      *
* along with this program.  If not, see <http://www.gnu.org/licenses/>          *
********************************************************************************/
#ifndef FXMAT4F_H
#define FXMAT4F_H

namespace FX {


class FXQuatf;
class FXMat3f;


/// Single-precision 4x4 matrix
class FXAPI FXMat4f {
protected:
  FXVec4f m[4];
public:

  /// Default constructor; value is not initialized
  FXMat4f(){}

  /// Initialize matrix from scalar
  FXMat4f(FXfloat s);

  /// Initialize with 3x3 rotation and scaling matrix
  FXMat4f(const FXMat3f& s);

  /// Initialize matrix from another matrix
  FXMat4f(const FXMat4f& s);

  /// Initialize matrix from array
  FXMat4f(const FXfloat s[]);

  /// Initialize diagonal matrix
  FXMat4f(FXfloat a,FXfloat b,FXfloat c,FXfloat d);

  /// Initialize matrix from components
  FXMat4f(FXfloat a00,FXfloat a01,FXfloat a02,FXfloat a03,
          FXfloat a10,FXfloat a11,FXfloat a12,FXfloat a13,
          FXfloat a20,FXfloat a21,FXfloat a22,FXfloat a23,
          FXfloat a30,FXfloat a31,FXfloat a32,FXfloat a33);

  /// Initialize matrix from four vectors
  FXMat4f(const FXVec4f& a,const FXVec4f& b,const FXVec4f& c,const FXVec4f& d);

  /// Initialize matrix from quaternion
  FXMat4f(const FXQuatf& quat);

  /// Assignment from scalar
  FXMat4f& operator=(FXfloat s);

  /// Assignment
  FXMat4f& operator=(const FXMat3f& s);
  FXMat4f& operator=(const FXMat4f& s);

  /// Assignment from quaternion
  FXMat4f& operator=(const FXQuatf& quat);

  /// Assignment from array
  FXMat4f& operator=(const FXfloat s[]);

  /// Set value from scalar
  FXMat4f& set(FXfloat s);

  /// Set value from 3x3 rotation and scaling matrix
  FXMat4f& set(const FXMat3f& s);

  /// Set value from another matrix
  FXMat4f& set(const FXMat4f& s);

  /// Set value from array
  FXMat4f& set(const FXfloat s[]);

  /// Set diagonal matrix
  FXMat4f& set(FXfloat a,FXfloat b,FXfloat c,FXfloat d);

  /// Set value from components
  FXMat4f& set(FXfloat a00,FXfloat a01,FXfloat a02,FXfloat a03,
               FXfloat a10,FXfloat a11,FXfloat a12,FXfloat a13,
               FXfloat a20,FXfloat a21,FXfloat a22,FXfloat a23,
               FXfloat a30,FXfloat a31,FXfloat a32,FXfloat a33);

  /// Set value from four vectors
  FXMat4f& set(const FXVec4f& a,const FXVec4f& b,const FXVec4f& c,const FXVec4f& d);

  /// Set value from quaternion
  FXMat4f& set(const FXQuatf& quat);

  /// Assignment operators
  FXMat4f& operator+=(const FXMat4f& s);
  FXMat4f& operator-=(const FXMat4f& s);
  FXMat4f& operator*=(const FXMat4f& s);
  FXMat4f& operator*=(FXfloat s);
  FXMat4f& operator/=(FXfloat s);

  /// Indexing
  FXVec4f& operator[](FXint i){return m[i];}
  const FXVec4f& operator[](FXint i) const {return m[i];}

  /// Conversion
  operator FXfloat*(){return m[0];}
  operator const FXfloat*() const {return m[0];}

  /// Unary minus
  FXMat4f operator-() const;

  /// Set to identity matrix
  FXMat4f& identity();

  /// Return true if identity matrix
  FXbool isIdentity() const;

  /// Set orthographic projection from view volume
  FXMat4f& setOrtho(FXfloat xlo,FXfloat xhi,FXfloat ylo,FXfloat yhi,FXfloat zlo,FXfloat zhi);

  /// Get view volume from orthographic projection
  void getOrtho(FXfloat& xlo,FXfloat& xhi,FXfloat& ylo,FXfloat& yhi,FXfloat& zlo,FXfloat& zhi) const;

  /// Set to inverse orthographic projection
  FXMat4f& setInverseOrtho(FXfloat xlo,FXfloat xhi,FXfloat ylo,FXfloat yhi,FXfloat zlo,FXfloat zhi);

  /// Set to perspective projection from view volume
  FXMat4f& setFrustum(FXfloat xlo,FXfloat xhi,FXfloat ylo,FXfloat yhi,FXfloat zlo,FXfloat zhi);

  /// Get view volume from perspective projection
  void getFrustum(FXfloat& xlo,FXfloat& xhi,FXfloat& ylo,FXfloat& yhi,FXfloat& zlo,FXfloat& zhi) const;

  /// Set to inverse perspective projection from view volume
  FXMat4f& setInverseFrustum(FXfloat xlo,FXfloat xhi,FXfloat ylo,FXfloat yhi,FXfloat zlo,FXfloat zhi);

  /// Multiply by left-hand matrix
  FXMat4f& left();

  /// Multiply by rotation matrix
  FXMat4f& rot(const FXMat3f& r);

  /// Multiply by rotation about unit-quaternion
  FXMat4f& rot(const FXQuatf& q);

  /// Multiply by rotation c,s about unit axis
  FXMat4f& rot(const FXVec3f& v,FXfloat c,FXfloat s);

  /// Multiply by rotation of phi about unit axis
  FXMat4f& rot(const FXVec3f& v,FXfloat phi);

  /// Multiply by x-rotation
  FXMat4f& xrot(FXfloat c,FXfloat s);
  FXMat4f& xrot(FXfloat phi);

  /// Multiply by y-rotation
  FXMat4f& yrot(FXfloat c,FXfloat s);
  FXMat4f& yrot(FXfloat phi);

  /// Multiply by z-rotation
  FXMat4f& zrot(FXfloat c,FXfloat s);
  FXMat4f& zrot(FXfloat phi);

  /// Look at
  FXMat4f& look(const FXVec3f& from,const FXVec3f& to,const FXVec3f& up);

  /// Multiply by translation
  FXMat4f& trans(FXfloat tx,FXfloat ty,FXfloat tz);
  FXMat4f& trans(const FXVec3f& v);

  /// Multiply by scaling
  FXMat4f& scale(FXfloat sx,FXfloat sy,FXfloat sz);
  FXMat4f& scale(const FXVec3f& v);
  FXMat4f& scale(FXfloat s);

  /// Determinant
  FXfloat det() const;

  /// Transpose
  FXMat4f transpose() const;

  /// Invert
  FXMat4f invert() const;

  /// Invert affine matrix
  FXMat4f affineInvert() const;

  /// Invert rigid body transform matrix
  FXMat4f rigidInvert() const;

  /// Return normal-transformation matrix
  FXMat3f normalMatrix() const;

  /// Destructor
 ~FXMat4f(){}
  };


/// Matrix times vector
extern FXAPI FXVec3f operator*(const FXMat4f& m,const FXVec3f& v);
extern FXAPI FXVec4f operator*(const FXMat4f& m,const FXVec4f& v);

/// Vector times matrix
extern FXAPI FXVec3f operator*(const FXVec3f& v,const FXMat4f& m);
extern FXAPI FXVec4f operator*(const FXVec4f& v,const FXMat4f& m);

/// Matrix and matrix addition
extern FXAPI FXMat4f operator+(const FXMat4f& a,const FXMat4f& b);
extern FXAPI FXMat4f operator-(const FXMat4f& a,const FXMat4f& b);

/// Matrix and matrix multiply
extern FXAPI FXMat4f operator*(const FXMat4f& a,const FXMat4f& b);

/// Scaling
extern FXAPI FXMat4f operator*(FXfloat x,const FXMat4f& a);
extern FXAPI FXMat4f operator*(const FXMat4f& a,FXfloat x);
extern FXAPI FXMat4f operator/(const FXMat4f& a,FXfloat x);
extern FXAPI FXMat4f operator/(FXfloat x,const FXMat4f& a);

/// Equality tests
extern FXAPI FXbool operator==(const FXMat4f& a,const FXMat4f& b);
extern FXAPI FXbool operator!=(const FXMat4f& a,const FXMat4f& b);
extern FXAPI FXbool operator==(const FXMat4f& a,FXfloat n);
extern FXAPI FXbool operator!=(const FXMat4f& a,FXfloat n);
extern FXAPI FXbool operator==(FXfloat n,const FXMat4f& a);
extern FXAPI FXbool operator!=(FXfloat n,const FXMat4f& a);

/// Orthogonalize matrix
extern FXAPI FXMat4f orthogonalize(const FXMat4f& m);

/// Save matrix to a stream
extern FXAPI FXStream& operator<<(FXStream& store,const FXMat4f& m);

/// Load matrix from a stream
extern FXAPI FXStream& operator>>(FXStream& store,FXMat4f& m);

}

#endif