1
0
Fork 1
mirror of https://github.com/TES3MP/openmw-tes3mp.git synced 2025-01-15 18:19:55 +00:00
openmw-tes3mp/apps/openmw/mwworld/physicssystem.hpp

132 lines
4.8 KiB
C++
Raw Normal View History

2011-08-01 13:55:36 +00:00
#ifndef GAME_MWWORLD_PHYSICSSYSTEM_H
#define GAME_MWWORLD_PHYSICSSYSTEM_H
2014-10-05 20:24:11 +00:00
#include <memory>
#include <OgreVector3.h>
2013-02-07 05:47:09 +00:00
#include <btBulletCollisionCommon.h>
#include "ptr.hpp"
namespace OEngine
{
namespace Physic
{
class PhysicEngine;
}
}
2011-08-01 13:55:36 +00:00
namespace MWWorld
{
2013-02-07 05:47:09 +00:00
class World;
typedef std::vector<std::pair<Ptr,Ogre::Vector3> > PtrVelocityList;
2011-08-01 13:55:36 +00:00
class PhysicsSystem
{
public:
2015-04-21 21:35:35 +00:00
PhysicsSystem ();
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, bool placeable=false);
2011-08-22 19:34:51 +00:00
void addActor (const MWWorld::Ptr& ptr, const std::string& mesh);
2011-08-22 19:34:51 +00:00
void addHeightField (float* heights,
int x, int y, float yoffset,
float triSize, float sqrtVerts);
void removeHeightField (int x, int y);
// have to keep this as handle for now as unloadcell only knows scenenode names
2011-08-01 13:55:36 +00:00
void removeObject (const std::string& handle);
2011-08-22 19:34:51 +00:00
void moveObject (const MWWorld::Ptr& ptr);
2011-08-22 19:34:51 +00:00
void rotateObject (const MWWorld::Ptr& ptr);
2011-08-22 19:34:51 +00:00
void scaleObject (const MWWorld::Ptr& ptr);
2011-08-22 19:34:51 +00:00
2011-08-01 13:55:36 +00:00
bool toggleCollisionMode();
void stepSimulation(float dt);
std::vector<std::string> getCollisions(const MWWorld::Ptr &ptr, int collisionGroup, int collisionMask); ///< get handles this object collides with
Ogre::Vector3 traceDown(const MWWorld::Ptr &ptr, float maxHeight);
std::pair<std::string,Ogre::Vector3> getHitContact(const std::string &name,
const Ogre::Vector3 &origin,
const Ogre::Quaternion &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
2012-07-25 16:25:53 +00:00
std::pair<bool, Ogre::Vector3>
castRay(const Ogre::Vector3 &orig, const Ogre::Vector3 &dir, float len);
OEngine::Physic::PhysicEngine* getEngine();
/// 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 Ptr &ptr, const Ogre::Vector3 &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;
2011-08-01 13:55:36 +00:00
private:
2014-10-05 20:24:11 +00:00
void updateWater();
2011-08-01 13:55:36 +00:00
OEngine::Physic::PhysicEngine* mEngine;
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;
std::map<std::string, std::string> mStandingCollisions;
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;
2011-08-22 19:34:51 +00:00
PhysicsSystem (const PhysicsSystem&);
PhysicsSystem& operator= (const PhysicsSystem&);
2011-08-01 13:55:36 +00:00
};
}
#endif