Permalink
Browse files

I was critically damp once. It was okay.

  • Loading branch information...
Shyotl committed Mar 14, 2017
1 parent 7dd6163 commit 4a9ff22eebe628f5ac547ddaffdc75918dbf2db2
@@ -240,7 +240,7 @@ BOOL LLEditingMotion::onUpdate(F32 time, U8* joint_mask)
mIKSolver.solve();
// use blending...
F32 slerp_amt = LLCriticalDamp::getInterpolant(TARGET_LAG_HALF_LIFE);
F32 slerp_amt = LLSmoothInterpolation::getInterpolant(TARGET_LAG_HALF_LIFE);
shoulderRot = slerp(slerp_amt, mShoulderJoint.getRotation(), shoulderRot);
elbowRot = slerp(slerp_amt, mElbowJoint.getRotation(), elbowRot);
@@ -181,8 +181,8 @@ BOOL LLHeadRotMotion::onUpdate(F32 time, U8* joint_mask)
LLQuaternion currentRootRotWorld = mRootJoint->getWorldRotation();
LLQuaternion currentInvRootRotWorld = ~currentRootRotWorld;
F32 head_slerp_amt = LLCriticalDamp::getInterpolant(HEAD_LOOKAT_LAG_HALF_LIFE);
F32 torso_slerp_amt = LLCriticalDamp::getInterpolant(TORSO_LOOKAT_LAG_HALF_LIFE);
F32 head_slerp_amt = LLSmoothInterpolation::getInterpolant(HEAD_LOOKAT_LAG_HALF_LIFE);
F32 torso_slerp_amt = LLSmoothInterpolation::getInterpolant(TORSO_LOOKAT_LAG_HALF_LIFE);
LLVector3* targetPos = (LLVector3*)mCharacter->getAnimationData("LookAtPoint");
@@ -1101,11 +1101,11 @@ void LLKeyframeMotion::applyConstraint(JointConstraint* constraint, F32 time, U8
if (constraint->mSharedData->mChainLength != 0 &&
dist_vec_squared(root_pos, target_pos) * 0.95f > constraint->mTotalLength * constraint->mTotalLength)
{
constraint->mWeight = lerp(constraint->mWeight, 0.f, LLCriticalDamp::getInterpolant(0.1f));
constraint->mWeight = lerp(constraint->mWeight, 0.f, LLSmoothInterpolation::getInterpolant(0.1f));
}
else
{
constraint->mWeight = lerp(constraint->mWeight, 1.f, LLCriticalDamp::getInterpolant(0.3f));
constraint->mWeight = lerp(constraint->mWeight, 1.f, LLSmoothInterpolation::getInterpolant(0.3f));
}
F32 weight = constraint->mWeight * ((shared_data->mEaseOutStopTime == 0.f) ? 1.f :
@@ -1152,9 +1152,9 @@ void LLKeyframeMotion::applyConstraint(JointConstraint* constraint, F32 time, U8
// convert intermediate joint positions to world coordinates
positions[joint_num] = ( constraint->mPositions[joint_num] * mPelvisp->getWorldRotation()) + mPelvisp->getWorldPosition();
F32 time_constant = 1.f / clamp_rescale(constraint->mFixupDistanceRMS, 0.f, 0.5f, 0.2f, 8.f);
// LL_INFOS() << "Interpolant " << LLCriticalDamp::getInterpolant(time_constant, FALSE) << " and fixup distance " << constraint->mFixupDistanceRMS << " on " << mCharacter->findCollisionVolume(shared_data->mSourceConstraintVolume)->getName() << LL_ENDL;
// LL_INFOS() << "Interpolant " << LLSmoothInterpolation::getInterpolant(time_constant, FALSE) << " and fixup distance " << constraint->mFixupDistanceRMS << " on " << mCharacter->findCollisionVolume(shared_data->mSourceConstraintVolume)->getName() << LL_ENDL;
positions[joint_num] = lerp(positions[joint_num], kinematic_position,
LLCriticalDamp::getInterpolant(time_constant, FALSE));
LLSmoothInterpolation::getInterpolant(time_constant, FALSE));
}
S32 iteration_count;
@@ -258,7 +258,7 @@ BOOL LLWalkAdjustMotion::onUpdate(F32 time, U8* joint_mask)
// but this will cause the animation playback rate calculation below to
// kick in too slowly and sometimes start playing the animation in reverse.
//mPelvisOffset -= PELVIS_COMPENSATION_WIEGHT * (foot_slip_vector * world_to_avatar_rot);//lerp(LLVector3::zero, -1.f * (foot_slip_vector * world_to_avatar_rot), LLCriticalDamp::getInterpolant(0.1f));
//mPelvisOffset -= PELVIS_COMPENSATION_WIEGHT * (foot_slip_vector * world_to_avatar_rot);//lerp(LLVector3::zero, -1.f * (foot_slip_vector * world_to_avatar_rot), LLSmoothInterpolation::getInterpolant(0.1f));
////F32 drift_comp_max = DRIFT_COMP_MAX_TOTAL * (llclamp(speed, 0.f, DRIFT_COMP_MAX_SPEED) / DRIFT_COMP_MAX_SPEED);
//F32 drift_comp_max = DRIFT_COMP_MAX_TOTAL;
@@ -287,7 +287,7 @@ BOOL LLWalkAdjustMotion::onUpdate(F32 time, U8* joint_mask)
F32 desired_speed_multiplier = llclamp(speed / foot_speed, min_speed_multiplier, ANIM_SPEED_MAX);
// blend towards new speed adjustment value
F32 new_speed_adjust = lerp(mAdjustedSpeed, desired_speed_multiplier, LLCriticalDamp::getInterpolant(SPEED_ADJUST_TIME_CONSTANT));
F32 new_speed_adjust = lerp(mAdjustedSpeed, desired_speed_multiplier, LLSmoothInterpolation::getInterpolant(SPEED_ADJUST_TIME_CONSTANT));
// limit that rate at which the speed adjustment changes
F32 speedDelta = llclamp(new_speed_adjust - mAdjustedSpeed, -SPEED_ADJUST_MAX_SEC * delta_time, SPEED_ADJUST_MAX_SEC * delta_time);
@@ -305,8 +305,8 @@ BOOL LLWalkAdjustMotion::onUpdate(F32 time, U8* joint_mask)
{ // standing/turning
// damp out speed adjustment to 0
mAnimSpeed = lerp(mAnimSpeed, 1.f, LLCriticalDamp::getInterpolant(0.2f));
//mPelvisOffset = lerp(mPelvisOffset, LLVector3::zero, LLCriticalDamp::getInterpolant(0.2f));
mAnimSpeed = lerp(mAnimSpeed, 1.f, LLSmoothInterpolation::getInterpolant(0.2f));
//mPelvisOffset = lerp(mPelvisOffset, LLVector3::zero, LLSmoothInterpolation::getInterpolant(0.2f));
}
// broadcast walk speed change
@@ -384,7 +384,7 @@ BOOL LLFlyAdjustMotion::onUpdate(F32 time, U8* joint_mask)
F32 target_roll = llclamp(ang_vel.mV[VZ], -4.f, 4.f) * roll_factor;
// roll is critically damped interpolation between current roll and angular velocity-derived target roll
mRoll = lerp(mRoll, target_roll, LLCriticalDamp::getInterpolant(0.1f));
mRoll = lerp(mRoll, target_roll, LLSmoothInterpolation::getInterpolant(0.1f));
LLQuaternion roll(mRoll, LLVector3(0.f, 0.f, 1.f));
mPelvisState->setRotation(roll);
@@ -199,7 +199,7 @@ void LLMotion::fadeOut()
{
if (mFadeWeight > 0.01f)
{
mFadeWeight = lerp(mFadeWeight, 0.f, LLCriticalDamp::getInterpolant(0.15f));
mFadeWeight = lerp(mFadeWeight, 0.f, LLSmoothInterpolation::getInterpolant(0.15f));
}
else
{
@@ -214,7 +214,7 @@ void LLMotion::fadeIn()
{
if (mFadeWeight < 0.99f)
{
mFadeWeight = lerp(mFadeWeight, 1.f, LLCriticalDamp::getInterpolant(0.15f));
mFadeWeight = lerp(mFadeWeight, 1.f, LLSmoothInterpolation::getInterpolant(0.15f));
}
else
{
@@ -104,7 +104,7 @@ LLMotion::LLMotionInitStatus LLTargetingMotion::onInitialize(LLCharacter *charac
//-----------------------------------------------------------------------------
BOOL LLTargetingMotion::onUpdate(F32 time, U8* joint_mask)
{
F32 slerp_amt = LLCriticalDamp::getInterpolant(TORSO_TARGET_HALF_LIFE);
F32 slerp_amt = LLSmoothInterpolation::getInterpolant(TORSO_TARGET_HALF_LIFE);
LLVector3 target;
LLVector3* lookAtPoint = (LLVector3*)mCharacter->getAnimationData("LookAtPoint");
@@ -33,63 +33,105 @@
#include "linden_common.h"
#include "llcriticaldamp.h"
#include <algorithm>
//-----------------------------------------------------------------------------
// static members
//-----------------------------------------------------------------------------
LLFrameTimer LLCriticalDamp::sInternalTimer;
std::map<F32, F32> LLCriticalDamp::sInterpolants;
F32 LLCriticalDamp::sTimeDelta;
LLFrameTimer LLSmoothInterpolation::sInternalTimer;
std::vector<LLSmoothInterpolation::Interpolant> LLSmoothInterpolation::sInterpolants;
F32 LLSmoothInterpolation::sTimeDelta;
std::pair<F32, F32> sCachedEntry;
// helper functors
struct LLSmoothInterpolation::CompareTimeConstants
{
bool operator()(const F32& a, const LLSmoothInterpolation::Interpolant& b) const
{
return a < b.mTimeScale;
}
bool operator()(const LLSmoothInterpolation::Interpolant& a, const F32& b) const
{
return a.mTimeScale < b; // bottom of a is higher than bottom of b
}
bool operator()(const LLSmoothInterpolation::Interpolant& a, const LLSmoothInterpolation::Interpolant& b) const
{
return a.mTimeScale < b.mTimeScale; // bottom of a is higher than bottom of b
}
};
//-----------------------------------------------------------------------------
// LLCriticalDamp()
// LLSmoothInterpolation()
//-----------------------------------------------------------------------------
LLCriticalDamp::LLCriticalDamp()
LLSmoothInterpolation::LLSmoothInterpolation()
{
sTimeDelta = 0.f;
sCachedEntry = std::pair<F32, F32>(-1.f, -1.f);
}
// static
//-----------------------------------------------------------------------------
// updateInterpolants()
//-----------------------------------------------------------------------------
void LLCriticalDamp::updateInterpolants()
void LLSmoothInterpolation::updateInterpolants()
{
sTimeDelta = sInternalTimer.getElapsedTimeAndResetF32();
F32 time_constant;
for (std::map<F32, F32>::iterator iter = sInterpolants.begin();
iter != sInterpolants.end(); iter++)
for (size_t i = 0; i < sInterpolants.size(); i++)
{
time_constant = iter->first;
F32 new_interpolant = 1.f - pow(2.f, -sTimeDelta / time_constant);
new_interpolant = llclamp(new_interpolant, 0.f, 1.f);
sInterpolants[time_constant] = new_interpolant;
Interpolant& interp = sInterpolants[i];
interp.mInterpolant = calcInterpolant(interp.mTimeScale);
if (sCachedEntry.first == interp.mTimeScale)
{
sCachedEntry.second = interp.mInterpolant;
}
}
}
//-----------------------------------------------------------------------------
// getInterpolant()
//-----------------------------------------------------------------------------
F32 LLCriticalDamp::getInterpolant(const F32 time_constant, BOOL use_cache)
F32 LLSmoothInterpolation::getInterpolant(F32SecondsImplicit time_constant, bool use_cache)
{
if (time_constant == 0.f)
{
return 1.f;
}
if (use_cache && sInterpolants.count(time_constant))
if (use_cache)
{
return sInterpolants[time_constant];
if (sCachedEntry.first == time_constant)
{
return sCachedEntry.second;
}
interpolant_vec_t::iterator find_it = std::lower_bound(sInterpolants.begin(), sInterpolants.end(), time_constant.value(), CompareTimeConstants());
if (find_it != sInterpolants.end() && find_it->mTimeScale == time_constant)
{
sCachedEntry = std::make_pair(time_constant.value(), find_it->mInterpolant);
return find_it->mInterpolant;
}
else
{
Interpolant interp;
interp.mTimeScale = time_constant.value();
interp.mInterpolant = calcInterpolant(time_constant.value());
sInterpolants.insert(find_it, interp);
sCachedEntry = std::make_pair(time_constant.value(), interp.mInterpolant);
return interp.mInterpolant;
}
}
F32 interpolant = 1.f - pow(2.f, -sTimeDelta / time_constant);
interpolant = llclamp(interpolant, 0.f, 1.f);
if (use_cache)
else
{
sInterpolants[time_constant] = interpolant;
return calcInterpolant(time_constant.value());
}
}
return interpolant;
//-----------------------------------------------------------------------------
// calcInterpolant()
//-----------------------------------------------------------------------------
F32 LLSmoothInterpolation::calcInterpolant(F32 time_constant)
{
return llclamp(1.f - powf(2.f, -sTimeDelta / time_constant), 0.f, 1.f);
}
@@ -34,26 +34,46 @@
#ifndef LL_LLCRITICALDAMP_H
#define LL_LLCRITICALDAMP_H
#include <map>
#include <vector>
#include "llframetimer.h"
#include "llunits.h"
class LL_COMMON_API LLCriticalDamp
class LL_COMMON_API LLSmoothInterpolation
{
public:
LLCriticalDamp();
LLSmoothInterpolation();
// MANIPULATORS
static void updateInterpolants();
// ACCESSORS
static F32 getInterpolant(const F32 time_constant, BOOL use_cache = TRUE);
static F32 getInterpolant(F32SecondsImplicit time_constant, bool use_cache = true);
protected:
template<typename T>
static T lerp(T a, T b, F32SecondsImplicit time_constant, bool use_cache = true)
{
F32 interpolant = getInterpolant(time_constant, use_cache);
return ((a * (1.f - interpolant))
+ (b * interpolant));
}
protected:
static F32 calcInterpolant(F32 time_constant);
struct CompareTimeConstants;
static LLFrameTimer sInternalTimer; // frame timer for calculating deltas
static std::map<F32, F32> sInterpolants;
struct Interpolant
{
F32 mTimeScale;
F32 mInterpolant;
};
typedef std::vector<Interpolant> interpolant_vec_t;
static interpolant_vec_t sInterpolants;
static F32 sTimeDelta;
};
typedef LLSmoothInterpolation LLCriticalDamp;
#endif // LL_LLCRITICALDAMP_H
@@ -2135,12 +2135,8 @@ void LLRender::end()
}
}
extern bool countFlushes;
extern unsigned int flushCount;
void LLRender::flush()
{
if (countFlushes) ++flushCount;
if (mCount > 0)
{
#if 0
View
@@ -704,11 +704,11 @@ void LLButton::draw()
mCurGlowStrength = lerp(mCurGlowStrength,
mFlashing ? (flash? 1.0 : 0.0)
: mHoverGlowStrength,
LLCriticalDamp::getInterpolant(0.05f));
LLSmoothInterpolation::getInterpolant(0.05f));
}
else
{
mCurGlowStrength = lerp(mCurGlowStrength, 0.f, LLCriticalDamp::getInterpolant(0.05f));
mCurGlowStrength = lerp(mCurGlowStrength, 0.f, LLSmoothInterpolation::getInterpolant(0.05f));
}
// Draw button image, if available.
@@ -621,7 +621,7 @@ bool LLLayoutStack::animatePanels()
{
if (!mAnimatedThisFrame)
{
panelp->mVisibleAmt = lerp(panelp->mVisibleAmt, 1.f, LLCriticalDamp::getInterpolant(mOpenTimeConstant));
panelp->mVisibleAmt = lerp(panelp->mVisibleAmt, 1.f, LLSmoothInterpolation::getInterpolant(mOpenTimeConstant));
if (panelp->mVisibleAmt > 0.99f)
{
panelp->mVisibleAmt = 1.f;
@@ -646,7 +646,7 @@ bool LLLayoutStack::animatePanels()
{
if (!mAnimatedThisFrame)
{
panelp->mVisibleAmt = lerp(panelp->mVisibleAmt, 0.f, LLCriticalDamp::getInterpolant(mCloseTimeConstant));
panelp->mVisibleAmt = lerp(panelp->mVisibleAmt, 0.f, LLSmoothInterpolation::getInterpolant(mCloseTimeConstant));
if (panelp->mVisibleAmt < 0.001f)
{
panelp->mVisibleAmt = 0.f;
@@ -673,7 +673,7 @@ bool LLLayoutStack::animatePanels()
{
if (!mAnimatedThisFrame)
{
panelp->mCollapseAmt = lerp(panelp->mCollapseAmt, collapse_state, LLCriticalDamp::getInterpolant(mCloseTimeConstant));
panelp->mCollapseAmt = lerp(panelp->mCollapseAmt, collapse_state, LLSmoothInterpolation::getInterpolant(mCloseTimeConstant));
}
if (llabs(panelp->mCollapseAmt - collapse_state) < 0.001f)
View
@@ -4509,7 +4509,7 @@ void LLTearOffMenu::draw()
if (getRect().getHeight() != mTargetHeight)
{
// animate towards target height
reshape(getRect().getWidth(), llceil(lerp((F32)getRect().getHeight(), mTargetHeight, LLCriticalDamp::getInterpolant(0.05f))));
reshape(getRect().getWidth(), llceil(lerp((F32)getRect().getHeight(), mTargetHeight, LLSmoothInterpolation::getInterpolant(0.05f))));
}
LLFloater::draw();
}
@@ -502,11 +502,11 @@ void LLScrollbar::draw()
BOOL hovered = getEnabled() && !other_captor && (hasMouseCapture() || mThumbRect.pointInRect(local_mouse_x, local_mouse_y));
if (hovered)
{
mCurGlowStrength = lerp(mCurGlowStrength, mHoverGlowStrength, LLCriticalDamp::getInterpolant(0.05f));
mCurGlowStrength = lerp(mCurGlowStrength, mHoverGlowStrength, LLSmoothInterpolation::getInterpolant(0.05f));
}
else
{
mCurGlowStrength = lerp(mCurGlowStrength, 0.f, LLCriticalDamp::getInterpolant(0.05f));
mCurGlowStrength = lerp(mCurGlowStrength, 0.f, LLSmoothInterpolation::getInterpolant(0.05f));
}
@@ -215,7 +215,7 @@ void LLTabContainer::draw()
}
}
setScrollPosPixels(mIsVertical ? target_pixel_scroll : lerp((F32)getScrollPosPixels(), (F32)target_pixel_scroll, LLCriticalDamp::getInterpolant(0.08f)));
setScrollPosPixels(mIsVertical ? target_pixel_scroll : lerp((F32)getScrollPosPixels(), (F32)target_pixel_scroll, LLSmoothInterpolation::getInterpolant(0.08f)));
BOOL has_scroll_arrows = !getTabsHidden() && ((mMaxScrollPos > 0) || (mScrollPosPixels > 0));
if (!mIsVertical)
Oops, something went wrong.

0 comments on commit 4a9ff22

Please sign in to comment.