Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

direct/src/interval/cLerpInterval.cxx

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

Generated on Fri May 2 01:37:41 2003 for Direct by doxygen1.3