Skip to content

Commit d39a4a9

Browse files
committed
correct implementation of setPosition in VRCamera
1 parent b9537e5 commit d39a4a9

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

mode/libraries/vr/src/processing/vr/VRCamera.java

+7-9
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@
2323
package processing.vr;
2424

2525
import processing.core.PApplet;
26+
import processing.core.PMatrix3D;
2627
import processing.core.PVector;
2728

2829
public class VRCamera {
2930
protected PApplet parent;
3031
protected VRGraphics graphics;
31-
protected PVector pos = new PVector();
32+
protected PMatrix3D eyeMat;
3233

3334
public VRCamera(PApplet parent) {
3435
if (parent.g instanceof VRGraphics) {
@@ -49,14 +50,11 @@ public void noSticky() {
4950
}
5051

5152
public void setPosition(float x, float y, float z) {
52-
if (pos.x != x || pos.y != y || pos.z != z) {
53-
graphics.beginCamera();
54-
// Eliminate previous position from matrix stack by applying inverse transformation.
55-
graphics.translate(-pos.x, -pos.y, -pos.z);
56-
pos.set(-x, -y, -z);
57-
graphics.translate(pos.x, pos.y, pos.z);
58-
graphics.endCamera();
59-
}
53+
eyeMat = graphics.getEyeMatrix(eyeMat);
54+
float x0 = eyeMat.m03;
55+
float y0 = eyeMat.m13;
56+
float z0 = eyeMat.m23;
57+
graphics.translate(x0 - x, y0 - y, z0 - z);
6058
}
6159

6260
public void setNear(float near) {

0 commit comments

Comments
 (0)