2011-08-01 15:55:36 +02:00
|
|
|
#ifndef GAME_MWWORLD_PHYSICSSYSTEM_H
|
|
|
|
#define GAME_MWWORLD_PHYSICSSYSTEM_H
|
|
|
|
|
2014-10-05 22:24:11 +02:00
|
|
|
#include <memory>
|
|
|
|
|
2013-02-07 12:11:10 -08:00
|
|
|
#include <OgreVector3.h>
|
|
|
|
|
2013-02-06 21:47:09 -08:00
|
|
|
#include <btBulletCollisionCommon.h>
|
|
|
|
|
2015-05-03 00:39:01 +02:00
|
|
|
#include <osg/ref_ptr>
|
|
|
|
|
2015-05-10 01:09:00 +02:00
|
|
|
#include "../mwworld/ptr.hpp"
|
2013-08-17 07:48:45 -07:00
|
|
|
|
2015-05-03 00:39:01 +02:00
|
|
|
namespace osg
|
|
|
|
{
|
|
|
|
class Group;
|
|
|
|
}
|
2013-02-07 12:11:10 -08:00
|
|
|
|
2015-05-03 00:39:01 +02:00
|
|
|
namespace MWRender
|
|
|
|
{
|
|
|
|
class DebugDrawer;
|
|
|
|
}
|
|
|
|
|
2015-05-10 01:09:00 +02:00
|
|
|
namespace MWPhysics
|
2011-08-01 15:55:36 +02:00
|
|
|
{
|
2015-05-10 01:09:00 +02:00
|
|
|
typedef std::vector<std::pair<MWWorld::Ptr,Ogre::Vector3> > PtrVelocityList;
|
2011-08-01 15:55:36 +02:00
|
|
|
|
|
|
|
class PhysicsSystem
|
|
|
|
{
|
|
|
|
public:
|
2015-05-03 00:39:01 +02:00
|
|
|
PhysicsSystem (osg::ref_ptr<osg::Group> parentNode);
|
2011-08-01 15:55:36 +02:00
|
|
|
~PhysicsSystem ();
|
2011-08-22 21:34:51 +02:00
|
|
|
|
2014-10-05 22:24:11 +02:00
|
|
|
void enableWater(float height);
|
|
|
|
void setWaterHeight(float height);
|
|
|
|
void disableWater();
|
|
|
|
|
2015-01-12 11:29:56 +01:00
|
|
|
void addObject (const MWWorld::Ptr& ptr, const std::string& mesh, bool placeable=false);
|
2011-08-22 21:34:51 +02:00
|
|
|
|
2015-01-12 11:29:56 +01:00
|
|
|
void addActor (const MWWorld::Ptr& ptr, const std::string& mesh);
|
2011-08-22 21:34:51 +02:00
|
|
|
|
2012-03-13 17:09:50 +01:00
|
|
|
void addHeightField (float* heights,
|
|
|
|
int x, int y, float yoffset,
|
|
|
|
float triSize, float sqrtVerts);
|
|
|
|
|
|
|
|
void removeHeightField (int x, int y);
|
|
|
|
|
2011-08-01 15:55:36 +02:00
|
|
|
bool toggleCollisionMode();
|
2013-08-20 11:31:49 -07:00
|
|
|
|
2014-06-23 20:43:24 +02:00
|
|
|
void stepSimulation(float dt);
|
|
|
|
|
2014-08-11 04:43:06 +02:00
|
|
|
std::vector<std::string> getCollisions(const MWWorld::Ptr &ptr, int collisionGroup, int collisionMask); ///< get handles this object collides with
|
2014-06-28 14:59:33 +02:00
|
|
|
Ogre::Vector3 traceDown(const MWWorld::Ptr &ptr, float maxHeight);
|
2013-02-05 12:45:10 -08:00
|
|
|
|
2013-08-23 07:01:30 -07:00
|
|
|
std::pair<std::string,Ogre::Vector3> getHitContact(const std::string &name,
|
|
|
|
const Ogre::Vector3 &origin,
|
|
|
|
const Ogre::Quaternion &orientation,
|
|
|
|
float queryDistance);
|
2012-03-25 20:52:56 +02:00
|
|
|
|
2015-05-01 21:43:21 +02:00
|
|
|
// cast ray, return true if it hit something.
|
|
|
|
bool castRay(const Ogre::Vector3& from, const Ogre::Vector3& to,bool ignoreHeightMap = false);
|
2011-08-22 21:34:51 +02:00
|
|
|
|
2012-07-25 20:25:53 +04:00
|
|
|
std::pair<bool, Ogre::Vector3>
|
|
|
|
castRay(const Ogre::Vector3 &orig, const Ogre::Vector3 &dir, float len);
|
|
|
|
|
2013-08-17 07:48:45 -07:00
|
|
|
/// Queues velocity movement for a Ptr. If a Ptr is already queued, its velocity will
|
|
|
|
/// be overwritten. Valid until the next call to applyQueuedMovement.
|
2015-05-10 01:09:00 +02:00
|
|
|
void queueObjectMovement(const MWWorld::Ptr &ptr, const Ogre::Vector3 &velocity);
|
2013-08-17 07:48:45 -07:00
|
|
|
|
2014-08-13 16:23:34 +02:00
|
|
|
/// Apply all queued movements, then clear the list.
|
2013-08-17 07:48:45 -07:00
|
|
|
const PtrVelocityList& applyQueuedMovement(float dt);
|
|
|
|
|
2014-08-13 16:23:34 +02:00
|
|
|
/// Clear the queued movements list without applying.
|
|
|
|
void clearQueuedMovement();
|
|
|
|
|
2014-07-29 19:01:40 +02:00
|
|
|
/// Return true if \a actor has been standing on \a object in this frame
|
|
|
|
/// This will trigger whenever the object is directly below the actor.
|
|
|
|
/// It doesn't matter if the actor is stationary or moving.
|
|
|
|
bool isActorStandingOn(const MWWorld::Ptr& actor, const MWWorld::Ptr& object) const;
|
|
|
|
|
|
|
|
/// Get the handle of all actors standing on \a object in this frame.
|
|
|
|
void getActorsStandingOn(const MWWorld::Ptr& object, std::vector<std::string>& out) const;
|
|
|
|
|
|
|
|
/// Return true if \a actor has collided with \a object in this frame.
|
|
|
|
/// This will detect running into objects, but will not detect climbing stairs, stepping up a small object, etc.
|
|
|
|
bool isActorCollidingWith(const MWWorld::Ptr& actor, const MWWorld::Ptr& object) const;
|
|
|
|
|
|
|
|
/// Get the handle of all actors colliding with \a object in this frame.
|
|
|
|
void getActorsCollidingWith(const MWWorld::Ptr& object, std::vector<std::string>& out) const;
|
|
|
|
|
2015-05-03 00:39:01 +02:00
|
|
|
bool toggleDebugRendering();
|
|
|
|
|
2011-08-01 15:55:36 +02:00
|
|
|
private:
|
2012-08-17 10:10:37 +04:00
|
|
|
|
2014-10-05 22:24:11 +02:00
|
|
|
void updateWater();
|
|
|
|
|
2015-05-03 00:39:01 +02:00
|
|
|
bool mDebugDrawEnabled;
|
|
|
|
|
2012-06-17 20:56:10 -04:00
|
|
|
std::map<std::string, std::string> handleToMesh;
|
2012-04-02 22:08:46 -04:00
|
|
|
|
2014-07-29 19:01:40 +02:00
|
|
|
// Tracks all movement collisions happening during a single frame. <actor handle, collided handle>
|
|
|
|
// This will detect e.g. running against a vertical wall. It will not detect climbing up stairs,
|
|
|
|
// stepping up small objects, etc.
|
|
|
|
std::map<std::string, std::string> mCollisions;
|
|
|
|
|
|
|
|
std::map<std::string, std::string> mStandingCollisions;
|
|
|
|
|
2013-08-17 07:48:45 -07:00
|
|
|
PtrVelocityList mMovementQueue;
|
|
|
|
PtrVelocityList mMovementResults;
|
|
|
|
|
2013-08-20 11:31:49 -07:00
|
|
|
float mTimeAccum;
|
|
|
|
|
2014-10-05 22:24:11 +02:00
|
|
|
float mWaterHeight;
|
|
|
|
float mWaterEnabled;
|
|
|
|
|
|
|
|
std::auto_ptr<btCollisionObject> mWaterCollisionObject;
|
|
|
|
std::auto_ptr<btCollisionShape> mWaterCollisionShape;
|
|
|
|
|
2015-05-03 00:39:01 +02:00
|
|
|
std::auto_ptr<MWRender::DebugDrawer> mDebugDrawer;
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::Group> mParentNode;
|
|
|
|
|
2011-08-22 21:34:51 +02:00
|
|
|
PhysicsSystem (const PhysicsSystem&);
|
|
|
|
PhysicsSystem& operator= (const PhysicsSystem&);
|
2011-08-01 15:55:36 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|