1 /********************************************************************************
2 *                                                                               *
3 *            D o u b 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: FXMat4d.h 3297 2015-12-14 20:30:04Z arthurcnorman $                            *
23 ********************************************************************************/
24 #ifndef FXMAT4D_H
25 #define FXMAT4D_H
26 
27 
28 namespace FX {
29 
30 
31 /// Double-precision 4x4 matrix
32 class FXAPI FXMat4d {
33 protected:
34   FXVec4d m[4];
35 public:
36   /// Constructors
FXMat4d()37   FXMat4d(){}
38   FXMat4d(FXdouble w);
39   FXMat4d(FXdouble a00,FXdouble a01,FXdouble a02,FXdouble a03,
40           FXdouble a10,FXdouble a11,FXdouble a12,FXdouble a13,
41           FXdouble a20,FXdouble a21,FXdouble a22,FXdouble a23,
42           FXdouble a30,FXdouble a31,FXdouble a32,FXdouble a33);
43   FXMat4d(const FXVec4d& a,const FXVec4d& b,const FXVec4d& c,const FXVec4d& d);
44   FXMat4d(const FXMat4d& other);
45 
46   /// Assignment
47   FXMat4d& operator=(const FXMat4d& other);
48   FXMat4d& operator=(FXdouble w);
49 
50   /// Set value from another matrix
51   FXMat4d& set(const FXMat4d& other);
52 
53   /// Set value from scalar
54   FXMat4d& set(FXdouble w);
55 
56   /// Set value from components
57   FXMat4d& set(FXdouble a00,FXdouble a01,FXdouble a02,FXdouble a03,
58                FXdouble a10,FXdouble a11,FXdouble a12,FXdouble a13,
59                FXdouble a20,FXdouble a21,FXdouble a22,FXdouble a23,
60                FXdouble a30,FXdouble a31,FXdouble a32,FXdouble a33);
61 
62   /// Set value from four vectors
63   FXMat4d& set(const FXVec4d& a,const FXVec4d& b,const FXVec4d& c,const FXVec4d& d);
64 
65   /// Assignment operators
66   FXMat4d& operator+=(const FXMat4d& w);
67   FXMat4d& operator-=(const FXMat4d& w);
68   FXMat4d& operator*=(FXdouble w);
69   FXMat4d& operator*=(const FXMat4d& w);
70   FXMat4d& operator/=(FXdouble w);
71 
72   /// Indexing
73   FXVec4d& operator[](FXint i){return m[i];}
74   const FXVec4d& operator[](FXint i) const {return m[i];}
75 
76   /// Conversion
77   operator FXdouble*(){return m[0];}
78   operator const FXdouble*() const {return m[0];}
79 
80   /// Unary minus
81   FXMat4d operator-() const;
82 
83   /// Matrix and matrix
84   FXMat4d operator+(const FXMat4d& w) const;
85   FXMat4d operator-(const FXMat4d& w) const;
86   FXMat4d operator*(const FXMat4d& w) const;
87 
88   /// Matrix and scalar
89   friend FXAPI FXMat4d operator*(FXdouble x,const FXMat4d& a);
90   friend FXAPI FXMat4d operator*(const FXMat4d& a,FXdouble x);
91   friend FXAPI FXMat4d operator/(const FXMat4d& a,FXdouble x);
92   friend FXAPI FXMat4d operator/(FXdouble x,const FXMat4d& a);
93 
94   /// Multiply matrix and vector
95   FXVec4d operator*(const FXVec4d& v) const;
96   FXVec3d operator*(const FXVec3d& v) const;
97 
98   /// Set identity matrix
99   FXMat4d& eye();
100 
101   /// Orthographic projection
102   FXMat4d& ortho(FXdouble left,FXdouble right,FXdouble bottom,FXdouble top,FXdouble hither,FXdouble yon);
103 
104   /// Perspective projection
105   FXMat4d& frustum(FXdouble left,FXdouble right,FXdouble bottom,FXdouble top,FXdouble hither,FXdouble yon);
106 
107   /// Multiply by left-hand matrix
108   FXMat4d& left();
109 
110   /// Multiply by rotation about unit-quaternion
111   FXMat4d& rot(const FXQuatd& q);
112 
113   /// Multiply by rotation c,s about axis
114   FXMat4d& rot(const FXVec3d& v,FXdouble c,FXdouble s);
115 
116   /// Multiply by rotation of phi about axis
117   FXMat4d& rot(const FXVec3d& v,FXdouble phi);
118 
119   /// Multiply by x-rotation
120   FXMat4d& xrot(FXdouble c,FXdouble s);
121   FXMat4d& xrot(FXdouble phi);
122 
123   /// Multiply by y-rotation
124   FXMat4d& yrot(FXdouble c,FXdouble s);
125   FXMat4d& yrot(FXdouble phi);
126 
127   /// Multiply by z-rotation
128   FXMat4d& zrot(FXdouble c,FXdouble s);
129   FXMat4d& zrot(FXdouble phi);
130 
131   /// Look at
132   FXMat4d& look(const FXVec3d& eye,const FXVec3d& cntr,const FXVec3d& vup);
133 
134   /// Multiply by translation
135   FXMat4d& trans(FXdouble tx,FXdouble ty,FXdouble tz);
136   FXMat4d& trans(const FXVec3d& v);
137 
138   /// Multiply by scaling
139   FXMat4d& scale(FXdouble sx,FXdouble sy,FXdouble sz);
140   FXMat4d& scale(FXdouble s);
141   FXMat4d& scale(const FXVec3d& v);
142 
143   /// Determinant
144   FXdouble det() const;
145 
146   /// Transpose
147   FXMat4d transpose() const;
148 
149   /// Invert
150   FXMat4d invert() const;
151 
152   /// Save to a stream
153   friend FXAPI FXStream& operator<<(FXStream& store,const FXMat4d& m);
154 
155   /// Load from a stream
156   friend FXAPI FXStream& operator>>(FXStream& store,FXMat4d& m);
157   };
158 
159 extern FXAPI FXMat4d operator*(FXdouble x,const FXMat4d& a);
160 extern FXAPI FXMat4d operator*(const FXMat4d& a,FXdouble x);
161 extern FXAPI FXMat4d operator/(const FXMat4d& a,FXdouble x);
162 extern FXAPI FXMat4d operator/(FXdouble x,const FXMat4d& a);
163 
164 extern FXAPI FXStream& operator<<(FXStream& store,const FXMat4d& m);
165 extern FXAPI FXStream& operator>>(FXStream& store,FXMat4d& m);
166 
167 }
168 
169 #endif
170