-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathObject.pde
More file actions
78 lines (54 loc) · 1.49 KB
/
Object.pde
File metadata and controls
78 lines (54 loc) · 1.49 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
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
71
72
73
74
75
76
77
78
abstract class Object{
Body body;
PVector location;
float mass;
PVector objColour;
boolean isDestroyed;
Object(float x, float y, float m, PVector c){
mass = m;
objColour = c.get();
}
void update(){
}
void display(){
Vec2 pos = getPos();
pushMatrix();
translate(pos.x, pos.y);
rotate(getAngle());
stroke(objColour.x,objColour.y,objColour.z);
fill(objColour.x,objColour.y,objColour.z);
Fixture f = body.getFixtureList();
Vec2 shapePos = null;
while(f != null)
{
switch (f.getType())
{
case CIRCLE:
{
CircleShape shape = (CircleShape)f.getShape();
float r = box2d.scalarWorldToPixels(shape.m_radius);
shapePos = box2d.vectorWorldToPixels(shape.m_p);
ellipse(shapePos.x,shapePos.y,r*2,r*2);
}
}
f = f.getNext();
}
popMatrix();
}
void destroy(){
box2d.destroyBody(body);
locInGrid().remove(this);
}
Vec2 getPos(){
return box2d.getBodyPixelCoord(body);
}
float getAngle(){
return atan2(box2d.vectorWorldToPixels(body.getLinearVelocity()).y,box2d.vectorWorldToPixels(body.getLinearVelocity()).x);
}
ArrayList<Object> locInGrid(){
Vec2 loc = getPos();
if(!(loc.x < 0 || loc.x > width || loc.y < 0 || loc.y > height))
return binlatticeGrid[int(loc.x / gridRes)][int (loc.y /gridRes)];
return null;
}
}