Store the vertical velocity in the physic actor

actorid
Chris Robinson 12 years ago
parent 82e4da4e64
commit a782a9109b

@ -15,7 +15,6 @@ namespace MWMechanics
MovementSolver::MovementSolver()
: 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.
float maxslope=45;
float verticalVelocity = mPhysicActor->getVerticalForce();
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 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 -= time*400;
mPhysicActor->setVerticalForce(verticalVelocity);
return newPosition;
}

@ -37,8 +37,6 @@ namespace MWMechanics
OEngine::Physic::PhysicEngine *mEngine;
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):
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);
Ogre::Quaternion inverse = mBoxRotation.Inverse();
@ -170,6 +170,17 @@ namespace Physic
return Ogre::Vector3(0.0f);
}
void PhysicActor::setVerticalForce(float force)
{
verticalForce = force;
}
float PhysicActor::getVerticalForce() const
{
return verticalForce;
}
void PhysicActor::runPmove(){
Pmove(pmove);
Ogre::Vector3 newpos = pmove->ps.origin;

@ -122,6 +122,16 @@ namespace Physic
*/
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
*/
@ -141,6 +151,7 @@ namespace Physic
Ogre::Vector3 mBoxScaledTranslation;
btQuaternion mBoxRotationInverse;
Ogre::Quaternion mBoxRotation;
float verticalForce;
bool collisionMode;
std::string mMesh;
PhysicEngine* mEngine;

Loading…
Cancel
Save