forked from lokesh-sharma/GameEngine
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
181 lines (152 loc) · 6.45 KB
/
main.cpp
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
178
179
180
#include <iostream>
#include <SDL2/SDL.h>
#include<math.h>
#include "./include/display.h"
#include "./include/mesh.h"
#include "./include/shader.h"
#include "./include/texture.h"
#include "./include/transform.h"
#include "./include/camera.h"
#include"./include/InputHandler.h"
#include"FreeLook.h"
#include"MeshRenderer.h"
#include"RenderingEngine.h"
#include"CoreEngine.h"
#include"GameObject.h"
#include"Game.h"
#include"Matrial.h"
#include"transform.h"
#include"BoundingSphere.h"
#include"AABB.h"
#include"Plane.h"
#include"PhysicsEngine.h"
#include"PhysicsEngineComponent.h"
#include"PhysicsObject.h"
#include"PhysicsObjectComponent.h"
#include"ForwardAmbient.h"
#include"Player.h"
#include"FPSCamera.h"
#include"GUIManager.h"
#include"ObjLoader.h"
int main(int argc, char** argv)
{
Display display("OpenGL game Engine");
GameObject* baseTerrain = new GameObject;
GameObject* g2 = new GameObject;
GameObject* g3 = new GameObject;
GameObject* g4 = new GameObject;
GameObject* g5 = new GameObject;
Mesh* terrainMesh = new Mesh("./res/Models/terrain2.obj");
//Mesh* mesh2 = new Mesh("./res/sphere2.obj");
Mesh* mesh3 = new Mesh("./res/Models/cube.obj");
Mesh* mesh4 = new Mesh("./res/Models/tree.obj");
// std::vector<glm::vec3> verts;
// std::vector<glm::vec2> uvs;
// std::vector<glm::vec3> normals;
// ObjLoader* o1 = new ObjLoader("./res/cubetest.obj" ,verts , uvs , normals );
// std::cout<<verts.size()<<" "<<uvs.size()<<" "<<normals.size()<<std::endl;
PhysicsEngine* pEngine = new PhysicsEngine();
pEngine->addObject(new PhysicsObject(terrainMesh , glm::vec3(0,0,0) , 0 , 1) , "terrain");
// pEngine->addObject(new PhysicsObject(glm::vec3(0,10,1) ,glm::vec3(2,2,2) ,
// 5 , PhysicsObject::TYPE_BOUNDINGSPHERE) , "sphere");
pEngine->addObject(new PhysicsObject(glm::vec3(20,50,0) , glm::vec3(2,2,2) , 2 ,
PhysicsObject::TYPE_BOX) , "cube");
PhysicsObjectComponent* terrainCollider = new PhysicsObjectComponent(pEngine->getObject("terrain"));
// PhysicsObjectComponent* comp2 = new PhysicsObjectComponent(pEngine->getObject("sphere"));
PhysicsObjectComponent* comp3 = new PhysicsObjectComponent(pEngine->getObject("cube"));
//PhysicsObjectComponent* comp3 = new PhysicsObjectComponent(pEngine->getObject("cube"));
// btTransform qt;
// qt = pEngine->getObject("cube")->getRigidBody()->getWorldTransform();
// qt.setRotation(btQuaternion(1,0,0,0));
// pEngine->getObject("cube")->getRigidBody()->setWorldTransform(qt);
Material* m = new Material();
Material* terrainTexture = new Material();
Material* treebark = new Material();
//Material* m2 = new Material();
m->addTexture("diffuse" , "./res/Textures/bricks2.jpg");
m->addTexture("normal" , "./res/Textures/bricks2_normal.jpg");
m->addTexture("dispMap" , "./res/Textures/bricks2_disp.jpg");
treebark->addTexture("diffuse" , "./res/Textures/bark.jpg");
treebark->addTexture("normal" , "./res/Textures/default_normal.jpg");
treebark->addTexture("dispMap" , "./res/Textures/default_disp.png");
terrainTexture->addTexture("diffuse" , "./res/Textures/grass.jpg");
terrainTexture->addTexture("normal" , "./res/Textures/default_normal.jpg");
terrainTexture->addTexture("dispMap" , "./res/Textures/default_disp.png");
//m2->addTexture("diffuse" , "./res/leaf.png");
// m2->addTexture("normal" , "./res/default_normal.jpg");
//m2->addTexture("dispMap" , "./res/default_disp.png");
GameComponent* player = new Player(pEngine);
MeshRenderer f( terrainMesh,terrainTexture);
MeshRenderer g( mesh3,m);
MeshRenderer h( mesh4,treebark);
Game* game = new Game();
TheInputHandler::getInstance()->disableCursor();
TheInputHandler::getInstance()->setDisplay(&display);
RenderingEngine* renderer = new RenderingEngine(&display);
GUIManager * manager = new GUIManager(display.getWidth()/display.getHeight());
manager->addGUI("./res/GUI/crosshair.png" , glm::vec3(0,0,0) , glm::vec3(0.03,0.03,1));
renderer->addSkyBox("./res/skybox" , "png");
renderer->addWaterTile(glm::vec3( 50 , 0 , 0) , glm::vec3(100 , 100 , 100));
CoreEngine core(&display , game , renderer , manager);
renderer->setCoreEngine(&core);
// g1->getTransform()->SetPos(glm::vec3(0,2,0));
// g2->getTransform()->SetPos(glm::vec3(0,-1,0));
baseTerrain->addComponent(&f);
baseTerrain->addComponent(terrainCollider);
game->addToScene(baseTerrain);
game->addToScene(g2);
game->addToScene(g3);
game->addToScene(g4);
game->addToScene(g5);
//g2->addComponent(&g);
game->setEngine(&core);
//SpotLight*sp = new SpotLight(glm::vec3(1,1,1) , 2.0f);
PointLight*point = new PointLight(glm::vec3(1,1,1) , 10.0f);
DirectionalLight * dir =new DirectionalLight(glm::vec3(1,1 ,1) , 1.3f);
SpotLight * spot =new SpotLight(glm::vec3(1,1 ,1) , 12.0f);
g3->addComponent(dir);
// g4->addComponent(comp3);
g4->addComponent(&g);
g4->getTransform()->SetPos(glm::vec3(3 , 2 , 0));
g4->getTransform()->SetScale(glm::vec3(2 , 2, 2));
g5->addComponent(&h);
g5->getTransform()->SetPos(glm::vec3(0 , 6.5 , 0));
g2->addComponent(new FreeLook(glm::vec3(0.0f, 6.0f, 10.0f), 70.0f
, (float)display.getWidth()/(float)display.getHeight(), 0.1f, 200.0f));
//g4->addComponent(&g);
//g4->addComponent(comp2);
//g2->addComponent(player); //order is important
//g5->addComponent(&h);
//g5->addComponent(comp3);
//g6->addComponent(&i);
// g6->addComponent(&i);
// g7->addComponent(&j);
// g8->addComponent(&k);
// g9->addComponent(&l);
// g10->addComponent(&m);
// g11->addComponent(&n);
const float offset = 88.35;
core.start();
float counter = 0.0f;
long framestart;
g3->getTransform()->SetPos(glm::vec3(0,4,0));
g3->getTransform()->rotate(glm::vec3(1,0,0) , -45);
g3->getTransform()->rotate(glm::vec3(0,1,0) , 90 + 45);
//g6->getTransform()->rotate(glm::vec3(1,0,0) , 90);
while(core.is_running())
{
// glMatrixMode(GL_PROJECTION);
//glLoadIdentity();
//glOrtho(0, display.getWidth(), display.getHeight(), 0, -1, 1);
//int t1 = SDL_GetTicks();
core.run();
pEngine->simulate(1/60.0);
pEngine->handleCollisions();
TheInputHandler::getInstance()->resetStates();
//g3->getTransform()->rotate(glm::vec3(1,0,0) , (glm::sin(counter)+1)*10);
//std::cout<<1000.0/(SDL_GetTicks()-t1)<<std::endl;
counter += 0.1;
//dir->setIntensity((glm::sin(counter) + 1)*3);
}
return 0;
}