2015-05-12 01:02:15 +00:00
|
|
|
#ifndef OPENMW_MWPHYSICS_PHYSICSSYSTEM_H
|
|
|
|
#define OPENMW_MWPHYSICS_PHYSICSSYSTEM_H
|
2011-08-01 13:55:36 +00:00
|
|
|
|
2014-10-05 20:24:11 +00:00
|
|
|
#include <memory>
|
2015-06-03 21:04:35 +00:00
|
|
|
#include <map>
|
2014-10-05 20:24:11 +00:00
|
|
|
|
2015-06-03 21:04:35 +00:00
|
|
|
#include <osg/Quat>
|
2015-05-02 22:39:01 +00:00
|
|
|
#include <osg/ref_ptr>
|
|
|
|
|
2015-05-09 23:09:00 +00:00
|
|
|
#include "../mwworld/ptr.hpp"
|
2013-08-17 14:48:45 +00:00
|
|
|
|
2015-05-31 23:57:15 +00:00
|
|
|
#include "collisiontype.hpp"
|
|
|
|
|
2015-05-02 22:39:01 +00:00
|
|
|
namespace osg
|
|
|
|
{
|
|
|
|
class Group;
|
|
|
|
}
|
2013-02-07 20:11:10 +00:00
|
|
|
|
2015-05-02 22:39:01 +00:00
|
|
|
namespace MWRender
|
|
|
|
{
|
|
|
|
class DebugDrawer;
|
|
|
|
}
|
|
|
|
|
2015-05-12 01:02:15 +00:00
|
|
|
namespace NifBullet
|
|
|
|
{
|
|
|
|
class BulletShapeManager;
|
|
|
|
}
|
|
|
|
|
2015-05-12 14:24:53 +00:00
|
|
|
namespace Resource
|
2015-05-12 01:02:15 +00:00
|
|
|
{
|
2015-05-12 14:24:53 +00:00
|
|
|
class ResourceSystem;
|
2015-05-12 01:02:15 +00:00
|
|
|
}
|
|
|
|
|
2015-05-27 21:09:38 +00:00
|
|
|
class btCollisionWorld;
|
2015-05-27 20:32:11 +00:00
|
|
|
class btBroadphaseInterface;
|
|
|
|
class btDefaultCollisionConfiguration;
|
|
|
|
class btCollisionDispatcher;
|
|
|
|
class btCollisionObject;
|
|
|
|
class btCollisionShape;
|
2015-05-10 00:08:25 +00:00
|
|
|
|
2015-05-09 23:09:00 +00:00
|
|
|
namespace MWPhysics
|
2011-08-01 13:55:36 +00:00
|
|
|
{
|
2015-05-12 01:02:15 +00:00
|
|
|
typedef std::vector<std::pair<MWWorld::Ptr,osg::Vec3f> > PtrVelocityList;
|
2015-05-10 00:08:25 +00:00
|
|
|
|
|
|
|
class HeightField;
|
2015-05-12 01:02:15 +00:00
|
|
|
class Object;
|
|
|
|
class Actor;
|
2015-05-10 00:08:25 +00:00
|
|
|
|
2011-08-01 13:55:36 +00:00
|
|
|
class PhysicsSystem
|
|
|
|
{
|
|
|
|
public:
|
2015-05-12 14:24:53 +00:00
|
|
|
PhysicsSystem (Resource::ResourceSystem* resourceSystem, osg::ref_ptr<osg::Group> parentNode);
|
2011-08-01 13:55:36 +00:00
|
|
|
~PhysicsSystem ();
|
2011-08-22 19:34:51 +00:00
|
|
|
|
2014-10-05 20:24:11 +00:00
|
|
|
void enableWater(float height);
|
|
|
|
void setWaterHeight(float height);
|
|
|
|
void disableWater();
|
|
|
|
|
2015-05-12 01:02:15 +00:00
|
|
|
void addObject (const MWWorld::Ptr& ptr, const std::string& mesh);
|
2015-05-12 17:02:56 +00:00
|
|
|
void addActor (const MWWorld::Ptr& ptr, const std::string& mesh);
|
|
|
|
|
|
|
|
void updatePtr (const MWWorld::Ptr& old, const MWWorld::Ptr& updated);
|
|
|
|
|
|
|
|
Actor* getActor(const MWWorld::Ptr& ptr);
|
2015-05-12 01:02:15 +00:00
|
|
|
|
|
|
|
// Object or Actor
|
|
|
|
void remove (const MWWorld::Ptr& ptr);
|
|
|
|
|
|
|
|
void updateScale (const MWWorld::Ptr& ptr);
|
|
|
|
void updateRotation (const MWWorld::Ptr& ptr);
|
|
|
|
void updatePosition (const MWWorld::Ptr& ptr);
|
|
|
|
|
2011-08-22 19:34:51 +00:00
|
|
|
|
2015-08-31 14:08:19 +00:00
|
|
|
void addHeightField (const float* heights, int x, int y, float triSize, float sqrtVerts);
|
2012-03-13 16:09:50 +00:00
|
|
|
|
|
|
|
void removeHeightField (int x, int y);
|
|
|
|
|
2011-08-01 13:55:36 +00:00
|
|
|
bool toggleCollisionMode();
|
2013-08-20 18:31:49 +00:00
|
|
|
|
2014-06-23 18:43:24 +00:00
|
|
|
void stepSimulation(float dt);
|
2015-06-07 15:00:00 +00:00
|
|
|
void debugDraw();
|
2014-06-23 18:43:24 +00:00
|
|
|
|
2015-05-24 01:59:22 +00:00
|
|
|
std::vector<MWWorld::Ptr> getCollisions(const MWWorld::Ptr &ptr, int collisionGroup, int collisionMask); ///< get handles this object collides with
|
2015-05-12 01:02:15 +00:00
|
|
|
osg::Vec3f traceDown(const MWWorld::Ptr &ptr, float maxHeight);
|
2013-02-05 20:45:10 +00:00
|
|
|
|
2015-05-22 02:36:17 +00:00
|
|
|
std::pair<MWWorld::Ptr, osg::Vec3f> getHitContact(const MWWorld::Ptr& actor,
|
|
|
|
const osg::Vec3f &origin,
|
|
|
|
const osg::Quat &orientation,
|
2013-08-23 14:01:30 +00:00
|
|
|
float queryDistance);
|
2012-03-25 18:52:56 +00:00
|
|
|
|
2015-05-31 23:57:15 +00:00
|
|
|
struct RayResult
|
|
|
|
{
|
|
|
|
bool mHit;
|
|
|
|
osg::Vec3f mHitPos;
|
|
|
|
osg::Vec3f mHitNormal;
|
|
|
|
MWWorld::Ptr mHitObject;
|
|
|
|
};
|
|
|
|
|
|
|
|
/// @param me Optional, a Ptr to ignore in the list of results
|
|
|
|
RayResult castRay(const osg::Vec3f &from, const osg::Vec3f &to, MWWorld::Ptr ignore = MWWorld::Ptr(), int mask =
|
2015-06-01 19:41:13 +00:00
|
|
|
CollisionType_World|CollisionType_HeightMap|CollisionType_Actor, int group=0xff);
|
2011-08-22 19:34:51 +00:00
|
|
|
|
2015-06-01 13:34:46 +00:00
|
|
|
RayResult castSphere(const osg::Vec3f& from, const osg::Vec3f& to, float radius);
|
|
|
|
|
2015-05-31 23:57:15 +00:00
|
|
|
/// Return true if actor1 can see actor2.
|
|
|
|
bool getLineOfSight(const MWWorld::Ptr& actor1, const MWWorld::Ptr& actor2);
|
2012-07-25 16:25:53 +00:00
|
|
|
|
2015-06-01 00:40:42 +00:00
|
|
|
bool isOnGround (const MWWorld::Ptr& actor);
|
|
|
|
|
2015-06-01 19:41:13 +00:00
|
|
|
osg::Vec3f getHalfExtents(const MWWorld::Ptr& actor);
|
|
|
|
|
2013-08-17 14:48:45 +00: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-12 01:02:15 +00:00
|
|
|
void queueObjectMovement(const MWWorld::Ptr &ptr, const osg::Vec3f &velocity);
|
2013-08-17 14:48:45 +00:00
|
|
|
|
2014-08-13 14:23:34 +00:00
|
|
|
/// Apply all queued movements, then clear the list.
|
2013-08-17 14:48:45 +00:00
|
|
|
const PtrVelocityList& applyQueuedMovement(float dt);
|
|
|
|
|
2014-08-13 14:23:34 +00:00
|
|
|
/// Clear the queued movements list without applying.
|
|
|
|
void clearQueuedMovement();
|
|
|
|
|
2014-07-29 17:01:40 +00: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.
|
2015-05-29 23:32:00 +00:00
|
|
|
void getActorsStandingOn(const MWWorld::Ptr& object, std::vector<MWWorld::Ptr>& out) const;
|
2014-07-29 17:01:40 +00:00
|
|
|
|
|
|
|
/// 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.
|
2015-05-29 23:32:00 +00:00
|
|
|
void getActorsCollidingWith(const MWWorld::Ptr& object, std::vector<MWWorld::Ptr>& out) const;
|
2014-07-29 17:01:40 +00:00
|
|
|
|
2015-05-02 22:39:01 +00:00
|
|
|
bool toggleDebugRendering();
|
|
|
|
|
2011-08-01 13:55:36 +00:00
|
|
|
private:
|
2012-08-17 06:10:37 +00:00
|
|
|
|
2014-10-05 20:24:11 +00:00
|
|
|
void updateWater();
|
|
|
|
|
2015-05-10 00:08:25 +00:00
|
|
|
btBroadphaseInterface* mBroadphase;
|
|
|
|
btDefaultCollisionConfiguration* mCollisionConfiguration;
|
|
|
|
btCollisionDispatcher* mDispatcher;
|
2015-05-27 21:09:38 +00:00
|
|
|
btCollisionWorld* mCollisionWorld;
|
2015-05-10 00:08:25 +00:00
|
|
|
|
2015-05-12 01:02:15 +00:00
|
|
|
std::auto_ptr<NifBullet::BulletShapeManager> mShapeManager;
|
|
|
|
|
|
|
|
typedef std::map<MWWorld::Ptr, Object*> ObjectMap;
|
|
|
|
ObjectMap mObjects;
|
|
|
|
|
|
|
|
typedef std::map<MWWorld::Ptr, Actor*> ActorMap;
|
|
|
|
ActorMap mActors;
|
|
|
|
|
2015-05-10 00:08:25 +00:00
|
|
|
typedef std::map<std::pair<int, int>, HeightField*> HeightFieldMap;
|
|
|
|
HeightFieldMap mHeightFields;
|
|
|
|
|
2015-05-02 22:39:01 +00:00
|
|
|
bool mDebugDrawEnabled;
|
|
|
|
|
2014-07-29 17:01:40 +00: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.
|
2015-05-29 23:32:00 +00:00
|
|
|
typedef std::map<MWWorld::Ptr, MWWorld::Ptr> CollisionMap;
|
|
|
|
CollisionMap mCollisions;
|
|
|
|
CollisionMap mStandingCollisions;
|
2014-07-29 17:01:40 +00:00
|
|
|
|
2015-05-29 23:32:00 +00:00
|
|
|
// replaces all occurences of 'old' in the map by 'updated', no matter if its a key or value
|
|
|
|
void updateCollisionMapPtr(CollisionMap& map, const MWWorld::Ptr &old, const MWWorld::Ptr &updated);
|
2014-07-29 17:01:40 +00:00
|
|
|
|
2013-08-17 14:48:45 +00:00
|
|
|
PtrVelocityList mMovementQueue;
|
|
|
|
PtrVelocityList mMovementResults;
|
|
|
|
|
2013-08-20 18:31:49 +00:00
|
|
|
float mTimeAccum;
|
|
|
|
|
2014-10-05 20:24:11 +00:00
|
|
|
float mWaterHeight;
|
|
|
|
float mWaterEnabled;
|
|
|
|
|
|
|
|
std::auto_ptr<btCollisionObject> mWaterCollisionObject;
|
|
|
|
std::auto_ptr<btCollisionShape> mWaterCollisionShape;
|
|
|
|
|
2015-05-02 22:39:01 +00:00
|
|
|
std::auto_ptr<MWRender::DebugDrawer> mDebugDrawer;
|
|
|
|
|
|
|
|
osg::ref_ptr<osg::Group> mParentNode;
|
|
|
|
|
2011-08-22 19:34:51 +00:00
|
|
|
PhysicsSystem (const PhysicsSystem&);
|
|
|
|
PhysicsSystem& operator= (const PhysicsSystem&);
|
2011-08-01 13:55:36 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|