-
Notifications
You must be signed in to change notification settings - Fork 3
/
Matrix2f.h
69 lines (48 loc) · 1.76 KB
/
Matrix2f.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#ifndef MATRIX2F_H
#define MATRIX2F_H
#include <cstdio>
class Vector2f;
// 2x2 Matrix, stored in column major order (OpenGL style)
class Matrix2f
{
public:
// Fill a 2x2 matrix with "fill", default to 0.
Matrix2f( float fill = 0.f );
Matrix2f( float m00, float m01,
float m10, float m11 );
// setColumns = true ==> sets the columns of the matrix to be [v0 v1]
// otherwise, sets the rows
Matrix2f( const Vector2f& v0, const Vector2f& v1, bool setColumns = true );
Matrix2f( const Matrix2f& rm ); // copy constructor
Matrix2f& operator = ( const Matrix2f& rm ); // assignment operator
// no destructor necessary
const float& operator () ( int i, int j ) const;
float& operator () ( int i, int j );
Vector2f getRow( int i ) const;
void setRow( int i, const Vector2f& v );
Vector2f getCol( int j ) const;
void setCol( int j, const Vector2f& v );
float determinant();
Matrix2f inverse( bool* pbIsSingular = NULL, float epsilon = 0.f );
void transpose();
Matrix2f transposed() const;
// ---- Utility ----
const float *getElements() const;
void print() const;
static float determinant2x2( float m00, float m01,
float m10, float m11 );
static Matrix2f ones();
static Matrix2f identity();
static Matrix2f rotation( float degrees );
private:
float m_elements[ 4 ];
};
// Scalar-Matrix multiplication
Matrix2f operator * ( float f, const Matrix2f& m );
Matrix2f operator * ( const Matrix2f& m, float f );
// Matrix-Vector multiplication
// 2x2 * 2x1 ==> 2x1
Vector2f operator * ( const Matrix2f& m, const Vector2f& v );
// Matrix-Matrix multiplication
Matrix2f operator * ( const Matrix2f& x, const Matrix2f& y );
#endif // MATRIX2F_H