-
Notifications
You must be signed in to change notification settings - Fork 0
/
Glue.pde
65 lines (51 loc) · 2.02 KB
/
Glue.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
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
// =============================================
// CLASS GLUE (from the Muscular Model Framework)
// by Guillem Benavent (Updated: 3/7/2023)
// For Research Project at Taradell School
// =============================================
// A Glue uses a Box2D WeldJoint to glue two two bodies together, usually bones.
// It joins two bodies by their center points displaced some offset (default value 0,0).
// And it's displayed as a red line between their centers (?).
// =============================================
class Glue
{
color GLUE_COLOR = color(255, 0, 0);
// Glue Properties
WeldJoint weldJoint;
String name;
Glue(Body bodyA, Body bodyB)
{
this(new String("Unknown Glue Joint #"), bodyA, bodyB);
}
Glue(String name, Body bodyA, Body bodyB)
{
this(name, bodyA, bodyB, new Vec2(0,0));
}
Glue(Body bodyA, Body bodyB, Vec2 relativePosition)
{
this(new String("Unknown Glue Joint #"), bodyA, bodyB, relativePosition);
}
Glue(String name, Body bodyA, Body bodyB, Vec2 relativePosition)
{
this.name = name;
WeldJointDef glueDef = new WeldJointDef();
glueDef.initialize(bodyA, bodyB, relativePosition);
//glueDef.bodyA = ulna.body;
//glueDef.bodyB = radius.body;
//glueDef.localAnchorA = new Vec2(+HUMERUS_LENGTH/2, -offsetUlnaY);
//glueDef.localAnchorB = new Vec2(-ULNA_LENGTH/2, 0);
weldJoint = (WeldJoint) box2d.world.createJoint(glueDef);
}
void display(float displayScale) {
// TODO: The glue is not displayed (no idea about how to show it)
Vec2 posA = new Vec2(0,0);
Vec2 posB = new Vec2(0,0);
weldJoint.getAnchorA(posA);
weldJoint.getAnchorB(posB);
Vec2 pixA = new Vec2(box2d.coordWorldToPixels(posA.x*displayScale, posA.y*displayScale));
Vec2 pixB = new Vec2(box2d.coordWorldToPixels(posB.x*displayScale, posB.y*displayScale));
fill(GLUE_COLOR);
stroke(128);
line(pixA.x, pixA.y, pixB.x, pixB.y);
}
}