Rigs of Rods 2023.09
Soft-body Physics Simulation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
Buoyance.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
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
21#pragma once
22
23#include "Application.h"
24#include "Vec3.h"
25
26namespace RoR {
27
30
32{
33 BuoyCachedNode(NodeNum_t _nodenum): nodenum(_nodenum) {}
34
35 // node_t fields
39 // additional fields
41};
42
44{
45 BuoyDebugSubCab(Vec3 _a, Vec3 _b, Vec3 _c, Vec3 _norm, Vec3 _drag, float _volume) :
46 a(_a), b(_b), c(_c), normal(_norm), drag(_drag), volume(_volume) {}
47 Vec3 a, b, c; // absolute positions
50 float volume;
51};
52
54{
55public:
56
57 Buoyance(DustPool* splash, DustPool* ripple);
58 ~Buoyance();
59
60 void computeNodeForce(BuoyCachedNode *a, BuoyCachedNode *b, BuoyCachedNode *c, int type, float timeshift);
61
63
64 bool sink = false;
65 bool update = false; // Update particles and debugview, if enabled.
66
70
71 std::vector<BuoyCachedNode> buoy_cached_nodes;
72 std::vector<BuoyCachedNode> buoy_projected_nodes;
73
74 bool buoy_debug_view = false;
75 std::vector<BuoyDebugSubCab> buoy_debug_subcabs;
76 long long buoy_total_steps = 0;
78
79private:
80
81 //compute tetrahedron volume
82 inline float computeVolume(Vec3 o, Vec3 a, Vec3 b, Vec3 c);
83
84 //compute pressure and drag force on a submerged triangle
85 Vec3 computePressureForceSub(Vec3 a, Vec3 b, Vec3 c, Vec3 vel, int type);
86
87 //compute pressure and drag forces on a random triangle
88 Vec3 computePressureForce(Vec3 a, Vec3 b, Vec3 c, Vec3 vel, int type);
89
91};
92
94
95} // namespace RoR
96
Central state/object manager and communications hub.
DustPool * splashp
Definition Buoyance.h:90
std::vector< BuoyDebugSubCab > buoy_debug_subcabs
Definition Buoyance.h:75
std::vector< BuoyCachedNode > buoy_cached_nodes
Definition Buoyance.h:71
BuoyCachedNodeID_t cacheBuoycabNode(node_t *n)
try adding the node to internal list (each node is only listed once).
Definition Buoyance.cpp:45
bool buoy_debug_view
Definition Buoyance.h:74
Vec3 computePressureForce(Vec3 a, Vec3 b, Vec3 c, Vec3 vel, int type)
Definition Buoyance.cpp:146
Vec3 computePressureForceSub(Vec3 a, Vec3 b, Vec3 c, Vec3 vel, int type)
Definition Buoyance.cpp:70
void computeNodeForce(BuoyCachedNode *a, BuoyCachedNode *b, BuoyCachedNode *c, int type, float timeshift)
Definition Buoyance.cpp:200
std::vector< BuoyCachedNode > buoy_projected_nodes
Definition Buoyance.h:72
long long buoy_total_steps
Definition Buoyance.h:76
DustPool * ripplep
Definition Buoyance.h:90
float computeVolume(Vec3 o, Vec3 a, Vec3 b, Vec3 c)
Definition Buoyance.cpp:64
long long buoy_last_sample_steps
Definition Buoyance.h:77
static const NodeNum_t NODENUM_INVALID
int BuoyCachedNodeID_t
uint16_t NodeNum_t
Node position within Actor::ar_nodes; use RoR::NODENUM_INVALID as empty value.
BuoyCachedNode(NodeNum_t _nodenum)
Definition Buoyance.h:33
NodeNum_t nodenum
Definition Buoyance.h:40
< Submerged cab triangle
Definition Buoyance.h:44
BuoyDebugSubCab(Vec3 _a, Vec3 _b, Vec3 _c, Vec3 _norm, Vec3 _drag, float _volume)
Definition Buoyance.h:45
Designed to work smoothly with optimizations disabled.
Definition Vec3.h:29
Physics: A vertex in the softbody structure.
Definition SimData.h:260