Panda3D
 All Classes Functions Variables Enumerations
cLerpInterval.cxx
00001 // Filename: cLerpInterval.cxx
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 #include "cLerpInterval.h"
00016 #include "string_utils.h"
00017 
00018 TypeHandle CLerpInterval::_type_handle;
00019 
00020 ////////////////////////////////////////////////////////////////////
00021 //     Function: CLerpInterval::string_blend_type
00022 //       Access: Published, Static
00023 //  Description: Returns the BlendType enumerated value corresponding
00024 //               to the indicated string, or BT_invalid if the string
00025 //               doesn't match anything.
00026 ////////////////////////////////////////////////////////////////////
00027 CLerpInterval::BlendType CLerpInterval::
00028 string_blend_type(const string &blend_type) {
00029   if (blend_type == "easeIn") {
00030     return BT_ease_in;
00031   } else if (blend_type == "easeOut") {
00032     return BT_ease_out;
00033   } else if (blend_type == "easeInOut") {
00034     return BT_ease_in_out;
00035   } else if (blend_type == "noBlend") {
00036     return BT_no_blend;
00037   } else {
00038     return BT_invalid;
00039   }
00040 }
00041 
00042 ////////////////////////////////////////////////////////////////////
00043 //     Function: CLerpInterval::compute_delta
00044 //       Access: Protected
00045 //  Description: Given a t value in the range [0, get_duration()],
00046 //               returns the corresponding delta value clamped to the
00047 //               range [0, 1], after scaling by duration and applying
00048 //               the blend type.
00049 ////////////////////////////////////////////////////////////////////
00050 double CLerpInterval::
00051 compute_delta(double t) const {
00052   double duration = get_duration();
00053   if (duration == 0.0) {
00054     // If duration is 0, the lerp works as a set.  Thus, the delta is
00055     // always 1.0, the terminating value.
00056     return 1.0;
00057   }
00058   t /= duration;
00059   t = min(max(t, 0.0), 1.0);
00060 
00061   switch (_blend_type) {
00062   case BT_ease_in:
00063     {
00064       double t2 = t * t;
00065       return ((3.0 * t2) - (t2 * t)) * 0.5;
00066     }
00067 
00068   case BT_ease_out:
00069     {
00070       double t2 = t * t;
00071       return ((3.0 * t) - (t2 * t)) * 0.5;
00072     }
00073 
00074   case BT_ease_in_out:
00075     {
00076       double t2 = t * t;
00077       return (3.0 * t2) - (2.0 * t * t2);
00078     }
00079 
00080   default:
00081     return t;
00082   }
00083 }
 All Classes Functions Variables Enumerations