-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBoundary.pde
40 lines (33 loc) · 896 Bytes
/
Boundary.pde
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
class Boundary {
Body body;
float w;
float h;
Boundary(float x, float y, float w_, float h_) {
w = w_;
h = h_;
BodyDef bd = new BodyDef();
bd.type = BodyType.STATIC;
bd.position.set(box2d.coordPixelsToWorld(x, y));
body = box2d.world.createBody(bd);
PolygonShape sd = new PolygonShape();
float box2dW = box2d.scalarPixelsToWorld(w/2);
float box2dH = box2d.scalarPixelsToWorld(h/2);
sd.setAsBox(box2dW, box2dH);
FixtureDef fd = new FixtureDef();
fd.shape = sd;
fd.density = 0.001;
fd.friction = 0.1;
fd.restitution = 0;
body.createFixture(fd);
}
void show() {
fill(255);
stroke(255);
Vec2 pos = box2d.getBodyPixelCoord(body);
pushMatrix();
translate(pos.x, pos.y);
rectMode(CENTER);
rect(0, 0, w, h);
popMatrix();
}
}