mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-31 14:36:39 +00:00
Add physics methods to queue and apply movements
This commit is contained in:
parent
0481e64b02
commit
96bab88da6
2 changed files with 48 additions and 3 deletions
|
@ -427,8 +427,6 @@ namespace MWWorld
|
||||||
|
|
||||||
void PhysicsSystem::removeObject (const std::string& handle)
|
void PhysicsSystem::removeObject (const std::string& handle)
|
||||||
{
|
{
|
||||||
//TODO:check if actor???
|
|
||||||
|
|
||||||
mEngine->removeCharacter(handle);
|
mEngine->removeCharacter(handle);
|
||||||
mEngine->removeRigidBody(handle);
|
mEngine->removeRigidBody(handle);
|
||||||
mEngine->deleteRigidBody(handle);
|
mEngine->deleteRigidBody(handle);
|
||||||
|
@ -540,4 +538,39 @@ namespace MWWorld
|
||||||
|
|
||||||
return true;
|
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 <btBulletCollisionCommon.h>
|
||||||
|
|
||||||
|
#include "ptr.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace OEngine
|
namespace OEngine
|
||||||
{
|
{
|
||||||
|
@ -21,7 +23,8 @@ namespace OEngine
|
||||||
namespace MWWorld
|
namespace MWWorld
|
||||||
{
|
{
|
||||||
class World;
|
class World;
|
||||||
class Ptr;
|
|
||||||
|
typedef std::vector<std::pair<Ptr,Ogre::Vector3> > PtrVelocityList;
|
||||||
|
|
||||||
class PhysicsSystem
|
class PhysicsSystem
|
||||||
{
|
{
|
||||||
|
@ -80,12 +83,21 @@ namespace MWWorld
|
||||||
|
|
||||||
bool getObjectAABB(const MWWorld::Ptr &ptr, Ogre::Vector3 &min, Ogre::Vector3 &max);
|
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:
|
private:
|
||||||
|
|
||||||
OEngine::Render::OgreRenderer &mRender;
|
OEngine::Render::OgreRenderer &mRender;
|
||||||
OEngine::Physic::PhysicEngine* mEngine;
|
OEngine::Physic::PhysicEngine* mEngine;
|
||||||
std::map<std::string, std::string> handleToMesh;
|
std::map<std::string, std::string> handleToMesh;
|
||||||
|
|
||||||
|
PtrVelocityList mMovementQueue;
|
||||||
|
PtrVelocityList mMovementResults;
|
||||||
|
|
||||||
PhysicsSystem (const PhysicsSystem&);
|
PhysicsSystem (const PhysicsSystem&);
|
||||||
PhysicsSystem& operator= (const PhysicsSystem&);
|
PhysicsSystem& operator= (const PhysicsSystem&);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue