-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSource.cpp
More file actions
177 lines (151 loc) · 6.62 KB
/
Copy pathSource.cpp
File metadata and controls
177 lines (151 loc) · 6.62 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
#include <stdio.h>
#include "Mesh.h"
#define SCREEN_WIDTH 1280
#define SCREEN_HEIGHT 720
Renderer renderer;
Pipeline pipeline;
// Main code
int main(int, char**) {
renderer.Init("Mid-Term Project", SCREEN_WIDTH, SCREEN_HEIGHT);
{
pipeline.InitPipeline(0.8f * SCREEN_WIDTH, SCREEN_HEIGHT, Camera());
Mat4 matRotZ = RotationZ(DegreesToRadians(30.f));
Mat4 matRotX = RotationX(DegreesToRadians(30.f));
Mat4 matTrans = TranslationMat4(0.f, 0.f, 10.f);
Mat4 matWorld = matTrans * matRotX * matRotZ;
Mat4 matView = pipeline.camera.GetViewMatrix();
Mat4 matProj = PerspectiveProjectionRH(DegreesToRadians(pipeline.fFov),
pipeline.fAspectRatio,
pipeline.fNear, pipeline.fFar);
pipeline.SetPipelineMatrix(matWorld, matView, matProj);
}
// SDL_SetRelativeMouseMode(SDL_TRUE);
Mesh mesh;
mesh.LoadFromObjectFile("res/models/terr/terr.obj", true);
// Preserved if need be
// Mesh mesh2;
// mesh2.tris = {
// // SOUTH
// {{Vec4{0.0f, 0.0f, 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.0f, 1.0f}}},
// {{Vec4{1.0f, 0.0f, 1.0f, 1.0f}, Vec4{0.0f, 0.0f, 0.0f, 1.0f},
// Vec4{1.0f, 0.0f, 0.0f, 1.0f}}},
//};
// Mesh mesh3;
// mesh3.tris = {
// // SOUTH
// {Vec4(0.0f, 0.0f, 0.0f, 1.0f), Vec4(0.0f, 1.0f, 0.0f, 1.0f),
// Vec4(1.0f, 1.0f, 0.0f, 1.0f), Vec3(0.0f, 1.0f, 1.0f),
// Vec3(0.0f, 0.0f, 1.0f), Vec3(1.0f, 0.0f, 1.0f)},
// {
// Vec4(0.0f, 0.0f, 0.0f, 1.0f),
// Vec4(1.0f, 1.0f, 0.0f, 1.0f),
// Vec4(1.0f, 0.0f, 0.0f, 1.0f),
// Vec3(0.0f, 1.0f, 1.0f),
// Vec3(1.0f, 0.0f, 1.0f),
// Vec3(1.0f, 1.0f, 1.0f),
// },
// // EAST
// {Vec4(1.0f, 0.0f, 0.0f, 1.0f), Vec4(1.0f, 1.0f, 0.0f, 1.0f),
// Vec4(1.0f, 1.0f, 1.0f, 1.0f), Vec3(0.0f, 1.0f, 1.0f),
// Vec3(0.0f, 0.0f, 1.0f), Vec3(1.0f, 0.0f, 1.0f)},
// {Vec4(1.0f, 0.0f, 0.0f, 1.0f), Vec4(1.0f, 1.0f, 1.0f, 1.0f),
// Vec4(1.0f, 0.0f, 1.0f, 1.0f), Vec3(0.0f, 1.0f, 1.0f),
// Vec3(1.0f, 0.0f, 1.0f), Vec3(1.0f, 1.0f, 1.0f)},
// // NORTH
// {
// Vec4(1.0f, 0.0f, 1.0f, 1.0f),
// Vec4(1.0f, 1.0f, 1.0f, 1.0f),
// Vec4(0.0f, 1.0f, 1.0f, 1.0f),
// Vec3(0.0f, 1.0f, 1.0f),
// Vec3(0.0f, 0.0f, 1.0f),
// Vec3(1.0f, 0.0f, 1.0f),
// },
// {Vec4(1.0f, 0.0f, 1.0f, 1.0f), Vec4(0.0f, 1.0f, 1.0f, 1.0f),
// Vec4(0.0f, 0.0f, 1.0f, 1.0f), Vec3(0.0f, 1.0f, 1.0f),
// Vec3(1.0f, 0.0f, 1.0f), Vec3(1.0f, 1.0f, 1.0f)},
// // WEST
// {Vec4(0.0f, 0.0f, 1.0f, 1.0f), Vec4(0.0f, 1.0f, 1.0f, 1.0f),
// Vec4(0.0f, 1.0f, 0.0f, 1.0f), Vec3(0.0f, 1.0f, 1.0f),
// Vec3(0.0f, 0.0f, 1.0f), Vec3(1.0f, 0.0f, 1.0f)},
// {Vec4(0.0f, 0.0f, 1.0f, 1.0f), Vec4(0.0f, 1.0f, 0.0f, 1.0f),
// Vec4(0.0f, 0.0f, 0.0f, 1.0f), Vec3(0.0f, 1.0f, 1.0f),
// Vec3(1.0f, 0.0f, 1.0f), Vec3(1.0f, 1.0f, 1.0f)},
// // TOP
// {Vec4(0.0f, 1.0f, 0.0f, 1.0f), Vec4(0.0f, 1.0f, 1.0f, 1.0f),
// Vec4(1.0f, 1.0f, 1.0f, 1.0f), Vec3(0.0f, 1.0f, 1.0f),
// Vec3(0.0f, 0.0f, 1.0f), Vec3(1.0f, 0.0f, 1.0f)},
// {Vec4(0.0f, 1.0f, 0.0f, 1.0f), Vec4(1.0f, 1.0f, 1.0f, 1.0f),
// Vec4(1.0f, 1.0f, 0.0f, 1.0f), Vec3(0.0f, 1.0f, 1.0f),
// Vec3(1.0f, 0.0f, 1.0f), Vec3(1.0f, 1.0f, 1.0f)},
// // BOTTOM
// {Vec4(1.0f, 0.0f, 1.0f, 1.0f), Vec4(0.0f, 0.0f, 1.0f, 1.0f),
// Vec4(0.0f, 0.0f, 0.0f, 1.0f), Vec3(0.0f, 1.0f, 1.0f),
// Vec3(0.0f, 0.0f, 1.0f), Vec3(1.0f, 0.0f, 1.0f)},
// {Vec4(1.0f, 0.0f, 1.0f, 1.0f), Vec4(0.0f, 0.0f, 0.0f, 1.0f),
// Vec4(1.0f, 0.0f, 0.0f, 1.0f), Vec3(0.0f, 1.0f, 1.0f),
// Vec3(1.0f, 0.0f, 1.0f), Vec3(1.0f, 1.0f, 1.0f)},
//};
// int sampler = pipeline.BindTexture(
// "test", IMG_LoadTexture(renderer.renderer, "res/images/test.jpg"));
// mesh3.SetTexUnit(sampler);
float fTheta = 0.01f;
while (renderer.isApplicationRunning) {
renderer.PollEvents();
fTheta += 0.0005f;
Mat4 matScale = ScalingMat4(0.001f, 0.001f, 0.001f);
Mat4 matRotZ = RotationZ(DegreesToRadians(0.f * fTheta * 1000.f));
Mat4 matRotX = RotationX(DegreesToRadians(0.f * fTheta * 1000.f));
Mat4 matTrans = TranslationMat4(0.f, 10.f, 20.f);
Mat4 matWorld = matTrans * matRotX * matRotZ * matScale;
Mat4 matView = pipeline.camera.GetViewMatrix();
Mat4 matProj = PerspectiveProjectionRH(
DegreesToRadians(pipeline.camera.Zoom), pipeline.fAspectRatio,
pipeline.fNear, pipeline.fFar);
pipeline.SetPipelineMatrix(matWorld, matView, matProj);
renderer.NewFrame();
renderer.Clear(Vec4(0.46f, 0.54f, 0.6f, 1.0f));
mesh.Draw();
/*Mat4 matScale2 = ScalingMat4(0.5f, 0.5f, 0.5f);
Mat4 matRotZ2 = RotationZ(DegreesToRadians(-10.f));
Mat4 matRotX2 = RotationX(DegreesToRadians(-10.f));
Mat4 matTrans2 = TranslationMat4(0.f, 0.f, 9.f);
Mat4 matWorld2 = matTrans2 * matRotX2 * matRotZ2 * matScale2;
pipeline.SetPipelineMatrix(matWorld2, matView, matProj);
mesh2.Draw(false);
Mat4 matScale3 = ScalingMat4(0.5f, 0.5f, 0.5f);
Mat4 matRotZ3 = RotationZ(DegreesToRadians(-10.f));
Mat4 matRotX3 = RotationX(DegreesToRadians(-10.f));
Mat4 matTrans3 = TranslationMat4(0.f, 4.f, 9.f);
Mat4 matWorld3 = matTrans3 * matRotX * matRotZ;
pipeline.SetPipelineMatrix(matWorld3, matView, matProj);
mesh3.Draw();*/
renderer.Present();
}
return 0;
}