-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUniverse.cpp
More file actions
executable file
·78 lines (62 loc) · 1.9 KB
/
Universe.cpp
File metadata and controls
executable file
·78 lines (62 loc) · 1.9 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
#include "Universe.h"
#include <LinearMath/btVector3.h>
using namespace std;
Universe::Universe()
: objects(), mainLight(btVector3({5.98f, -26.12f, 15.39f}), btVector3({0.32f, 0.76f, -0.57f}))
{
broadphase = new btDbvtBroadphase();
collisionConfiguration = new btDefaultCollisionConfiguration();
dispatcher = new btCollisionDispatcher(collisionConfiguration);
solver = new btSequentialImpulseConstraintSolver;
dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher, broadphase,
solver, collisionConfiguration);
dynamicsWorld->setGravity(btVector3(0, -10, 0));
}
size_t Universe::addPlanet(const std::string& name)
{
objects.insert(unique_ptr<Object>(new Planet(name)));
return objects.size() - 1;
}
size_t Universe::addPlanet(const std::string& name, const btVector3 pos)
{
// objects.insert(unique_ptr<Object>(new Planet(name, pos)));
return objects.size() - 1;
}
void Universe::addRigidBody(btRigidBody* rigidBody)
{
dynamicsWorld->addRigidBody(rigidBody);
}
void Universe::removeRigidBody(btRigidBody* rigidBody)
{
dynamicsWorld->removeRigidBody(rigidBody);
}
const std::set<std::unique_ptr<Object>>& Universe::getObjects()
{
return objects;
}
// Event
void Universe::event(const unique_ptr<Event>& event)
{
}
void Universe::physics(const double& dt)
{
dynamicsWorld->stepSimulation(dt, 10); // TODO Settings
}
void Universe::draw() const
{
for (auto& object: objects)
object->draw();
}
void Universe::calculateLevel(const Camera& camera)
{
// for (auto& object: objects)
// object->calculateLevel(this->camera.getPosition());
}
Universe::~Universe()
{
delete dynamicsWorld;
delete solver;
delete dispatcher;
delete collisionConfiguration;
delete broadphase;
}