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
SlideNode.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 2009 Christopher Ritchey
6 Copyright 2018 Petr Ohlidal
7
8 For more information, see http://www.rigsofrods.org/
9
10 Rigs of Rods is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License version 3, as
12 published by the Free Software Foundation.
13
14 Rigs of Rods is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
21*/
22
26
27#pragma once
28
29#include "ForwardDeclarations.h"
30
31#include <OgreVector3.h>
32#include <vector>
33
34namespace RoR {
35
38
41{
42 RailSegment(beam_t* beam): rs_prev(nullptr), rs_next(nullptr), rs_beam(beam) {}
43
45 RailSegment* CheckCurSlideSegment(Ogre::Vector3 const& point );
46
50};
51
54{
55 RailGroup(): rg_id(-1) {}
56
58 RailSegment* FindClosestSegment(Ogre::Vector3 const& point );
59
60 std::vector<RailSegment> rg_segments;
61 int rg_id;
62};
63
65{
66public:
69 SlideNode(node_t* sliding_node, RailGroup* rail);
70
72 int GetSlideNodeId();
73
76 void UpdateForces(float dt);
77
79 void UpdatePosition();
80
83 {
85 this->ResetPositions();
86 }
87
89 void ResetPositions();
90
98
99 void SetCorThreshold(float threshold ) { m_initial_threshold = m_cur_threshold = fabs( threshold ); }
100 void SetSpringRate(float rate ) { m_spring_rate = fabs( rate); }
101 void SetBreakForce(float breakRate ) { m_break_force = fabs( breakRate); }
102 void SetAttachmentRate(float rate ) { m_attach_rate = fabs( rate); }
103 void SetAttachmentDistance(float dist ) { m_attach_distance = fabs( dist); }
104 float GetAttachmentDistance() const { return m_attach_distance; }
105
109
110private:
112 Ogre::Vector3 CalcCorrectiveForces();
113
120 Ogre::Vector3 m_ideal_position;
127
128// Methods //////////////////////////// TO BE SORTED /////////////////////////////////////////
129public:
130
134 const Ogre::Vector3& GetSlideNodePosition() const;
135
140 void AttachToRail(RailGroup* toAttach)
141 {
142 m_cur_railgroup = toAttach;
143 this->ResetPositions();
145 }
146
152 static Ogre::Real getLenTo( const RailGroup* group, const Ogre::Vector3& point );
153
159 static Ogre::Real getLenTo( const RailSegment* rail, const Ogre::Vector3& point );
160
166 static Ogre::Real getLenTo( const beam_t* beam, const Ogre::Vector3& point );
167
168
173 Ogre::Real getLenTo( const RailGroup* group ) const;
174
179 Ogre::Real getLenTo( const RailSegment* rail ) const;
180
186 Ogre::Real getLenTo( const beam_t* beam) const;
187};
188
190
191} // namespace RoR
192
Global forward declarations.
void UpdateForces(float dt)
Updates the corrective forces and applies these forces to the beam.
Definition SlideNode.cpp:87
void SetAttachmentRate(float rate)
How long it will take for springs to fully attach to the Rail.
Definition SlideNode.h:102
int GetSlideNodeId()
Returns the node index of the slide node.
void ResetPositions()
Recalculates the closest position on current RailGroup.
RailGroup * m_cur_railgroup
Current Rail group, used for attachments.
Definition SlideNode.h:117
float m_attach_rate
How fast the cur threshold changes when attaching (i.e. how long it will take for springs to fully at...
Definition SlideNode.h:125
void SetBreakForce(float breakRate)
Force required to break the Node from the Rail.
Definition SlideNode.h:101
void SetCorThreshold(float threshold)
Distance from a beam before corrective forces take effect.
Definition SlideNode.h:99
Ogre::Vector3 m_ideal_position
Where the node SHOULD be. (World, m)
Definition SlideNode.h:120
void UpdatePosition()
Checks for current rail segment and updates ideal position of the node.
void SetDefaultRail(RailGroup *rail)
Sets rail to initially use when spawned or reset.
Definition SlideNode.h:82
void SetSpringRate(float rate)
Spring force used to calculate corrective forces.
Definition SlideNode.h:100
float GetAttachmentDistance() const
Maximum distance this spring node is allowed to reach out for a Rail.
Definition SlideNode.h:104
bool sn_attach_self
Attach/detach to rails on the current vehicle only.
Definition SlideNode.h:106
void SetAttachmentDistance(float dist)
Maximum distance this spring node is allowed to reach out for a Rail.
Definition SlideNode.h:103
float m_initial_threshold
Distance from beam calculating corrective forces (m)
Definition SlideNode.h:121
float m_spring_rate
Spring rate holding node to rail (N/m)
Definition SlideNode.h:123
bool sn_slide_broken
The slidenode was pulled away from the rail.
Definition SlideNode.h:108
float m_cur_threshold
Distance away from beam before corrective forces begin to act on the node (m)
Definition SlideNode.h:122
float m_attach_distance
Maximum distance slide node will attach to a beam (m)
Definition SlideNode.h:126
Ogre::Vector3 CalcCorrectiveForces()
Calculate forces between the ideal and actual position of the sliding node.
node_t * m_sliding_node
Pointer to node that is sliding.
Definition SlideNode.h:114
void AttachToRail(RailGroup *toAttach)
Definition SlideNode.h:140
beam_t * m_sliding_beam
Pointer to current beam sliding on.
Definition SlideNode.h:115
void ResetSlideNode()
Move back to initial rail, reset 'broken' flag and recalculate closest position.
Definition SlideNode.h:92
RailSegment * m_cur_rail_seg
Current rail segment we are sliding on.
Definition SlideNode.h:118
float m_break_force
Force at which Slide Node breaks away from the rail (N)
Definition SlideNode.h:124
static Ogre::Real getLenTo(const RailGroup *group, const Ogre::Vector3 &point)
bool sn_attach_foreign
Attach/detach to rails only on other vehicles.
Definition SlideNode.h:107
float m_node_forces_ratio
Ratio of length along the slide beam where the virtual node is "0.0f = p1, 1.0f = p2".
Definition SlideNode.h:119
const Ogre::Vector3 & GetSlideNodePosition() const
RailGroup * m_initial_railgroup
Initial Rail group on spawn.
Definition SlideNode.h:116
A series of RailSegment-s for SlideNode to slide along. Can be closed in a loop.
Definition SlideNode.h:54
RailSegment * FindClosestSegment(Ogre::Vector3 const &point)
Search for closest rail segment (the one with closest node in it) in the entire RailGroup.
std::vector< RailSegment > rg_segments
Definition SlideNode.h:60
int rg_id
Spawn context - matching separately defined rails with slidenodes.
Definition SlideNode.h:61
A single beam in a chain.
Definition SlideNode.h:41
RailSegment * rs_prev
Definition SlideNode.h:47
RailSegment * rs_next
Definition SlideNode.h:48
RailSegment(beam_t *beam)
Definition SlideNode.h:42
RailSegment * CheckCurSlideSegment(Ogre::Vector3 const &point)
Check if the slidenode should skip to a neighbour rail segment.
beam_t * rs_beam
Definition SlideNode.h:49
Simulation: An edge in the softbody structure.
Definition SimData.h:305
Physics: A vertex in the softbody structure.
Definition SimData.h:260