mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 23:53:52 +00:00
Fix deleted pointer access (getPosition, getRotation)
This commit is contained in:
parent
2c70074dd7
commit
b98063bba0
1 changed files with 11 additions and 3 deletions
|
@ -19,7 +19,7 @@ namespace Physic
|
||||||
|
|
||||||
PhysicActor::PhysicActor(const std::string &name, const std::string &mesh, PhysicEngine *engine, const Ogre::Vector3 &position, const Ogre::Quaternion &rotation, float scale)
|
PhysicActor::PhysicActor(const std::string &name, const std::string &mesh, PhysicEngine *engine, const Ogre::Vector3 &position, const Ogre::Quaternion &rotation, float scale)
|
||||||
: mName(name), mEngine(engine), mMesh(mesh), mBoxScaledTranslation(0,0,0), mBoxRotationInverse(0,0,0,0)
|
: mName(name), mEngine(engine), mMesh(mesh), mBoxScaledTranslation(0,0,0), mBoxRotationInverse(0,0,0,0)
|
||||||
, mBody(0), onGround(false), collisionMode(true), mBoxRotation(0,0,0,0), verticalForce(0.0f)
|
, mBody(0), mRaycastingBody(0), onGround(false), collisionMode(true), mBoxRotation(0,0,0,0), verticalForce(0.0f)
|
||||||
{
|
{
|
||||||
// FIXME: Force player to start in no-collision mode for now, until he spawns at a proper door marker.
|
// FIXME: Force player to start in no-collision mode for now, until he spawns at a proper door marker.
|
||||||
if(name == "player")
|
if(name == "player")
|
||||||
|
@ -47,6 +47,7 @@ namespace Physic
|
||||||
|
|
||||||
void PhysicActor::enableCollisions(bool collision)
|
void PhysicActor::enableCollisions(bool collision)
|
||||||
{
|
{
|
||||||
|
assert(mBody);
|
||||||
if(collision && !collisionMode) mBody->translate(btVector3(0,0,-1000));
|
if(collision && !collisionMode) mBody->translate(btVector3(0,0,-1000));
|
||||||
if(!collision && collisionMode) mBody->translate(btVector3(0,0,1000));
|
if(!collision && collisionMode) mBody->translate(btVector3(0,0,1000));
|
||||||
collisionMode = collision;
|
collisionMode = collision;
|
||||||
|
@ -55,6 +56,7 @@ namespace Physic
|
||||||
|
|
||||||
void PhysicActor::setPosition(const Ogre::Vector3 &pos)
|
void PhysicActor::setPosition(const Ogre::Vector3 &pos)
|
||||||
{
|
{
|
||||||
|
assert(mBody);
|
||||||
if(pos != getPosition())
|
if(pos != getPosition())
|
||||||
{
|
{
|
||||||
mEngine->adjustRigidBody(mBody, pos, getRotation(), mBoxScaledTranslation, mBoxRotation);
|
mEngine->adjustRigidBody(mBody, pos, getRotation(), mBoxScaledTranslation, mBoxRotation);
|
||||||
|
@ -64,6 +66,7 @@ namespace Physic
|
||||||
|
|
||||||
void PhysicActor::setRotation(const Ogre::Quaternion &quat)
|
void PhysicActor::setRotation(const Ogre::Quaternion &quat)
|
||||||
{
|
{
|
||||||
|
assert(mBody);
|
||||||
if(!quat.equals(getRotation(), Ogre::Radian(0))){
|
if(!quat.equals(getRotation(), Ogre::Radian(0))){
|
||||||
mEngine->adjustRigidBody(mBody, getPosition(), quat, mBoxScaledTranslation, mBoxRotation);
|
mEngine->adjustRigidBody(mBody, getPosition(), quat, mBoxScaledTranslation, mBoxRotation);
|
||||||
mEngine->adjustRigidBody(mRaycastingBody, getPosition(), quat, mBoxScaledTranslation, mBoxRotation);
|
mEngine->adjustRigidBody(mRaycastingBody, getPosition(), quat, mBoxScaledTranslation, mBoxRotation);
|
||||||
|
@ -74,6 +77,7 @@ namespace Physic
|
||||||
|
|
||||||
Ogre::Vector3 PhysicActor::getPosition()
|
Ogre::Vector3 PhysicActor::getPosition()
|
||||||
{
|
{
|
||||||
|
assert(mBody);
|
||||||
btVector3 vec = mBody->getWorldTransform().getOrigin();
|
btVector3 vec = mBody->getWorldTransform().getOrigin();
|
||||||
Ogre::Quaternion rotation = Ogre::Quaternion(mBody->getWorldTransform().getRotation().getW(), mBody->getWorldTransform().getRotation().getX(),
|
Ogre::Quaternion rotation = Ogre::Quaternion(mBody->getWorldTransform().getRotation().getW(), mBody->getWorldTransform().getRotation().getX(),
|
||||||
mBody->getWorldTransform().getRotation().getY(), mBody->getWorldTransform().getRotation().getZ());
|
mBody->getWorldTransform().getRotation().getY(), mBody->getWorldTransform().getRotation().getZ());
|
||||||
|
@ -84,14 +88,18 @@ namespace Physic
|
||||||
|
|
||||||
Ogre::Quaternion PhysicActor::getRotation()
|
Ogre::Quaternion PhysicActor::getRotation()
|
||||||
{
|
{
|
||||||
|
assert(mBody);
|
||||||
btQuaternion quat = mBody->getWorldTransform().getRotation() * mBoxRotationInverse;
|
btQuaternion quat = mBody->getWorldTransform().getRotation() * mBoxRotationInverse;
|
||||||
return Ogre::Quaternion(quat.getW(), quat.getX(), quat.getY(), quat.getZ());
|
return Ogre::Quaternion(quat.getW(), quat.getX(), quat.getY(), quat.getZ());
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhysicActor::setScale(float scale){
|
void PhysicActor::setScale(float scale){
|
||||||
//We only need to change the scaled box translation, box rotations remain the same.
|
//We only need to change the scaled box translation, box rotations remain the same.
|
||||||
|
assert(mBody);
|
||||||
mBoxScaledTranslation = mBoxScaledTranslation / mBody->getCollisionShape()->getLocalScaling().getX();
|
mBoxScaledTranslation = mBoxScaledTranslation / mBody->getCollisionShape()->getLocalScaling().getX();
|
||||||
mBoxScaledTranslation *= scale;
|
mBoxScaledTranslation *= scale;
|
||||||
|
Ogre::Vector3 pos = getPosition();
|
||||||
|
Ogre::Quaternion rot = getRotation();
|
||||||
if(mBody){
|
if(mBody){
|
||||||
mEngine->dynamicsWorld->removeRigidBody(mBody);
|
mEngine->dynamicsWorld->removeRigidBody(mBody);
|
||||||
mEngine->dynamicsWorld->removeRigidBody(mRaycastingBody);
|
mEngine->dynamicsWorld->removeRigidBody(mRaycastingBody);
|
||||||
|
@ -99,8 +107,8 @@ namespace Physic
|
||||||
delete mRaycastingBody;
|
delete mRaycastingBody;
|
||||||
}
|
}
|
||||||
//Create the newly scaled rigid body
|
//Create the newly scaled rigid body
|
||||||
mBody = mEngine->createAndAdjustRigidBody(mMesh, mName, scale, getPosition(), getRotation());
|
mBody = mEngine->createAndAdjustRigidBody(mMesh, mName, scale, pos, rot);
|
||||||
mRaycastingBody = mEngine->createAndAdjustRigidBody(mMesh, mName, scale, getPosition(), getRotation(), 0, 0, true);
|
mRaycastingBody = mEngine->createAndAdjustRigidBody(mMesh, mName, scale, pos, rot, 0, 0, true);
|
||||||
mEngine->addRigidBody(mBody, false, mRaycastingBody); //Add rigid body to dynamics world, but do not add to object map
|
mEngine->addRigidBody(mBody, false, mRaycastingBody); //Add rigid body to dynamics world, but do not add to object map
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue