-
Notifications
You must be signed in to change notification settings - Fork 0
/
Trivial3DSenario.cpp
62 lines (50 loc) · 1.5 KB
/
Trivial3DSenario.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
#include "Trivial3DSenario.h"
REGISTER_SIMULATION(Trivial3DSenario, "trivial3d");
#include "helpers.h"
void Trivial3DSenario::initialize()
{
sideWorld.SetGravity(b2Vec2(0, 20));
sf::Vector2f w_center(windowHalfDimensions());
backPlane = VanishPlane::backPlane(w_center, 0);
floorPlane = VanishPlane::floorPlane(w_center, 0);
sidePlane = VanishPlane::sidePlane(w_center, 0);
auto p_center = physicsHalfDimensions();
polygonDef def;
def.bodyDef.position.Set(0, 50);
def.bodyDef.angle = 0;
def.bodyDef.type = b2_dynamicBody;
def.bodyDef.angularVelocity = 5;
def.bodyDef.linearVelocity.Set(20, -10);
def.shape.SetAsBox(5, 5);
def.fixtureDef.density = 1;
sideBodies.push_back(make_shape(sideWorld, def));
polygonDef def2;
def2.bodyDef.position.Set(50, 100);
def2.bodyDef.angle = 0;
def2.bodyDef.type = b2_staticBody;
def2.shape.SetAsBox(50, 5);
def2.fixtureDef.density = 1;
sideBodies.push_back(make_shape(sideWorld, def2));
}
void Trivial3DSenario::think(unsigned long frame)
{
floorWorld.Step(
simParams().inv_frame_rate,
simParams().velocityIterations,
simParams().positionIterations);
sideWorld.Step(
simParams().inv_frame_rate,
simParams().velocityIterations,
simParams().positionIterations);
backWorld.Step(
simParams().inv_frame_rate,
simParams().velocityIterations,
simParams().positionIterations);
sidePlane.intersect += 5;
}
void Trivial3DSenario::render()
{
drawBodies(floorBodies, floorPlane);
drawBodies(sideBodies, sidePlane);
drawBodies(backBodies, backPlane);
}