@@ -69,6 +69,8 @@ public class VRGraphics extends PGraphics3D {
69
69
private PVector origInObjCoord = new PVector ();
70
70
private PVector hitInObjCoord = new PVector ();
71
71
private PVector dirInObjCoord = new PVector ();
72
+ private PVector origInWorldCoord = new PVector ();
73
+ private PVector dirInWorldCoord = new PVector ();
72
74
73
75
@ Override
74
76
protected PGL createPGL (PGraphicsOpenGL pg ) {
@@ -299,8 +301,6 @@ protected boolean lineIntersectsAABB(PVector orig, PVector dir, float w, float h
299
301
}
300
302
301
303
302
-
303
-
304
304
@ Override
305
305
public PVector intersectsPlane (float screenX , float screenY ) {
306
306
ray = getRayFromScreen (screenX , screenY , ray );
@@ -310,8 +310,19 @@ public PVector intersectsPlane(float screenX, float screenY) {
310
310
311
311
@ Override
312
312
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 ;
315
326
}
316
327
317
328
0 commit comments