blob: 5970123ef2bdce504638d252bed1b794c4233f48 (
plain)
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
|
#include "matrix.h"
#include <cmath>
Matrix2::Matrix2() {
m[0][0] = m[0][1] =
m[1][0] = m[1][1] = 0;
}
Matrix2::Matrix2(float m00, float m01, float m10, float m11) {
m[0][0] = m00;
m[0][1] = m01;
m[1][0] = m10;
m[1][1] = m11;
}
Matrix2 Matrix2::operator*(const Matrix2& mat) {
return Matrix2(
m[0][0] * mat.m[0][0] + m[0][1] * mat.m[1][0],
m[0][0] * mat.m[0][1] + m[0][1] * mat.m[1][1],
m[1][0] * mat.m[0][0] + m[1][1] * mat.m[1][0],
m[1][0] * mat.m[0][1] + m[1][1] * mat.m[1][1]);
}
Matrix2 Matrix2::operator*(float f) {
return Matrix2(
m[0][0] * f,
m[0][1] * f,
m[1][0] * f,
m[1][1] * f);
}
Vector2 Matrix2::operator*(const Vector2& v) {
return Vector2(
m[0][0] * v.x + m[0][1] * v.y,
m[1][0] * v.x + m[1][1] * v.y);
}
Matrix2 rotation_matrix(float rot) {
float s = sinf(rot);
float c = cosf(rot);
return Matrix2(
c, -s,
s, c);
}
|