Problem with getCollisionResultPosition

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
Post Reply
Squarefox
Competition winner
Posts: 113
Joined: Tue Aug 19, 2008 6:46 pm
Location: Delta quadrant, Borg nexus 0001
Contact:

Problem with getCollisionResultPosition

Post by Squarefox »

Hi,

I have some problem with ISceneCollisionManager::getCollisionResultPosition.
I use a meta triangle selector for the collision
In the function, there is some parameter outNode, which should give you the colliding node.
The collision works so far, but outNode gives me the first node, I added to the meta triangle selector, every time.

Is this a bug? Can anyone help me please?

Kind regards,
Squarefox
Squarefox
Competition winner
Posts: 113
Joined: Tue Aug 19, 2008 6:46 pm
Location: Delta quadrant, Borg nexus 0001
Contact:

Re: Problem with getCollisionResultPosition

Post by Squarefox »

HI,

I just found the error. The implementation is borked.

CCollisionManager::collideWithWorld:

Code: Select all

colData.selector->getTriangles(Triangles.pointer(), totalTriangleCnt, triangleCnt, box, &scaleMatrix);
for (irr::s32 i=0; i<triangleCnt; ++i)
    if(testTriangleIntersection(&colData, Triangles[i]))
         colData.triangleIndex = i;
CCollisionManager::collideEllipsoidWithWorld

Code: Select all

if (colData.triangleHits)
{
    triout = colData.intersectionTriangle;
    triout.pointA *= colData.eRadius;
    triout.pointB *= colData.eRadius;
    triout.pointC *= colData.eRadius;
    outNode = selector->getSceneNodeForTriangle(colData.triangleIndex);
    int a = 5;
}

Code: Select all

//! Return the scene node associated with a given triangle.
ISceneNode* CMetaTriangleSelector::getSceneNodeForTriangle(u32 triangleIndex) const
{
    u32 totalTriangles = 0;
    for (u32 i=0; i<TriangleSelectors.size(); ++i)
    {
        totalTriangles += TriangleSelectors[i]->getTriangleCount();
        if(totalTriangles > triangleIndex)
            return TriangleSelectors[i]->getSceneNodeForTriangle(0);
    }
    // For lack of anything more sensible, return the first selector.
    return TriangleSelectors[0]->getSceneNodeForTriangle(0);
}
The error is that the colData.triangleIndex is used for retrieving the colliding node,
but it's only a temporary counter that comes from colData.selector->getTriangles
and has nothing to do with the index in the MetaTriangleSelector.

Kind regards,
Squarefox
CuteAlien
Admin
Posts: 9634
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: Problem with getCollisionResultPosition

Post by CuteAlien »

Sorry, not getting what's happening there so quickly. You could help if you could give me a complete examples which I can compile and use to reproduce the problem. I think CCollisionManager::collideWithWorld is not an Irrlicht function - so I know nothing about that and about which indices you are working with. Same with colData - it's not an Irrlicht structure and I know nothing about it or how you use it. testTriangleIntersection also doesn't look like an Irrlicht function. So the only thing I could go on was CMetaTriangleSelector::getSceneNodeForTriangle which on a quick look seemed correct to me - but maybe I would get the problem if I had an example which I could read.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply