-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.cpp
More file actions
90 lines (70 loc) · 2.79 KB
/
Copy pathMain.cpp
File metadata and controls
90 lines (70 loc) · 2.79 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
#include "Main.h"
using namespace std;
void TestGame::Render(){
Game::Render();
scene->Draw();
}
bool TestGame::Init(){
bool status = Game::Init();
PerspectiveCamera* camera = new PerspectiveCamera(CameraControlType::ArcBall, glm::radians(45.0f), (float)this->window.width / (float)this->window.height, 1.0f, 200.0f);
camera->position = glm::vec3(10.0f);
scene = new Scene(camera);
//SceneObject* box = new Shapes::Sphere(2.0f);
//box->material = new ColoredMaterial(Color(.4f, 1.0f, 0.2f, 1.0f), Color(1.0f, 1.0f, 1.0f, 1.0f), Color(1.0f, 1.0f, 1.0f, 1.0f), 1.0);
//
//SceneObject* box2 = new Shapes::Sphere(1.0f);
//box2->material = new ColoredMaterial(Color(0.1f, 0.1f, 0.1f, 1.0f), Color(1.0f, 1.0f, 1.0f, 1.0f), Color(1.0f, 1.0f, 1.0f, 1.0f), 1.0);
//box2->transform->SetTranslation(glm::vec3(5.0, 0.0, 0.0));
//box->AddChild(box2);
//scene->AddSceneObject(box);
vector<Vertex> vertices;
vertices.push_back(Vertex(Position(1.0, 0.0, 1.0), TextureCoordinate(1.0, 1.0)));
vertices.push_back(Vertex(Position(1.0, 0.0, -1.0), TextureCoordinate(1.0, 0.0)));
vertices.push_back(Vertex(Position(-1.0, 0.0, -1.0), TextureCoordinate(0.0, 0.0)));
vertices.push_back(Vertex(Position(-1.0, 0.0, 1.0), TextureCoordinate(0.0, 1.0)));
vector<unsigned short> indices;
indices.push_back(0); indices.push_back(1); indices.push_back(2);
indices.push_back(2); indices.push_back(3); indices.push_back(0);
Model3D* model3D = new Model3D();
model3D->Init(vertices, indices);
Entity* entity = new Entity(*model3D);
entity->transform->SetScale(glm::vec3(10, 10, 10));
//entity->material = new ColoredMaterial(Color(0.1f, 0.1f, 0.1f, 1.0f), Color(1.0f, 1.0f, 1.0f, 1.0f), Color(1.0f, 1.0f, 1.0f, 1.0f), 1.0);
entity->material = new TexturedMaterial("sample_pic.jpg");
scene->AddSceneObject(entity);
return status;
}
void TestGame::Update(){
Game::Update();
scene->Update();
for (unsigned int i = 0; i < scene->sceneObjects.size(); i++)
{
SceneObject* sceneObj = scene->sceneObjects[i];
sceneObj->transform->SetRotation(sceneObj->transform->GetRotation() * glm::quat(glm::vec3(0.0, 0.01f, 0.0)));
auto children = sceneObj->children;
for (unsigned int j = 0; j < children.size(); j++)
{
auto childObj = children[j];
childObj->transform->SetRotation(childObj->transform->GetRotation() * glm::quat(glm::vec3(0.0, 0.1f, 0.0)));
}
}
}
void TestGame::OnEvent(SDL_Event* event)
{
Game::OnEvent(event);
if (Input::IsKeyDown(SDLK_ESCAPE))
{
RequestQuit();
}
}
void TestGame::CleanUp()
{
Game::CleanUp();
delete scene;
}
int main(int argc, char* argv[]){
Window window("Test Game Engine", 800, 600);
TestGame game(window, 60);
int status = game.Execute();
return status;
}