#ifndef CSV_WORLD_PHYSICSENGINE_H #define CSV_WORLD_PHYSICSENGINE_H //#include #include #include //#include "BulletCollision/CollisionDispatch/btGhostObject.h" //#include //#include "BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.h" //#include //#include //#include //class btRigidBody; class btBroadphaseInterface; class btDefaultCollisionConfiguration; class btSequentialImpulseConstraintSolver; class btCollisionDispatcher; class btDiscreteDynamicsWorld; class btHeightfieldTerrainShape; //class btCollisionObject; namespace BtOgre { class DebugDrawer; } namespace Ogre { class Vector3; class SceneNode; class SceneManager; class Quaternion; } namespace OEngine { namespace Physic { class BulletShapeLoader; } } namespace CSVWorld { // enum btIDebugDraw::DebugDrawModes // { // DBG_NoDebug=0, // DBG_DrawWireframe = 1, // DBG_DrawAabb=2, // DBG_DrawFeaturesText=4, // DBG_DrawContactPoints=8, // DBG_NoDeactivation=16, // DBG_NoHelpText = 32, // DBG_DrawText=64, // DBG_ProfileTimings = 128, // DBG_EnableSatComparison = 256, // DBG_DisableBulletLCP = 512, // DBG_EnableCCD = 1024, // DBG_DrawConstraints = (1 << 11), // DBG_DrawConstraintLimits = (1 << 12), // DBG_FastWireframe = (1<<13), // DBG_DrawNormals = (1<<14), // DBG_MAX_DEBUG_DRAW_MODE // }; // #if 0 class CSVDebugDrawer : public BtOgre::DebugDrawer { BtOgre::DebugDrawer *mDebugDrawer; Ogre::SceneManager *mSceneMgr; Ogre::SceneNode *mSceneNode; int mDebugMode; public: CSVDebugDrawer(Ogre::SceneManager *sceneMgr, btDiscreteDynamicsWorld *dynamicsWorld); ~CSVDebugDrawer(); void setDebugMode(int mode); bool toggleDebugRendering(); }; #endif // This class is just an extension of normal btRigidBody in order to add extra info. // When bullet give back a btRigidBody, you can just do a static_cast to RigidBody, // so one never should use btRigidBody directly! class RigidBody: public btRigidBody { std::string mReferenceId; public: RigidBody(btRigidBody::btRigidBodyConstructionInfo &CI, const std::string &referenceId); virtual ~RigidBody(); std::string getReferenceId() const { return mReferenceId; } }; struct HeightField { btHeightfieldTerrainShape* mShape; RigidBody* mBody; }; /** * The PhysicsEngine class contain everything which is needed for Physic. * It's needed that Ogre Resources are set up before the PhysicsEngine is created. * Note:deleting it WILL NOT delete the RigidBody! * TODO:unload unused resources? */ class PhysicsEngine { //Bullet Stuff btBroadphaseInterface *mBroadphase; btDefaultCollisionConfiguration *mCollisionConfiguration; btSequentialImpulseConstraintSolver *mSolver; btCollisionDispatcher *mDispatcher; btDiscreteDynamicsWorld *mDynamicsWorld; //the NIF file loader. OEngine::Physic::BulletShapeLoader *mShapeLoader; typedef std::map HeightFieldContainer; HeightFieldContainer mHeightFieldMap; typedef std::map RigidBodyContainer; RigidBodyContainer mCollisionObjectMap; RigidBodyContainer mRaycastingObjectMap; std::map mDebugDrawers; std::map mDebugSceneNodes; #if 0 // from bullet enum CollisionFilterGroups { DefaultFilter = 1, StaticFilter = 2, KinematicFilter = 4, DebrisFilter = 8, SensorTrigger = 16, CharacterFilter = 32, AllFilter = -1 //all bits sets: DefaultFilter | StaticFilter | KinematicFilter | DebrisFilter | SensorTrigger }; #endif enum CollisionType { CollisionType_Nothing = 0, // rayTest(const btVector3 &from, const btVector3 &to, bool raycastingObjectOnly = true, bool ignoreHeightMap = false, Ogre::Vector3* normal = NULL); private: PhysicsEngine(const PhysicsEngine&); PhysicsEngine& operator=(const PhysicsEngine&); // Create a debug rendering. It is called by setDebgRenderingMode if it's // not created yet. // Important Note: this will crash if the Render is not yet initialised! void createDebugRendering(); // Set the debug rendering mode. 0 to turn it off. // Important Note: this will crash if the Render is not yet initialised! void setDebugRenderingMode(int mode); #if 0 void getObjectAABB(const std::string &mesh, float scale, btVector3 &min, btVector3 &max); /** * Return all objects hit by a ray. */ std::vector< std::pair > rayTest2(const btVector3 &from, const btVector3 &to, int filterGroup=0xff); std::pair sphereCast (float radius, btVector3 &from, btVector3 &to); ///< @return (hit, relative distance) std::vector getCollisions(const std::string &name, int collisionGroup, int collisionMask); // Get the nearest object that's inside the given object, filtering out objects of the // provided name std::pair getFilteredContact(const std::string &filter, const btVector3 &origin, btCollisionObject *object); #endif }; } #endif // CSV_WORLD_PHYSICSENGINE_H