In/Out Lerp in one function

This topic is 3896 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Hi, I often find myself writing conditionals to produce a function which lerps from min to max to min. Eg:

inline float Lerp( const float& a, const float& b, const float& t )
{
return ( b * t + a * ( 1.0f - t ) );
}

inline float MinMaxMin( const float& a, const float& b, const float& t )
{
if ( t < 0.5f )
return Lerp( a, b, t * 2.0f );
else
return Lerp( b, a, t * 2.0f - 1.0f );
}


As Lerp() is represented without using a conditional, is there a way to do the same for MinMaxMin()? I could work it out if my head wasn't spinning! Your fresh perspective may help me! Thanks Si

Share on other sites
If your platform supports a non-branching absolute value instruction you can use a factor of 1-2*abs(t-0.5).

Thanks!

1. 1
Rutin
37
2. 2
3. 3
4. 4
5. 5

• 9
• 12
• 14
• 9
• 9
• Forum Statistics

• Total Topics
633348
• Total Posts
3011459
• Who's Online (See full list)

There are no registered users currently online

×