Loading...
Searching...
No Matches
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
16namespace CubbyFlow
17{
25{
26 public:
29
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
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
165using PhysicsAnimationPtr = std::shared_ptr<PhysicsAnimation>;
166} // namespace CubbyFlow
167
168#endif
Abstract base class for animation-related class.
Definition Animation.hpp:29
Abstract base class for physics-based animation.
Definition PhysicsAnimation.hpp:25
bool GetIsUsingFixedSubTimeSteps() const
Returns true if fixed sub-timestepping is used.
unsigned int GetNumberOfFixedSubTimeSteps() const
Returns the number of fixed sub-timesteps.
virtual void OnAdvanceTimeStep(double timeIntervalInSeconds)=0
Called when a single time-step should be advanced.
void SetNumberOfFixedSubTimeSteps(unsigned int numberOfSteps)
Sets the number of fixed sub-timesteps.
virtual void OnInitialize()
Called at frame 0 to initialize the physics state.
void SetIsUsingFixedSubTimeSteps(bool isUsing)
Sets true if fixed sub-timestepping is used.
Frame GetCurrentFrame() const
Returns current frame.
PhysicsAnimation(PhysicsAnimation &&) noexcept=default
Default move constructor.
double GetCurrentTimeInSeconds() const
Returns current time in seconds.
void AdvanceSingleFrame()
Advances a single frame.
PhysicsAnimation()
Default constructor.
virtual unsigned int GetNumberOfSubTimeSteps(double timeIntervalInSeconds) const
Returns the required number of sub-timesteps for given time interval.
PhysicsAnimation(const PhysicsAnimation &)=default
Default copy constructor.
void SetCurrentFrame(const Frame &frame)
Sets current frame cursor (but do not invoke update()).
Definition pybind11Utils.hpp:21
std::shared_ptr< PhysicsAnimation > PhysicsAnimationPtr
Definition PhysicsAnimation.hpp:165
Representation of an animation frame.
Definition Frame.hpp:23