OpenMW
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Classes | Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
MWPhysics::PhysicsSystem Class Reference

#include <physicssystem.hpp>

Collaboration diagram for MWPhysics::PhysicsSystem:

Classes

struct  RayResult
 

Public Member Functions

 PhysicsSystem (Resource::ResourceSystem *resourceSystem, osg::ref_ptr< osg::Group > parentNode)
 
 ~PhysicsSystem ()
 
void setUnrefQueue (SceneUtil::UnrefQueue *unrefQueue)
 
Resource::BulletShapeManagergetShapeManager ()
 
void enableWater (float height)
 
void setWaterHeight (float height)
 
void disableWater ()
 
void addObject (const MWWorld::Ptr &ptr, const std::string &mesh, int collisionType=CollisionType_World)
 
void addActor (const MWWorld::Ptr &ptr, const std::string &mesh)
 
void updatePtr (const MWWorld::Ptr &old, const MWWorld::Ptr &updated)
 
ActorgetActor (const MWWorld::Ptr &ptr)
 
const ActorgetActor (const MWWorld::ConstPtr &ptr) const
 
const ObjectgetObject (const MWWorld::ConstPtr &ptr) const
 
void remove (const MWWorld::Ptr &ptr)
 
void updateScale (const MWWorld::Ptr &ptr)
 
void updateRotation (const MWWorld::Ptr &ptr)
 
void updatePosition (const MWWorld::Ptr &ptr)
 
void addHeightField (const float *heights, int x, int y, float triSize, float sqrtVerts, float minH, float maxH, const osg::Object *holdObject)
 
void removeHeightField (int x, int y)
 
bool toggleCollisionMode ()
 
void stepSimulation (float dt)
 
void debugDraw ()
 
std::vector< MWWorld::PtrgetCollisions (const MWWorld::ConstPtr &ptr, int collisionGroup, int collisionMask) const
 get handles this object collides with More...
 
osg::Vec3f traceDown (const MWWorld::Ptr &ptr, const osg::Vec3f &position, float maxHeight)
 
std::pair< MWWorld::Ptr,
osg::Vec3f > 
getHitContact (const MWWorld::ConstPtr &actor, const osg::Vec3f &origin, const osg::Quat &orientation, float queryDistance, std::vector< MWWorld::Ptr > targets=std::vector< MWWorld::Ptr >())
 
float getHitDistance (const osg::Vec3f &point, const MWWorld::ConstPtr &target) const
 
RayResult castRay (const osg::Vec3f &from, const osg::Vec3f &to, const MWWorld::ConstPtr &ignore=MWWorld::ConstPtr(), std::vector< MWWorld::Ptr > targets=std::vector< MWWorld::Ptr >(), int mask=CollisionType_World|CollisionType_HeightMap|CollisionType_Actor|CollisionType_Door, int group=0xff) const
 
RayResult castSphere (const osg::Vec3f &from, const osg::Vec3f &to, float radius)
 
bool getLineOfSight (const MWWorld::ConstPtr &actor1, const MWWorld::ConstPtr &actor2) const
 Return true if actor1 can see actor2. More...
 
bool isOnGround (const MWWorld::Ptr &actor)
 
bool canMoveToWaterSurface (const MWWorld::ConstPtr &actor, const float waterlevel)
 
osg::Vec3f getHalfExtents (const MWWorld::ConstPtr &actor) const
 Get physical half extents (scaled) of the given actor. More...
 
osg::Vec3f getRenderingHalfExtents (const MWWorld::ConstPtr &actor) const
 
osg::Vec3f getCollisionObjectPosition (const MWWorld::ConstPtr &actor) const
 
void queueObjectMovement (const MWWorld::Ptr &ptr, const osg::Vec3f &velocity)
 
const PtrVelocityListapplyQueuedMovement (float dt)
 Apply all queued movements, then clear the list. More...
 
void clearQueuedMovement ()
 Clear the queued movements list without applying. More...
 
bool isActorStandingOn (const MWWorld::Ptr &actor, const MWWorld::ConstPtr &object) const
 
void getActorsStandingOn (const MWWorld::ConstPtr &object, std::vector< MWWorld::Ptr > &out) const
 Get the handle of all actors standing on object in this frame. More...
 
bool isActorCollidingWith (const MWWorld::Ptr &actor, const MWWorld::ConstPtr &object) const
 
void getActorsCollidingWith (const MWWorld::ConstPtr &object, std::vector< MWWorld::Ptr > &out) const
 Get the handle of all actors colliding with object in this frame. More...
 
bool toggleDebugRendering ()
 
void markAsNonSolid (const MWWorld::ConstPtr &ptr)
 
bool isOnSolidGround (const MWWorld::Ptr &actor) const
 

Private Types

typedef std::map
< MWWorld::ConstPtr, Object * > 
ObjectMap
 
typedef std::map
< MWWorld::ConstPtr, Actor * > 
ActorMap
 
typedef std::map< std::pair
< int, int >, HeightField * > 
HeightFieldMap
 
typedef std::map< MWWorld::Ptr,
MWWorld::Ptr
CollisionMap
 

Private Member Functions

void updateWater ()
 
void updateCollisionMapPtr (CollisionMap &map, const MWWorld::Ptr &old, const MWWorld::Ptr &updated)
 
 PhysicsSystem (const PhysicsSystem &)
 
PhysicsSystemoperator= (const PhysicsSystem &)
 

Private Attributes

osg::ref_ptr
< SceneUtil::UnrefQueue
mUnrefQueue
 
btBroadphaseInterface * mBroadphase
 
btDefaultCollisionConfiguration * mCollisionConfiguration
 
btCollisionDispatcher * mDispatcher
 
btCollisionWorld * mCollisionWorld
 
std::unique_ptr
< Resource::BulletShapeManager
mShapeManager
 
Resource::ResourceSystemmResourceSystem
 
ObjectMap mObjects
 
std::set< Object * > mAnimatedObjects
 
ActorMap mActors
 
HeightFieldMap mHeightFields
 
bool mDebugDrawEnabled
 
CollisionMap mStandingCollisions
 
PtrVelocityList mMovementQueue
 
PtrVelocityList mMovementResults
 
float mTimeAccum
 
float mWaterHeight
 
bool mWaterEnabled
 
std::unique_ptr
< btCollisionObject > 
mWaterCollisionObject
 
std::unique_ptr< btCollisionShape > mWaterCollisionShape
 
std::unique_ptr
< MWRender::DebugDrawer
mDebugDrawer
 
osg::ref_ptr< osg::Group > mParentNode
 
float mPhysicsDt
 

Member Typedef Documentation

typedef std::map<std::pair<int, int>, HeightField*> MWPhysics::PhysicsSystem::HeightFieldMap
private

Constructor & Destructor Documentation

MWPhysics::PhysicsSystem::PhysicsSystem ( Resource::ResourceSystem resourceSystem,
osg::ref_ptr< osg::Group >  parentNode 
)

Here is the call graph for this function:

MWPhysics::PhysicsSystem::~PhysicsSystem ( )

Here is the call graph for this function:

MWPhysics::PhysicsSystem::PhysicsSystem ( const PhysicsSystem )
private

Member Function Documentation

void MWPhysics::PhysicsSystem::addActor ( const MWWorld::Ptr ptr,
const std::string &  mesh 
)

Here is the caller graph for this function:

void MWPhysics::PhysicsSystem::addHeightField ( const float *  heights,
int  x,
int  y,
float  triSize,
float  sqrtVerts,
float  minH,
float  maxH,
const osg::Object *  holdObject 
)

Here is the call graph for this function:

void MWPhysics::PhysicsSystem::addObject ( const MWWorld::Ptr ptr,
const std::string &  mesh,
int  collisionType = CollisionType_World 
)

Here is the call graph for this function:

Here is the caller graph for this function:

const PtrVelocityList & MWPhysics::PhysicsSystem::applyQueuedMovement ( float  dt)

Apply all queued movements, then clear the list.

Here is the call graph for this function:

bool MWPhysics::PhysicsSystem::canMoveToWaterSurface ( const MWWorld::ConstPtr actor,
const float  waterlevel 
)

Here is the call graph for this function:

Here is the caller graph for this function:

PhysicsSystem::RayResult MWPhysics::PhysicsSystem::castRay ( const osg::Vec3f &  from,
const osg::Vec3f &  to,
const MWWorld::ConstPtr ignore = MWWorld::ConstPtr(),
std::vector< MWWorld::Ptr targets = std::vector<MWWorld::Ptr>(),
int  mask = CollisionType_World|CollisionType_HeightMap|CollisionType_Actor|CollisionType_Door,
int  group = 0xff 
) const
Parameters
meOptional, a Ptr to ignore in the list of results. targets are actors to filter for, ignoring all other actors.

Here is the call graph for this function:

Here is the caller graph for this function:

PhysicsSystem::RayResult MWPhysics::PhysicsSystem::castSphere ( const osg::Vec3f &  from,
const osg::Vec3f &  to,
float  radius 
)

Here is the call graph for this function:

void MWPhysics::PhysicsSystem::clearQueuedMovement ( )

Clear the queued movements list without applying.

void MWPhysics::PhysicsSystem::debugDraw ( )
void MWPhysics::PhysicsSystem::disableWater ( )

Here is the call graph for this function:

void MWPhysics::PhysicsSystem::enableWater ( float  height)

Here is the call graph for this function:

Actor * MWPhysics::PhysicsSystem::getActor ( const MWWorld::Ptr ptr)

Here is the caller graph for this function:

const Actor * MWPhysics::PhysicsSystem::getActor ( const MWWorld::ConstPtr ptr) const
void MWPhysics::PhysicsSystem::getActorsCollidingWith ( const MWWorld::ConstPtr object,
std::vector< MWWorld::Ptr > &  out 
) const

Get the handle of all actors colliding with object in this frame.

Here is the call graph for this function:

void MWPhysics::PhysicsSystem::getActorsStandingOn ( const MWWorld::ConstPtr object,
std::vector< MWWorld::Ptr > &  out 
) const

Get the handle of all actors standing on object in this frame.

osg::Vec3f MWPhysics::PhysicsSystem::getCollisionObjectPosition ( const MWWorld::ConstPtr actor) const

Get the position of the collision shape for the actor. Use together with getHalfExtents() to get the collision bounds in world space.

Note
The collision shape's origin is in its center, so the position returned can be described as center of the actor collision box in world space.

Here is the call graph for this function:

std::vector< MWWorld::Ptr > MWPhysics::PhysicsSystem::getCollisions ( const MWWorld::ConstPtr ptr,
int  collisionGroup,
int  collisionMask 
) const

get handles this object collides with

Here is the caller graph for this function:

osg::Vec3f MWPhysics::PhysicsSystem::getHalfExtents ( const MWWorld::ConstPtr actor) const

Get physical half extents (scaled) of the given actor.

Here is the call graph for this function:

Here is the caller graph for this function:

std::pair< MWWorld::Ptr, osg::Vec3f > MWPhysics::PhysicsSystem::getHitContact ( const MWWorld::ConstPtr actor,
const osg::Vec3f &  origin,
const osg::Quat &  orientation,
float  queryDistance,
std::vector< MWWorld::Ptr targets = std::vector<MWWorld::Ptr>() 
)

Here is the call graph for this function:

float MWPhysics::PhysicsSystem::getHitDistance ( const osg::Vec3f &  point,
const MWWorld::ConstPtr target 
) const

Get distance from point to the collision shape of target. Uses a raycast to find where the target vector hits the collision shape and then calculates distance from the intersection point. This can be used to find out how much nearer we need to move to the target for a "getHitContact" to be successful.

Note
Only Actor targets are supported at the moment.

Here is the call graph for this function:

bool MWPhysics::PhysicsSystem::getLineOfSight ( const MWWorld::ConstPtr actor1,
const MWWorld::ConstPtr actor2 
) const

Return true if actor1 can see actor2.

Here is the call graph for this function:

const Object * MWPhysics::PhysicsSystem::getObject ( const MWWorld::ConstPtr ptr) const

Here is the caller graph for this function:

osg::Vec3f MWPhysics::PhysicsSystem::getRenderingHalfExtents ( const MWWorld::ConstPtr actor) const
See Also
MWPhysics::Actor::getRenderingHalfExtents

Here is the call graph for this function:

Resource::BulletShapeManager * MWPhysics::PhysicsSystem::getShapeManager ( )

Here is the caller graph for this function:

bool MWPhysics::PhysicsSystem::isActorCollidingWith ( const MWWorld::Ptr actor,
const MWWorld::ConstPtr object 
) const

Return true if actor has collided with object in this frame. This will detect running into objects, but will not detect climbing stairs, stepping up a small object, etc.

Here is the call graph for this function:

bool MWPhysics::PhysicsSystem::isActorStandingOn ( const MWWorld::Ptr actor,
const MWWorld::ConstPtr object 
) const

Return true if actor has been standing on 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 MWPhysics::PhysicsSystem::isOnGround ( const MWWorld::Ptr actor)

Here is the call graph for this function:

bool MWPhysics::PhysicsSystem::isOnSolidGround ( const MWWorld::Ptr actor) const

Here is the call graph for this function:

void MWPhysics::PhysicsSystem::markAsNonSolid ( const MWWorld::ConstPtr ptr)

