Page 1 of 1

Retrieving raycast collision point from LocalRayResult

Posted: Fri Aug 05, 2011 7:53 pm
by Starfox
How can I get the point (in world coordinates) where the ray cast hit the object from the LocalRayResult struct?

Re: Retrieving raycast collision point from LocalRayResult

Posted: Sun Apr 14, 2013 10:51 pm
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);
myTriangleIndexVertexArray.getScaling(scale);
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.