1 /********************************************************************************
2 *                                                                               *
3 *            D o u b l e - P r e c i s i o n   3 x 3   M a t r i x              *
4 *                                                                               *
5 *********************************************************************************
6 * Copyright (C) 2003,2005 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: FXMat3d.h,v 1.5.2.1 2006/03/21 07:08:28 fox Exp $                            *
23 ********************************************************************************/
24 #ifndef FXMAT3D_H
25 #define FXMAT3D_H
26 
27 
28 namespace FX {
29 
30 
31 class FXQuatd;
32 
33 
34 /// Double-precision 3x3 matrix
35 class FXAPI FXMat3d {
36 protected:
37   FXVec3d m[3];
38 public:
39 
40   /// Default constructor
FXMat3d()41   FXMat3d(){}
42 
43   /// Copy constructor
44   FXMat3d(const FXMat3d& other);
45 
46   /// Construct from scalar number
47   FXMat3d(FXdouble w);
48 
49   /// Construct from components
50   FXMat3d(FXdouble a00,FXdouble a01,FXdouble a02,
51           FXdouble a10,FXdouble a11,FXdouble a12,
52           FXdouble a20,FXdouble a21,FXdouble a22);
53 
54   /// Construct matrix from three vectors
55   FXMat3d(const FXVec3d& a,const FXVec3d& b,const FXVec3d& c);
56 
57   /// Construct rotation matrix from quaternion
58   FXMat3d(const FXQuatd& quat);
59 
60   /// Assignment operators
61   FXMat3d& operator=(const FXMat3d& other);
62   FXMat3d& operator=(FXdouble w);
63   FXMat3d& operator+=(const FXMat3d& w);
64   FXMat3d& operator-=(const FXMat3d& w);
65   FXMat3d& operator*=(FXdouble w);
66   FXMat3d& operator*=(const FXMat3d& w);
67   FXMat3d& operator/=(FXdouble w);
68 
69   /// Indexing
70   FXVec3d& operator[](FXint i){return m[i];}
71   const FXVec3d& operator[](FXint i) const {return m[i];}
72 
73   /// Conversion
74   operator FXdouble*(){return m[0];}
75   operator const FXdouble*() const {return m[0];}
76 
77   /// Other operators
78   friend FXAPI FXMat3d operator+(const FXMat3d& a,const FXMat3d& b);
79   friend FXAPI FXMat3d operator-(const FXMat3d& a,const FXMat3d& b);
80   friend FXAPI FXMat3d operator-(const FXMat3d& a);
81   friend FXAPI FXMat3d operator*(const FXMat3d& a,const FXMat3d& b);
82   friend FXAPI FXMat3d operator*(FXdouble x,const FXMat3d& a);
83   friend FXAPI FXMat3d operator*(const FXMat3d& a,FXdouble x);
84   friend FXAPI FXMat3d operator/(const FXMat3d& a,FXdouble x);
85   friend FXAPI FXMat3d operator/(FXdouble x,const FXMat3d& a);
86 
87   /// Multiply matrix and vector
88   friend FXAPI FXVec3d operator*(const FXVec3d& v,const FXMat3d& m);
89   friend FXAPI FXVec3d operator*(const FXMat3d& a,const FXVec3d& v);
90 
91   /// Mutiply matrix and vector, for non-projective matrix
92   friend FXAPI FXVec2d operator*(const FXVec2d& v,const FXMat3d& m);
93   friend FXAPI FXVec2d operator*(const FXMat3d& a,const FXVec2d& v);
94 
95   /// Set identity matrix
96   FXMat3d& eye();
97 
98   /// Multiply by rotation of phi
99   FXMat3d& rot(FXdouble c,FXdouble s);
100   FXMat3d& rot(FXdouble phi);
101 
102   /// Multiply by translation
103   FXMat3d& trans(FXdouble tx,FXdouble ty);
104 
105   /// Multiply by scaling
106   FXMat3d& scale(FXdouble sx,FXdouble sy);
107   FXMat3d& scale(FXdouble s);
108 
109   /// Determinant
110   friend FXAPI FXdouble det(const FXMat3d& m);
111 
112   /// Transpose
113   friend FXAPI FXMat3d transpose(const FXMat3d& m);
114 
115   /// Invert
116   friend FXAPI FXMat3d invert(const FXMat3d& m);
117 
118   /// Save to a stream
119   friend FXAPI FXStream& operator<<(FXStream& store,const FXMat3d& m);
120 
121   /// Load from a stream
122   friend FXAPI FXStream& operator>>(FXStream& store,FXMat3d& m);
123   };
124 
125 
126 extern FXAPI FXMat3d operator+(const FXMat3d& a,const FXMat3d& b);
127 extern FXAPI FXMat3d operator-(const FXMat3d& a,const FXMat3d& b);
128 extern FXAPI FXMat3d operator-(const FXMat3d& a);
129 extern FXAPI FXMat3d operator*(const FXMat3d& a,const FXMat3d& b);
130 extern FXAPI FXMat3d operator*(FXdouble x,const FXMat3d& a);
131 extern FXAPI FXMat3d operator*(const FXMat3d& a,FXdouble x);
132 extern FXAPI FXMat3d operator/(const FXMat3d& a,FXdouble x);
133 extern FXAPI FXMat3d operator/(FXdouble x,const FXMat3d& a);
134 
135 extern FXAPI FXVec3d operator*(const FXVec3d& v,const FXMat3d& m);
136 extern FXAPI FXVec3d operator*(const FXMat3d& a,const FXVec3d& v);
137 
138 extern FXAPI FXVec2d operator*(const FXVec2d& v,const FXMat3d& m);
139 extern FXAPI FXVec2d operator*(const FXMat3d& a,const FXVec2d& v);
140 
141 extern FXAPI FXdouble det(const FXMat3d& m);
142 extern FXAPI FXMat3d transpose(const FXMat3d& m);
143 extern FXAPI FXMat3d invert(const FXMat3d& m);
144 
145 extern FXAPI FXStream& operator<<(FXStream& store,const FXMat3d& m);
146 extern FXAPI FXStream& operator>>(FXStream& store,FXMat3d& m);
147 
148 }
149 
150 #endif
151