-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoundaryEdge.pde
More file actions
43 lines (37 loc) · 1.27 KB
/
BoundaryEdge.pde
File metadata and controls
43 lines (37 loc) · 1.27 KB
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
class BoundaryEdge {
Body boundaryBody;
Vec2 startPoint,endPoint;
// Constructor
BoundaryEdge (Vec2 startPoint, Vec2 endPoint) {
this.startPoint = startPoint;
this.endPoint = endPoint;
//Body defination and body.
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyType.STATIC;
//bodyDef.position.set(box2d.vectorPixelsToWorld(center)); // not working.
float distance = dist(startPoint.x,startPoint.y,endPoint.x,endPoint.y);
bodyDef.position.set(box2d.coordPixelsToWorld(startPoint.x + distance/2,startPoint.y));
boundaryBody = box2d.createBody(bodyDef);
//Shape
EdgeShape edge = new EdgeShape();
edge.set(box2d.coordPixelsToWorld(startPoint.x, startPoint.y), box2d.coordPixelsToWorld(endPoint.x, endPoint.y));
//Fixture
boundaryBody.createFixture(edge, 1.0);
}
// Drawing the edge
void display() {
Vec2 localCenter = boundaryBody.getPosition();
pushStyle();
fill(#4D56F0);
stroke(1);
line(startPoint.x,startPoint.y,endPoint.x,endPoint.y);
popStyle();
pushStyle();
strokeWeight(8);
stroke(255, 0, 0);
//point(centerPoint.x, centerPoint.y);
Vec2 loc = box2d.coordWorldToPixels(localCenter);
point(loc.x, loc.y);
popStyle();
}
}