diff --git a/core/src/processing/opengl/PGraphics2D.java b/core/src/processing/opengl/PGraphics2D.java index fbb8779e3..18df3b2a6 100644 --- a/core/src/processing/opengl/PGraphics2D.java +++ b/core/src/processing/opengl/PGraphics2D.java @@ -119,8 +119,11 @@ public class PGraphics2D extends PGraphicsOpenGL { @Override protected void defaultPerspective() { -// super.ortho(width/2f, (3f/2f) * width, -height/2f, height/2f, -1, +1); - super.ortho(0, width, 0, height, -1, +1); + // The camera part of the modelview is simply the identity matrix, so in + // order to the ortho projection to be consistent with this, it needs to be + // set as follows, because ortho() will shift the viewing rectangle at + // (width/2, height/2) and will also apply the axis inversion along Y: + super.ortho(width/2f, (3f/2f) * width, -height/2f, height/2f, -1, +1); } @@ -157,8 +160,7 @@ public class PGraphics2D extends PGraphicsOpenGL { @Override protected void defaultCamera() { - super.camera(width/2f, height/2f); -// resetMatrix(); + resetMatrix(); } @@ -182,11 +184,6 @@ public class PGraphics2D extends PGraphicsOpenGL { popProjection(); } - @Override - public void resetMatrix() { - super.resetMatrix(); - defaultCamera(); - } ////////////////////////////////////////////////////////////// diff --git a/core/src/processing/opengl/PGraphics3D.java b/core/src/processing/opengl/PGraphics3D.java index 43aa52251..38b3e775d 100644 --- a/core/src/processing/opengl/PGraphics3D.java +++ b/core/src/processing/opengl/PGraphics3D.java @@ -87,7 +87,20 @@ public class PGraphics3D extends PGraphicsOpenGL { pushProjection(); ortho(0, width, 0, height, -1, +1); pushMatrix(); - camera(width/2, height/2); + + // Set camera for 2D rendering, it simply centers at (width/2, height/2) + float centerX = width/2; + float centerY = height/2; + modelview.reset(); + modelview.translate(-centerX, -centerY); + + modelviewInv.set(modelview); + modelviewInv.invert(); + + camera.set(modelview); + cameraInv.set(modelviewInv); + + updateProjmodelview(); } diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index cb5aab67f..e174b3254 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -2508,7 +2508,7 @@ public class PGraphicsOpenGL extends PGraphics { // an 'in-place' implementation of quick I whipped together late at night // based off of the algorithm found on wikipedia: http://en.wikipedia.org/wiki/Quicksort private void quickSortTris(int leftI, int rightI) { - if(leftI < rightI) { + if (leftI < rightI) { int pivotIndex = (leftI + rightI)/2; int newPivotIndex = partition(leftI,rightI,pivotIndex); quickSortTris(leftI, newPivotIndex-1); @@ -4390,21 +4390,6 @@ public class PGraphicsOpenGL extends PGraphics { } - // Sets a camera for 2D rendering, which only involves centering - public void camera(float centerX, float centerY) { - modelview.reset(); - modelview.translate(-centerX, -centerY); - - modelviewInv.set(modelview); - modelviewInv.invert(); - - camera.set(modelview); - cameraInv.set(modelviewInv); - - updateProjmodelview(); - } - - /** * Print the current camera matrix. */ @@ -4453,6 +4438,9 @@ public class PGraphicsOpenGL extends PGraphics { public void ortho(float left, float right, float bottom, float top, float near, float far) { + // Translating the origin to (widht/2, height/2) since the matrix math + // below assumes the center of the screen to be (0, 0), but in Processing + // it is (w/2, h/2). left -= width/2f; right -= width/2f; bottom -= height/2f;