Panda3D
cLerpInterval.cxx
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 cLerpInterval.cxx
10  * @author drose
11  * @date 2002-08-27
12  */
13 
14 #include "cLerpInterval.h"
15 #include "string_utils.h"
16 
17 TypeHandle CLerpInterval::_type_handle;
18 
19 /**
20  * Returns the BlendType enumerated value corresponding to the indicated
21  * string, or BT_invalid if the string doesn't match anything.
22  */
23 CLerpInterval::BlendType CLerpInterval::
24 string_blend_type(const std::string &blend_type) {
25  if (blend_type == "easeIn") {
26  return BT_ease_in;
27  } else if (blend_type == "easeOut") {
28  return BT_ease_out;
29  } else if (blend_type == "easeInOut") {
30  return BT_ease_in_out;
31  } else if (blend_type == "noBlend") {
32  return BT_no_blend;
33  } else {
34  return BT_invalid;
35  }
36 }
37 
38 /**
39  * Given a t value in the range [0, get_duration()], returns the corresponding
40  * delta value clamped to the range [0, 1], after scaling by duration and
41  * applying the blend type.
42  */
43 double CLerpInterval::
44 compute_delta(double t) const {
45  double duration = get_duration();
46  if (duration == 0.0) {
47  // If duration is 0, the lerp works as a set. Thus, the delta is always
48  // 1.0, the terminating value.
49  return 1.0;
50  }
51  t /= duration;
52  t = std::min(std::max(t, 0.0), 1.0);
53 
54  switch (_blend_type) {
55  case BT_ease_in:
56  {
57  double t2 = t * t;
58  return ((3.0 * t2) - (t2 * t)) * 0.5;
59  }
60 
61  case BT_ease_out:
62  {
63  double t2 = t * t;
64  return ((3.0 * t) - (t2 * t)) * 0.5;
65  }
66 
67  case BT_ease_in_out:
68  {
69  double t2 = t * t;
70  return (3.0 * t2) - (2.0 * t * t2);
71  }
72 
73  default:
74  return t;
75  }
76 }
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
static BlendType string_blend_type(const std::string &blend_type)
Returns the BlendType enumerated value corresponding to the indicated string, or BT_invalid if the st...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81