Bug fix for OBB Ray Intersection

I fixed a bug in OrientedBoundingBox.intersectsWhere(). The code there was the same as BoundingBox.intersectsWhere(), and it needed to transform the ray into box coordinates before using the existing code to test against the box planes. I added a test to BoundsTest that is fixed by my change.



I'm not a regular contributor to jme and I'm not working on any improvements to the framework. Does someone want to just submit this change for me? If not, I'm happy to submit the change myself, I just need the necessary permissions. If you have written instructions for submitting that would also be helpful.



New code:

[pre]

    public IntersectionRecord intersectsWhere(Ray ray) {

        // convert ray to box coordinates

        Vector3f diff = _compVect1.set(ray.origin).subtractLocal(center);

        diff.set(xAxis.dot(diff), yAxis.dot(diff), zAxis.dot(diff));

        Vector3f direction = _compVect2.set(xAxis.dot(ray.direction),

            yAxis.dot(ray.direction), zAxis.dot(ray.direction));



        float[] t = { 0f, Float.POSITIVE_INFINITY };



        // existing code below…

[/pre]



New test:

[pre]

    public void testRayOBBIntersection() {

      OrientedBoundingBox obb = new OrientedBoundingBox();

      obb.setCenter( Vector3f.ZERO );

      obb.setExtent( Vector3f.UNIT_XYZ );

      Quaternion rotation = new Quaternion();

      rotation.fromAngleAxis( FastMath.PI / 4, Vector3f.UNIT_Z );

      obb.transform( rotation, Vector3f.ZERO, Vector3f.UNIT_XYZ, obb);

     

      Ray ray = new Ray( new Vector3f(1, -10, 0), Vector3f.UNIT_Y );

     

      assertTrue( obb.intersects(ray) );

      IntersectionRecord record = obb.intersectsWhere( ray );

      assertEquals( 2, record.getQuantity() );

    }

[/pre]


I just encountered this same issue, and the proposed fix did the trick. Why hasn't this been merged into the official trunk?

Okay thanks. I committed it.