mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-01-25 15:35:23 +00:00
Set scale implemented
This commit is contained in:
parent
c5b25ef70b
commit
a1a7733730
@ -218,9 +218,8 @@ namespace MWWorld
|
||||
std::vector< std::pair<std::string, Ogre::Vector3> > response;
|
||||
for(std::map<std::string,OEngine::Physic::PhysicActor*>::iterator it = mEngine->PhysicActorMap.begin(); it != mEngine->PhysicActorMap.end();it++)
|
||||
{
|
||||
btVector3 newPos = it->second->getPosition();
|
||||
|
||||
Ogre::Vector3 coord(newPos.x(), newPos.y(), newPos.z());
|
||||
Ogre::Vector3 coord = it->second->getPosition();
|
||||
if(it->first == "player"){
|
||||
|
||||
coord = playerphysics->ps.origin ;
|
||||
@ -332,6 +331,12 @@ namespace MWWorld
|
||||
Ogre::Vector3 vec = node->getPosition();
|
||||
addObject(handle, handleToMesh[handle], quat, scale, vec);
|
||||
}
|
||||
|
||||
if (OEngine::Physic::PhysicActor* act = mEngine->getCharacter(handle))
|
||||
{
|
||||
float scale = node->getScale().x;
|
||||
act->setScale(scale);
|
||||
}
|
||||
}
|
||||
|
||||
bool PhysicsSystem::toggleCollisionMode()
|
||||
|
@ -29,7 +29,7 @@ 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(mesh, mName, scale, position, rotation, &mBoxScaledTranslation, &mBoxRotation, &mBoxRotationInverse);
|
||||
mBody = mEngine->createAndAdjustRigidBody(mMesh, mName, scale, position, rotation, &mBoxScaledTranslation, &mBoxRotation, &mBoxRotationInverse);
|
||||
mEngine->addRigidBody(mBody, false); //Add rigid body to dynamics world, but do not add to object map
|
||||
}
|
||||
|
||||
@ -74,19 +74,20 @@ namespace Physic
|
||||
//internalGhostObject->getWorldTransform().setRotation( quat );
|
||||
}
|
||||
|
||||
btVector3 PhysicActor::getPosition(void)
|
||||
Ogre::Vector3 PhysicActor::getPosition(void)
|
||||
{
|
||||
btVector3 vec = mBody->getWorldTransform().getOrigin();
|
||||
Ogre::Quaternion rotation = Ogre::Quaternion(mBody->getWorldTransform().getRotation().getW(), mBody->getWorldTransform().getRotation().getX(),
|
||||
mBody->getWorldTransform().getRotation().getY(), mBody->getWorldTransform().getRotation().getZ());
|
||||
Ogre::Vector3 transrot = rotation * mBoxScaledTranslation;
|
||||
btVector3 visualPosition = vec - btVector3(transrot.x, transrot.y, transrot.z);
|
||||
Ogre::Vector3 visualPosition = Ogre::Vector3(vec.getX(), vec.getY(), vec.getZ()) - transrot;
|
||||
return visualPosition;
|
||||
}
|
||||
|
||||
btQuaternion PhysicActor::getRotation(void)
|
||||
Ogre::Quaternion PhysicActor::getRotation(void)
|
||||
{
|
||||
return mBody->getWorldTransform().getRotation() * mBoxRotationInverse;
|
||||
btQuaternion quat = mBody->getWorldTransform().getRotation() * mBoxRotationInverse;
|
||||
return Ogre::Quaternion(quat.getW(), quat.getX(), quat.getY(), quat.getZ());
|
||||
}
|
||||
|
||||
void PhysicActor::setPosition(const btVector3& pos)
|
||||
@ -95,6 +96,22 @@ namespace Physic
|
||||
//externalGhostObject->getWorldTransform().setOrigin(pos+mTranslation);
|
||||
}
|
||||
|
||||
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.
|
||||
mBoxScaledTranslation = mBoxScaledTranslation / mBody->getCollisionShape()->getLocalScaling().getX();
|
||||
mBoxScaledTranslation *= scale;
|
||||
if(mBody){
|
||||
mEngine->dynamicsWorld->removeRigidBody(mBody);
|
||||
delete mBody;
|
||||
}
|
||||
//Create the newly scaled rigid body
|
||||
mBody = mEngine->createAndAdjustRigidBody(mMesh, mName, scale, position, rotation);
|
||||
mEngine->addRigidBody(mBody, false); //Add rigid body to dynamics world, but do not add to object map
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
@ -77,13 +77,13 @@ namespace Physic
|
||||
|
||||
bool getCollisionMode();
|
||||
|
||||
btVector3 getPosition(void);
|
||||
Ogre::Vector3 getPosition(void);
|
||||
|
||||
btQuaternion getRotation(void);
|
||||
Ogre::Quaternion getRotation(void);
|
||||
|
||||
void setPosition(const btVector3& pos);
|
||||
|
||||
|
||||
void setScale(float scale);
|
||||
|
||||
std::string mName;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user