Skip to content
Snippets Groups Projects
Commit 8b064070 authored by Loren Shih's avatar Loren Shih
Browse files

SH-1381 FIXED avatar physics behavior is tightly tied to viewer framerate

Breaking up physics into smaller integration steps.
parent 91409d40
Branches
Tags
No related merge requests found
...@@ -43,7 +43,8 @@ ...@@ -43,7 +43,8 @@
typedef std::map<std::string, std::string> controller_map_t; typedef std::map<std::string, std::string> controller_map_t;
typedef std::map<std::string, F32> default_controller_map_t; typedef std::map<std::string, F32> default_controller_map_t;
#define MIN_REQUIRED_PIXEL_AREA_AVATAR_PHYSICS_MOTION 0.f; #define MIN_REQUIRED_PIXEL_AREA_AVATAR_PHYSICS_MOTION 0.f
#define TIME_ITERATION_STEP 0.1f
inline F64 llsgn(const F64 a) inline F64 llsgn(const F64 a)
{ {
...@@ -453,7 +454,8 @@ BOOL LLPhysicsMotion::onUpdate(F32 time) ...@@ -453,7 +454,8 @@ BOOL LLPhysicsMotion::onUpdate(F32 time)
return FALSE; return FALSE;
} }
if (time_delta > 3.0) // If less than 1FPS, we don't want to be spending time updating physics at all.
if (time_delta > 1.0)
{ {
mLastTime = time; mLastTime = time;
return FALSE; return FALSE;
...@@ -481,6 +483,18 @@ BOOL LLPhysicsMotion::onUpdate(F32 time) ...@@ -481,6 +483,18 @@ BOOL LLPhysicsMotion::onUpdate(F32 time)
if (physics_test) if (physics_test)
behavior_maxeffect = 1.0f; behavior_maxeffect = 1.0f;
BOOL update_visuals = FALSE;
// 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)
{
F32 time_iteration_step = TIME_ITERATION_STEP;
if (time_iteration + TIME_ITERATION_STEP > time_delta)
{
time_iteration_step = time_delta;
}
// mPositon_local should be in normalized 0,1 range already. Just making sure... // mPositon_local should be in normalized 0,1 range already. Just making sure...
F32 position_current_local = llclamp(mPosition_local, F32 position_current_local = llclamp(mPosition_local,
0.0f, 0.0f,
...@@ -509,8 +523,8 @@ BOOL LLPhysicsMotion::onUpdate(F32 time) ...@@ -509,8 +523,8 @@ BOOL LLPhysicsMotion::onUpdate(F32 time)
// Calculate velocity and acceleration in parameter space. // Calculate velocity and acceleration in parameter space.
// //
const F32 velocity_joint_local = calculateVelocity_local(time_delta); const F32 velocity_joint_local = calculateVelocity_local(time_iteration_step);
const F32 acceleration_joint_local = calculateAcceleration_local(velocity_joint_local, time_delta); const F32 acceleration_joint_local = calculateAcceleration_local(velocity_joint_local, time_iteration_step);
// //
// End velocity and acceleration // End velocity and acceleration
...@@ -572,7 +586,7 @@ BOOL LLPhysicsMotion::onUpdate(F32 time) ...@@ -572,7 +586,7 @@ BOOL LLPhysicsMotion::onUpdate(F32 time)
velocity_new_local = sin(time*4.0); velocity_new_local = sin(time*4.0);
} }
// Calculate the new parameters, or remain unchanged if max speed is 0. // Calculate the new parameters, or remain unchanged if max speed is 0.
F32 position_new_local = position_current_local + velocity_new_local*time_delta; F32 position_new_local = position_current_local + velocity_new_local*time_iteration_step;
if (behavior_maxeffect == 0) if (behavior_maxeffect == 0)
position_new_local = position_user_local; position_new_local = position_user_local;
...@@ -638,8 +652,6 @@ BOOL LLPhysicsMotion::onUpdate(F32 time) ...@@ -638,8 +652,6 @@ BOOL LLPhysicsMotion::onUpdate(F32 time)
// So only update if the params have changed enough, and also take into account // So only update if the params have changed enough, and also take into account
// the graphics LOD settings. // the graphics LOD settings.
BOOL update_visuals = FALSE;
// For non-self, if the avatar is small enough visually, then don't update. // For non-self, if the avatar is small enough visually, then don't update.
const F32 area_for_max_settings = 0.0; const F32 area_for_max_settings = 0.0;
const F32 area_for_min_settings = 1400.0; const F32 area_for_min_settings = 1400.0;
...@@ -669,6 +681,8 @@ BOOL LLPhysicsMotion::onUpdate(F32 time) ...@@ -669,6 +681,8 @@ BOOL LLPhysicsMotion::onUpdate(F32 time)
mPosition_local = position_new_local; mPosition_local = position_new_local;
mPosition_world = joint->getWorldPosition(); mPosition_world = joint->getWorldPosition();
}
mLastTime = time; mLastTime = time;
/* /*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment