Skip to content

Instantly share code, notes, and snippets.

@ThePhD
Last active August 29, 2015 13:55
Show Gist options
  • Save ThePhD/8758283 to your computer and use it in GitHub Desktop.
Save ThePhD/8758283 to your computer and use it in GitHub Desktop.
Lerp
template <typename T, ulword n, typename Tw>
RVector<T, n> lerp( const RVector<T, n>& from, const RVector<T, n>& towards, Tw weight ) {
weight = Mathema<Tw>::MiniMax( weight, static_cast<Tw>( 0 ), static_cast<Tw>( 1 ) );
Tw affweight = 1.0f - weight;
RVector<T, n> r;
for ( ulword i = 0; i < n; ++i ) {
r[ i ] = static_cast<T>( from[i] * weight + affweight * towards[i] );
}
return r;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment