-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRevoluteJoint.java
102 lines (75 loc) · 2.07 KB
/
RevoluteJoint.java
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import processing.core.*;
import org.jbox2d.util.nonconvex.*;
import org.jbox2d.dynamics.contacts.*;
import org.jbox2d.testbed.*;
import org.jbox2d.collision.*;
import org.jbox2d.common.*;
import org.jbox2d.dynamics.joints.*;
import org.jbox2d.p5.*;
import org.jbox2d.dynamics.*;
public class RevoluteJoint extends PApplet {
Physics physics;
public void setup() {
size(640, 480, P3D);
frameRate(60);
initScene();
initJoint();
}
public void draw() {
background(0);
if (keyPressed) {
switch(key) {
// circles
case '1':
physics.createCircle(mouseX, mouseY, random(5, 10));
break;
// rectangles
case '2':
float sz = random(5, 10);
physics.createRect(mouseX - sz, mouseY - sz, mouseX + sz,
mouseY + sz);
break;
// reset everything
default:
physics.destroy();
initScene();
break;
}
}
}
void initScene() {
float gravX = 0.0f;
float gravY = -10.0f;
float AABBWidth = 2*width;
float AABBHeight = 2*height;
float borderBoxWidth = width;
float borderBoxHeight = height;
float pixelsPerMeter = 30;
physics = new Physics(this, width, height, gravX,
gravY, AABBWidth, AABBHeight,
borderBoxWidth, borderBoxHeight,
pixelsPerMeter);
}
void initJoint() {
org.jbox2d.dynamics.Body c, d;
c = null;
d = null;
physics.setDensity(0.0f);
c = physics.createRect(295, 200, 345, 250);
physics.setDensity(1.0f);
d = physics.createCircle(320, 350, 20);
RevoluteJointDef myJoint = new RevoluteJointDef();
Vec2 myVec = new Vec2();
myJoint.body1 = c;
myJoint.body2 = d;
//myJoint.localAnchor1 = c.getLocalPoint(worldCenter);
/*
myVec.set(320, 225);
myJoint.initialize(c, d, myVec);
myJoint.enableMotor = true;
myJoint.motorSpeed = 10;
myJoint.maxMotorTorque = 200;
*/
//physics.createRevoluteJoint(c, d, 320, 225);
}
}