RigsofRods
Soft-body Physics Simulation
GUI_FrictionSettings.cpp
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 
6  For more information, see http://www.rigsofrods.org/
7 
8  Rigs of Rods is free software: you can redistribute it and/or modify
9  it under the terms of the GNU General Public License version 3, as
10  published by the Free Software Foundation.
11 
12  Rigs of Rods is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
19 */
20 
24 
25 // Remade using DearIMGUI by Petr Ohlidal, 10/2019
26 
27 
28 #include "GUI_FrictionSettings.h"
29 
30 #include "Application.h"
31 #include "SimData.h"
32 #include "Collisions.h"
33 #include "GameContext.h"
34 #include "GUIManager.h"
35 #include "Language.h"
36 #include "Terrain.h"
37 #include "Utils.h"
38 
39 using namespace RoR;
40 using namespace GUI;
41 
43 {
44  ImGui::SetNextWindowPosCenter(ImGuiCond_FirstUseEver);
45  ImGuiWindowFlags win_flags = ImGuiWindowFlags_NoCollapse;
46  bool keep_open = true;
47  ImGui::Begin(_LC("FrictionSettings", "Friction Settings"), &keep_open, win_flags);
48 
49  ImGui::Text("%s", _LC("FrictionSettings", "Current active Ground: "));
50  ImGui::SameLine();
51  ImGui::Text("%s", (m_nearest_gm != nullptr) ? m_nearest_gm->name : "~");
52 
53  ImGui::Separator();
54  ImGui::PushItemWidth(200.f);
55 
56  ImGui::Combo(_LC("FrictionSettings", "selected Ground Type:"), &m_selected_gm,
58  static_cast<int>(m_gm_entries.size()));
59  ground_model_t& gm = m_gm_entries[m_selected_gm].working_copy;
60  bool dirty = false;
61 
62  ImGui::TextDisabled("%s", _LC("FrictionSettings", "Solid ground settings"));
63 
64  if (ImGui::SliderFloat(_LC("FrictionSettings", "Solid ground level:"), &gm.solid_ground_level, 0.f, 200.f)) { dirty = true; }
65  this->DrawTooltip(_LC("FrictionSettings", "Solid ground level"), _LC("FrictionSettings", "With this you can define how deep the solid ground is. If it is 0 then the surface will be solid. If it is 0.1 then you'll have 10 cm of fluid on top of solid ground. If it is 100 then the solid ground will be way deep (100m), with fluid on top."));
66 
67  if (ImGui::SliderFloat(_LC("FrictionSettings", "Strength:"), &gm.strength, 0.f, 2.f)) { dirty = true; }
68  this->DrawTooltip(_LC("FrictionSettings", "Strength"), _LC("FrictionSettings", "This parameter raises or diminishes surface friction in a generic way. It is here so as to be able to do quick calibrations of friction. Start with having this to 1.0 and after tuning the rest of the surface variables, come back and play with this."));
69 
70  if (ImGui::SliderFloat(_LC("FrictionSettings", "Static friction coef:"), &gm.ms, 0.1f, 2.f)) { dirty = true; }
71  this->DrawTooltip(_LC("FrictionSettings", "Static friction coef"), _LC("FrictionSettings", "Static friction keeps you in the same place when you are stopped on a hill. In the real world this friction is always bigger than dynamic friction (sliding friction). Start with 0.5 and work from there. It is better to try to find some experimentally validated values for this and the rest of surface friction variables in the net, and then to fine tune via strength."));
72 
73  if (ImGui::SliderFloat(_LC("FrictionSettings", "Adhesion velocity:"), &gm.va, 0.1f, 5.f)) { dirty = true; }
74  this->DrawTooltip(_LC("FrictionSettings", "Adhesion velocity"), _LC("FrictionSettings", "Below this value static friction laws apply, above it dynamic friction laws apply. Value should be small, in the range of 0.1-0.4 . This velocity threshold is also used by fluid dynamics so you should always define it. NEVER set it to 0."));
75 
76  if (ImGui::SliderFloat(_LC("FrictionSettings", "Dynamic friction coef:"), &gm.mc, 0.1f, 1.5f)) { dirty = true; }
77  this->DrawTooltip(_LC("FrictionSettings", "Dynamic friction coef"), _LC("FrictionSettings", "Or sliding friction coef. It should be smaller than static friction coef. This parameter defines how much friction you'll have when sliding. Try to find some values for it from the net."));
78 
79  if (ImGui::SliderFloat(_LC("FrictionSettings", "Hydrodynamic friction coef:"), &gm.t2, 0.f, 1.5f)) { dirty = true; }
80  this->DrawTooltip(_LC("FrictionSettings", "Hydrodynamic friction coef"), _LC("FrictionSettings", "This friction defines the added friction that you'll feel from a surface that has a little film of fluid on it. It is kind of redundant with all the fluid physics below, but it is here so as for experimentally validated values from the net to be usable. If you decide that you'll simulate the film of fluid with the more complex fluid physics below, then just set this to 0."));
81 
82  if (ImGui::SliderFloat(_LC("FrictionSettings", "Stribeck velocity:"), &gm.vs, 0.f, 1000.f)) { dirty = true; }
83  this->DrawTooltip(_LC("FrictionSettings", "Stribeck velocity"), _LC("FrictionSettings", "You'll either find stribeck velocity in the net, or the inverse (1/stribeck velocity) of it described as 'stribeck coef'. It defines the shape of the dynamic friction curve. Lets leave it at that. Just find some nice values for it from the net."));
84 
85  if (ImGui::SliderFloat(_LC("FrictionSettings", "alpha:"), &gm.alpha, 0.f, 200.f)) { dirty = true; }
86  this->DrawTooltip(_LC("FrictionSettings", "Alpha"), _LC("FrictionSettings", "Its usual value is 2. But you can try others."));
87 
88  ImGui::TextDisabled("%s", _LC("FrictionSettings", "Fluid Settings"));
89 
90  if (ImGui::SliderFloat(_LC("FrictionSettings", "Flow behavior index:"), &gm.flow_behavior_index, -2.f, 2.f)) { dirty = true; }
91  this->DrawTooltip(_LC("FrictionSettings", "Flow behavior index"), _LC("FrictionSettings", "If it is 1.0 then the fluid will behave like water. The lower you get from 1.0, the more like mud the fluid will behave, meaning that for small velocities the fluid will resist motion and for large velocities the fluid will not resist so much. The higher you get from 1.0 the more like sand the fluid will behave. The bigger the velocity, the bigger the resistance of the fluid (try to hit sand hard it'll feel like stone)."));
92 
93  if (ImGui::SliderFloat(_LC("FrictionSettings", "Flow consistency:"), &gm.flow_consistency_index, 10.f, 100000.f)) { dirty = true; }
94  this->DrawTooltip(_LC("FrictionSettings", "Flow consistency"), _LC("FrictionSettings", "Think of it as default fluid resistance. Behavior index above changes it at real time. Useful values in practice are quite large."));
95 
96  if (ImGui::SliderFloat(_LC("FrictionSettings", "Fluid density:"), &gm.fluid_density, 10.f, 100000.f)) { dirty = true; }
97  this->DrawTooltip(_LC("FrictionSettings", "Fluid density"), _LC("FrictionSettings", "In mud (or sand) the resistance of the fluid described by the parameters above will stop you and so keep you from sinking. But for substances like water it isn't the drag that stops you from sinking. Its buoyancy. This parameter is here so as to keep you from sinking when you wish to simulate fluids with low drag (resistance). For fluids like mud or sand you can put it at 0, but it is best to keep it at some minimum value. For fluids with behavior index >=1 it will behave like you are in water. For fluids with behavior index <1 it'll behave like you are in mud."));
98 
99  if (ImGui::SliderFloat(_LC("FrictionSettings", "Drag anisotropy:"), &gm.drag_anisotropy, 0.f, 1.f)) { dirty = true; }
100  this->DrawTooltip(_LC("FrictionSettings", "Drag anisotropy"), _LC("FrictionSettings", "This parameter is for making it easier(cheating) to get out from mud. To get stuck in real mud isn't fun at all, so this makes the mud push up. Ranges in this parameter are from 0 to 1 . If you set it at 1 then you'll get real mud. For values from 0 to 1, the behavior goes from real mud to easy mud depending on this parameter and the value of Adhesion velocity. For velocity 0 real mud it is. For velocity >= adhesion velocity easy mud it is."));
101 
102  //TODO: _LC("FrictionSettings", "fx_type:")
103  // _LC("FrictionSettings", "FX Type"), _LC("FrictionSettings", "The type of special effects that RoR will use to give the appearance of a surface. It doesn't affect the physics at all")
104 
105  // TODO _LC("FrictionSettings", "fx_color:")
106  // _LC("FrictionSettings", "FX Colour"), _LC("FrictionSettings", "The color of RoR's special effects")
107 
108  // TODO ... all other fx
109 
110  //Unused: _LC("FrictionSettings", "Friction Help")
111 
112  if (dirty)
113  {
115  }
116 
117  ImGui::PopItemWidth();
118 
119  m_is_hovered = ImGui::IsWindowHovered(ImGuiHoveredFlags_RootAndChildWindows);
121 
122  ImGui::End();
123 
124  if (!keep_open)
125  {
126  this->SetVisible(false);
127  }
128 }
129 
130 // Static helper
131 bool FrictionSettings::GmComboItemGetter(void* data, int idx, const char** out_text)
132 {
133  auto items = static_cast<std::vector<FrictionSettings::Entry>*>(data);
134  if (out_text)
135  *out_text = (*items)[idx].live_data->name;
136  return true;
137 }
138 
140 {
141  m_gm_entries.clear();
142  auto itor = App::GetGameContext()->GetTerrain()->GetCollisions()->getGroundModels()->begin();
143  auto endi = App::GetGameContext()->GetTerrain()->GetCollisions()->getGroundModels()->end();
144  for (; itor != endi; ++itor)
145  {
146  m_gm_entries.emplace_back(&itor->second);
147  }
148 }
149 
150 void FrictionSettings::DrawTooltip(const char* title, const char* text)
151 {
152  ImGui::SameLine();
153  ImGui::TextDisabled("[?]");
154  if (ImGui::IsItemHovered())
155  {
156  ImGui::SetNextWindowSizeConstraints(/*size_min=*/ImVec2(250.f, 50.f), /*size_max=*/ImVec2(1000.f, 1000.f));
157  ImGui::BeginTooltip();
158  ImGui::Text("%s", title);
159  ImGui::Separator();
160  ImGui::TextWrapped("%s", text);
161  ImGui::EndTooltip();
162  }
163 }
164 
GameContext.h
Game state manager and message-queue provider.
RoR::ground_model_t::solid_ground_level
float solid_ground_level
how deep the solid ground is
Definition: SimData.h:758
RoR::GUI::FrictionSettings::Draw
void Draw()
Definition: GUI_FrictionSettings.cpp:42
RoR::ground_model_t::strength
float strength
ground strength
Definition: SimData.h:747
RoR::ground_model_t::va
float va
adhesion velocity
Definition: SimData.h:741
RoR::App::GetGuiManager
GUIManager * GetGuiManager()
Definition: Application.cpp:269
GUI_FrictionSettings.h
RoR::GUI::FrictionSettings::GmComboItemGetter
static bool GmComboItemGetter(void *data, int idx, const char **out_text)
Definition: GUI_FrictionSettings.cpp:131
RoR::GUI::FrictionSettings::m_nearest_gm
const ground_model_t * m_nearest_gm
Definition: GUI_FrictionSettings.h:65
RoR::GUI::FrictionSettings::m_gm_entries
std::vector< Entry > m_gm_entries
Definition: GUI_FrictionSettings.h:63
RoR::ground_model_t::alpha
float alpha
steady-steady
Definition: SimData.h:746
Utils.h
Language.h
GUIManager.h
RoR::ground_model_t::mc
float mc
sliding friction coefficient
Definition: SimData.h:743
RoR::GUI::FrictionSettings::AnalyzeTerrain
void AnalyzeTerrain()
Definition: GUI_FrictionSettings.cpp:139
RoR::ground_model_t::vs
float vs
stribeck velocity (m/s)
Definition: SimData.h:745
SimData.h
Core data structures for simulation; Everything affected by by either physics, network or user intera...
RoR::GameContext::PushMessage
void PushMessage(Message m)
Doesn't guarantee order! Use ChainMessage() if order matters.
Definition: GameContext.cpp:65
RoR::Terrain::GetCollisions
Collisions * GetCollisions()
Definition: Terrain.h:83
Application.h
Central state/object manager and communications hub.
RoR::App::GetGameContext
GameContext * GetGameContext()
Definition: Application.cpp:280
RoR::GUI::FrictionSettings::SetVisible
void SetVisible(bool visible)
Definition: GUI_FrictionSettings.h:51
RoR::ground_model_t::name
char name[256]
Definition: SimData.h:763
RoR::ground_model_t::t2
float t2
hydrodynamic friction (s/m)
Definition: SimData.h:744
RoR::GUI::FrictionSettings::DrawTooltip
void DrawTooltip(const char *title, const char *text)
Definition: GUI_FrictionSettings.cpp:150
_LC
#define _LC(ctx, str)
Definition: Language.h:42
RoR::ground_model_t::ms
float ms
static friction coefficient
Definition: SimData.h:742
RoR::ground_model_t::flow_behavior_index
float flow_behavior_index
if flow_behavior_index<1 then liquid is Pseudoplastic (ketchup, whipped cream, paint) if =1 then liqu...
Definition: SimData.h:755
RoR::Message
Unified game event system - all requests and state changes are reported using a message.
Definition: GameContext.h:51
RoR::GUI::FrictionSettings::m_selected_gm
int m_selected_gm
Definition: GUI_FrictionSettings.h:64
RoR::ground_model_t::fluid_density
float fluid_density
Density of liquid.
Definition: SimData.h:749
RoR::ground_model_t
Surface friction properties.
Definition: SimData.h:739
RoR::ground_model_t::drag_anisotropy
float drag_anisotropy
Upwards/Downwards drag anisotropy.
Definition: SimData.h:759
RoR::Collisions::getGroundModels
std::map< Ogre::String, ground_model_t > * getGroundModels()
Definition: Collisions.h:208
RoR::MSG_EDI_MODIFY_GROUNDMODEL_REQUESTED
@ MSG_EDI_MODIFY_GROUNDMODEL_REQUESTED
Payload = RoR::ground_model_t* (weak)
Definition: Application.h:144
Terrain.h
RoR::ground_model_t::flow_consistency_index
float flow_consistency_index
general drag coefficient
Definition: SimData.h:750
items
or anywhere else will not be considered a but parsed as regular data ! Each line is treated as values separated by separators Possible i e animators Multiline description Single does not affect it Directive usualy set global attributes or change behavior of the parsing Directive may appear in any block section Modularity The elements can be grouped into modules Each module must belong to one or more configurations Directives sectionconfig specify truck configurations the user can choose from Exactly one must be selected If the first defined is used lettercase matches original docs(parsing is insensitive). NAME TYPE NOTES advdrag BLOCK add_animation DIRECTIVE Special syntax airbrakes BLOCK animators BLOCK Special syntax IF(values[0]=="") bad trailing chars are silently ignored no space at the end Items delimited On each side of there is max item Empty invalid string parses as node num items
Definition: ReadMe.txt:295
Collisions.h
RoR::GUIManager::RequestGuiCaptureKeyboard
void RequestGuiCaptureKeyboard(bool val)
Pass true during frame to prevent input passing to application.
Definition: GUIManager.cpp:439
RoR
Definition: AppContext.h:36
RoR::GUI::FrictionSettings::m_is_hovered
bool m_is_hovered
Definition: GUI_FrictionSettings.h:67
RoR::GameContext::GetTerrain
const TerrainPtr & GetTerrain()
Definition: GameContext.h:117