GteController.cpp
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #include <GTEnginePCH.h>
10 #include <cmath>
11 #include <limits>
12 using namespace gte;
13 
15  :
16  repeat(RT_CLAMP),
17  minTime(0.0),
18  maxTime(0.0),
19  phase(0.0),
20  frequency(1.0),
21  active(true),
22  name(""),
23  mObject(nullptr),
24  mApplicationTime(-std::numeric_limits<double>::max())
25 {
26 }
27 
29 {
30 }
31 
32 bool Controller::Update(double applicationTime)
33 {
34  if (active)
35  {
36  mApplicationTime = applicationTime;
37  return true;
38  }
39  return false;
40 }
41 
43 {
44  mObject = object;
45 }
46 
47 double Controller::GetControlTime(double applicationTime)
48 {
49  double controlTime = frequency * applicationTime + phase;
50 
51  if (repeat == RT_CLAMP)
52  {
53  // Clamp the time to the [min,max] interval.
54  if (controlTime < minTime)
55  {
56  return minTime;
57  }
58  if (controlTime > maxTime)
59  {
60  return maxTime;
61  }
62  return controlTime;
63  }
64 
65  double timeRange = maxTime - minTime;
66  if (timeRange > 0.0)
67  {
68  double multiples = (controlTime - minTime) / timeRange;
69  double integerTime = floor(multiples);
70  double fractionTime = multiples - integerTime;
71  if (repeat == RT_WRAP)
72  {
73  return minTime + fractionTime*timeRange;
74  }
75 
76  // repeat == RT_CYCLE
77  if (static_cast<int>(integerTime) & 1)
78  {
79  // Go backward in time.
80  return maxTime - fractionTime * timeRange;
81  }
82  else
83  {
84  // Go forward in time.
85  return minTime + fractionTime * timeRange;
86  }
87  }
88 
89  // The minimum and maximum times are the same, so return the minimum.
90  return minTime;
91 }
ControlledObject * mObject
Definition: GteController.h:71
virtual ~Controller()
GLuint const GLchar * name
Definition: glcorearb.h:781
double GetControlTime(double applicationTime)
virtual bool Update(double applicationTime)
RT_CLAMP
Definition: GteController.h:38
virtual void SetObject(ControlledObject *object)
RepeatType repeat
Definition: GteController.h:44
RT_WRAP
Definition: GteController.h:38
double mApplicationTime
Definition: GteController.h:74
GLuint object
Definition: glext.h:6426


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 03:59:59