Some reorganisation of the abf directories.
[fail.git] / scenegraph / matrix.h
blob4f9585159b47bc6e6cdb920cea991e2001b3db03
1 #ifndef AWFUL_SCENEGRAPH_MATRIX_H_
2 #define AWFUL_SCENEGRAPH_MATRIX_H_
4 #include "vector3.h"
6 namespace sluggish
8 class Matrix
10 public:
11 Vec3 right;
12 Vec3 up;
13 Vec3 back;
14 Vec3 pos;
16 Matrix()
18 identity();
21 Matrix( const Vec3& _Right, const Vec3& _Up, const Vec3& _Back, const Vec3& _Pos )
23 right = _Right;
24 up = _Up;
25 back =_Back;
26 pos = _Pos;
29 void identity()
31 right = Vec3( 1.f, 0.f, 0.f);
32 up = Vec3( 0.f, 1.f, 0.f);
33 back = Vec3( 0.f, 0.f, 1.f);
34 pos = Vec3();
37 // Matrix addition
38 friend Matrix operator+( const Matrix& a, const Matrix& b )
40 return Matrix( a.right + b.right,
41 a.up + b.up,
42 a.back + b.back,
43 a.pos + b.pos );
46 // Matrix substraction
47 friend Matrix operator-( const Matrix& a, const Matrix& b )
49 return Matrix( a.right - b.right,
50 a.up - b.up,
51 a.back - b.back,
52 a.pos - b.pos );
55 // Matrix multiplication
56 friend Matrix operator*( const Matrix& a, const Matrix& b );
58 friend Matrix& operator*=( Matrix& a, const Matrix& b )
60 a = a * b;
61 return a;
64 // Matrix multiplication by a scalar
65 friend Matrix operator*( const Matrix& m, float s )
67 return Matrix( m.right * s,
68 m.up * s,
69 m.back * s,
70 m.pos * s );
73 // Matrix multiplication by a scalar
74 friend Matrix operator*( float s, const Matrix& m )
76 return Matrix( m.right * s,
77 m.up * s,
78 m.back * s,
79 m.pos * s );
82 // Vector multiplication
83 friend Vec3 operator*( const Matrix& a, const Vec3& b )
85 return b.x * a.right + b.y * a.up + b.z * a.back;
88 // Vector multiplication
89 friend Vec3 operator*( const Vec3& b, const Matrix& a )
91 return b.x * a.right + b.y * a.up + b.z * a.back;
95 // Vertex transformation
96 Vec3 transform( const Vec3& a ) const
98 return ( *this * a ) + pos;
101 bool inverse( Matrix* _pResult ) const;
103 // Setup the rotation part of the matrix as a lookat matrix
104 void lookAt( const Vec3& _Back, const Vec3& _Up );
106 // Setup the translation part of the matrix
107 void translation( const Vec3& _Trans )
109 pos = _Trans;
112 // Setup the matrix as a rotation of a given angle around a given direction
113 void rotation( float _Angle, const Vec3& _Dir );
115 // Load the matrix to opengl
116 void load() const;
118 // Multiply the matrix with the current opengl matrix
119 void mult() const;
123 #endif