Skip to content

Commit 049628c

Browse files
committed
Fixed up comments and rotation
1 parent ea341e9 commit 049628c

2 files changed

Lines changed: 72 additions & 71 deletions

File tree

api/src/main/java/com/javaphysicsengine/api/PWorld.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
public class PWorld {
2121
// Physic properties about this world
2222
private static final Vector GRAVITY = Vector.of(0, -9.81);
23-
private static final double SCALE = 1; //100;
23+
private static final double SCALE = 100;
2424

2525
// List containing the physical bodies and joints
2626
private ArrayList<PBody> bodies = new ArrayList<>();
@@ -29,24 +29,23 @@ public class PWorld {
2929
public ConcurrentLinkedQueue<Vector> pointsToDraw = new ConcurrentLinkedQueue<>();
3030

3131
/**
32-
* Post-condition: Returns the list of bodies added to the world
32+
* Returns the list of bodies added to the world
3333
* @return Returns the list of bodies added to the world
3434
*/
3535
public ArrayList<PBody> getBodies() {
3636
return bodies;
3737
}
3838

3939
/**
40-
* Post-condition: Returns the list of constraints added to the world
40+
* Returns the list of constraints added to the world
4141
* @return Returns the list of constraints added to the world
4242
*/
4343
public ArrayList<PConstraints> getConstraints() {
4444
return constraints;
4545
}
4646

4747
/**
48-
* Pre-condition: The "g" must not be null
49-
* Post-condition: Draws the bodies and constraints to the screen
48+
* Draws the bodies and constraints to the screen
5049
* @param g The Graphics Object
5150
*/
5251
public void draw(Graphics g) {
@@ -69,8 +68,7 @@ public void draw(Graphics g) {
6968
}
7069

7170
/**
72-
* Post-condition: Simulates the bodies for a certain time
73-
* Pre-condition: "timeEllapsed" should be greater than 0
71+
* Simulates the bodies for a certain time
7472
* @param timeEllapsed The time that has ellapsed in seconds
7573
*/
7674
public void simulate(double timeEllapsed) {
@@ -115,7 +113,7 @@ public void simulate(double timeEllapsed) {
115113
}
116114

117115
/**
118-
* Post-condition: Adds the forces to all the bodies
116+
* Adds the forces to all the bodies
119117
*/
120118
private void addForces() {
121119
for (PBody body : bodies) {
@@ -136,8 +134,7 @@ private void addForces() {
136134
}
137135

138136
/**
139-
* Post-condition: Translates all the bodies based on a certain time frame
140-
* Pre-condition: "timeEllapsed" should be greater than 0
137+
* Translates all the bodies based on a certain time frame
141138
* @param timeEllapsed The time that has ellapsed
142139
*/
143140
private void translateBodies(double timeEllapsed) {
@@ -249,8 +246,8 @@ private void applyImpulse(PBody body, Vector impulse, Vector contactPt) {
249246
}
250247

251248
/**
252-
* Post-condition: Moves the two bodies by a slight bit after a collision occured (to prevent gittering)
253-
* Pre-condition: "body1", "body2", "mtv" should not be null
249+
* Moves the two bodies by a slight bit after a collision occured (to prevent gittering)
250+
*
254251
* @param body1 The first body involved in the collision
255252
* @param body2 The second body involved in the collision
256253
* @param mtv The MTD of the two bodies

api/src/main/java/com/javaphysicsengine/api/PhysicsDebuggerPanel.java

Lines changed: 63 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ public PhysicsDebuggerPanel() {
4949
// pEngine.getBodies().add(polygon);
5050

5151

52-
PPolygon polygon1 = new PPolygon("Hehe1");
53-
polygon1.getVertices().add(new Vector(310, 510));
54-
polygon1.getVertices().add(new Vector(310, 600));
55-
polygon1.getVertices().add(new Vector(400, 600));
56-
polygon1.getVertices().add(new Vector(400, 510));
57-
polygon1.computeCenterOfMass();
58-
polygon1.rotate(0.174533);
59-
pEngine.getBodies().add(polygon1);
52+
// PPolygon polygon1 = new PPolygon("Hehe1");
53+
// polygon1.getVertices().add(new Vector(310, 510));
54+
// polygon1.getVertices().add(new Vector(310, 600));
55+
// polygon1.getVertices().add(new Vector(400, 600));
56+
// polygon1.getVertices().add(new Vector(400, 510));
57+
// polygon1.computeCenterOfMass();
58+
// polygon1.rotate(0.174533);
59+
// pEngine.getBodies().add(polygon1);
6060
// polygon1.rotate(0.174533);
6161

6262

@@ -126,19 +126,19 @@ public PhysicsDebuggerPanel() {
126126
// PString string2 = new PString(circle3, circle4);
127127
// pEngine.getConstraints().add(string2);
128128

129-
PPolygon triangle = new PPolygon("Triangle");
130-
triangle.setMoveable(false);
131-
triangle.getVertices().add(new Vector(600, 500));
132-
triangle.getVertices().add(new Vector(240, 240));
133-
triangle.getVertices().add(new Vector(600, 240));
134-
triangle.computeCenterOfMass();
135-
pEngine.getBodies().add(triangle);
136-
137-
PCircle circle = new PCircle("Circle");
138-
circle.setCenterPt(Vector.of(420, 640));
139-
circle.setRadius(20);
140-
circle.setMass(1);
141-
pEngine.getBodies().add(circle);
129+
// PPolygon triangle = new PPolygon("Triangle");
130+
// triangle.setMoveable(false);
131+
// triangle.getVertices().add(new Vector(600, 500));
132+
// triangle.getVertices().add(new Vector(240, 240));
133+
// triangle.getVertices().add(new Vector(600, 240));
134+
// triangle.computeCenterOfMass();
135+
// pEngine.getBodies().add(triangle);
136+
//
137+
// PCircle circle = new PCircle("Circle");
138+
// circle.setCenterPt(Vector.of(420, 640));
139+
// circle.setRadius(20);
140+
// circle.setMass(1);
141+
// pEngine.getBodies().add(circle);
142142

143143
/**
144144
* Test 1: Two boxes on top of each other
@@ -163,44 +163,48 @@ public PhysicsDebuggerPanel() {
163163
// polygon2.translate(Vector.of(0, 10));
164164
// pEngine.getBodies().add(polygon2);
165165

166-
// PCircle circle = new PCircle("Circle");
167-
// circle.setCenterPt(Vector.of(522, 440));
168-
// circle.setRadius(20);
169-
// circle.setMass(1);
170-
// pEngine.getBodies().add(circle);
171-
//
172-
// PCircle circle5 = new PCircle("Circle");
173-
// circle5.setCenterPt(Vector.of(510, 240));
174-
// circle5.setRadius(20);
175-
// circle5.setMass(1);
176-
// circle5.setVelocity(Vector.of(0, 10));
177-
// pEngine.getBodies().add(circle5);
178-
//
179-
// PPolygon polygon = new PPolygon("Box");
180-
// polygon.getVertices().add(Vector.of(300, 400));
181-
// polygon.getVertices().add(Vector.of(340, 400));
182-
// polygon.getVertices().add(Vector.of(340, 440));
183-
// polygon.getVertices().add(Vector.of(300, 440));
184-
// polygon.computeCenterOfMass();
185-
// pEngine.getBodies().add(polygon);
186-
//
187-
// for (int i = 0; i < 20; i++) {
188-
// PCircle circle2 = new PCircle("Circle2");
189-
// circle2.setMoveable(false);
190-
// circle2.setCenterPt(Vector.of(100 + 40 * i, 140));
191-
// circle2.setRadius(40);
192-
// circle2.setMass(1);
193-
// pEngine.getBodies().add(circle2);
194-
// }
195-
//
196-
// for (int i = 0; i < 20; i++) {
197-
// PCircle circle2 = new PCircle("Circle2");
198-
// circle2.setMoveable(false);
199-
// circle2.setCenterPt(Vector.of(100, 140 + 40 * i));
200-
// circle2.setRadius(40);
201-
// circle2.setMass(1);
202-
// pEngine.getBodies().add(circle2);
203-
// }
166+
/**
167+
* Test 2
168+
*/
169+
170+
PCircle circle = new PCircle("Circle");
171+
circle.setCenterPt(Vector.of(522, 440));
172+
circle.setRadius(20);
173+
circle.setMass(1);
174+
pEngine.getBodies().add(circle);
175+
176+
PCircle circle5 = new PCircle("Circle");
177+
circle5.setCenterPt(Vector.of(510, 240));
178+
circle5.setRadius(20);
179+
circle5.setMass(1);
180+
circle5.setVelocity(Vector.of(0, 10));
181+
pEngine.getBodies().add(circle5);
182+
183+
PPolygon polygon = new PPolygon("Box");
184+
polygon.getVertices().add(Vector.of(300, 400));
185+
polygon.getVertices().add(Vector.of(340, 400));
186+
polygon.getVertices().add(Vector.of(340, 440));
187+
polygon.getVertices().add(Vector.of(300, 440));
188+
polygon.computeCenterOfMass();
189+
pEngine.getBodies().add(polygon);
190+
191+
for (int i = 0; i < 20; i++) {
192+
PCircle circle2 = new PCircle("Circle2");
193+
circle2.setMoveable(false);
194+
circle2.setCenterPt(Vector.of(100 + 40 * i, 140));
195+
circle2.setRadius(40);
196+
circle2.setMass(1);
197+
pEngine.getBodies().add(circle2);
198+
}
199+
200+
for (int i = 0; i < 20; i++) {
201+
PCircle circle2 = new PCircle("Circle2");
202+
circle2.setMoveable(false);
203+
circle2.setCenterPt(Vector.of(100, 140 + 40 * i));
204+
circle2.setRadius(40);
205+
circle2.setMass(1);
206+
pEngine.getBodies().add(circle2);
207+
}
204208

205209

206210
// Create the game timer

0 commit comments

Comments
 (0)