forked from teamnwah/openmw-tes3coop
Setrotate working
This commit is contained in:
parent
a1a7733730
commit
02bca98e9f
3 changed files with 18 additions and 18 deletions
|
@ -257,10 +257,7 @@ namespace MWWorld
|
|||
const Ogre::Vector3& position, float scale, const Ogre::Quaternion& rotation)
|
||||
{
|
||||
//TODO:optimize this. Searching the std::map isn't very efficient i think.
|
||||
std::cout << "NPC position" << position << "\n";
|
||||
mEngine->addCharacter(handle, mesh, position, scale, rotation);
|
||||
|
||||
|
||||
}
|
||||
|
||||
void PhysicsSystem::removeObject (const std::string& handle)
|
||||
|
@ -309,7 +306,7 @@ namespace MWWorld
|
|||
if (OEngine::Physic::PhysicActor* act = mEngine->getCharacter(handle))
|
||||
{
|
||||
//Needs to be changed
|
||||
act->setRotation(btQuaternion(rotation.x, rotation.y, rotation.z, rotation.w));
|
||||
act->setRotation(rotation);
|
||||
}
|
||||
if (OEngine::Physic::RigidBody* body = mEngine->getRigidBody(handle))
|
||||
{
|
||||
|
|
|
@ -29,7 +29,9 @@ namespace Physic
|
|||
PhysicActor::PhysicActor(std::string name, std::string mesh, PhysicEngine* engine, Ogre::Vector3 position, Ogre::Quaternion rotation, float scale):
|
||||
mName(name), mEngine(engine), mMesh(mesh), mBoxScaledTranslation(0,0,0), mBoxRotationInverse(0,0,0,0), mBody(0), collisionMode(false), mBoxRotation(0,0,0,0)
|
||||
{
|
||||
mBody = mEngine->createAndAdjustRigidBody(mMesh, mName, scale, position, rotation, &mBoxScaledTranslation, &mBoxRotation, &mBoxRotationInverse);
|
||||
mBody = mEngine->createAndAdjustRigidBody(mMesh, mName, scale, position, rotation, &mBoxScaledTranslation, &mBoxRotation);
|
||||
Ogre::Quaternion inverse = mBoxRotation.Inverse();
|
||||
mBoxRotationInverse = btQuaternion(inverse.x, inverse.y, inverse.z,inverse.w);
|
||||
mEngine->addRigidBody(mBody, false); //Add rigid body to dynamics world, but do not add to object map
|
||||
}
|
||||
|
||||
|
@ -68,10 +70,11 @@ namespace Physic
|
|||
|
||||
|
||||
|
||||
void PhysicActor::setRotation(const btQuaternion& quat)
|
||||
void PhysicActor::setRotation(const Ogre::Quaternion quat)
|
||||
{
|
||||
//externalGhostObject->getWorldTransform().setRotation( quat );
|
||||
//internalGhostObject->getWorldTransform().setRotation( quat );
|
||||
if(!quat.equals(getRotation(), Ogre::Radian(0))){
|
||||
mEngine->adjustRigidBody(mBody, getPosition(), quat, mBoxScaledTranslation, mBoxRotation);
|
||||
}
|
||||
}
|
||||
|
||||
Ogre::Vector3 PhysicActor::getPosition(void)
|
||||
|
@ -97,7 +100,6 @@ namespace Physic
|
|||
}
|
||||
|
||||
void PhysicActor::setScale(float scale){
|
||||
std::cout << "Trying to set scale to " << scale << "\n";
|
||||
Ogre::Vector3 position = getPosition();
|
||||
Ogre::Quaternion rotation = getRotation();
|
||||
//We only need to change the scaled box translation, box rotations remain the same.
|
||||
|
@ -334,7 +336,7 @@ namespace Physic
|
|||
}
|
||||
|
||||
RigidBody* PhysicEngine::createAndAdjustRigidBody(std::string mesh,std::string name,float scale, Ogre::Vector3 position, Ogre::Quaternion rotation,
|
||||
Ogre::Vector3* scaledBoxTranslation, btQuaternion* boxRotation, btQuaternion* boxRotationInverse)
|
||||
Ogre::Vector3* scaledBoxTranslation, Ogre::Quaternion* boxRotation)
|
||||
{
|
||||
std::string sid = (boost::format("%07.3f") % scale).str();
|
||||
std::string outputstring = mesh + sid;
|
||||
|
@ -357,11 +359,7 @@ namespace Physic
|
|||
if(scaledBoxTranslation != 0)
|
||||
*scaledBoxTranslation = shape->boxTranslation * scale;
|
||||
if(boxRotation != 0)
|
||||
*boxRotation = btQuaternion(shape->boxRotation.x, shape->boxRotation.y, shape->boxRotation.z,shape->boxRotation.w);
|
||||
if(boxRotationInverse != 0){
|
||||
Ogre::Quaternion inverse = shape->boxRotation.Inverse();
|
||||
*boxRotationInverse = btQuaternion(inverse.x,inverse.y,inverse.z,inverse.w);
|
||||
}
|
||||
*boxRotation = shape->boxRotation;
|
||||
|
||||
adjustRigidBody(body, position, rotation, shape->boxTranslation * scale, shape->boxRotation);
|
||||
|
||||
|
|
|
@ -67,7 +67,12 @@ namespace Physic
|
|||
*/
|
||||
void setWalkDirection(const btVector3& mvt);
|
||||
|
||||
void setRotation(const btQuaternion& quat);
|
||||
/**
|
||||
* This adjusts the rotation of a PhysicActor
|
||||
* If we have any problems with this (getting stuck in pmove) we should change it
|
||||
* from setting the visual orientation to setting the orientation of the rigid body directly.
|
||||
*/
|
||||
void setRotation(const Ogre::Quaternion quat);
|
||||
|
||||
void setGravity(float gravity);
|
||||
|
||||
|
@ -92,7 +97,7 @@ namespace Physic
|
|||
OEngine::Physic::RigidBody* mBody;
|
||||
Ogre::Vector3 mBoxScaledTranslation;
|
||||
btQuaternion mBoxRotationInverse;
|
||||
btQuaternion mBoxRotation;
|
||||
Ogre::Quaternion mBoxRotation;
|
||||
bool collisionMode;
|
||||
std::string mMesh;
|
||||
PhysicEngine* mEngine;
|
||||
|
@ -144,7 +149,7 @@ namespace Physic
|
|||
* After created, the body is set to the correct rotation, position, and scale
|
||||
*/
|
||||
RigidBody* createAndAdjustRigidBody(std::string mesh,std::string name,float scale, Ogre::Vector3 position, Ogre::Quaternion rotation,
|
||||
Ogre::Vector3* scaledBoxTranslation = 0, btQuaternion* boxRotation = 0, btQuaternion* boxRotationInverse = 0);
|
||||
Ogre::Vector3* scaledBoxTranslation = 0, Ogre::Quaternion* boxRotation = 0);
|
||||
|
||||
/**
|
||||
* Adjusts a rigid body to the right position and rotation
|
||||
|
|
Loading…
Reference in a new issue