forked from tharvik/COG
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUnivers.cpp
88 lines (74 loc) · 2.02 KB
/
Univers.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
#include "Univers.h"
using namespace std;
static Univers* local;
static void cleanup()
{
local->~Univers();
}
Univers::Univers() : objects(), camera(), mainLight(5.98f, -26.12f, 15.39f,
0.32f, 0.76f, -0.57f)
{
local = this;
atexit(cleanup);
}
Univers::Univers(const GLdouble posX, const GLdouble posY, const GLdouble posZ,
const GLdouble anglePhi, const GLdouble angleTeta,
const GLdouble anglepsi) :
objects(), camera(posX, posY, posZ, anglePhi, angleTeta, anglepsi),
mainLight(5.98f, -26.12f, 15.39f, 0.32f, 0.76f, -0.57f)
{}
size_t Univers::addPlanet(const std::string& name)
{
objects.insert(unique_ptr<Object>(new Planet(name)));
return objects.size() - 1;
}
size_t Univers::addPlanet(const std::string& name, const Vvector pos)
{
objects.insert(unique_ptr<Object>(new Planet(name, pos)));
return objects.size() - 1;
}
void Univers::printInfo() const
{
std::cout << "CAMERA:" << std::endl
<< "\tPOSITION: ["
<< camera.getPositionX() << "; "
<< camera.getPositionY() << "; "
<< camera.getPositionZ() << ']'
<< std::endl
<< "\tORIENTATION: ["
<< camera.getOrientationX() << "; "
<< camera.getOrientationY() << "; "
<< camera.getOrientationZ() << ']'
<< std::endl
<< std::endl;
}
// Tick
void Univers::keyboard(std::set<int>& keysPressed)
{
camera.keyDown(keysPressed);
}
void Univers::physic(double& physicDelta)
{
camera.physic(physicDelta);
//sphere.physic(physicDelta);
}
void Univers::draw() const
{
for (auto& object: objects)
object->draw();
}
void Univers::refresh(universRefreshFlags flags)
{
if (flags & LEVEL)
for (auto& object: objects)
object->calculateLevel(this->camera.getPosition());
glLoadIdentity();
// Shadows(&univers)
perspective();
camera.look();
draw();
glFinish();
glutSwapBuffers();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glutShowWindow();
}