-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGame.cpp
More file actions
141 lines (111 loc) · 3.45 KB
/
Game.cpp
File metadata and controls
141 lines (111 loc) · 3.45 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
/*
* File :
* ./Game.cpp
*
* Author :
* Xonar <Paul le Roux>
*
* Description :
* Definitions of ./Game.h
*
*/
#include "Camera/Camera.h"
#include "Camera/PlayerFreeCamera.h"
#include "Container/Container.h"
#include "Engine/ModelEngine.h"
#include "Engine/LightEngine.h"
#include "GUI/Font.h"
#include "Game.h"
#include "Graphics/Graphics.h"
#include "Lib/FGLext.h"
#include "Lib/Log.h"
#include "Light/Light.h"
#include "Material/Material.h"
#include "Model/Model.h"
#include "Model/Model.h"
#include "Model/ModelGroup.h"
#include "Model/ModelLoader.h"
#include "Shader/Shader.h"
#include "Texture/Texture.h"
#include "Time/Time.h"
#include "Window/Window.h"
//TODO Temp Resources
FModel **models;
int modelNum;
FModelGroup *modelGroup;
FMaterial **materials;
int materialNum;
FCamera *gCamera = NULL;
FShader *shader = NULL;
FFont *font = NULL;
FPlayerFreeCamera* playerCamera;
FLightDirectional* light1;
GLint initializeGame()
{
//Load Scene
FModelLoader loader = FModelLoader();
const aiScene *scene = loader.loadScene("Assets/sponza/sponza.obj");
//Log Information
gLogv << "Model File : " << "Assets/sponza/sponza.obj" << std::endl;
gLogv << "\tLights : " << scene->mNumLights << " (IGNORED)" << std::endl;
gLogv << "\tAnimations : " << scene->mNumAnimations << " (IGNORED)" << std::endl;
gLogv << "\tMaterials : " << scene->mNumMaterials << " (PARTIALLY IMPLEMENTED)" << std::endl;
gLogv << "\tMeshes : " << scene->mNumMeshes << std::endl;
gLogv << "\tCameras : " << scene->mNumCameras << std::endl;
gLogv << "\tTextures : " << scene->mNumTextures << " (IGNORED)" << std::endl;
//Set Camera
if(scene->mNumCameras < 1)
{
//Create Default Camera
gLogv << "Using Default Camera" << std::endl;
gCamera = new FCamera();
gCamera->setViewPort(0,0,gWindow->getWindowWidth(),gWindow->getWindowHeight());
gCamera->setPosition(glm::vec3(4.f,3.f,-3.f));
gCamera->lookAt(glm::vec3(0.f,0.f,0.f));
gCamera->InitProjectionMatrix(glm::radians(45.f),0.1f,100.f);
}
else
{
//Create Camera from scene data
gLogv << "Using Camera from model file" << std::endl;
if(scene->mNumCameras > 1)
gLogv << "\tIgnoring cameras after camera 1" << std::endl;
gCamera = loader.getCamera(0,scene);
//TODO Improve
gCamera->setUp(glm::vec3(0,0,1));
}
//Load ModelParts
models = new FModel*[loader.getMeshCount()];
for(GLuint i = 0;i < loader.getMeshCount();i++)
models[i] = loader.getMesh(i);
modelNum = loader.getMeshCount();
//Load Materials
materials = new FMaterial*[loader.getMaterialCount()];
for(GLuint i = 0; i < loader.getMaterialCount();i++)
materials[i] = loader.getMaterial(i);
materialNum = loader.getMaterialCount();
//Create Model Group
modelGroup = new FModelGroup();
modelGroup->addModels(models, modelNum);
modelGroup->addMaterials(materials, materialNum);
modelGroup->finalize();
gModelEngine->registerModelGroup(modelGroup);
//FFont
font = new FFont();
font->createFromTTF("Assets/newscycle-regular.ttf", 18);
gFontEngine->addFont(font);
//Free Look Camera
playerCamera = new FPlayerFreeCamera(gCamera);
//Add Lights to scene
light1 = new FLightDirectional(glm::vec3(1, 1, 1), glm::vec3(1.0f,1.0f,1.0f));
//Register Light with LightEngine
gLightEngine->registerLight(light1);
return 0;
}
GLvoid updateGame()
{
//Draw some text
font->drawText("Sponza Scene DEMO", glm::vec2( 10, 10) );
//Update
playerCamera->update();
}