-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
107 lines (81 loc) · 2.95 KB
/
main.cpp
File metadata and controls
107 lines (81 loc) · 2.95 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
/**
* File Name : main.cu
* Author : Yang Fan
* Date : 2018/11/27
* program entrance
*/
#include "common/render.h"
#include "common/device.h"
#include "includes/math/matrix.hpp"
#include "common/camera.h"
using namespace std;
using namespace Math;
/**
* sdl defined main to SDL_main , so we undef it on here
*/
#undef main
int main()
/*
* redefine main
*/
#define main SDL_main
{
PRINT_DEVICE_INFORMATION();
Device::initialize(SCREEN_WIDTH, SCREEN_HEIGHT, IS_FULL_SCREEN, "Mixed-Renderer");
auto d = Device::getInstance();
Renderer::initialize(NUM_PIXELS , NUM_COLORS , NUM_TRIANGLES);
auto r = Renderer::getInstance();
auto cubeModel1 = Matrix::identity() * Matrix::scale(0.1 , 0.1 , 0.1);
auto cubeModel2 = Matrix::identity() * Matrix::scale(0.1 , 0.1 , 0.1);
auto waterModel = Matrix::identity() * Matrix::scale(1.5 , 1 , 1.5);
auto lightModel = Matrix::identity() * Matrix::scale( 0.02 , 0.02 , 0.02);
auto camera = PerspectiveCamera(60 , Vector3(0, 5, 5) , Vector3(0, 0, 0) , Vector3(0, 1, 0) , 0.1 , 100);
r.setPerspectiveCamera(camera);
auto rotation1 = Matrix::identity();
auto rotation2 = Matrix::identity();
auto view = Matrix::lookAtLH(camera.eye, camera.target, Vector3(0, 1, 0));
auto perspective = Matrix::perspectiveFovLH( 1 , SCREEN_WIDTH / SCREEN_HEIGHT, camera.near, camera.far);
auto cube1 = Model::cube();
auto cube2 = Model::cube();
auto floor = Model::floor();
auto light = Model::cube();
auto cubeShader = Shader(CUBE);
cubeShader.setMat(view, VIEW);
cubeShader.setMat(perspective, PERSPECTIVE);
auto floorShader = Shader(WATER);
floorShader.setMat(view , VIEW);
floorShader.setMat(perspective , PERSPECTIVE);
auto lightShader = Shader(LIGHT);
lightShader.setMat(view ,VIEW);
lightShader.setMat(perspective , PERSPECTIVE);
//
// cubeShader.setTexture(Texture::LoadFromFile("resources/cube.png" , true), 0);
// waterShader.setTexture(Texture::LoadFromFile("resources/water.png" , true), 0);
d.show();
Args args{0.0f};
float bis = 0.0008f;
while (!d.windowShouldClose()) {
d.clear();
r.clear();
rotation1 = rotation1 * Matrix::rotationY(-0.02f) * Matrix::rotationZ(-0.02f) * Matrix::rotationX(-0.02f);
rotation2 = rotation2 * Matrix::rotationY( 0.02f) * Matrix::rotationZ( 0.02f) * Matrix::rotationX( 0.02f);
cubeShader.setMat(cubeModel1 * rotation1 * Matrix::translate(0.6 , 1 , 0), MODEL);
r.add(cube1 , cubeShader , 0 , SOLID);
cubeShader.setMat(cubeModel2 * rotation2 * Matrix::translate(-0.6 , 1 , 0), MODEL);
r.add(cube2 , cubeShader , 0 , SOLID);
// args.bis += bis;
// if (args.bis >= 0.1f || args.bis <= -0.1f) {bis = -bis;}
// waterShader.setArgs(args);
floorShader.setMat(waterModel * Matrix::translate(0 , 0 , 0.5), MODEL);
r.add(floor , floorShader ,0.5 , SOLID);
//
lightShader.setMat(lightModel * rotation1 * Matrix::translate(0 , 2 , 0) , MODEL);
r.add(light , lightShader , 0 , SOLID);
r.render();
d.handleEvent();
d.updateRender();
}
d.destory();
r.destory();
return 0;
}