RigsofRods
Soft-body Physics Simulation
CmdKeyInertia.h
Go to the documentation of this file.
1 /*
2  This source file is part of Rigs of Rods
3  Copyright 2005-2012 Pierre-Michel Ricordel
4  Copyright 2007-2012 Thomas Fischer
5  Copyright 2020-2023 Petr Ohlidal
6 
7  For more information, see http://www.rigsofrods.org/
8 
9  Rigs of Rods is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License version 3, as
11  published by the Free Software Foundation.
12 
13  Rigs of Rods is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
20 */
21 
22 #pragma once
23 
24 #include <OgrePrerequisites.h>
25 #include <string>
26 #include <unordered_map>
27 
28 namespace RoR {
29 
32 
35 {
36 public:
38  Ogre::SimpleSpline* GetSplineByName(Ogre::String model);
39 
40 private:
41  std::map<Ogre::String, Ogre::SimpleSpline> m_splines;
42 };
43 
46 {
47 public:
48  CmdKeyInertia();
49 
50  float CalcCmdKeyDelay(float cmd_input, float dt);
51  int SetCmdKeyDelay(RoR::CmdKeyInertiaConfig& cfg, float start_delay, float stop_delay, std::string start_function, std::string stop_function);
52  void ResetCmdKeyDelay();
53 
54 protected:
57  float m_stop_delay;
58  float m_time;
59  Ogre::SimpleSpline* m_start_spline;
60  Ogre::SimpleSpline* m_stop_spline;
61 
62  float CalculateCmdOutput(float time, Ogre::SimpleSpline* spline);
63 };
64 
67 {
68 public:
69  void SetSimpleDelay(RoR::CmdKeyInertiaConfig& cfg, float start_delay, float stop_delay, std::string start_function, std::string stop_function);
70 
72  float CalcSimpleDelay(bool input, float dt);
73 
74 private:
75  bool m_last_input = false;
76  float m_start_delay = 0;
77  float m_stop_delay = 0;
78  float m_spline_time = 0;
79  Ogre::SimpleSpline* m_start_spline = nullptr;
80  Ogre::SimpleSpline* m_stop_spline = nullptr;
81 };
82 
84 
85 } // namespace RoR
RoR::SimpleInertia::m_stop_spline
Ogre::SimpleSpline * m_stop_spline
Definition: CmdKeyInertia.h:80
RoR::CmdKeyInertia::m_start_spline
Ogre::SimpleSpline * m_start_spline
Definition: CmdKeyInertia.h:59
RoR::SimpleInertia::m_start_spline
Ogre::SimpleSpline * m_start_spline
Definition: CmdKeyInertia.h:79
RoR::SimpleInertia::SetSimpleDelay
void SetSimpleDelay(RoR::CmdKeyInertiaConfig &cfg, float start_delay, float stop_delay, std::string start_function, std::string stop_function)
Definition: CmdKeyInertia.cpp:189
RoR::SimpleInertia::CalcSimpleDelay
float CalcSimpleDelay(bool input, float dt)
Expected to be invoked in main/rendering loop, once per frame. The dt is in seconds.
Definition: CmdKeyInertia.cpp:216
RoR::CmdKeyInertia::m_last_output
float m_last_output
Definition: CmdKeyInertia.h:55
RoR::CmdKeyInertia::m_stop_spline
Ogre::SimpleSpline * m_stop_spline
Definition: CmdKeyInertia.h:60
RoR::SimpleInertia::m_stop_delay
float m_stop_delay
Definition: CmdKeyInertia.h:77
RoR::SimpleInertia
Designed to be run on main/rendering loop (FPS)
Definition: CmdKeyInertia.h:66
RoR::CmdKeyInertia::ResetCmdKeyDelay
void ResetCmdKeyDelay()
Definition: CmdKeyInertia.cpp:180
RoR::CmdKeyInertia::m_start_delay
float m_start_delay
Definition: CmdKeyInertia.h:56
RoR::CmdKeyInertia::CalculateCmdOutput
float CalculateCmdOutput(float time, Ogre::SimpleSpline *spline)
Definition: CmdKeyInertia.cpp:116
RoR::CmdKeyInertiaConfig::LoadDefaultInertiaModels
void LoadDefaultInertiaModels()
Definition: CmdKeyInertia.cpp:138
RoR::CmdKeyInertia::m_stop_delay
float m_stop_delay
Definition: CmdKeyInertia.h:57
RoR::CmdKeyInertia
Designed to be run in physics loop (2khz)
Definition: CmdKeyInertia.h:45
RoR::CmdKeyInertiaConfig::m_splines
std::map< Ogre::String, Ogre::SimpleSpline > m_splines
Definition: CmdKeyInertia.h:41
RoR::CmdKeyInertia::m_time
float m_time
Definition: CmdKeyInertia.h:58
RoR::SimpleInertia::m_last_input
bool m_last_input
Definition: CmdKeyInertia.h:75
RoR::CmdKeyInertiaConfig::GetSplineByName
Ogre::SimpleSpline * GetSplineByName(Ogre::String model)
Definition: CmdKeyInertia.cpp:129
RoR::CmdKeyInertia::CmdKeyInertia
CmdKeyInertia()
Definition: CmdKeyInertia.cpp:31
RoR::CmdKeyInertiaConfig
Loads and manages 'inertia_models.cfg'.
Definition: CmdKeyInertia.h:34
RoR::SimpleInertia::m_start_delay
float m_start_delay
Definition: CmdKeyInertia.h:76
RoR::CmdKeyInertia::CalcCmdKeyDelay
float CalcCmdKeyDelay(float cmd_input, float dt)
Definition: CmdKeyInertia.cpp:40
RoR
Definition: AppContext.h:36
RoR::CmdKeyInertia::SetCmdKeyDelay
int SetCmdKeyDelay(RoR::CmdKeyInertiaConfig &cfg, float start_delay, float stop_delay, std::string start_function, std::string stop_function)
Definition: CmdKeyInertia.cpp:87
RoR::SimpleInertia::m_spline_time
float m_spline_time
Definition: CmdKeyInertia.h:78