Fix for framerate-dependent maximum stepping distance (Bug #1638)

This commit is contained in:
scrawl 2015-01-02 00:34:16 +01:00
parent 4a734f5cd3
commit 593ca6bd48

View file

@ -108,7 +108,7 @@ namespace MWWorld
} }
static bool stepMove(btCollisionObject *colobj, Ogre::Vector3 &position, static bool stepMove(btCollisionObject *colobj, Ogre::Vector3 &position,
const Ogre::Vector3 &velocity, float &remainingTime, const Ogre::Vector3 &toMove, float &remainingTime,
OEngine::Physic::PhysicEngine *engine) OEngine::Physic::PhysicEngine *engine)
{ {
/* /*
@ -124,7 +124,7 @@ namespace MWWorld
* If not successful return 'false'. May fail for these reasons: * If not successful return 'false'. May fail for these reasons:
* - can't move directly up from current position * - can't move directly up from current position
* - having moved up by between epsilon() and sStepSize, can't move forward * - having moved up by between epsilon() and sStepSize, can't move forward
* - having moved forward by between epsilon() and velocity*remainingTime, * - having moved forward by between epsilon() and toMove,
* = moved down between 0 and just under sStepSize but slope was too steep, or * = moved down between 0 and just under sStepSize but slope was too steep, or
* = moved the full sStepSize down (FIXME: this could be a bug) * = moved the full sStepSize down (FIXME: this could be a bug)
* *
@ -133,7 +133,7 @@ namespace MWWorld
* Starting position. Obstacle or stairs with height upto sStepSize in front. * Starting position. Obstacle or stairs with height upto sStepSize in front.
* *
* +--+ +--+ |XX * +--+ +--+ |XX
* | | -------> velocity | | +--+XX * | | -------> toMove | | +--+XX
* | | | | |XXXXX * | | | | |XXXXX
* | | +--+ | | +--+XXXXX * | | +--+ | | +--+XXXXX
* | | |XX| | | |XXXXXXXX * | | |XX| | | |XXXXXXXX
@ -171,11 +171,11 @@ namespace MWWorld
* | | * | |
* <------------------->| | * <------------------->| |
* +--+ +--+ * +--+ +--+
* |XX| the moved amount is velocity*remainingTime*tracer.mFraction * |XX| the moved amount is toMove*tracer.mFraction
* +--+ * +--+
* ============================================== * ==============================================
*/ */
tracer.doTrace(colobj, stepper.mEndPos, stepper.mEndPos + velocity*remainingTime, engine); tracer.doTrace(colobj, stepper.mEndPos, stepper.mEndPos + toMove, engine);
if(tracer.mFraction < std::numeric_limits<float>::epsilon()) if(tracer.mFraction < std::numeric_limits<float>::epsilon())
return false; // didn't even move the smallest representable amount return false; // didn't even move the smallest representable amount
@ -428,9 +428,9 @@ namespace MWWorld
Ogre::Vector3 oldPosition = newPosition; Ogre::Vector3 oldPosition = newPosition;
// We hit something. Try to step up onto it. (NOTE: stepMove does not allow stepping over) // We hit something. Try to step up onto it. (NOTE: stepMove does not allow stepping over)
// NOTE: stepMove modifies newPosition if successful // NOTE: stepMove modifies newPosition if successful
bool result = stepMove(colobj, newPosition, velocity, remainingTime, engine); bool result = stepMove(colobj, newPosition, velocity*remainingTime, remainingTime, engine);
if (!result) if (!result) // to make sure the maximum stepping distance isn't framerate-dependent or movement-speed dependent
result = stepMove(colobj, newPosition, velocity.normalisedCopy()*300.f, remainingTime, engine); result = stepMove(colobj, newPosition, velocity.normalisedCopy()*10.f, remainingTime, engine);
if(result) if(result)
{ {
// don't let pure water creatures move out of water after stepMove // don't let pure water creatures move out of water after stepMove