Mark the given object as a 'non-solid' object. A non-solid object means that isOnSolidGround will return false for actors standing on that object.

PhysicsSystem& MWPhysics::PhysicsSystem::operator= ( const PhysicsSystem )
private
void MWPhysics::PhysicsSystem::queueObjectMovement ( const MWWorld::Ptr ptr,
const osg::Vec3f &  velocity 
)

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 MWPhysics::PhysicsSystem::remove ( const MWWorld::Ptr ptr)

Here is the caller graph for this function:

void MWPhysics::PhysicsSystem::removeHeightField ( int  x,
int  y 
)
void MWPhysics::PhysicsSystem::setUnrefQueue ( SceneUtil::UnrefQueue unrefQueue)

Here is the caller graph for this function:

void MWPhysics::PhysicsSystem::setWaterHeight ( float  height)

Here is the call graph for this function:

void MWPhysics::PhysicsSystem::stepSimulation ( float  dt)
bool MWPhysics::PhysicsSystem::toggleCollisionMode ( )

Here is the call graph for this function:

bool MWPhysics::PhysicsSystem::toggleDebugRendering ( )
osg::Vec3f MWPhysics::PhysicsSystem::traceDown ( const MWWorld::Ptr ptr,
const osg::Vec3f &  position,
float  maxHeight 
)

Here is the call graph for this function:

void MWPhysics::PhysicsSystem::updateCollisionMapPtr ( CollisionMap map,
const MWWorld::Ptr old,
const MWWorld::Ptr updated 
)
private

Here is the caller graph for this function:

void MWPhysics::PhysicsSystem::updatePosition ( const MWWorld::Ptr ptr)

Here is the call graph for this function:

void MWPhysics::PhysicsSystem::updatePtr ( const MWWorld::Ptr old,
const MWWorld::Ptr updated 
)

Here is the call graph for this function:

void MWPhysics::PhysicsSystem::updateRotation ( const MWWorld::Ptr ptr)

Here is the call graph for this function:

Here is the caller graph for this function:

void MWPhysics::PhysicsSystem::updateScale ( const MWWorld::Ptr ptr)

Here is the call graph for this function:

Here is the caller graph for this function:

void MWPhysics::PhysicsSystem::updateWater ( )
private

Here is the caller graph for this function:

Member Data Documentation

ActorMap MWPhysics::PhysicsSystem::mActors
private
std::set<Object*> MWPhysics::PhysicsSystem::mAnimatedObjects
private
btBroadphaseInterface* MWPhysics::PhysicsSystem::mBroadphase
private
btDefaultCollisionConfiguration* MWPhysics::PhysicsSystem::mCollisionConfiguration
private
btCollisionWorld* MWPhysics::PhysicsSystem::mCollisionWorld
private
bool MWPhysics::PhysicsSystem::mDebugDrawEnabled
private
std::unique_ptr<MWRender::DebugDrawer> MWPhysics::PhysicsSystem::mDebugDrawer
private
btCollisionDispatcher* MWPhysics::PhysicsSystem::mDispatcher
private
HeightFieldMap MWPhysics::PhysicsSystem::mHeightFields
private
PtrVelocityList MWPhysics::PhysicsSystem::mMovementQueue
private
PtrVelocityList MWPhysics::PhysicsSystem::mMovementResults
private
ObjectMap MWPhysics::PhysicsSystem::mObjects
private
osg::ref_ptr<osg::Group> MWPhysics::PhysicsSystem::mParentNode
private
float MWPhysics::PhysicsSystem::mPhysicsDt
private
Resource::ResourceSystem* MWPhysics::PhysicsSystem::mResourceSystem
private
std::unique_ptr<Resource::BulletShapeManager> MWPhysics::PhysicsSystem::mShapeManager
private
CollisionMap MWPhysics::PhysicsSystem::mStandingCollisions
private
float MWPhysics::PhysicsSystem::mTimeAccum
private
osg::ref_ptr<SceneUtil::UnrefQueue> MWPhysics::PhysicsSystem::mUnrefQueue
private
std::unique_ptr<btCollisionObject> MWPhysics::PhysicsSystem::mWaterCollisionObject
private
std::unique_ptr<btCollisionShape> MWPhysics::PhysicsSystem::mWaterCollisionShape
private
bool MWPhysics::PhysicsSystem::mWaterEnabled
private
float MWPhysics::PhysicsSystem::mWaterHeight
private

The documentation for this class was generated from the following files: