From 89fabdb3a935a9512df98d91cbe20fabc24332cf Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Tue, 19 Feb 2013 04:18:15 -0800 Subject: [PATCH] Update the PhysicActor's RigidBody when moving This works, but is less than ideal. As it is now, the rigid body gets updated twice as the position and rotation are set separately. They should instead be updated together. --- apps/openmw/mwworld/physicssystem.cpp | 4 ++++ libs/openengine/bullet/physic.cpp | 7 +++++++ libs/openengine/bullet/physic.hpp | 2 ++ 3 files changed, 13 insertions(+) diff --git a/apps/openmw/mwworld/physicssystem.cpp b/apps/openmw/mwworld/physicssystem.cpp index 63f9cb949..ec867326d 100644 --- a/apps/openmw/mwworld/physicssystem.cpp +++ b/apps/openmw/mwworld/physicssystem.cpp @@ -414,6 +414,10 @@ namespace MWWorld mEngine->boxAdjustExternal(handleToMesh[handle], body, node->getScale().x, position, node->getOrientation()); } } + else if(OEngine::Physic::PhysicActor *physact = mEngine->getCharacter(handle)) + { + physact->setPosition(position); + } } void PhysicsSystem::rotateObject (const Ptr& ptr) diff --git a/libs/openengine/bullet/physic.cpp b/libs/openengine/bullet/physic.cpp index e5045eee6..4a1c33fb8 100644 --- a/libs/openengine/bullet/physic.cpp +++ b/libs/openengine/bullet/physic.cpp @@ -55,6 +55,12 @@ namespace Physic } + void PhysicActor::setPosition(const Ogre::Vector3 &pos) + { + if(pos != getPosition()) + mEngine->adjustRigidBody(mBody, pos, getRotation(), mBoxScaledTranslation, mBoxRotation); + } + void PhysicActor::setRotation(const Ogre::Quaternion &quat) { if(!quat.equals(getRotation(), Ogre::Radian(0))){ @@ -62,6 +68,7 @@ namespace Physic } } + Ogre::Vector3 PhysicActor::getPosition() { btVector3 vec = mBody->getWorldTransform().getOrigin(); diff --git a/libs/openengine/bullet/physic.hpp b/libs/openengine/bullet/physic.hpp index 8ea9657e6..bd5d3d50a 100644 --- a/libs/openengine/bullet/physic.hpp +++ b/libs/openengine/bullet/physic.hpp @@ -69,6 +69,8 @@ namespace Physic ~PhysicActor(); + void setPosition(const Ogre::Vector3 &pos); + /** * This adjusts the rotation of a PhysicActor * If we have any problems with this (getting stuck in pmove) we should change it