1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-19 22:23:51 +00:00
openmw-tes3mp/apps/openmw/mwphysics/physicssystem.hpp

175 lines
5.9 KiB
C++
Raw Normal View History

#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>
#include <OgreVector3.h>
2015-05-02 22:39:01 +00:00
#include <osg/ref_ptr>
#include "../mwworld/ptr.hpp"
2015-05-22 02:36:17 +00:00
#include <osg/Quat>
2015-05-02 22:39:01 +00:00
namespace osg
{
class Group;
}
2015-05-02 22:39:01 +00:00
namespace MWRender
{
class DebugDrawer;
}
namespace NifBullet
{
class BulletShapeManager;
}
namespace Resource
{
class ResourceSystem;
}
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
namespace MWPhysics
2011-08-01 13:55:36 +00:00
{
typedef std::vector<std::pair<MWWorld::Ptr,osg::Vec3f> > PtrVelocityList;
2015-05-10 00:08:25 +00:00
class HeightField;
class Object;
class Actor;
2015-05-10 00:08:25 +00:00
2011-08-01 13:55:36 +00:00
class PhysicsSystem
{
public:
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();
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);
// 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-05-10 00:08:25 +00:00
void addHeightField (float* heights, int x, int y, float triSize, float sqrtVerts);
void removeHeightField (int x, int y);
2011-08-01 13:55:36 +00:00
bool toggleCollisionMode();
void stepSimulation(float dt);
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
osg::Vec3f traceDown(const MWWorld::Ptr &ptr, float maxHeight);
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,
float queryDistance);
2012-03-25 18:52:56 +00: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 19:34:51 +00:00
2015-05-21 23:43:45 +00:00
/// @return <bool hit, world hit position>
std::pair<bool, osg::Vec3f> castRay(const osg::Vec3f &from, const osg::Vec3f &to);
2012-07-25 16:25:53 +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.
void queueObjectMovement(const MWWorld::Ptr &ptr, const osg::Vec3f &velocity);
/// Apply all queued movements, then clear the list.
const PtrVelocityList& applyQueuedMovement(float dt);
/// Clear the queued movements list without applying.
void clearQueuedMovement();
/// 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-02 22:39:01 +00:00
bool toggleDebugRendering();
2011-08-01 13:55:36 +00:00
private:
2014-10-05 20:24:11 +00:00
void updateWater();
2015-05-10 00:08:25 +00:00
btBroadphaseInterface* mBroadphase;
btDefaultCollisionConfiguration* mCollisionConfiguration;
btCollisionDispatcher* mDispatcher;
btCollisionWorld* mCollisionWorld;
2015-05-10 00:08:25 +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;
2012-06-18 00:56:10 +00:00
std::map<std::string, std::string> handleToMesh;
2012-04-03 02:08:46 +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.
std::map<std::string, std::string> mCollisions; // FIXME: reimplement
std::map<std::string, std::string> mStandingCollisions; // FIXME: reimplement
PtrVelocityList mMovementQueue;
PtrVelocityList mMovementResults;
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