mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-25 06:35:30 +00:00
Add physics methods to queue and apply movements
This commit is contained in:
parent
0481e64b02
commit
96bab88da6
@ -427,8 +427,6 @@ namespace MWWorld
|
||||
|
||||
void PhysicsSystem::removeObject (const std::string& handle)
|
||||
{
|
||||
//TODO:check if actor???
|
||||
|
||||
mEngine->removeCharacter(handle);
|
||||
mEngine->removeRigidBody(handle);
|
||||
mEngine->deleteRigidBody(handle);
|
||||
@ -540,4 +538,39 @@ namespace MWWorld
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void PhysicsSystem::queueObjectMovement(const Ptr &ptr, const Ogre::Vector3 &movement)
|
||||
{
|
||||
PtrVelocityList::iterator iter = mMovementQueue.begin();
|
||||
for(;iter != mMovementQueue.end();iter++)
|
||||
{
|
||||
if(iter->first == ptr)
|
||||
{
|
||||
iter->second = movement;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
mMovementQueue.push_back(std::make_pair(ptr, movement));
|
||||
}
|
||||
|
||||
const PtrVelocityList& PhysicsSystem::applyQueuedMovement(float dt)
|
||||
{
|
||||
mMovementResults.clear();
|
||||
|
||||
const MWBase::World *world = MWBase::Environment::get().getWorld();
|
||||
PtrVelocityList::iterator iter = mMovementQueue.begin();
|
||||
for(;iter != mMovementQueue.end();iter++)
|
||||
{
|
||||
Ogre::Vector3 newpos;
|
||||
newpos = move(iter->first, iter->second, dt,
|
||||
!world->isSwimming(iter->first) && !world->isFlying(iter->first));
|
||||
mMovementResults.push_back(std::make_pair(iter->first, newpos));
|
||||
}
|
||||
|
||||
mMovementQueue.clear();
|
||||
|
||||
return mMovementResults;
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,8 @@
|
||||
|
||||
#include <btBulletCollisionCommon.h>
|
||||
|
||||
#include "ptr.hpp"
|
||||
|
||||
|
||||
namespace OEngine
|
||||
{
|
||||
@ -21,7 +23,8 @@ namespace OEngine
|
||||
namespace MWWorld
|
||||
{
|
||||
class World;
|
||||
class Ptr;
|
||||
|
||||
typedef std::vector<std::pair<Ptr,Ogre::Vector3> > PtrVelocityList;
|
||||
|
||||
class PhysicsSystem
|
||||
{
|
||||
@ -80,12 +83,21 @@ namespace MWWorld
|
||||
|
||||
bool getObjectAABB(const MWWorld::Ptr &ptr, Ogre::Vector3 &min, Ogre::Vector3 &max);
|
||||
|
||||
/// 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);
|
||||
|
||||
const PtrVelocityList& applyQueuedMovement(float dt);
|
||||
|
||||
private:
|
||||
|
||||
OEngine::Render::OgreRenderer &mRender;
|
||||
OEngine::Physic::PhysicEngine* mEngine;
|
||||
std::map<std::string, std::string> handleToMesh;
|
||||
|
||||
PtrVelocityList mMovementQueue;
|
||||
PtrVelocityList mMovementResults;
|
||||
|
||||
PhysicsSystem (const PhysicsSystem&);
|
||||
PhysicsSystem& operator= (const PhysicsSystem&);
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user