OpenMW
apps/openmw/mwworld/physicssystem.hpp
Go to the documentation of this file.
00001 #ifndef GAME_MWWORLD_PHYSICSSYSTEM_H
00002 #define GAME_MWWORLD_PHYSICSSYSTEM_H
00003 
00004 #include <OgreVector3.h>
00005 
00006 #include <btBulletCollisionCommon.h>
00007 
00008 #include "ptr.hpp"
00009 
00010 
00011 namespace OEngine
00012 {
00013     namespace Render
00014     {
00015         class OgreRenderer;
00016     }
00017     namespace Physic
00018     {
00019         class PhysicEngine;
00020     }
00021 }
00022 
00023 namespace MWWorld
00024 {
00025     class World;
00026 
00027     typedef std::vector<std::pair<Ptr,Ogre::Vector3> > PtrVelocityList;
00028 
00029     class PhysicsSystem
00030     {
00031         public:
00032             PhysicsSystem (OEngine::Render::OgreRenderer &_rend);
00033             ~PhysicsSystem ();
00034 
00035             void addObject (const MWWorld::Ptr& ptr, bool placeable=false);
00036 
00037             void addActor (const MWWorld::Ptr& ptr);
00038 
00039             void addHeightField (float* heights,
00040                 int x, int y, float yoffset,
00041                 float triSize, float sqrtVerts);
00042 
00043             void removeHeightField (int x, int y);
00044 
00045             // have to keep this as handle for now as unloadcell only knows scenenode names
00046             void removeObject (const std::string& handle);
00047 
00048             void moveObject (const MWWorld::Ptr& ptr);
00049 
00050             void rotateObject (const MWWorld::Ptr& ptr);
00051 
00052             void scaleObject (const MWWorld::Ptr& ptr);
00053 
00054             bool toggleCollisionMode();
00055 
00056             std::vector<std::string> getCollisions(const MWWorld::Ptr &ptr); 
00057             Ogre::Vector3 traceDown(const MWWorld::Ptr &ptr);
00058 
00059             std::pair<float, std::string> getFacedHandle(float queryDistance);
00060             std::pair<std::string,Ogre::Vector3> getHitContact(const std::string &name,
00061                                                                const Ogre::Vector3 &origin,
00062                                                                const Ogre::Quaternion &orientation,
00063                                                                float queryDistance);
00064             std::vector < std::pair <float, std::string> > getFacedHandles (float queryDistance);
00065             std::vector < std::pair <float, std::string> > getFacedHandles (float mouseX, float mouseY, float queryDistance);
00066 
00067             // cast ray, return true if it hit something. if raycasringObjectOnlt is set to false, it ignores NPCs and objects with no collisions.
00068             bool castRay(const Ogre::Vector3& from, const Ogre::Vector3& to, bool raycastingObjectOnly = true,bool ignoreHeightMap = false);
00069 
00070             std::pair<bool, Ogre::Vector3>
00071             castRay(const Ogre::Vector3 &orig, const Ogre::Vector3 &dir, float len);
00072 
00073             std::pair<bool, Ogre::Vector3> castRay(float mouseX, float mouseY);
00075 
00076             OEngine::Physic::PhysicEngine* getEngine();
00077 
00078             bool getObjectAABB(const MWWorld::Ptr &ptr, Ogre::Vector3 &min, Ogre::Vector3 &max);
00079 
00082             void queueObjectMovement(const Ptr &ptr, const Ogre::Vector3 &velocity);
00083 
00084             const PtrVelocityList& applyQueuedMovement(float dt);
00085 
00086         private:
00087 
00088             OEngine::Render::OgreRenderer &mRender;
00089             OEngine::Physic::PhysicEngine* mEngine;
00090             std::map<std::string, std::string> handleToMesh;
00091 
00092             PtrVelocityList mMovementQueue;
00093             PtrVelocityList mMovementResults;
00094 
00095             float mTimeAccum;
00096 
00097             PhysicsSystem (const PhysicsSystem&);
00098             PhysicsSystem& operator= (const PhysicsSystem&);
00099     };
00100 }
00101 
00102 #endif