@@ -38,7 +38,7 @@ public abstract class Box2DProcessing {
3838 private final float yFlip ;// = -1.0f; //flip y coordinate
3939
4040 /**
41- * Controls access to processing draw loop (via reflection)
41+ * Controls access to processing pre loop (via reflection)
4242 */
4343 private boolean isActive = false ;
4444
@@ -58,13 +58,13 @@ public Box2DProcessing(PApplet p) {
5858
5959 /**
6060 * Abstract method implement on ruby side
61+ *
6162 * @param listener Custom Listener, Sketch?
6263 */
63-
6464 public abstract void addListener (org .jbox2d .callbacks .ContactListener listener );
6565
6666 /**
67- *
67+ *
6868 * @param scale
6969 * @param gravity
7070 * @param warmStart
@@ -84,7 +84,6 @@ protected void setStep(float timeStep, int velocity, int position) {
8484 stepO = new Step (timeStep , velocity , position );
8585 }
8686
87-
8887 /**
8988 * This is the all important physics "step" function Says to move ahead one
9089 * unit in time Default
@@ -100,10 +99,9 @@ protected void step() {
10099 /**
101100 * Create a world
102101 */
103-
104102 public void createWorld () {
105- if (options == null ){
106- options = new Options ();
103+ if (options == null ) {
104+ options = new Options ();
107105 }
108106 Vec2 gravity = new Vec2 (options .gravity [0 ], options .gravity [1 ]);
109107 scaleFactor = options .scaleFactor ;
@@ -145,17 +143,14 @@ public Vec2 worldToProcessing(Vec2 world) {
145143 /**
146144 * Box2d has its own coordinate system and we have to move back and forth
147145 * between them to convert from Box2d world to processing pixel space
148- *
146+ * Note reverse Y mapping (processing poxy coord system again)
149147 * @param worldX
150148 * @param worldY
151149 * @return
152150 */
153151 public Vec2 worldToProcessing (float worldX , float worldY ) {
154- float pixelX = map (worldX , 0f , 1f , parent .width / 2 , parent .width / 2 + scaleFactor );
155- float pixelY = map (worldY , 0f , 1f , parent .height / 2 , parent .height / 2 + scaleFactor );
156- if (yFlip == -1.0f ) {
157- pixelY = map (pixelY , 0f , height , height , 0f );
158- }
152+ float pixelX = map (worldX , 0f , 1f , parent .width / 2 , parent .width / 2 + scaleFactor );
153+ float pixelY = map (worldY , 1f , 0f , parent .height / 2 , parent .height / 2 + scaleFactor );
159154 return new Vec2 (pixelX , pixelY );
160155 }
161156
@@ -170,18 +165,14 @@ public Vec2 processingToWorld(Vec2 screen) {
170165 }
171166
172167 /**
173- *
168+ * Note reverse Y mapping (processing poxy coord system again)
174169 * @param pixelX
175170 * @param pixelY
176171 * @return
177172 */
178173 public Vec2 processingToWorld (float pixelX , float pixelY ) {
179- float worldX = map (pixelX , parent .width / 2 , parent .width / 2 + scaleFactor , 0f , 1f );
180- float worldY = pixelY ;
181- if (yFlip == -1.0f ) {
182- worldY = map (pixelY , height , 0f , 0f , height );
183- }
184- worldY = map (worldY , parent .height / 2 , parent .height / 2 + scaleFactor , 0f , 1f );
174+ float worldX = map (pixelX , parent .width / 2 , parent .width / 2 + scaleFactor , 0f , 1f );
175+ float worldY = map (pixelY , parent .height / 2 , parent .height / 2 + scaleFactor , 1f , 0f );
185176 return new Vec2 (worldX , worldY );
186177 }
187178
@@ -268,8 +259,7 @@ public Joint createJoint(JointDef jd) {
268259 * @return body coord as Vec2
269260 */
270261 public Vec2 bodyCoord (Body b ) {
271- Transform xf = b .getTransform ();//b.getXForm();
272- //return coordWorldToPixels(xf.position);
262+ Transform xf = b .getTransform ();
273263 return worldToProcessing (xf .p );
274264 }
275265
@@ -282,9 +272,9 @@ public void destroyBody(Body b) {
282272 }
283273
284274 /**
285- * Access the processing draw loop by java reflection
275+ * Access the processing pre loop by java reflection
286276 */
287- public void draw () {
277+ public void pre () {
288278 step ();
289279 }
290280
@@ -320,9 +310,9 @@ private void setActive(boolean active) {
320310 isActive = active ;
321311 if (active ) {
322312 parent .registerMethod ("dispose" , this );
323- parent .registerMethod ("draw " , this );
313+ parent .registerMethod ("pre " , this );
324314 } else {
325- parent .unregisterMethod ("draw " , this );
315+ parent .unregisterMethod ("pre " , this );
326316 }
327317 }
328318 }
0 commit comments