diff options
Diffstat (limited to 'indra/newview/llphysicsmotion.cpp')
-rw-r--r-- | indra/newview/llphysicsmotion.cpp | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/indra/newview/llphysicsmotion.cpp b/indra/newview/llphysicsmotion.cpp index 15d39c231f..f48ce680fd 100644 --- a/indra/newview/llphysicsmotion.cpp +++ b/indra/newview/llphysicsmotion.cpp @@ -44,7 +44,9 @@ typedef std::map<std::string, std::string> controller_map_t; typedef std::map<std::string, F32> default_controller_map_t; #define MIN_REQUIRED_PIXEL_AREA_AVATAR_PHYSICS_MOTION 0.f -#define TIME_ITERATION_STEP 0.1f +// we use TIME_ITERATION_STEP_MAX in division operation, make sure this is a simple +// value and devision result won't end with repeated/recurring tail like 1.333(3) +#define TIME_ITERATION_STEP_MAX 0.05f // minimal step size will end up as 0.025 inline F64 llsgn(const F64 a) { @@ -480,7 +482,7 @@ BOOL LLPhysicsMotion::onUpdate(F32 time) if (!mParamDriver) return FALSE; - if (!mLastTime) + if (!mLastTime || mLastTime >= time) { mLastTime = time; return FALSE; @@ -491,12 +493,6 @@ BOOL LLPhysicsMotion::onUpdate(F32 time) // const F32 time_delta = time - mLastTime; - - // Don't update too frequently, to avoid precision errors from small time slices. - if (time_delta <= .01) - { - return FALSE; - } // If less than 1FPS, we don't want to be spending time updating physics at all. if (time_delta > 1.0) @@ -555,14 +551,22 @@ BOOL LLPhysicsMotion::onUpdate(F32 time) // Break up the physics into a bunch of iterations so that differing framerates will show // roughly the same behavior. - for (F32 time_iteration = 0; time_iteration <= time_delta; time_iteration += TIME_ITERATION_STEP) + // Explanation/example: Lets assume we have a bouncing object. Said abjects bounces at a + // trajectory that has points A>B>C. Object bounces from A to B with specific speed. + // It needs time T to move from A to B. + // As long as our frame's time significantly smaller then T our motion will be split into + // multiple parts. with each part speed will decrease. Object will reach B position (roughly) + // and bounce/fall back to A. + // But if frame's time (F_T) is larger then T, object will move with same speed for whole F_T + // and will jump over point B up to C ending up with increased amplitude. To avoid that we + // split F_T into smaller portions so that when frame's time is too long object can virtually + // bounce at right (relatively) position. + // Note: this doesn't look to be optimal, since it provides only "roughly same" behavior, but + // irregularity at higher fps looks to be insignificant so it works good enough for low fps. + U32 steps = (U32)(time_delta / TIME_ITERATION_STEP_MAX) + 1; + F32 time_iteration_step = time_delta / (F32)steps; //minimal step size ends up as 0.025 + for (U32 i = 0; i < steps; i++) { - F32 time_iteration_step = TIME_ITERATION_STEP; - if (time_iteration + TIME_ITERATION_STEP > time_delta) - { - time_iteration_step = time_delta-time_iteration; - } - // mPositon_local should be in normalized 0,1 range already. Just making sure... const F32 position_current_local = llclamp(mPosition_local, 0.0f, |