mirror of
https://github.com/OpenMW/openmw.git
synced 2025-06-19 13:11:32 +00:00
Store the vertical velocity in the physic actor
This commit is contained in:
parent
82e4da4e64
commit
a782a9109b
4 changed files with 25 additions and 4 deletions
|
@ -15,7 +15,6 @@ namespace MWMechanics
|
||||||
|
|
||||||
MovementSolver::MovementSolver()
|
MovementSolver::MovementSolver()
|
||||||
: mEngine(MWBase::Environment::get().getWorld()->getPhysicEngine())
|
: mEngine(MWBase::Environment::get().getWorld()->getPhysicEngine())
|
||||||
, verticalVelocity(0.0f)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,6 +88,7 @@ Ogre::Vector3 MovementSolver::move(const MWWorld::Ptr &ptr, const Ogre::Vector3
|
||||||
int iterations=0, maxIterations=50; //arbitrary number. To prevent infinite loops. They shouldn't happen but it's good to be prepared.
|
int iterations=0, maxIterations=50; //arbitrary number. To prevent infinite loops. They shouldn't happen but it's good to be prepared.
|
||||||
float maxslope=45;
|
float maxslope=45;
|
||||||
|
|
||||||
|
float verticalVelocity = mPhysicActor->getVerticalForce();
|
||||||
Ogre::Vector3 horizontalVelocity = movement/time;
|
Ogre::Vector3 horizontalVelocity = movement/time;
|
||||||
Ogre::Vector3 velocity(horizontalVelocity.x, horizontalVelocity.y, verticalVelocity); // we need a copy of the velocity before we start clipping it for steps
|
Ogre::Vector3 velocity(horizontalVelocity.x, horizontalVelocity.y, verticalVelocity); // we need a copy of the velocity before we start clipping it for steps
|
||||||
Ogre::Vector3 clippedVelocity(horizontalVelocity.x, horizontalVelocity.y, verticalVelocity);
|
Ogre::Vector3 clippedVelocity(horizontalVelocity.x, horizontalVelocity.y, verticalVelocity);
|
||||||
|
@ -156,6 +156,7 @@ Ogre::Vector3 MovementSolver::move(const MWWorld::Ptr &ptr, const Ogre::Vector3
|
||||||
|
|
||||||
verticalVelocity = clippedVelocity.z;
|
verticalVelocity = clippedVelocity.z;
|
||||||
verticalVelocity -= time*400;
|
verticalVelocity -= time*400;
|
||||||
|
mPhysicActor->setVerticalForce(verticalVelocity);
|
||||||
|
|
||||||
return newPosition;
|
return newPosition;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,8 +37,6 @@ namespace MWMechanics
|
||||||
|
|
||||||
OEngine::Physic::PhysicEngine *mEngine;
|
OEngine::Physic::PhysicEngine *mEngine;
|
||||||
OEngine::Physic::PhysicActor *mPhysicActor;
|
OEngine::Physic::PhysicActor *mPhysicActor;
|
||||||
|
|
||||||
float verticalVelocity;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ namespace Physic
|
||||||
};
|
};
|
||||||
|
|
||||||
PhysicActor::PhysicActor(std::string name, std::string mesh, PhysicEngine* engine, Ogre::Vector3 position, Ogre::Quaternion rotation, float scale):
|
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)
|
mName(name), mEngine(engine), mMesh(mesh), mBoxScaledTranslation(0,0,0), mBoxRotationInverse(0,0,0,0), mBody(0), collisionMode(false), mBoxRotation(0,0,0,0), verticalForce(0.0f)
|
||||||
{
|
{
|
||||||
mBody = mEngine->createAndAdjustRigidBody(mMesh, mName, scale, position, rotation, &mBoxScaledTranslation, &mBoxRotation);
|
mBody = mEngine->createAndAdjustRigidBody(mMesh, mName, scale, position, rotation, &mBoxScaledTranslation, &mBoxRotation);
|
||||||
Ogre::Quaternion inverse = mBoxRotation.Inverse();
|
Ogre::Quaternion inverse = mBoxRotation.Inverse();
|
||||||
|
@ -170,6 +170,17 @@ namespace Physic
|
||||||
return Ogre::Vector3(0.0f);
|
return Ogre::Vector3(0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PhysicActor::setVerticalForce(float force)
|
||||||
|
{
|
||||||
|
verticalForce = force;
|
||||||
|
}
|
||||||
|
|
||||||
|
float PhysicActor::getVerticalForce() const
|
||||||
|
{
|
||||||
|
return verticalForce;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void PhysicActor::runPmove(){
|
void PhysicActor::runPmove(){
|
||||||
Pmove(pmove);
|
Pmove(pmove);
|
||||||
Ogre::Vector3 newpos = pmove->ps.origin;
|
Ogre::Vector3 newpos = pmove->ps.origin;
|
||||||
|
|
|
@ -122,6 +122,16 @@ namespace Physic
|
||||||
*/
|
*/
|
||||||
Ogre::Vector3 getHalfExtents() const;
|
Ogre::Vector3 getHalfExtents() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the current amount of vertical force (gravity) affecting this physic actor
|
||||||
|
*/
|
||||||
|
void setVerticalForce(float force);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the current amount of vertical force (gravity) affecting this physic actor
|
||||||
|
*/
|
||||||
|
float getVerticalForce() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs pmove for this PhysicActor
|
* Runs pmove for this PhysicActor
|
||||||
*/
|
*/
|
||||||
|
@ -141,6 +151,7 @@ namespace Physic
|
||||||
Ogre::Vector3 mBoxScaledTranslation;
|
Ogre::Vector3 mBoxScaledTranslation;
|
||||||
btQuaternion mBoxRotationInverse;
|
btQuaternion mBoxRotationInverse;
|
||||||
Ogre::Quaternion mBoxRotation;
|
Ogre::Quaternion mBoxRotation;
|
||||||
|
float verticalForce;
|
||||||
bool collisionMode;
|
bool collisionMode;
|
||||||
std::string mMesh;
|
std::string mMesh;
|
||||||
PhysicEngine* mEngine;
|
PhysicEngine* mEngine;
|
||||||
|
|
Loading…
Reference in a new issue