BSP Collision problem

Problems building or running the engine, queries about how to use features etc.
Sanchez108
Gnoblar
Posts: 10
Joined: Thu Dec 02, 2004 9:03 pm
Location: West Chester, PA

BSP Collision problem

Post by Sanchez108 »

Hello all,

I'm trying to implement BSP collision using Ogre and OgreOde and I have it working by following the method in the demo in the Ogre suite, and I'm having problems with my objects passing through doorways.

The objects work fine when in a rectangular room, but when they try to pass through a doorway, they bounce off the plane geometry that they're being collided with. I've adjusted some aspects of the demo implementation of this to gel with OgreOde. Here's what I'm doing.

Code: Select all

    // Detect collisions between entities and objects
    IntersectionSceneQueryResult & results = m_pIntersectionQuery->execute();

    // Do some UserDefinedObject magic to get the BaseObject stuff we need from the result
    SceneQueryMovableWorldFragmentIntersectionList::iterator iterColPair, iterEnd;
    iterEnd = results.movables2world.end();
    for(iterColPair = results.movables2world.begin(); iterColPair != iterEnd; ++iterColPair)
    {
        // Get the object and the world fragment for this collision pair
        MovableObject * pMovObj = iterColPair->first;
        SceneQuery::WorldFragment * pFrag = iterColPair->second;
        // Get the UserDefinedObject from the moving object
        UserDefinedObject * pUserObj = pMovObj->getUserObject();
        // Only go on if we have valid object
        if(pUserObj)
        {
            CBaseObj * pObj = static_cast<CBaseObj *>(pUserObj);
            // only go on it we have valid physics for this object
            if(pObj->GetProps())
            {
                // Test for an actual collision
                LevelCollide(pObj, pFrag);
            }
        }
    }
And here's the LevelCollide function

Code: Select all

    // The space to collide
    OgreOde::SimpleSpace * pSpace = pObj->GetProps()->m_pSpace;
    // Iterators for the list of planes in the region
    std::list<Plane>::iterator iterPlane, iterPlaneEnd;
    iterPlaneEnd = pFrag->planes->end();

    float fMaxDist = -1.0f;
    const Plane * pBestPlane = 0;

    // For each plane in the region
    for(iterPlane = pFrag->planes->begin();  iterPlane != iterPlaneEnd; ++iterPlane)
    {
        Plane pBoundPlane = (*iterPlane);
        float fDist = pBoundPlane.getDistance(pObj->GetPosition());
        if(fDist >= 0.0f)
        {
            // Create an OgreOde plane to collide with
            OgreOde::InfinitePlaneGeometry pCollPlane = OgreOde::InfinitePlaneGeometry((pBoundPlane));

            pSpace->collide(&pCollPlane, this);
        }
    }
A good example of the poblem I'm experiencing is that the objects move towards the doorway, but the plane that forms either side of the door resides in the same node as the actual doorway that the object is supposed to pass through, so that plane covers the doorway, and the object bounces back into the room instead of passing through.

I'm not sure how far the BSP tree in the ogretestmap.bsp is divided, so that the ball doesn't bounce off of the planes extended from the edges of stairs.

I see two possible solutions to this problem, but I'm not sure about the feasibility or even possibility of each.

1 - Further subdivide our BSP tree so that less planes reside in each leaf.

2 - Access the vertex and index data of the map at each leaf and use them to create a TriangleMeshGeometry object and let that collide with the MovableObject.

If anyone has a way around this problem by any means, please let me know, because this is obviously a pretty major problem.

Thanks for any help that might be forthcoming.

- Alex

[Edit]
I've tested our map in the BSP Collision demo with Ogre, and none of these problems occur. I've also changed my LevelCollide function to collide plane created with the TransformGeometry for each object, rather than colliding the plane with the Space in which that object resides, and this did nothing to aleviate the bad behavior.
[/Edit]
User avatar
sinbad
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 19269
Joined: Sun Oct 06, 2002 11:19 pm
Location: Guernsey, Channel Islands
x 67

Post by sinbad »

I've tested our map in the BSP Collision demo with Ogre, and none of these problems occur.
I've also tested throwing a ball around quite a few Q3A levels and I've never had any problems throwing it through a door. All I can suggest (other than debugging your code for you, which I don't really have time for right now ;)) is that you try using our code and work slowly towards what you want to do so you can identify where the behaviour diverges.