Skip to content

Commit e0b1b87

Browse files
committed
bounds of orthographics projection region are relative to viewport
center, so it follows gluOrtho()
1 parent 78e78b5 commit e0b1b87

File tree

3 files changed

+21
-31
lines changed

3 files changed

+21
-31
lines changed

core/src/processing/opengl/PGraphics2D.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ public void camera(float eyeX, float eyeY, float eyeZ,
151151

152152
@Override
153153
protected void defaultCamera() {
154-
cameraEyeX = cameraEyeY = cameraEyeZ = 0;
154+
eyeDist = 1;
155155
resetMatrix();
156156
}
157157

core/src/processing/opengl/PGraphics2D2X.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public void camera(float eyeX, float eyeY, float eyeZ,
156156

157157
@Override
158158
protected void defaultCamera() {
159-
cameraEyeX = cameraEyeY = cameraEyeZ = 0;
159+
eyeDist = 1;
160160
resetMatrix();
161161
}
162162

core/src/processing/opengl/PGraphicsOpenGL.java

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ public class PGraphicsOpenGL extends PGraphics {
218218
/** Aspect ratio of camera's view. */
219219
public float cameraAspect;
220220

221-
/** Actual position of the camera. */
222-
protected float cameraEyeX, cameraEyeY, cameraEyeZ;
221+
/** Distance between camera eye and center. */
222+
protected float eyeDist;
223223

224224
/** Flag to indicate that we are inside beginCamera/endCamera block. */
225225
protected boolean manipulatingCamera;
@@ -4559,15 +4559,12 @@ public void camera(float eyeX, float eyeY, float eyeZ,
45594559
float z0 = eyeX - centerX;
45604560
float z1 = eyeY - centerY;
45614561
float z2 = eyeZ - centerZ;
4562-
float mag = PApplet.sqrt(z0 * z0 + z1 * z1 + z2 * z2);
4563-
if (nonZero(mag)) {
4564-
z0 /= mag;
4565-
z1 /= mag;
4566-
z2 /= mag;
4562+
eyeDist = PApplet.sqrt(z0 * z0 + z1 * z1 + z2 * z2);
4563+
if (nonZero(eyeDist)) {
4564+
z0 /= eyeDist;
4565+
z1 /= eyeDist;
4566+
z2 /= eyeDist;
45674567
}
4568-
cameraEyeX = eyeX;
4569-
cameraEyeY = eyeY;
4570-
cameraEyeZ = eyeZ;
45714568

45724569
// Calculating Y vector
45734570
float y0 = upX;
@@ -4586,18 +4583,18 @@ public void camera(float eyeX, float eyeY, float eyeZ,
45864583

45874584
// Cross product gives area of parallelogram, which is < 1.0 for
45884585
// non-perpendicular unit-length vectors; so normalize x, y here:
4589-
mag = PApplet.sqrt(x0 * x0 + x1 * x1 + x2 * x2);
4590-
if (nonZero(mag)) {
4591-
x0 /= mag;
4592-
x1 /= mag;
4593-
x2 /= mag;
4586+
float xmag = PApplet.sqrt(x0 * x0 + x1 * x1 + x2 * x2);
4587+
if (nonZero(xmag)) {
4588+
x0 /= xmag;
4589+
x1 /= xmag;
4590+
x2 /= xmag;
45944591
}
45954592

4596-
mag = PApplet.sqrt(y0 * y0 + y1 * y1 + y2 * y2);
4597-
if (nonZero(mag)) {
4598-
y0 /= mag;
4599-
y1 /= mag;
4600-
y2 /= mag;
4593+
float ymag = PApplet.sqrt(y0 * y0 + y1 * y1 + y2 * y2);
4594+
if (nonZero(ymag)) {
4595+
y0 /= ymag;
4596+
y1 /= ymag;
4597+
y2 /= ymag;
46014598
}
46024599

46034600
modelview.set(x0, x1, x2, 0,
@@ -4645,7 +4642,7 @@ protected void defaultCamera() {
46454642
*/
46464643
@Override
46474644
public void ortho() {
4648-
ortho(0, width, 0, height, 0, cameraEyeZ * 10);
4645+
ortho(-width/2f, width/2f, -height/2f, height/2f, 0, eyeDist * 10);
46494646
}
46504647

46514648

@@ -4656,7 +4653,7 @@ public void ortho() {
46564653
@Override
46574654
public void ortho(float left, float right,
46584655
float bottom, float top) {
4659-
ortho(left, right, bottom, top, 0, cameraEyeZ * 10);
4656+
ortho(left, right, bottom, top, 0, eyeDist * 10);
46604657
}
46614658

46624659

@@ -4672,13 +4669,6 @@ public void ortho(float left, float right,
46724669
float h = top - bottom;
46734670
float d = far - near;
46744671

4675-
// Applying the camera translation (only on x and y, as near and far
4676-
// are given as distances from the viewer)
4677-
left -= cameraEyeX;
4678-
right -= cameraEyeX;
4679-
bottom -= cameraEyeY;
4680-
top -= cameraEyeY;
4681-
46824672
// Flushing geometry with a different perspective configuration.
46834673
flush();
46844674

0 commit comments

Comments
 (0)