TriangleShape RayTest method with compound bodies.
Posted: Fri Jun 01, 2012 8:57 pm
I'm performing a ray test against every triangle in a compound body in order to ignore those that are intersected but are facing away from the camera (i.e. culled)
The ray doesn't return true for triangle intersection even though the object is intersected.
Does the ray need to be transformed from world space or is the compound shape's LocalTransform not what I should be passing into the ray casting method?
Code: Select all
// Test ray against all triangles that make up the hollow object
var compoundBody = hollowObject.Entity as CompoundBody;
int numTriangles = compoundBody.Shapes.Count;
var ray = new Microsoft.Xna.Framework.Ray(cursorRay.Origin, cursorRay.Direction);
for (int t = 0; t < numTriangles; ++t)
{
RigidTransform rigidTransform = compoundBody.Shapes[t].LocalTransform;
TriangleShape tri = compoundBody.Shapes[t].Shape as TriangleShape;
RayHit triangleResults = new RayHit();
// Test ray for triangle intersection
if (tri.RayTest(ref ray, ref rigidTransform, 1000f, out triangleResults))
{
Vector3 normal = Vector3.Normalize(triangleResults.Normal);
if (Vector3.Dot(normal, game.ActiveCamera.Forward) < 0f)
{
continue;
}
else if (result != null && results[i].HitData.T < tMin)
{
// Find the closest IGrabbableObject
index = i;
o = result;
tMin = results[i].HitData.T;
}
}
}
Does the ray need to be transformed from world space or is the compound shape's LocalTransform not what I should be passing into the ray casting method?