-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWaveMachine.h
63 lines (53 loc) · 1.51 KB
/
WaveMachine.h
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
#pragma once
#include "SceneBase.h"
class WaveMachine : public SceneBase {
public:
virtual void setup(b2World* world, b2ParticleSystem* particleSystem, const OP_Inputs* inputs) override {
b2Body* ground = NULL;
{
b2BodyDef bd;
ground = world->CreateBody(&bd);
}
{
b2BodyDef bd;
bd.type = b2_dynamicBody;
bd.allowSleep = false;
bd.position.Set(0.0f, 1.0f);
b2Body* body = world->CreateBody(&bd);
b2PolygonShape shape;
shape.SetAsBox(0.05f, 1.0f, b2Vec2(2.0f, 0.0f), 0.0);
body->CreateFixture(&shape, 5.0f);
shape.SetAsBox(0.05f, 1.0f, b2Vec2(-2.0f, 0.0f), 0.0);
body->CreateFixture(&shape, 5.0f);
shape.SetAsBox(2.0f, 0.05f, b2Vec2(0.0f, 1.0f), 0.0);
body->CreateFixture(&shape, 5.0f);
shape.SetAsBox(2.0f, 0.05f, b2Vec2(0.0f, -1.0f), 0.0);
body->CreateFixture(&shape, 5.0f);
b2RevoluteJointDef jd;
jd.bodyA = ground;
jd.bodyB = body;
jd.localAnchorA.Set(0.0f, 1.0f);
jd.localAnchorB.Set(0.0f, 0.0f);
jd.referenceAngle = 0.0f;
jd.motorSpeed = 0.05f * b2_pi;
jd.maxMotorTorque = 1e7f;
jd.enableMotor = true;
_joint = (b2RevoluteJoint*)world->CreateJoint(&jd);
}
{
b2ParticleGroupDef pd;
b2PolygonShape shape;
shape.SetAsBox(0.9f, 0.9f, b2Vec2(0.0f, 1.0f), 0.0);
pd.shape = &shape;
b2ParticleGroup* const group = particleSystem->CreateParticleGroup(pd);
}
_time = 0;
}
virtual void update(float dt) {
_time += dt;
_joint->SetMotorSpeed(0.05f * cosf(_time) * b2_pi);
}
private:
b2RevoluteJoint* _joint;
float32 _time;
};