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);
}
}
}
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);
}
}
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]
