add physic.

actorid
gugus 14 years ago
parent 1dc452ec91
commit 746cf3a45a

@ -112,37 +112,66 @@ void MWScene::doPhysics (float duration, MWWorld::World& world,
for (std::vector<std::pair<std::string, Ogre::Vector3> >::const_iterator iter (actors.begin());
iter!=actors.end(); ++iter)
{
MWWorld::Ptr ptr = world.getPtrViaHandle (iter->first);
OEngine::Physic::PhysicActor* act = eng->getCharacter(iter->first);
//first adjust the rotation of the object, which is not handled by the physic engine i believe.
Ogre::SceneNode *sceneNode = rend.getScene()->getSceneNode (iter->first);
Ogre::Quaternion quat = sceneNode->getOrientation();
act->setRotation(btQuaternion(quat.x,quat.y,quat.z,quat.w));
Ogre::SceneNode *sceneNode = rend.getScene()->getSceneNode (iter->first);
//the add the movement:
act->setWalkDirection(btVector3(iter->second.x,iter->second.y,iter->second.z));
}
Ogre::Vector3 newPos = sceneNode->getPosition() + sceneNode->getOrientation() * iter->second;
eng->stepSimulation(0.30);
world.moveObject (ptr, newPos.x, newPos.y, newPos.z);
for (std::vector<std::pair<std::string, Ogre::Vector3> >::const_iterator iter (actors.begin());
iter!=actors.end(); ++iter)
{
MWWorld::Ptr ptr = world.getPtrViaHandle (iter->first);
OEngine::Physic::PhysicActor* act = eng->getCharacter(iter->first);
btVector3 newPos = act->externalGhostObject->getWorldTransform().getOrigin();
world.moveObject (ptr, newPos.x(), newPos.y(), newPos.z());
}
}
void MWScene::addObject (const std::string& handle, const std::string& mesh,
const Ogre::Quaternion& rotation, float scale, const Ogre::Vector3& position)
{
OEngine::Physic::RigidBody* body = eng->createRigidBody(mesh,handle);
eng->addRigidBody(body);
btTransform tr;
tr.setOrigin(btVector3(position.x,position.y,position.z));
tr.setRotation(btQuaternion(rotation.x,rotation.y,rotation.z,rotation.w));
body->setWorldTransform(tr);
}
void MWScene::addActor (const std::string& handle, const std::string& mesh,
const Ogre::Vector3& position)
{
//TODO:optimize this. Searching the std::map isn't very efficient i think.
eng->addCharacter(handle);
OEngine::Physic::PhysicActor* act = eng->getCharacter(handle);
act->setPosition(btVector3(position.x,position.y,position.z));
}
void MWScene::removeObject (const std::string& handle)
{
//TODO:check if actor???
eng->removeRigidBody(handle);
eng->deleteRigidBody(handle);
}
void MWScene::moveObject (const std::string& handle, const Ogre::Vector3& position, bool updatePhysics)
{
rend.getScene()->getSceneNode (handle)->setPosition (position);
if(updatePhysics)//TODO: is it an actor?
{
OEngine::Physic::RigidBody* body = eng->getRigidBody(handle);
btTransform tr = body->getWorldTransform();
tr.setOrigin(btVector3(position.x,position.y,position.z));
body->setWorldTransform(tr);
}
}
void MWScene::rotateObject (const std::string& handle, const Ogre::Quaternion& rotation)

@ -3,6 +3,7 @@
#include <utility>
#include <openengine/ogre/renderer.hpp>
#include <openengine\bullet\physic.hpp>
#include <vector>
#include <string>
@ -39,6 +40,8 @@ namespace MWRender
Ogre::SceneNode *mwRoot;
Ogre::RaySceneQuery *mRaySceneQuery;
OEngine::Physic::PhysicEngine* eng;
MWRender::Player *mPlayer;
public:

Loading…
Cancel
Save