From 7b8b4c366d5de40e148b780b86e409544975385d Mon Sep 17 00:00:00 2001 From: Jason Hooks Date: Tue, 14 Aug 2012 20:29:48 -0400 Subject: [PATCH] Set angle now working for npcs and creatures --- apps/openmw/mwclass/npc.cpp | 3 +-- apps/openmw/mwworld/physicssystem.cpp | 16 ++++++++++++---- libs/openengine/bullet/physic.cpp | 12 ++++++++++++ libs/openengine/bullet/physic.hpp | 2 +- 4 files changed, 26 insertions(+), 7 deletions(-) diff --git a/apps/openmw/mwclass/npc.cpp b/apps/openmw/mwclass/npc.cpp index 72501e8ac..217d92025 100644 --- a/apps/openmw/mwclass/npc.cpp +++ b/apps/openmw/mwclass/npc.cpp @@ -379,8 +379,7 @@ namespace MWClass void Npc::adjustRotation(const MWWorld::Ptr& ptr,float& x,float& y,float& z) const { - y = 0; - x = 0; + } MWWorld::Ptr diff --git a/apps/openmw/mwworld/physicssystem.cpp b/apps/openmw/mwworld/physicssystem.cpp index faacc5b06..3d4a08c69 100644 --- a/apps/openmw/mwworld/physicssystem.cpp +++ b/apps/openmw/mwworld/physicssystem.cpp @@ -286,10 +286,15 @@ namespace MWWorld { // TODO very dirty hack to avoid crash during setup -> needs cleaning up to allow // start positions others than 0, 0, 0 - btTransform tr = body->getWorldTransform(); Ogre::Vector3 position = node->getPosition(); - tr.setOrigin(btVector3(position.x,position.y,position.z)); - body->setWorldTransform(tr); + + if(dynamic_cast(body->getCollisionShape()) == NULL){ + btTransform tr = body->getWorldTransform(); + tr.setOrigin(btVector3(position.x,position.y,position.z)); + body->setWorldTransform(tr); + } + else + mEngine->boxAdjustExternal(handleToMesh[handle], body, node->getScale().x, position, node->getOrientation()); } if (OEngine::Physic::PhysicActor* act = mEngine->getCharacter(handle)) { @@ -315,7 +320,10 @@ namespace MWWorld if (OEngine::Physic::RigidBody* body = mEngine->getRigidBody(handle)) { Ogre::Quaternion rotation = node->getOrientation(); - body->getWorldTransform().setRotation(btQuaternion(rotation.x, rotation.y, rotation.z, rotation.w)); + if(dynamic_cast(body->getCollisionShape()) == NULL) + body->getWorldTransform().setRotation(btQuaternion(rotation.x, rotation.y, rotation.z, rotation.w)); + else + mEngine->boxAdjustExternal(handleToMesh[handle], body, node->getScale().x, node->getPosition(), rotation); } } diff --git a/libs/openengine/bullet/physic.cpp b/libs/openengine/bullet/physic.cpp index af73a42a6..2f0624470 100644 --- a/libs/openengine/bullet/physic.cpp +++ b/libs/openengine/bullet/physic.cpp @@ -345,6 +345,18 @@ namespace Physic tr.setRotation(btQuaternion(rotation.x,rotation.y,rotation.z,rotation.w)); body->setWorldTransform(tr); } + void PhysicEngine::boxAdjustExternal(std::string mesh, RigidBody* body, float scale, Ogre::Vector3 position, Ogre::Quaternion rotation){ + std::string sid = (boost::format("%07.3f") % scale).str(); + std::string outputstring = mesh + sid; + //std::cout << "The string" << outputstring << "\n"; + + //get the shape from the .nif + mShapeLoader->load(outputstring,"General"); + BulletShapeManager::getSingletonPtr()->load(outputstring,"General"); + BulletShapePtr shape = BulletShapeManager::getSingleton().getByName(outputstring,"General"); + + adjustRigidBody(shape, body, scale, position, rotation); + } RigidBody* PhysicEngine::createAndAdjustRigidBody(std::string mesh,std::string name,float scale, Ogre::Vector3 position, Ogre::Quaternion rotation) { diff --git a/libs/openengine/bullet/physic.hpp b/libs/openengine/bullet/physic.hpp index fc52ad127..088bbc465 100644 --- a/libs/openengine/bullet/physic.hpp +++ b/libs/openengine/bullet/physic.hpp @@ -149,7 +149,7 @@ namespace Physic RigidBody* createAndAdjustRigidBody(std::string mesh,std::string name,float scale, Ogre::Vector3 position, Ogre::Quaternion rotation); void adjustRigidBody(BulletShapePtr shape, RigidBody* body, float scale, Ogre::Vector3 position, Ogre::Quaternion rotation); - + void boxAdjustExternal(std::string mesh, RigidBody* body, float scale, Ogre::Vector3 position, Ogre::Quaternion rotation); /** * Add a HeightField to the simulation */