00001 // Filename: lerp_helpers.h 00002 // Created by: drose (27Aug02) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 #ifndef LERP_HELPERS_H 00020 #define LERP_HELPERS_H 00021 00022 #include "directbase.h" 00023 00024 // 00025 // This header file is only included within .cxx files in this 00026 // directory. 00027 // 00028 00029 // 00030 // The functions defined here include some trivial template functions 00031 // for handling basic lerp computations, common to several .cxx files 00032 // here. 00033 // 00034 00035 //////////////////////////////////////////////////////////////////// 00036 // Function: lerp_value 00037 // Description: Applies the linear lerp computation for a single 00038 // parameter. 00039 //////////////////////////////////////////////////////////////////// 00040 template<class NumericType> 00041 INLINE void 00042 lerp_value(NumericType ¤t_value, 00043 double d, 00044 const NumericType &starting_value, 00045 const NumericType &ending_value) { 00046 current_value = starting_value + d * (ending_value - starting_value); 00047 } 00048 00049 //////////////////////////////////////////////////////////////////// 00050 // Function: lerp_value_from_prev 00051 // Description: Applies the linear lerp computation for a single 00052 // parameter, when the starting value is implicit. 00053 // 00054 // This computes the new value based on assuming the 00055 // prev_value represents the value computed at delta 00056 // prev_d. 00057 //////////////////////////////////////////////////////////////////// 00058 template<class NumericType> 00059 INLINE void 00060 lerp_value_from_prev(NumericType ¤t_value, 00061 double d, double prev_d, 00062 const NumericType &prev_value, 00063 const NumericType &ending_value) { 00064 if (prev_d == 1.0) { 00065 current_value = ending_value; 00066 } else { 00067 NumericType starting_value = 00068 (prev_value - prev_d * ending_value) / (1.0 - prev_d); 00069 current_value = starting_value + d * (ending_value - starting_value); 00070 } 00071 } 00072 00073 00074 #endif 00075