Collision with scaled interiors / difs
by Stefan Beffy Moises · in Torque Game Engine · 05/13/2004 (10:35 am) · 4 replies
I've never done that, but there seem to be folks who scale interiors (DIFs) in-engine/in the mission editor... this seems to screw a lot of things up, e.g. the object box isn't scaled with them and therefore (?) collision doesn't work as expected etc. - and, more important to me, the navgraph generation for our AI stuff isn't working for scaled interiors either... here is how the navmesh would look for them:

We are using the objBox of the interiors to place all nodes in object space, and as you can see, the box isnt scaled with the interior... :/
Now, I figured I could just scale the box accordingly, and I took some code from worldEditor.cc (and the help of Paul Dana - thanks dude! :)) to do this... it basically looks like this:
So far, so good... but unfortunately, this crashes the engine... I've printed out the box values and they all look good, but for some reason it just crashes while doing raycasts inside the interior to generate the Nodes...
the final crash is at interior.h, 683:

We are using the objBox of the interiors to place all nodes in object space, and as you can see, the box isnt scaled with the interior... :/
Box3F box = interiors[i]->getObjBox();
Now, I figured I could just scale the box accordingly, and I took some code from worldEditor.cc (and the help of Paul Dana - thanks dude! :)) to do this... it basically looks like this:
Box3F objBox = interiors[i]->getObjBox();
MatrixF mat = interiors[i]->getTransform();
VectorF scale = interiors[i]->getScale();
Point3F projPnts[8];
for(U32 j = 0; j < 8; j++)
{
Point3F pnt;
pnt.set(BoxPnts[j].x ? objBox.max.x : objBox.min.x,
BoxPnts[j].y ? objBox.max.y : objBox.min.y,
BoxPnts[j].z ? objBox.max.z : objBox.min.z);
// scale the point
pnt.convolve(scale);
projPnts[j] = pnt;
}
// now find min and max values for our new Box3F
Point3F min,max;
min = projPnts[0];
max = projPnts[0];
for (U32 k=0; k<8; k++)
{
if (projPnts[k].x < min.x)
min.x = projPnts[k].x;
if (projPnts[k].x > max.x)
max.x = projPnts[k].x;
if (projPnts[k].y < min.y)
min.y = projPnts[k].y;
if (projPnts[k].y > max.y)
max.y = projPnts[k].y;
if (projPnts[k].z < min.z)
min.z = projPnts[k].z;
if (projPnts[k].z > max.z)
max.z = projPnts[k].z;
}
// ok, this should hold the scaled objBox now:
Box3F box(min, max);So far, so good... but unfortunately, this crashes the engine... I've printed out the box values and they all look good, but for some reason it just crashes while doing raycasts inside the interior to generate the Nodes...
the final crash is at interior.h, 683:
inline bool Interior::isBSPLeafIndex(U16 index) constcalled from interiorCollision.cc, line 289:
bool Interior::castRay_r(const U16 node,
const U16 planeIndex,
const Point3F& s,
const Point3F& e,
RayInfo* info)the RayInfo passed in here seems to be invalid... so I guess there really are some serious collision problems with scaled interiors... does anybody have any insights on scaling interiors and collision?About the author
#2
the objBox scaling I've posted above seems to work correctly...
but later in the process, I am using:
Now, since I am passing in the correct (i.e. scaled) start and end points, but I'm still
getting either the same results as with the unscaled values (Nodes generated in the wrong places as if the interior wasn't scaled at all) OR crashes while raycasting,
I suspect Interior::castRay() using the UNSCALED interior...
Can anybody verify this? And if I'm right, is there a way to get the interior use the correct scale of the InteriorInstance for its raycasts? Or is there any other way to do raycasts INSIDE an interior (in object space)?
05/23/2004 (11:31 pm)
Hm, still investigating this...the objBox scaling I've posted above seems to work correctly...
but later in the process, I am using:
if(!interior->castRay(start, end, &ri))
{
PROFILE_END();
return;
}
Point3F worldPoint = ri.point;
interior->getTransform().mulP(worldPoint);InteriorInstance::castRay() falls back on Interior::castRay() by calling if (mInteriorRes->getDetailLevel(0)->castRay(s, e, info))
Now, since I am passing in the correct (i.e. scaled) start and end points, but I'm still
getting either the same results as with the unscaled values (Nodes generated in the wrong places as if the interior wasn't scaled at all) OR crashes while raycasting,
I suspect Interior::castRay() using the UNSCALED interior...
Can anybody verify this? And if I'm right, is there a way to get the interior use the correct scale of the InteriorInstance for its raycasts? Or is there any other way to do raycasts INSIDE an interior (in object space)?
#3
InteriorInstance is scaled and Interior, which is a singleton, is not.
-John
05/24/2004 (3:42 am)
Hi Beffy,InteriorInstance is scaled and Interior, which is a singleton, is not.
-John
#4
Thank god I was able to solve this differently, so I dont need to mess with it anymore ;)
05/24/2004 (3:51 am)
Ah, thx John, that's what I was expecting... so no wonder it doesnt work this way - the Interior raycasts will always go bogus with positions from a scaled interiorInstance since the values just dont match.... isnt that an engine bug then since as soon as you scale an instance castRay will never work correctly?Thank god I was able to solve this differently, so I dont need to mess with it anymore ;)
Associate Kyle Carter