From 6f8700731d299d061b084baf376cfce3d4039185 Mon Sep 17 00:00:00 2001 From: codeanticode Date: Tue, 2 Jun 2015 15:27:08 -0400 Subject: [PATCH] bounds of orthographics projection region are relative to viewport center, so it follows gluOrtho() --- core/src/processing/opengl/PGraphics2D.java | 2 +- core/src/processing/opengl/PGraphics2D2X.java | 2 +- .../processing/opengl/PGraphicsOpenGL.java | 48 ++++++++----------- 3 files changed, 21 insertions(+), 31 deletions(-) diff --git a/core/src/processing/opengl/PGraphics2D.java b/core/src/processing/opengl/PGraphics2D.java index 779f86e9d..cb61d131c 100644 --- a/core/src/processing/opengl/PGraphics2D.java +++ b/core/src/processing/opengl/PGraphics2D.java @@ -151,7 +151,7 @@ public class PGraphics2D extends PGraphicsOpenGL { @Override protected void defaultCamera() { - cameraEyeX = cameraEyeY = cameraEyeZ = 0; + eyeDist = 1; resetMatrix(); } diff --git a/core/src/processing/opengl/PGraphics2D2X.java b/core/src/processing/opengl/PGraphics2D2X.java index 9fe8c72d4..73c1f9589 100644 --- a/core/src/processing/opengl/PGraphics2D2X.java +++ b/core/src/processing/opengl/PGraphics2D2X.java @@ -156,7 +156,7 @@ public class PGraphics2D2X extends PGraphicsOpenGL { @Override protected void defaultCamera() { - cameraEyeX = cameraEyeY = cameraEyeZ = 0; + eyeDist = 1; resetMatrix(); } diff --git a/core/src/processing/opengl/PGraphicsOpenGL.java b/core/src/processing/opengl/PGraphicsOpenGL.java index 34dbf8e03..ba595855d 100644 --- a/core/src/processing/opengl/PGraphicsOpenGL.java +++ b/core/src/processing/opengl/PGraphicsOpenGL.java @@ -218,8 +218,8 @@ public class PGraphicsOpenGL extends PGraphics { /** Aspect ratio of camera's view. */ public float cameraAspect; - /** Actual position of the camera. */ - protected float cameraEyeX, cameraEyeY, cameraEyeZ; + /** Distance between camera eye and center. */ + protected float eyeDist; /** Flag to indicate that we are inside beginCamera/endCamera block. */ protected boolean manipulatingCamera; @@ -4559,15 +4559,12 @@ public class PGraphicsOpenGL extends PGraphics { float z0 = eyeX - centerX; float z1 = eyeY - centerY; float z2 = eyeZ - centerZ; - float mag = PApplet.sqrt(z0 * z0 + z1 * z1 + z2 * z2); - if (nonZero(mag)) { - z0 /= mag; - z1 /= mag; - z2 /= mag; + eyeDist = PApplet.sqrt(z0 * z0 + z1 * z1 + z2 * z2); + if (nonZero(eyeDist)) { + z0 /= eyeDist; + z1 /= eyeDist; + z2 /= eyeDist; } - cameraEyeX = eyeX; - cameraEyeY = eyeY; - cameraEyeZ = eyeZ; // Calculating Y vector float y0 = upX; @@ -4586,18 +4583,18 @@ public class PGraphicsOpenGL extends PGraphics { // Cross product gives area of parallelogram, which is < 1.0 for // non-perpendicular unit-length vectors; so normalize x, y here: - mag = PApplet.sqrt(x0 * x0 + x1 * x1 + x2 * x2); - if (nonZero(mag)) { - x0 /= mag; - x1 /= mag; - x2 /= mag; + float xmag = PApplet.sqrt(x0 * x0 + x1 * x1 + x2 * x2); + if (nonZero(xmag)) { + x0 /= xmag; + x1 /= xmag; + x2 /= xmag; } - mag = PApplet.sqrt(y0 * y0 + y1 * y1 + y2 * y2); - if (nonZero(mag)) { - y0 /= mag; - y1 /= mag; - y2 /= mag; + float ymag = PApplet.sqrt(y0 * y0 + y1 * y1 + y2 * y2); + if (nonZero(ymag)) { + y0 /= ymag; + y1 /= ymag; + y2 /= ymag; } modelview.set(x0, x1, x2, 0, @@ -4645,7 +4642,7 @@ public class PGraphicsOpenGL extends PGraphics { */ @Override public void ortho() { - ortho(0, width, 0, height, 0, cameraEyeZ * 10); + ortho(-width/2f, width/2f, -height/2f, height/2f, 0, eyeDist * 10); } @@ -4656,7 +4653,7 @@ public class PGraphicsOpenGL extends PGraphics { @Override public void ortho(float left, float right, float bottom, float top) { - ortho(left, right, bottom, top, 0, cameraEyeZ * 10); + ortho(left, right, bottom, top, 0, eyeDist * 10); } @@ -4672,13 +4669,6 @@ public class PGraphicsOpenGL extends PGraphics { float h = top - bottom; float d = far - near; - // Applying the camera translation (only on x and y, as near and far - // are given as distances from the viewer) - left -= cameraEyeX; - right -= cameraEyeX; - bottom -= cameraEyeY; - top -= cameraEyeY; - // Flushing geometry with a different perspective configuration. flush();