-
Notifications
You must be signed in to change notification settings - Fork 0
/
Surface.pde
36 lines (31 loc) · 1.01 KB
/
Surface.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
class Surface{
ArrayList<Vec2> surface;
Surface(){
surface = new ArrayList<Vec2>();
surface.add(new Vec2(0, 0));
surface.add(new Vec2(-10, height-10));
surface.add(new Vec2(width+10, height-10));
surface.add(new Vec2(width+10, 0));
// surface.add(new Vec2(0, height-10));
//surface.add(new Vec2(width+10, height-10));
ChainShape chain = new ChainShape();
Vec2[] vertices = new Vec2[surface.size()];
for (int i = 0; i < vertices.length; i++) {//Convert each vertex to Box2D World coordinates.
vertices[i] = box2d.coordPixelsToWorld(surface.get(i));
}
chain.createChain(vertices, vertices.length);
BodyDef bd = new BodyDef();
Body body = box2d.world.createBody(bd);
body.createFixture(chain, 1);
}
void display(){
stroke(0);
noFill();
//Draw the ChainShape as a series of vertices.
beginShape();
for (Vec2 v: surface) {
vertex(v.x,v.y);
}
endShape();
}
}