Panda3D
 All Classes Functions Variables Enumerations
lerp_helpers.h
00001 // Filename: lerp_helpers.h
00002 // Created by:  drose (27Aug02)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef LERP_HELPERS_H
00016 #define LERP_HELPERS_H
00017 
00018 #include "directbase.h"
00019 
00020 //
00021 // The functions defined here include some trivial template functions
00022 // for handling basic lerp computations, common to several .cxx files
00023 // here.
00024 //
00025 
00026 ////////////////////////////////////////////////////////////////////
00027 //     Function: lerp_value
00028 //  Description: Applies the linear lerp computation for a single
00029 //               parameter.
00030 ////////////////////////////////////////////////////////////////////
00031 template<class NumericType>
00032 INLINE void
00033 lerp_value(NumericType &current_value,
00034            double d,
00035            const NumericType &starting_value,
00036            const NumericType &ending_value) {
00037   current_value = starting_value + d * (ending_value - starting_value);
00038 }
00039 
00040 ////////////////////////////////////////////////////////////////////
00041 //     Function: lerp_value_from_prev
00042 //  Description: Applies the linear lerp computation for a single
00043 //               parameter, when the starting value is implicit.
00044 //
00045 //               This computes the new value based on assuming the
00046 //               prev_value represents the value computed at delta
00047 //               prev_d.
00048 ////////////////////////////////////////////////////////////////////
00049 template<class NumericType>
00050 INLINE void
00051 lerp_value_from_prev(NumericType &current_value,
00052                      double d, double prev_d,
00053                      const NumericType &prev_value,
00054                      const NumericType &ending_value) {
00055   if (prev_d == 1.0) {
00056     current_value = ending_value;
00057   } else {
00058     NumericType starting_value = 
00059       (prev_value - prev_d * ending_value) / (1.0 - prev_d);
00060     current_value = starting_value + d * (ending_value - starting_value);
00061   }
00062 }
00063 
00064 
00065 #endif
00066 
 All Classes Functions Variables Enumerations