Retrieving raycast collision point from LocalRayResult

Post Reply
Posts: 37
Joined: Wed Jul 27, 2011 12:01 am

Retrieving raycast collision point from LocalRayResult

Post by Starfox »

How can I get the point (in world coordinates) where the ray cast hit the object from the LocalRayResult struct?
Posts: 5
Joined: Tue Nov 20, 2012 11:04 pm

Re: Retrieving raycast collision point from LocalRayResult

Post by byte56 »

A little old... but for you future visitors:

You'll need the collisionObject, and the localShapeInfo. Depending on how you have things set up, you need to be able to access the TriangleIndexVertexArray object that defines your triangle mesh. I stored mine in my object, and use the collisionObject user pointer to point to it.

From the localShapeInfo you can access the subPart and the triangleIndex. Use that info with your TriangleIndexVertexArray to find the specific collision triangle in the following way:

Code: Select all

VertexData data = myTriangleIndexVertexArray.getLockedReadOnlyVertexIndexBase(subPartIndex);
Vector3f scale = new Vector3f(1,1,1);
Vector3f[] triangle = new Vector3f[]{new Vector3f(), new Vector3f(), new Vector3f()};
data.getTriangle(triangleIndex*3, scale, triangle);
Now the triangle array will contain the points that make up the triangle that's been intersected with.

As far as I know to get the exact collision position, you'll have to do a ray/triangle collision test on your own.
Post Reply