1 #ifndef AWFUL_SCENEGRAPH_MATRIX_H_
2 #define AWFUL_SCENEGRAPH_MATRIX_H_
21 Matrix( const Vec3
& _Right
, const Vec3
& _Up
, const Vec3
& _Back
, const Vec3
& _Pos
)
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
);
38 friend Matrix
operator+( const Matrix
& a
, const Matrix
& b
)
40 return Matrix( a
.right
+ b
.right
,
46 // Matrix substraction
47 friend Matrix
operator-( const Matrix
& a
, const Matrix
& b
)
49 return Matrix( a
.right
- b
.right
,
55 // Matrix multiplication
56 friend Matrix
operator*( const Matrix
& a
, const Matrix
& b
);
58 friend Matrix
& operator*=( Matrix
& a
, const Matrix
& b
)
64 // Matrix multiplication by a scalar
65 friend Matrix
operator*( const Matrix
& m
, float s
)
67 return Matrix( m
.right
* s
,
73 // Matrix multiplication by a scalar
74 friend Matrix
operator*( float s
, const Matrix
& m
)
76 return Matrix( m
.right
* 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
)
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
118 // Multiply the matrix with the current opengl matrix