Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXMat4f.h
Go to the documentation of this file.
1 /********************************************************************************
2 * *
3 * S i n g l e - P r e c i s i o n 4 x 4 M a t r i x *
4 * *
5 *********************************************************************************
6 * Copyright (C) 1994,2006 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or *
9 * modify it under the terms of the GNU Lesser General Public *
10 * License as published by the Free Software Foundation; either *
11 * version 2.1 of the License, or (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16 * Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with this library; if not, write to the Free Software *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
21 *********************************************************************************
22 * $Id: FXMat4f.h,v 1.9 2006/01/22 17:58:06 fox Exp $ *
23 ********************************************************************************/
24 #ifndef FXMAT4F_H
25 #define FXMAT4F_H
26 
27 
28 namespace FX {
29 
30 
31 /// Single-precision 4x4 matrix
32 class FXAPI FXMat4f {
33 protected:
34  FXVec4f m[4];
35 public:
36  /// Constructors
37  FXMat4f(){}
38  FXMat4f(FXfloat w);
39  FXMat4f(FXfloat a00,FXfloat a01,FXfloat a02,FXfloat a03,
40  FXfloat a10,FXfloat a11,FXfloat a12,FXfloat a13,
41  FXfloat a20,FXfloat a21,FXfloat a22,FXfloat a23,
42  FXfloat a30,FXfloat a31,FXfloat a32,FXfloat a33);
43  FXMat4f(const FXVec4f& a,const FXVec4f& b,const FXVec4f& c,const FXVec4f& d);
44  FXMat4f(const FXMat4f& other);
45 
46  /// Assignment
47  FXMat4f& operator=(const FXMat4f& other);
48  FXMat4f& operator=(FXfloat w);
49 
50  /// Set value from another matrix
51  FXMat4f& set(const FXMat4f& other);
52 
53  /// Set value from scalar
54  FXMat4f& set(FXfloat w);
55 
56  /// Set value from components
57  FXMat4f& set(FXfloat a00,FXfloat a01,FXfloat a02,FXfloat a03,
58  FXfloat a10,FXfloat a11,FXfloat a12,FXfloat a13,
59  FXfloat a20,FXfloat a21,FXfloat a22,FXfloat a23,
60  FXfloat a30,FXfloat a31,FXfloat a32,FXfloat a33);
61 
62  /// Set value from four vectors
63  FXMat4f& set(const FXVec4f& a,const FXVec4f& b,const FXVec4f& c,const FXVec4f& d);
64 
65  /// Assignment operators
66  FXMat4f& operator+=(const FXMat4f& w);
67  FXMat4f& operator-=(const FXMat4f& w);
68  FXMat4f& operator*=(FXfloat w);
69  FXMat4f& operator*=(const FXMat4f& w);
70  FXMat4f& operator/=(FXfloat w);
71 
72  /// Indexing
73  FXVec4f& operator[](FXint i){return m[i];}
74  const FXVec4f& operator[](FXint i) const {return m[i];}
75 
76  /// Conversion
77  operator FXfloat*(){return m[0];}
78  operator const FXfloat*() const {return m[0];}
79 
80  /// Unary minus
81  FXMat4f operator-() const;
82 
83  /// Matrix and matrix
84  FXMat4f operator+(const FXMat4f& w) const;
85  FXMat4f operator-(const FXMat4f& w) const;
86  FXMat4f operator*(const FXMat4f& w) const;
87 
88  /// Other operators
89  friend FXAPI FXMat4f operator*(FXfloat x,const FXMat4f& a);
90  friend FXAPI FXMat4f operator*(const FXMat4f& a,FXfloat x);
91  friend FXAPI FXMat4f operator/(const FXMat4f& a,FXfloat x);
92  friend FXAPI FXMat4f operator/(FXfloat x,const FXMat4f& a);
93 
94  /// Multiply matrix and vector
95  FXVec4f operator*(const FXVec4f& v) const;
96  FXVec3f operator*(const FXVec3f& v) const;
97 
98  /// Set identity matrix
99  FXMat4f& eye();
100 
101  /// Orthographic projection
102  FXMat4f& ortho(FXfloat left,FXfloat right,FXfloat bottom,FXfloat top,FXfloat hither,FXfloat yon);
103 
104  /// Perspective projection
105  FXMat4f& frustum(FXfloat left,FXfloat right,FXfloat bottom,FXfloat top,FXfloat hither,FXfloat yon);
106 
107  /// Multiply by left-hand matrix
108  FXMat4f& left();
109 
110  /// Multiply by rotation about unit-quaternion
111  FXMat4f& rot(const FXQuatf& q);
112 
113  /// Multiply by rotation c,s about axis
114  FXMat4f& rot(const FXVec3f& v,FXfloat c,FXfloat s);
115 
116  /// Multiply by rotation of phi about axis
117  FXMat4f& rot(const FXVec3f& v,FXfloat phi);
118 
119  /// Multiply by x-rotation
120  FXMat4f& xrot(FXfloat c,FXfloat s);
121  FXMat4f& xrot(FXfloat phi);
122 
123  /// Multiply by y-rotation
124  FXMat4f& yrot(FXfloat c,FXfloat s);
125  FXMat4f& yrot(FXfloat phi);
126 
127  /// Multiply by z-rotation
128  FXMat4f& zrot(FXfloat c,FXfloat s);
129  FXMat4f& zrot(FXfloat phi);
130 
131  /// Look at
132  FXMat4f& look(const FXVec3f& eye,const FXVec3f& cntr,const FXVec3f& vup);
133 
134  /// Multiply by translation
135  FXMat4f& trans(FXfloat tx,FXfloat ty,FXfloat tz);
136  FXMat4f& trans(const FXVec3f& v);
137 
138  /// Multiply by scaling
139  FXMat4f& scale(FXfloat sx,FXfloat sy,FXfloat sz);
140  FXMat4f& scale(FXfloat s);
141  FXMat4f& scale(const FXVec3f& v);
142 
143  /// Determinant
144  FXfloat det() const;
145 
146  /// Transpose
147  FXMat4f transpose() const;
148 
149  /// Invert
150  FXMat4f invert() const;
151 
152  /// Save to a stream
153  friend FXAPI FXStream& operator<<(FXStream& store,const FXMat4f& m);
154 
155  /// Load from a stream
156  friend FXAPI FXStream& operator>>(FXStream& store,FXMat4f& m);
157  };
158 
159 extern FXAPI FXMat4f operator*(FXfloat x,const FXMat4f& a);
160 extern FXAPI FXMat4f operator*(const FXMat4f& a,FXfloat x);
161 extern FXAPI FXMat4f operator/(const FXMat4f& a,FXfloat x);
162 extern FXAPI FXMat4f operator/(FXfloat x,const FXMat4f& a);
163 
164 extern FXAPI FXStream& operator<<(FXStream& store,const FXMat4f& m);
165 extern FXAPI FXStream& operator>>(FXStream& store,FXMat4f& m);
166 
167 }
168 
169 #endif
FXMat3d operator/(const FXMat3d &a, FXdouble x)
FXStream & operator>>(FXStream &store, FXDate &d)
#define FXAPI
Definition: fxdefs.h:122
Definition: FX4Splitter.h:31
int FXint
Definition: fxdefs.h:390
FXDate operator+(const FXDate &d, FXint x)
Definition: FXDate.h:148
Single-precision 4x4 matrix.
Definition: FXMat4f.h:32
FXint operator-(const FXDate &a, const FXDate &b)
Definition: FXDate.h:150
float FXfloat
Definition: fxdefs.h:391
FXStream & operator<<(FXStream &store, const FXDate &d)
FXMat3d operator*(FXdouble x, const FXMat3d &a)
Single-precision 4-element vector.
Definition: FXVec4f.h:35

Copyright © 1997-2005 Jeroen van der Zijp