Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrices.cpp
More file actions
Latest commit
101 lines (80 loc) · 1.93 KB
/
Copy pathMatrices.cpp
File metadata and controls
101 lines (80 loc) · 1.93 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
#include"../Include/defGameEngine.hpp"
structmat2x2
{
float* operator[](size_t i) { return m[i]; }
float m[2][2]{ 0 };
};
voidMat_MultiplyMat(mat2x2& matA, mat2x2& matB, mat2x2& matResult)
{
for (size_t i = 0; i < 2; i++)
for (size_t j = 0; j < 2; j++)
{
for (size_t k = 0; k < 2; k++)
matResult[i][j] += matA[i][k] * matB[k][j];
}
}
voidMat_MultiplyVec(mat2x2& matA, def::Vector2f& vecB, def::Vector2f& vResult)
{
vResult.x = matA[0][0] * vecB.x + matA[0][1] * vecB.y;
vResult.y = matA[1][0] * vecB.x + matA[1][1] * vecB.y;
}
voidMat_MakeRotation(mat2x2& matA, constfloatfAngle)
{
float s = sin(fAngle), c = cos(fAngle);
matA[0][0] = c;
matA[0][1] = s;
matA[1][0] = -s;
matA[1][1] = c;
}
voidMat_MakeScale(mat2x2& matA, const def::Vector2f& vScale)
{
matA[0][0] = vScale.x;
matA[0][1] = 0.0f;
matA[1][0] = 0.0f;
matA[1][1] = vScale.y;
}
classSample : publicdef::GameEngine
{
public:
Sample()
{
Window().SetTitle("Sample");
}
protected:
boolOnUserCreate() override
{
sprDemo = newdef::Sprite("assets/road.jpg");
returntrue;
}
boolOnUserUpdate(floatfDeltaTime) override
{
mat2x2 matRotated, matScaled;
Mat_MakeRotation(matRotated, fTheta);
Mat_MakeScale(matScaled, { 0.5f, 0.5f });
Clear(def::BLACK);
def::Vector2f vPos;
for (vPos.y = 0; vPos.y < sprDemo->size.y; vPos.y++)
for (vPos.x = 0; vPos.x < sprDemo->size.x; vPos.x++)
{
def::Vector2f vScaled;
Mat_MultiplyVec(matScaled, vPos, vScaled);
def::Vector2f vRotated;
Mat_MultiplyVec(matRotated, vScaled, vRotated);
def::Vector2f vTranslated;
vTranslated = vRotated + def::Vector2f(Window().GetScreenWidth() * 0.5f, Window().GetScreenHeight() * 0.5f);
Draw(vTranslated, sprDemo->GetPixel(vPos.x, vPos.y));
}
fTheta += fDeltaTime;
returntrue;
}
private:
def::Sprite* sprDemo = nullptr;
floatfTheta = 0.0f;
};
intmain()
{
Sample demo;
demo.Construct(1280, 720, 1, 1);
demo.Run();
return0;
}