-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrix.hpp
More file actions
212 lines (164 loc) · 6.87 KB
/
Matrix.hpp
File metadata and controls
212 lines (164 loc) · 6.87 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
// Matrix.hpp
// Gabriel Ortega
//
//
#pragma once
#ifndef MATRIX_H
#define MATRIX_H
#ifndef VECTOR_H
#include "Vector.hpp"
#endif
#ifdef _WINDLL
#define CGM_DLL __declspec(dllexport)
#else
#define CGM_DLL __declspec(dllimport)
#endif
namespace cliqCity
{
namespace graphicsMath
{
struct CGM_DLL Matrix2
{
union
{
struct
{
Vector2 u, v;
};
Vector2 pRows[2];
float pData[2 * 2];
};
Matrix2(const Vector2& u, const Vector2& v);
Matrix2(
const float& u1, const float& u2,
const float& v1, const float& v2);
Matrix2(float m[2][2]);
Matrix2(float s);
Matrix2();
Matrix2(const Matrix2& other);
Matrix2 transpose() const;
Matrix2 inverse() const;
float determinant() const;
Matrix2& operator+=(const Matrix2& rhs);
Matrix2& operator-=(const Matrix2& rhs);
Matrix2& operator*=(const float& rhs);
Matrix2& operator=(const Matrix2& rhs);
Matrix2 operator-();
Vector2& operator[](const unsigned int& index);
float operator()(const unsigned int& row, const unsigned int& column);
};
struct CGM_DLL Matrix3
{
union
{
struct
{
Vector3 u, v, w;
};
Vector3 pRows[3];
float pData[3 * 3];
};
static Matrix3 scale(const Vector3& s);
static Matrix3 rotate(const float& angle, const Vector3& a);
static Matrix3 rotateX(const float& angle);
static Matrix3 rotateY(const float& angle);
static Matrix3 rotateZ(const float& angle);
Matrix3(const Vector3& u, const Vector3& v, const Vector3& w);
Matrix3(
const float& u1, const float& u2, const float& u3,
const float& v1, const float& v2, const float& v3,
const float& w1, const float& w2, const float& w3);
Matrix3(float m[3][3]);
Matrix3(float s);
Matrix3();
Matrix3(const Matrix3& other);
Matrix3 transpose() const;
Matrix3 inverse() const;
float determinant() const;
Matrix3& operator+=(const Matrix3& rhs);
Matrix3& operator-=(const Matrix3& rhs);
Matrix3& operator*=(const float& rhs);
Matrix3& operator=(const Matrix3& rhs);
Matrix3& operator-();
Vector3& operator[](const unsigned int& index);
float operator()(const unsigned int& row, const unsigned int& column);
};
struct CGM_DLL Matrix4
{
union
{
struct
{
Vector4 u, v, w, t;
};
Vector4 pRows[4];
float pData[4 * 4];
};
static Matrix4 orthographicRH(const float& left, const float& right, const float& bottom, const float& top, const float& zNear, const float& zFar);
static Matrix4 perspectiveRH(const float& fovy, const float& aspectRatio, const float& zNear, const float& zFar);
static Matrix4 frustumRH(const float& left, const float& right, const float& bottom, const float& top, const float& zNear, const float& zFar);
static Matrix4 orthographicLH(const float& left, const float& right, const float& bottom, const float& top, const float& zNear, const float& zFar);
static Matrix4 perspectiveLH(const float& fovy, const float& aspectRatio, const float& zNear, const float& zFar);
static Matrix4 frustumLH(const float& left, const float& right, const float& bottom, const float& top, const float& zNear, const float& zFar);
static Matrix4 normalizedOrthographicRH(const float& left, const float& right, const float& bottom, const float& top, const float& zNear, const float& zFar);
static Matrix4 normalizedPerspectiveRH(const float& fovy, const float& aspectRatio, const float& zNear, const float& zFar);
static Matrix4 normalizedFrustumRH(const float& left, const float& right, const float& bottom, const float& top, const float& zNear, const float& zFar);
static Matrix4 normalizedOrthographicLH(const float& left, const float& right, const float& bottom, const float& top, const float& zNear, const float& zFar);
static Matrix4 normalizedPerspectiveLH(const float& fovy, const float& aspectRatio, const float& zNear, const float& zFar);
static Matrix4 normalizedFrustumLH(const float& left, const float& right, const float& bottom, const float& top, const float& zNear, const float& zFar);
static Matrix4 lookToRH(const Vector3& direction, const Vector3& position, const Vector3& up);
static Matrix4 lookAtRH(const Vector3& target, const Vector3& position, const Vector3& up);
static Matrix4 lookToLH(const Vector3& direction, const Vector3& position, const Vector3& up);
static Matrix4 lookAtLH(const Vector3& target, const Vector3& position, const Vector3& up);
static Matrix4 scale(const Vector3& s);
static Matrix4 rotate(const float& angle, const Vector3& a);
static Matrix4 rotateX(const float& angle);
static Matrix4 rotateY(const float& angle);
static Matrix4 rotateZ(const float& angle);
static Matrix4 translate(const Vector3& t);
Matrix4(const Vector4& u, const Vector4& v, const Vector4& w, const Vector4& t);
Matrix4(
const float& u1, const float& u2, const float& u3, const float& u4,
const float& v1, const float& v2, const float& v3, const float& v4,
const float& w1, const float& w2, const float& w3, const float& w4,
const float& t1, const float& t2, const float& t3, const float& t4);
Matrix4(float m[4][4]);
Matrix4(float s);
Matrix4();
Matrix4(const Matrix4& other);
Matrix4 transpose() const;
Matrix4 inverse() const;
float determinant() const;
Matrix4 operator+=(const Matrix4& rhs);
Matrix4 operator-=(const Matrix4& rhs);
Matrix4 operator*=(const float& rhs);
Matrix4& operator=(const Matrix4& rhs);
Matrix4 operator-();
Vector4& operator[](const unsigned int& index);
float operator()(const unsigned int& row, const unsigned int& column);
operator Matrix3();
};
// Binary (Matrix2)
CGM_DLL Matrix2 operator+(const Matrix2& lhs, const Matrix2& rhs);
CGM_DLL Matrix2 operator-(const Matrix2& lhs, const Matrix2& rhs);
CGM_DLL Matrix2 operator*(const Matrix2& lhs, const Matrix2& rhs);
CGM_DLL Matrix2 operator*(const Matrix2& lhs, const float& rhs);
CGM_DLL Matrix2 operator*(const float& lhs, const Matrix2& rhs);
CGM_DLL Vector2 operator*(const Vector2& lhs, const Matrix2& rhs);
// Binary (Matrix3)
CGM_DLL Matrix3 operator+(const Matrix3& lhs, const Matrix3& rhs);
CGM_DLL Matrix3 operator-(const Matrix3& lhs, const Matrix3& rhs);
CGM_DLL Matrix3 operator*(const Matrix3& lhs, const Matrix3& rhs);
CGM_DLL Matrix3 operator*(const Matrix3& lhs, const float& rhs);
CGM_DLL Matrix3 operator*(const float& lhs, const Matrix3& rhs);
CGM_DLL Vector3 operator*(const Vector3& lhs, const Matrix3& rhs);
// Binary (Matrix4)
CGM_DLL Matrix4 operator+(const Matrix4& lhs, const Matrix4& rhs);
CGM_DLL Matrix4 operator-(const Matrix4& lhs, const Matrix4& rhs);
CGM_DLL Matrix4 operator*(const Matrix4& lhs, const Matrix4& rhs);
CGM_DLL Vector4 operator*(const Vector4& lhs, const Matrix4& rhs);
CGM_DLL Matrix4 operator*(const Matrix4& lhs, const float& rhs);
CGM_DLL Matrix4 operator*(const float& lhs, const Matrix4& rhs);
}
}
#endif