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
ActorSlideNode.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 Copyright 2009 Christopher Ritchey
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
25
26#include "SlideNode.h"
27
28#include "Actor.h"
29#include "GameContext.h"
30
31using namespace RoR;
32
33// ug... BAD PERFORMNCE, BAD!!
35{
36 // for every slide node on this truck
37 for (std::vector<SlideNode>::iterator itNode = m_slidenodes.begin(); itNode != m_slidenodes.end(); itNode++)
38 {
39 std::pair<RailGroup*, Ogre::Real> closest((RailGroup*)NULL, std::numeric_limits<Ogre::Real>::infinity());
40 std::pair<RailGroup*, Ogre::Real> current((RailGroup*)NULL, std::numeric_limits<Ogre::Real>::infinity());
41
42 // if neither foreign, nor self attach is set then we cannot change the
43 // Rail attachments
44 if (!itNode->sn_attach_self && !itNode->sn_attach_foreign)
45 {
46 continue;
47 }
48
50 {
51 itNode->AttachToRail(NULL);
52 continue;
53 }
54
55 // check all the slide rail on all the other trucks :(
57 {
58 // make sure this truck is allowed
59 if ((this != actor.GetRef() && !itNode->sn_attach_foreign) || (this == actor.GetRef() && !itNode->sn_attach_self))
60 continue;
61
62 current = GetClosestRailOnActor(actor, (*itNode));
63 if (current.second < closest.second)
64 closest = current;
65 } // this many
66
67 itNode->AttachToRail(closest.first);
68 } // nests
69
71} // is ugly....
72
73std::pair<RailGroup*, Ogre::Real> Actor::GetClosestRailOnActor(ActorPtr actor, const SlideNode& node)
74{
75 std::pair<RailGroup*, Ogre::Real> closest((RailGroup*)NULL, std::numeric_limits<Ogre::Real>::infinity());
76
77 RailSegment* curRail = NULL;
78 Ogre::Real lenToCurRail = std::numeric_limits<Ogre::Real>::infinity();
79
80 for (std::vector<RailGroup*>::iterator itGroup = actor->m_railgroups.begin();
81 itGroup != actor->m_railgroups.end();
82 itGroup++)
83 {
84 // find the rail closest to the Node
85 if (*itGroup == nullptr)
86 continue;
87
88 curRail = (*itGroup)->FindClosestSegment(node.GetSlideNodePosition());
89 lenToCurRail = node.getLenTo(curRail);
90
91 if (lenToCurRail < node.GetAttachmentDistance() && lenToCurRail < closest.second)
92 {
93 closest.first = (*itGroup);
94 closest.second = lenToCurRail;
95 }
96 }
97
98 return closest;
99}
100
101// SlideNode Utility functions /////////////////////////////////////////////////
102
103void Actor::updateSlideNodeForces(const Ogre::Real dt)
104{
105 for (std::vector<SlideNode>::iterator it = m_slidenodes.begin(); it != m_slidenodes.end(); ++it)
106 {
107 it->UpdatePosition();
108 it->UpdateForces(dt);
109 }
110}
111
113{
114 if (m_slidenodes.empty())
115 return;
116 for (std::vector<SlideNode>::iterator it = m_slidenodes.begin(); it != m_slidenodes.end(); ++it)
117 {
118 it->ResetPositions();
119 }
120}
121
123{
124 for (std::vector<SlideNode>::iterator it = m_slidenodes.begin(); it != m_slidenodes.end(); ++it)
125 {
126 it->ResetSlideNode();
127 }
128}
129
131{
132 for (std::vector<SlideNode>::iterator it = m_slidenodes.begin(); it != m_slidenodes.end(); ++it)
133 {
134 it->UpdatePosition();
135 }
136}
Game state manager and message-queue provider.
void resetSlideNodePositions()
Recalculate SlideNode positions.
void updateSlideNodeForces(const Ogre::Real delta_time_sec)
calculate and apply Corrective forces
void toggleSlideNodeLock()
void resetSlideNodes()
Reset all the SlideNodes.
std::pair< RailGroup *, Ogre::Real > GetClosestRailOnActor(ActorPtr actor, const SlideNode &node)
std::vector< SlideNode > m_slidenodes
all the SlideNodes available on this actor
Definition Actor.h:611
bool m_slidenodes_locked
Physics state; Are SlideNodes locked?
Definition Actor.h:697
std::vector< RailGroup * > m_railgroups
all the available RailGroups for this actor
Definition Actor.h:612
void updateSlideNodePositions()
incrementally update the position of all SlideNodes
ActorPtrVec & GetActors()
ActorManager * GetActorManager()
float GetAttachmentDistance() const
Maximum distance this spring node is allowed to reach out for a Rail.
Definition SlideNode.h:104
static Ogre::Real getLenTo(const RailGroup *group, const Ogre::Vector3 &point)
const Ogre::Vector3 & GetSlideNodePosition() const
GameContext * GetGameContext()
A series of RailSegment-s for SlideNode to slide along. Can be closed in a loop.
Definition SlideNode.h:54
A single beam in a chain.
Definition SlideNode.h:41