From c8a932fa8a09a925c0cb3a0bc25e90456bb56d68 Mon Sep 17 00:00:00 2001 From: andreykproductengine Date: Fri, 25 Aug 2017 16:43:19 +0300 Subject: MAINT-989 Fixed Avatar Physics Vary Extremely With Different Framerates --- indra/newview/llphysicsmotion.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'indra/newview/llphysicsmotion.cpp') diff --git a/indra/newview/llphysicsmotion.cpp b/indra/newview/llphysicsmotion.cpp index ea10d03264..65b57a2790 100644 --- a/indra/newview/llphysicsmotion.cpp +++ b/indra/newview/llphysicsmotion.cpp @@ -44,7 +44,7 @@ typedef std::map controller_map_t; typedef std::map default_controller_map_t; #define MIN_REQUIRED_PIXEL_AREA_AVATAR_PHYSICS_MOTION 0.f -#define TIME_ITERATION_STEP 0.1f +#define TIME_ITERATION_STEP 0.033f // roughtly 30 fps inline F64 llsgn(const F64 a) { @@ -493,8 +493,8 @@ 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) + // Don't update too frequently (below 0.01), to avoid precision errors from small time slices. + if (time_delta <= TIME_ITERATION_STEP) { return FALSE; } @@ -561,7 +561,10 @@ BOOL LLPhysicsMotion::onUpdate(F32 time) F32 time_iteration_step = TIME_ITERATION_STEP; if (time_iteration + TIME_ITERATION_STEP > time_delta) { - time_iteration_step = time_delta-time_iteration; + time_iteration_step = time_delta - time_iteration; + // Leave the rest for next update. + mLastTime = time - time_iteration_step; + break; } // mPositon_local should be in normalized 0,1 range already. Just making sure... @@ -716,7 +719,6 @@ BOOL LLPhysicsMotion::onUpdate(F32 time) mAccelerationJoint_local = acceleration_joint_local; mPosition_local = position_new_local; } - mLastTime = time; mPosition_world = joint->getWorldPosition(); mVelocityJoint_local = velocity_joint_local; -- cgit v1.2.3 From 86314969e6cbb5bb9b3fdedfafc3d82d9d57f854 Mon Sep 17 00:00:00 2001 From: andreykproductengine Date: Mon, 16 Oct 2017 12:24:42 +0300 Subject: Backed out MAINT-989, changeset: 0a9a1e276e57 --- indra/newview/llphysicsmotion.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'indra/newview/llphysicsmotion.cpp') diff --git a/indra/newview/llphysicsmotion.cpp b/indra/newview/llphysicsmotion.cpp index 65b57a2790..ea10d03264 100644 --- a/indra/newview/llphysicsmotion.cpp +++ b/indra/newview/llphysicsmotion.cpp @@ -44,7 +44,7 @@ typedef std::map controller_map_t; typedef std::map default_controller_map_t; #define MIN_REQUIRED_PIXEL_AREA_AVATAR_PHYSICS_MOTION 0.f -#define TIME_ITERATION_STEP 0.033f // roughtly 30 fps +#define TIME_ITERATION_STEP 0.1f inline F64 llsgn(const F64 a) { @@ -493,8 +493,8 @@ BOOL LLPhysicsMotion::onUpdate(F32 time) const F32 time_delta = time - mLastTime; - // Don't update too frequently (below 0.01), to avoid precision errors from small time slices. - if (time_delta <= TIME_ITERATION_STEP) + // Don't update too frequently, to avoid precision errors from small time slices. + if (time_delta <= .01) { return FALSE; } @@ -561,10 +561,7 @@ BOOL LLPhysicsMotion::onUpdate(F32 time) F32 time_iteration_step = TIME_ITERATION_STEP; if (time_iteration + TIME_ITERATION_STEP > time_delta) { - time_iteration_step = time_delta - time_iteration; - // Leave the rest for next update. - mLastTime = time - time_iteration_step; - break; + time_iteration_step = time_delta-time_iteration; } // mPositon_local should be in normalized 0,1 range already. Just making sure... @@ -719,6 +716,7 @@ BOOL LLPhysicsMotion::onUpdate(F32 time) mAccelerationJoint_local = acceleration_joint_local; mPosition_local = position_new_local; } + mLastTime = time; mPosition_world = joint->getWorldPosition(); mVelocityJoint_local = velocity_joint_local; -- cgit v1.2.3 From c0492e5448ed7bb3265af2f0e5385faaeab85ba5 Mon Sep 17 00:00:00 2001 From: andreykproductengine Date: Tue, 17 Oct 2017 20:02:29 +0300 Subject: MAINT-989 Velocity and acceleration should take time into account --- indra/newview/llphysicsmotion.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'indra/newview/llphysicsmotion.cpp') diff --git a/indra/newview/llphysicsmotion.cpp b/indra/newview/llphysicsmotion.cpp index ea10d03264..15d39c231f 100644 --- a/indra/newview/llphysicsmotion.cpp +++ b/indra/newview/llphysicsmotion.cpp @@ -171,8 +171,8 @@ protected: F32 behavior_maxeffect); F32 toLocal(const LLVector3 &world); - F32 calculateVelocity_local(); - F32 calculateAcceleration_local(F32 velocity_local); + F32 calculateVelocity_local(const F32 time_delta); + F32 calculateAcceleration_local(F32 velocity_local, const F32 time_delta); private: const std::string mParamDriverName; const std::string mParamControllerName; @@ -425,23 +425,22 @@ F32 LLPhysicsMotion::toLocal(const LLVector3 &world) return world * dir_world; } -F32 LLPhysicsMotion::calculateVelocity_local() +F32 LLPhysicsMotion::calculateVelocity_local(const F32 time_delta) { const F32 world_to_model_scale = 100.0f; LLJoint *joint = mJointState->getJoint(); const LLVector3 position_world = joint->getWorldPosition(); const LLVector3 last_position_world = mPosition_world; const LLVector3 positionchange_world = (position_world-last_position_world) * world_to_model_scale; - const LLVector3 velocity_world = positionchange_world; - const F32 velocity_local = toLocal(velocity_world); + const F32 velocity_local = toLocal(positionchange_world) / time_delta; return velocity_local; } -F32 LLPhysicsMotion::calculateAcceleration_local(const F32 velocity_local) +F32 LLPhysicsMotion::calculateAcceleration_local(const F32 velocity_local, const F32 time_delta) { // const F32 smoothing = getParamValue("Smoothing"); static const F32 smoothing = 3.0f; // Removed smoothing param since it's probably not necessary - const F32 acceleration_local = velocity_local - mVelocityJoint_local; + const F32 acceleration_local = (velocity_local - mVelocityJoint_local) / time_delta; const F32 smoothed_acceleration_local = acceleration_local * 1.0/smoothing + @@ -544,9 +543,9 @@ BOOL LLPhysicsMotion::onUpdate(F32 time) // Calculate velocity and acceleration in parameter space. // - //const F32 velocity_joint_local = calculateVelocity_local(time_iteration_step); - const F32 velocity_joint_local = calculateVelocity_local(); - const F32 acceleration_joint_local = calculateAcceleration_local(velocity_joint_local); + const F32 joint_local_factor = 30.0; + const F32 velocity_joint_local = calculateVelocity_local(time_delta * joint_local_factor); + const F32 acceleration_joint_local = calculateAcceleration_local(velocity_joint_local, time_delta * joint_local_factor); // // End velocity and acceleration -- cgit v1.2.3