#include "OgreOdePrecompiledHeaders.h" #include "OgreOdeWorld.h" #include "OgreOdeBody.h" #include "OgreOdeJoint.h" #include "OgreOdeGeometry.h" #include "OgreOdeSpace.h" #include "OgreOdeDebugObject.h" using namespace OgreOde; using namespace Ogre; CollisionListener* World::_collision_listener = 0; //------------------------------------------------------------------------------------------------ void World::setCollisionListener(CollisionListener* collision_listener) { _collision_listener = collision_listener; } //------------------------------------------------------------------------------------------------ CollisionListener* World::getCollisionListener() { return _collision_listener; } //------------------------------------------------------------------------------------------------ World::World(SceneManager* manager) : _show_debug_geoms (false), _show_debug_contact (false), _manager (manager) { #if ODE_VERSION_MINOR > 9 dInitODE2(0); dAllocateODEDataForThread(dAllocateMaskAll); #endif _world = dWorldCreate(); _contacts = dJointGroupCreate(0); _default_space = new HashTableSpace(this); _default_space->setAutoCleanup(false); _default_space->setInternalCollisions(true); setDamping(0.0,0.0); setHistorySize (1); } //------------------------------------------------------------------------------------------------ void World::setHistorySize(size_t historySize) { _history_size = historySize; MaintainedItemIterator
it = _body_list.getIterator(); while(!it.end ()) { Body * const b = (Body *) (it.getNext ()); b->_historyResize(historySize); } } //------------------------------------------------------------------------------------------------ size_t World::getHistorySize() const { return _history_size; } //------------------------------------------------------------------------------------------------ void World::setGravity(const Ogre::Vector3& gravity) { dWorldSetGravity(_world,(dReal)gravity.x,(dReal)gravity.y,(dReal)gravity.z); } //------------------------------------------------------------------------------------------------ const Ogre::Vector3& World::getGravity() { dVector3 g; dWorldGetGravity(_world,g); _gravity.x = (Real)g[0]; _gravity.y = (Real)g[1]; _gravity.z = (Real)g[2]; return _gravity; } //------------------------------------------------------------------------------------------------ void World::setERP(Real erp) { dWorldSetERP(_world,(dReal)erp); } //------------------------------------------------------------------------------------------------ Real World::getERP() { return (Real)dWorldGetERP(_world); } //------------------------------------------------------------------------------------------------ void World::setCFM(Real cfm) { dWorldSetCFM(_world,(dReal)cfm); } //------------------------------------------------------------------------------------------------ Real World::getCFM() { return (Real)dWorldGetCFM(_world); } //------------------------------------------------------------------------------------------------ void World::setAutoSleep(bool auto_sleep) { dWorldSetAutoDisableFlag(_world,(auto_sleep)?1:0); } //------------------------------------------------------------------------------------------------ bool World::getAutoSleep() { return (dWorldGetAutoDisableFlag(_world))?true:false; } //------------------------------------------------------------------------------------------------ void World::setAutoSleepLinearThreshold(Real linear_threshold) { dWorldSetAutoDisableLinearThreshold(_world,(dReal)linear_threshold); } //------------------------------------------------------------------------------------------------ Real World::getAutoSleepLinearThreshold() { return (Real)dWorldGetAutoDisableLinearThreshold(_world); } //------------------------------------------------------------------------------------------------ void World::setAutoSleepAngularThreshold(Real angular_threshold) { dWorldSetAutoDisableAngularThreshold(_world,(dReal)angular_threshold); } //------------------------------------------------------------------------------------------------ Real World::getAutoSleepAngularThreshold() { return (Real)dWorldGetAutoDisableAngularThreshold(_world); } //------------------------------------------------------------------------------------------------ void World::setAutoSleepSteps(int steps) { dWorldSetAutoDisableSteps(_world,steps); } //------------------------------------------------------------------------------------------------ int World::getAutoSleepSteps() { return dWorldGetAutoDisableSteps(_world); } //------------------------------------------------------------------------------------------------ void World::setAutoSleepTime(Real time) { dWorldSetAutoDisableTime(_world,(dReal)time); } //------------------------------------------------------------------------------------------------ Real World::getAutoSleepTime() { return (Real)dWorldGetAutoDisableTime(_world); } //------------------------------------------------------------------------------------------------ void World::setAutoSleepAverageSamplesCount(unsigned int time) { dWorldSetAutoDisableAverageSamplesCount(_world, time); } //------------------------------------------------------------------------------------------------ size_t World::getAutoSleepAverageSamplesCount() { return (Real)dWorldGetAutoDisableAverageSamplesCount(_world); } //------------------------------------------------------------------------------------------------ void World::setContactCorrectionVelocity(Real velocity) { dWorldSetContactMaxCorrectingVel(_world,(dReal)velocity); } //------------------------------------------------------------------------------------------------ void World::setContactSurfaceLayer(Real layer) { dWorldSetContactSurfaceLayer(_world,(dReal)layer); } //------------------------------------------------------------------------------------------------ void World::collisionCallback(void *data,dGeomID geom_a,dGeomID geom_b) { const bool a_space = (dGeomIsSpace(geom_a))?true:false; const bool b_space = (dGeomIsSpace(geom_b))?true:false; void* const ptr_a = dGeomGetData(geom_a); void* const ptr_b = dGeomGetData(geom_b); if(a_space || b_space ) { // Collide a space with a space if(a_space && b_space) static_cast