Skip to content

Commit

Permalink
correct implementation of setPosition in VRCamera
Browse files Browse the repository at this point in the history
  • Loading branch information
codeanticode committed Nov 4, 2019
1 parent b9537e5 commit d39a4a9
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions mode/libraries/vr/src/processing/vr/VRCamera.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@
package processing.vr;

import processing.core.PApplet;
import processing.core.PMatrix3D;
import processing.core.PVector;

public class VRCamera {
protected PApplet parent;
protected VRGraphics graphics;
protected PVector pos = new PVector();
protected PMatrix3D eyeMat;

public VRCamera(PApplet parent) {
if (parent.g instanceof VRGraphics) {
Expand All @@ -49,14 +50,11 @@ public void noSticky() {
}

public void setPosition(float x, float y, float z) {
if (pos.x != x || pos.y != y || pos.z != z) {
graphics.beginCamera();
// Eliminate previous position from matrix stack by applying inverse transformation.
graphics.translate(-pos.x, -pos.y, -pos.z);
pos.set(-x, -y, -z);
graphics.translate(pos.x, pos.y, pos.z);
graphics.endCamera();
}
eyeMat = graphics.getEyeMatrix(eyeMat);
float x0 = eyeMat.m03;
float y0 = eyeMat.m13;
float z0 = eyeMat.m23;
graphics.translate(x0 - x, y0 - y, z0 - z);
}

public void setNear(float near) {
Expand Down

0 comments on commit d39a4a9

Please sign in to comment.