PhysicsAnimation.h
Go to the documentation of this file.
1 /*************************************************************************
2 > File Name: PhysicsAnimation.h
3 > Project Name: CubbyFlow
4 > Author: Chan-Ho Chris Ohk
5 > Purpose: Abstract base class for physics-based animation.
6 > Created Time: 2017/04/23
7 > Copyright (c) 2018, Chan-Ho Chris Ohk
8 *************************************************************************/
9 #ifndef CUBBYFLOW_PHYSICS_ANIMATION_H
10 #define CUBBYFLOW_PHYSICS_ANIMATION_H
11 
13 
14 namespace CubbyFlow
15 {
22  class PhysicsAnimation : public Animation
23  {
24  public:
27 
29  virtual ~PhysicsAnimation();
30 
41  bool GetIsUsingFixedSubTimeSteps() const;
42 
53  void SetIsUsingFixedSubTimeSteps(bool isUsing);
54 
65  unsigned int GetNumberOfFixedSubTimeSteps() const;
66 
77  void SetNumberOfFixedSubTimeSteps(unsigned int numberOfSteps);
78 
80  void AdvanceSingleFrame();
81 
85  Frame GetCurrentFrame() const;
86 
90  void SetCurrentFrame(const Frame& frame);
91 
98  double GetCurrentTimeInSeconds() const;
99 
100  protected:
112  virtual void OnAdvanceTimeStep(double timeIntervalInSeconds) = 0;
113 
126  virtual unsigned int GetNumberOfSubTimeSteps(double timeIntervalInSeconds) const;
127 
134  virtual void OnInitialize();
135 
136  private:
137  Frame m_currentFrame;
138  bool m_isUsingFixedSubTimeSteps = true;
139  unsigned int m_numberOfFixedSubTimeSteps = 1;
140  double m_currentTime = 0.0;
141 
142  void OnUpdate(const Frame& frame) final;
143 
144  void AdvanceTimeStep(double timeIntervalInSeconds);
145 
146  void Initialize();
147  };
148 
149  using PhysicsAnimationPtr = std::shared_ptr<PhysicsAnimation>;
150 }
151 
152 #endif
void SetNumberOfFixedSubTimeSteps(unsigned int numberOfSteps)
Sets the number of fixed sub-timesteps.
virtual ~PhysicsAnimation()
Destructor.
std::shared_ptr< PhysicsAnimation > PhysicsAnimationPtr
Definition: PhysicsAnimation.h:149
virtual unsigned int GetNumberOfSubTimeSteps(double timeIntervalInSeconds) const
Returns the required number of sub-timesteps for given time interval.
Abstract base class for physics-based animation.
Definition: PhysicsAnimation.h:22
Definition: pybind11Utils.h:24
void SetIsUsingFixedSubTimeSteps(bool isUsing)
Sets true if fixed sub-timestepping is used.
virtual void OnAdvanceTimeStep(double timeIntervalInSeconds)=0
Called when a single time-step should be advanced.
void SetCurrentFrame(const Frame &frame)
Sets current frame cursor (but do not invoke update()).
bool GetIsUsingFixedSubTimeSteps() const
Returns true if fixed sub-timestepping is used.
double GetCurrentTimeInSeconds() const
Returns current time in seconds.
Frame GetCurrentFrame() const
Returns current frame.
Abstract base class for animation-related class.
Definition: Animation.h:26
Representation of an animation frame.
Definition: Frame.h:20
PhysicsAnimation()
Default constructor.
unsigned int GetNumberOfFixedSubTimeSteps() const
Returns the number of fixed sub-timesteps.
void AdvanceSingleFrame()
Advances a single frame.
virtual void OnInitialize()
Called at frame 0 to initialize the physics state.