Getting the fully transformed render meshes
by Gerald Fishel · in Torque Game Engine · 10/02/2005 (4:18 pm) · 4 replies
Hi all,
I'm working on a ray/polygon collision detection system for DTS objects, based on the render meshes rather than the collision meshes. I got it working for the most part, with one exception; the objects aren't transformed as they would be for rendering. i.e. when colliding against the healthkits, the meshes that I am getting are the base meshes, without the rotations applied.
Is there an easy way to have an object perform all required animations before getting the meshes? I tried using the TSShapeInstance::animate method first but that doesnt seem to have any effect on the Item objects, I'm guessing that's only for objects with animation sequences (but not sure).
Any ideas would be great.
Thanks
I'm working on a ray/polygon collision detection system for DTS objects, based on the render meshes rather than the collision meshes. I got it working for the most part, with one exception; the objects aren't transformed as they would be for rendering. i.e. when colliding against the healthkits, the meshes that I am getting are the base meshes, without the rotations applied.
Is there an easy way to have an object perform all required animations before getting the meshes? I tried using the TSShapeInstance::animate method first but that doesnt seem to have any effect on the Item objects, I'm guessing that's only for objects with animation sequences (but not sure).
Any ideas would be great.
Thanks
#2
Have you updated all the collision stuff to not assume convex geometry?
10/02/2005 (9:56 pm)
All the TSShapeInstsance stuff is in object space. So in cases like the Item, which can be set to rotate by actually changing its Obj->World transform, you have problems. If you want it to work properly, I suggest taking those transforms into account as well (notice there are two sets, one that is updated per tick and one that is updated per frame).Have you updated all the collision stuff to not assume convex geometry?
#3
Yes, I'm doing all of this with straight ray/triangle collision tests, so it doesn't require convex geometry. I'm leaving the existing castRay intact so nothing else should break, this castray is only used when the user toggles into a mouse selection mode, and clicks on an object. The overall goal is to determine the LOD and index of the polygon that is clicked, so that certain other calculations can be made later.
This is the basics of my castRay:
In TSStatic::castRay2 and ShapeBase::castRay2 I'm calculating the necessary detail level, and a couple other things.
fullCastRay is a function that iterates through all of the polygons in the polylist, performs a ray/tri test, and sets rayInfo->t to the nearest hit if it's closer than the existing rayInfo->t. It also sets rayInfo->face to the index of the polygon in the polylist that is collided; then here I add 'count' to it so that it is an index that can be found later for my other purposes. I also record the LOD in a new RayInfo field. It's not the most efficient hunk of code, but for it's purpose, speed isn't real important.
So considering this what would be a good way of going about taking the world transforms into account?
Thanks a bunch
10/03/2005 (12:39 am)
Hi,Yes, I'm doing all of this with straight ray/triangle collision tests, so it doesn't require convex geometry. I'm leaving the existing castRay intact so nothing else should break, this castray is only used when the user toggles into a mouse selection mode, and clicks on an object. The overall goal is to determine the LOD and index of the polygon that is clicked, so that certain other calculations can be made later.
This is the basics of my castRay:
bool TSShapeInstance::castRay2(const Point3F & a, const Point3F & b, RayInfo * rayInfo )
{
setStatics(mCurrentDetailLevel);
animate(mCurrentDetailLevel);
int count = 0;
int found = 0;
int nummeshes = mMeshObjects.size();
for (int i = 0; i < nummeshes; i++)
{
Point3F ta, tb;
ConcretePolyList polyList;
MeshObjectInstance* meshinstance = &mMeshObjects[i];
TSMesh* mesh = meshinstance->getMesh(mCurrentDetailLevel);
if (mesh)
{
MatrixF mat;
MatrixF * previousMat = meshinstance->getTransform();
if (previousMat)
{
mat = *previousMat;
mat.inverse();
mat.mulP(a,&ta);
mat.mulP(b,&tb);
}
U32 key = 0;
mesh->buildPolyList2( 0, &polyList, key );
bool raytest = fullCastRay( &polyList, ta, tb, rayInfo );
if (raytest)
{
rayInfo->face += count;
rayInfo->mLOD = mCurrentDetailLevel;
found = 1;
}
count += polyList.mPolyList.size();
}
}
return found;
}In TSStatic::castRay2 and ShapeBase::castRay2 I'm calculating the necessary detail level, and a couple other things.
fullCastRay is a function that iterates through all of the polygons in the polylist, performs a ray/tri test, and sets rayInfo->t to the nearest hit if it's closer than the existing rayInfo->t. It also sets rayInfo->face to the index of the polygon in the polylist that is collided; then here I add 'count' to it so that it is an index that can be found later for my other purposes. I also record the LOD in a new RayInfo field. It's not the most efficient hunk of code, but for it's purpose, speed isn't real important.
So considering this what would be a good way of going about taking the world transforms into account?
Thanks a bunch
#4
10/03/2005 (1:09 am)
Apply whatever transforms the renderer does, but in reverse? :) Note that the castRay code already gives you points in objectspace, as indicated by the getWorldTransform() call.
Torque Owner Josh Moore