Skip to content

Commit fc581e0

Browse files
committed
added intersectsPlane implementation
1 parent b27d212 commit fc581e0

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ public class VRGraphics extends PGraphics3D {
6969
private PVector origInObjCoord = new PVector();
7070
private PVector hitInObjCoord = new PVector();
7171
private PVector dirInObjCoord = new PVector();
72+
private PVector origInWorldCoord = new PVector();
73+
private PVector dirInWorldCoord = new PVector();
7274

7375
@Override
7476
protected PGL createPGL(PGraphicsOpenGL pg) {
@@ -299,8 +301,6 @@ protected boolean lineIntersectsAABB(PVector orig, PVector dir, float w, float h
299301
}
300302

301303

302-
303-
304304
@Override
305305
public PVector intersectsPlane(float screenX, float screenY) {
306306
ray = getRayFromScreen(screenX, screenY, ray);
@@ -310,8 +310,19 @@ public PVector intersectsPlane(float screenX, float screenY) {
310310

311311
@Override
312312
public PVector intersectsPlane(PVector origin, PVector direction) {
313-
showMissingWarning("intersectsPlane");
314-
return null;
313+
modelview.mult(origin, origInWorldCoord);
314+
modelview.mult(direction, dirInWorldCoord);
315+
316+
// Ray-plane intersection algorithm
317+
PVector w = new PVector(-origInWorldCoord.x, -origInWorldCoord.y, -origInWorldCoord.z);
318+
float d = PApplet.abs(dirInWorldCoord.z * dirInWorldCoord.z);
319+
320+
if (d == 0) return null;
321+
322+
float k = PApplet.abs((w.z * w.z)/d);
323+
PVector p = PVector.add(origInWorldCoord, dirInWorldCoord).setMag(k);
324+
325+
return p;
315326
}
316327

317328

0 commit comments

Comments
 (0)