PhysicsAnimation.hpp
Go to the documentation of this file.
1 // This code is based on Jet framework.
2 // Copyright (c) 2018 Doyub Kim
3 // CubbyFlow is voxel-based fluid simulation engine for computer games.
4 // Copyright (c) 2020 CubbyFlow Team
5 // Core Part: Chris Ohk, Junwoo Hwang, Jihong Sin, Seungwoo Yoo
6 // AI Part: Dongheon Cho, Minseo Kim
7 // We are making my contributions/submissions to this project solely in our
8 // personal capacity and are not conveying any rights to any intellectual
9 // property of any third parties.
10 
11 #ifndef CUBBYFLOW_PHYSICS_ANIMATION_HPP
12 #define CUBBYFLOW_PHYSICS_ANIMATION_HPP
13 
15 
16 namespace CubbyFlow
17 {
25 {
26  public:
29 
31  PhysicsAnimation(const PhysicsAnimation&) = default;
32 
34  PhysicsAnimation(PhysicsAnimation&&) noexcept = default;
35 
37  virtual ~PhysicsAnimation() = default;
38 
40  PhysicsAnimation& operator=(const PhysicsAnimation&) = default;
41 
43  PhysicsAnimation& operator=(PhysicsAnimation&&) noexcept = default;
44 
55  [[nodiscard]] bool GetIsUsingFixedSubTimeSteps() const;
56 
67  void SetIsUsingFixedSubTimeSteps(bool isUsing);
68 
79  [[nodiscard]] unsigned int GetNumberOfFixedSubTimeSteps() const;
80 
91  void SetNumberOfFixedSubTimeSteps(unsigned int numberOfSteps);
92 
94  void AdvanceSingleFrame();
95 
99  [[nodiscard]] Frame GetCurrentFrame() const;
100 
104  void SetCurrentFrame(const Frame& frame);
105 
112  [[nodiscard]] double GetCurrentTimeInSeconds() const;
113 
114  protected:
126  virtual void OnAdvanceTimeStep(double timeIntervalInSeconds) = 0;
127 
141  [[nodiscard]] virtual unsigned int GetNumberOfSubTimeSteps(
142  double timeIntervalInSeconds) const;
143 
150  virtual void OnInitialize();
151 
152  private:
153  void OnUpdate(const Frame& frame) final;
154 
155  void AdvanceTimeStep(double timeIntervalInSeconds);
156 
157  void Initialize();
158 
159  Frame m_currentFrame;
160  bool m_isUsingFixedSubTimeSteps = true;
161  unsigned int m_numberOfFixedSubTimeSteps = 1;
162  double m_currentTime = 0.0;
163 };
164 
165 using PhysicsAnimationPtr = std::shared_ptr<PhysicsAnimation>;
166 } // namespace CubbyFlow
167 
168 #endif
void SetNumberOfFixedSubTimeSteps(unsigned int numberOfSteps)
Sets the number of fixed sub-timesteps.
std::shared_ptr< PhysicsAnimation > PhysicsAnimationPtr
Definition: PhysicsAnimation.hpp:165
virtual ~PhysicsAnimation()=default
Default virtual destructor.
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.hpp:24
Definition: pybind11Utils.hpp:20
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.
PhysicsAnimation & operator=(const PhysicsAnimation &)=default
Default copy assignment operator.
Abstract base class for animation-related class.
Definition: Animation.hpp:28
Representation of an animation frame.
Definition: Frame.hpp:22
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.