Skip to content

Commit a9cdfab

Browse files
committed
fixed initialization of forward/right/up vectors
1 parent 78751d8 commit a9cdfab

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

core/src/processing/opengl/PGraphicsOpenGL.java

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,18 @@ public void dispose() {
341341
/** Projection matrix stack **/
342342
protected float[][] projectionStack = new float[MATRIX_STACK_DEPTH][16];
343343

344+
345+
/** Matrix that transform coordinates to the eye coordinate system **/
346+
protected PMatrix3D eyeMatrix;
347+
348+
/** Matrix that transform coordinates to the system that results from appling the modelview transformation **/
349+
protected PMatrix3D objMatrix;
350+
351+
/** Vectors defining the eye axes **/
352+
public float forwardX, forwardY, forwardZ;
353+
public float rightX, rightY, rightZ;
354+
public float upX, upY, upZ;
355+
344356
// ........................................................
345357

346358
// Lights:
@@ -520,14 +532,8 @@ public void dispose() {
520532

521533
// ........................................................
522534

523-
protected PMatrix3D eyeMatrix;
524-
protected PMatrix3D objMatrix;
535+
// Variables used in ray casting:
525536

526-
public float forwardX, forwardY, forwardZ;
527-
public float rightX, rightY, rightZ;
528-
public float upX, upY, upZ;
529-
530-
// Variables used in ray casting
531537
protected PVector[] ray;
532538
protected PVector hit = new PVector();
533539
protected PVector screen = new PVector();
@@ -4869,33 +4875,33 @@ public void camera(float eyeX, float eyeY, float eyeZ,
48694875
z2 /= eyeDist;
48704876
}
48714877

4878+
forwardX = z0;
4879+
forwardY = z1;
4880+
forwardZ = z2;
4881+
48724882
// Calculating Y vector
48734883
float y0 = upX;
48744884
float y1 = upY;
48754885
float y2 = upZ;
48764886

4887+
this.upX = upX;
4888+
this.upY = upY;
4889+
this.upZ = upZ;
4890+
48774891
// Computing X vector as Y cross Z
48784892
float x0 = y1 * z2 - y2 * z1;
48794893
float x1 = -y0 * z2 + y2 * z0;
48804894
float x2 = y0 * z1 - y1 * z0;
48814895

4896+
rightX = x0;
4897+
rightY = x1;
4898+
rightZ = x2;
4899+
48824900
// Recompute Y = Z cross X
48834901
y0 = z1 * x2 - z2 * x1;
48844902
y1 = -z0 * x2 + z2 * x0;
48854903
y2 = z0 * x1 - z1 * x0;
48864904

4887-
forwardX = 0;
4888-
forwardY = 0;
4889-
forwardZ = 1;
4890-
4891-
rightX = 1;
4892-
rightY = 0;
4893-
rightZ = 0;
4894-
4895-
this.upX = 0;
4896-
this.upY = -1;
4897-
this.upZ = 0;
4898-
48994905
// Cross product gives area of parallelogram, which is < 1.0 for
49004906
// non-perpendicular unit-length vectors; so normalize x, y here:
49014907
float xmag = PApplet.sqrt(x0 * x0 + x1 * x1 + x2 * x2);

0 commit comments

Comments
 (0)