Panda3D
lerp_helpers.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file lerp_helpers.h
10  * @author drose
11  * @date 2002-08-27
12  */
13 
14 #ifndef LERP_HELPERS_H
15 #define LERP_HELPERS_H
16 
17 #include "directbase.h"
18 
19 // The functions defined here include some trivial template functions for
20 // handling basic lerp computations, common to several .cxx files here.
21 
22 /**
23  * Applies the linear lerp computation for a single parameter.
24  */
25 template<class NumericType>
26 INLINE void
27 lerp_value(NumericType &current_value,
28  double d,
29  const NumericType &starting_value,
30  const NumericType &ending_value) {
31  current_value = starting_value + d * (ending_value - starting_value);
32 }
33 
34 /**
35  * Applies the linear lerp computation for a single parameter, when the
36  * starting value is implicit.
37  *
38  * This computes the new value based on assuming the prev_value represents the
39  * value computed at delta prev_d.
40  */
41 template<class NumericType>
42 INLINE void
43 lerp_value_from_prev(NumericType &current_value,
44  double d, double prev_d,
45  const NumericType &prev_value,
46  const NumericType &ending_value) {
47  if (prev_d == 1.0) {
48  current_value = ending_value;
49  } else {
50  NumericType starting_value =
51  (prev_value - prev_d * ending_value) / (1.0 - prev_d);
52  current_value = starting_value + d * (ending_value - starting_value);
53  }
54 }
55 
56 
57 #endif
void lerp_value_from_prev(NumericType &current_value, double d, double prev_d, const NumericType &prev_value, const NumericType &ending_value)
Applies the linear lerp computation for a single parameter, when the starting value is implicit.
Definition: lerp_helpers.h:43
void lerp_value(NumericType &current_value, double d, const NumericType &starting_value, const NumericType &ending_value)
Applies the linear lerp computation for a single parameter.
Definition: lerp_helpers.h:27
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.