-
Notifications
You must be signed in to change notification settings - Fork 0
/
Implied.cpp
70 lines (59 loc) · 1.57 KB
/
Implied.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
#pragma once
#include "Simulation.h"
#include "helpers.h"
#include "rand.h"
SIM(Implied, "implied")
{
b2Body* circle;
b2Body* circle2;
std::list<b2Body*> bodies;
b2Vec2 center;
b2Vec2 dimensions;
std::string title() override {return "Implied Line";}
void initialize() override
{
center = physicsHalfDimensions();
dimensions = physicsDimensions();
world().SetGravity(b2Vec2(0, 20));
circleDef def;
def.fixtureDef.isSensor = true;
def.bodyDef.position.Set(-5, 75);
const float radius = 90;
def.shape.m_radius = radius;
def.shape.m_p.Set(-radius, -radius);
circle = make_shape(world(), def);
const float radius2 = 20;
def.shape.m_radius = radius2;
def.shape.m_p.Set(-radius2, -radius2);
circle2 = make_shape(world(), def);
}
void think(unsigned long frame) override
{
auto pred = [this](b2Body* body)
{
return body->GetPosition().y > (dimensions.y * 1.5);
};
bodies.remove_if(pred);
if(frame % 3 == 0)
{
polygonDef def;
def.bodyDef.angle = to_radians(randuniform(0, 360));
def.bodyDef.position.Set(center.x/2, -5);
def.bodyDef.linearVelocity.Set(
randcentered(20, 5),
randcentered(-10, 5));
def.bodyDef.angularVelocity = to_radians(randcentered(0, 10));
def.bodyDef.type = b2_dynamicBody;
def.fixtureDef.isSensor = true;
def.fixtureDef.density = 1;
def.shape.SetAsBox(1, 5);
bodies.push_front(make_shape(world(), def));
}
}
void render() override
{
drawBodies(bodies, sf::Color::Black, sf::Color::White, -1);
drawBody(*circle, sf::Color::White, sf::Color::Black, 0);
drawBody(*circle2);
}
};