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
GfxActor.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 2016-2020 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
26
27#pragma once
28
29#include "AutoPilot.h"
30#include "Differentials.h"
31#include "ForwardDeclarations.h"
32#include "GfxData.h"
34#include "SimBuffers.h"
35#include "SurveyMapEntity.h"
36#include "ThreadPool.h" // class Task
37
38#include <OgreAxisAlignedBox.h>
39#include <OgreColourValue.h>
40#include <OgreMaterial.h>
41#include <OgreQuaternion.h>
42#include <OgreTexture.h>
43#include <OgreVector3.h>
44#include <string>
45#include <vector>
46
47namespace RoR {
48
51
53{
54 friend class ActorSpawner; // The factory
55
56public:
57
58 GfxActor(ActorPtr actor, ActorSpawner* spawner, std::string ogre_resource_group,
59 RoR::Renderdash* renderdash);
60
61 ~GfxActor();
62
63 // Adding elements
64
65 void RegisterCabMaterial(Ogre::MaterialPtr mat, Ogre::MaterialPtr mat_trans);
66 void RegisterCabMesh(Ogre::Entity* ent, Ogre::SceneNode* snode, FlexObj* flexobj);
67 void SortFlexbodies();
68
69 // Retrieving elements
70
71 std::vector<FlexBody*>& GetFlexbodies() { return m_flexbodies; };
72 std::vector<Prop>& getProps() { return m_props; }
73 std::vector<CParticle>& getCParticles() { return m_cparticles; }
74 std::vector<Exhaust>& getExhausts() { return m_exhausts; }
75 std::vector<VideoCamera>& getVideoCameras() { return m_videocameras; }
76
77 // Visual changes
78
79 void SetMaterialFlareOn(int flare_index, bool state_on);
80 void SetCabLightsActive(bool state_on);
82 void ScaleActor(Ogre::Vector3 relpos, float ratio);
83 void ToggleDebugView();
84 void CycleDebugViews();
85 void ResetFlexbodies();
86 void SetRenderdashActive(bool active);
87 void SetBeaconsEnabled(bool beacon_light_is_active);
89 void SetNodeHot(NodeNum_t nodenum, bool value);
90 void RemoveBeam(int beam_index);
91
92 // Visibility
93
94 void SetRodsVisible(bool visible);
95 void SetFlexbodyVisible (bool visible);
96 void SetWheelsVisible(bool value);
97 void SetAllMeshesVisible(bool value);
98 void SetWingsVisible(bool visible);
99 void SetCastShadows(bool value);
100 void SetFlexbodiesVisible(bool visible);
101 void SetPropsVisible(bool visible);
102 void SetAeroEnginesVisible(bool visible);
103
104 // Visual updates
105
106 void UpdateVideoCameras(float dt);
107 void UpdateParticles(float dt);
108 void UpdateRods();
109 void UpdateWheelVisuals();
110 void UpdateFlexbodies();
111 void UpdateDebugView();
112 void UpdateCabMesh();
113 void UpdateWingMeshes();
114 void UpdateBeaconFlare(Prop & prop, float dt, bool is_player_actor);
115 void UpdateProps(float dt, bool is_player_actor);
116 void UpdatePropAnimations(float dt);
117 void UpdateAirbrakes();
118 void UpdateCParticles();
119 void UpdateExhausts();
120 void UpdateAeroEngines();
121 void UpdateNetLabels(float dt);
122 void UpdateFlares(float dt, bool is_player);
123 void UpdateRenderdashRTT ();
124
125 // SimBuffers
126
127 void UpdateSimDataBuffer();
130
131 // Internal updates
132
133 void FinishWheelUpdates();
134 void FinishFlexbodyTasks();
135
136 // Helpers
137
138 bool IsActorLive() const;
139 bool IsActorInitialized() const { return m_initialized; }
140 void InitializeActor() { m_initialized = true; }
141 void CalculateDriverPos(Ogre::Vector3& out_pos, Ogre::Quaternion& out_rot);
142 int GetActorId() const;
143 int GetActorState() const;
146 Ogre::String GetResourceGroup() { return m_custom_resource_group; }
147 ActorPtr GetActor(); // Watch out for multithreading with this!
148 Ogre::MaterialPtr& GetCabTransMaterial() { return m_cab_mat_visual_trans; }
149 Ogre::TexturePtr GetHelpTex() { return m_help_tex; }
150 Ogre::MaterialPtr GetHelpMat() { return m_help_mat; }
151 bool HasDriverSeatProp() const { return m_driverseat_prop_index != -1; }
152 void CalcPropAnimation(PropAnim& anim, float& cstate, int& div, float dt);
154 WheelSide getWheelSide(WheelID_t wheel_id) { return (wheel_id >= 0 && (size_t)wheel_id < m_wheels.size()) ? m_wheels[wheel_id].wx_side : WheelSide::INVALID; }
155 std::string getWheelRimMeshName(WheelID_t wheel_id) { return (wheel_id >= 0 && (size_t)wheel_id < m_wheels.size()) ? m_wheels[wheel_id].wx_rim_mesh_name : ""; }
156 const ActorPtr& getOwningActor() { return m_actor; }
157 int countBeaconProps() const;
159private:
160
161 float UpdateSmoothShift(PropAnim& anim, float dt, float new_target_cstate); // Helper for `CalcPropAnimation()`
162
163 // Static info
167 Ogre::SceneNode* m_gfx_beams_parent_scenenode = nullptr;
168
169 // Game state
170 bool m_initialized = false;
174 bool m_beaconlight_active = true; // 'true' will trigger SetBeaconsEnabled(false) on the first buffer update
178
179 // Threaded tasks
180 std::vector<std::shared_ptr<Task>> m_flexwheel_tasks;
181 std::vector<std::shared_ptr<Task>> m_flexbody_tasks;
182
183 // Elements
184 std::vector<NodeGfx> m_gfx_nodes;
185 std::vector<BeamGfx> m_gfx_beams;
186 std::vector<AirbrakeGfx> m_gfx_airbrakes;
187 std::vector<Prop> m_props;
188 std::vector<FlexBody*> m_flexbodies;
189 std::vector<WheelGfx> m_wheels;
190 std::vector<VideoCamera> m_videocameras;
191 std::vector<FlareMaterial> m_flare_materials;
193 std::vector<CParticle> m_cparticles;
194 std::vector<Exhaust> m_exhausts;
195
196 // Particles
198 DustPool* m_particles_dust = nullptr; // dust, vapour and tyre smoke
203
204 // Cab mesh ('submesh' in truck fileformat)
205 FlexObj* m_cab_mesh = nullptr;
206 Ogre::SceneNode* m_cab_scene_node = nullptr;
207 Ogre::Entity* m_cab_entity = nullptr;
208 Ogre::MaterialPtr m_cab_mat_visual;
209 Ogre::MaterialPtr m_cab_mat_visual_trans;
210 Ogre::MaterialPtr m_cab_mat_template_plain;
212
213 // GUI
214 Ogre::MaterialPtr m_help_mat;
215 Ogre::TexturePtr m_help_tex;
217
219};
220
222
223} // Namespace RoR
Global forward declarations.
Processes a RigDef::Document (parsed from 'truck' file format) into a simulated gameplay object (Acto...
A visual mesh, forming a chassis for softbody actor At most one instance is created per actor.
Definition FlexObj.h:60
Ogre::MaterialPtr m_cab_mat_template_emissive
Definition GfxActor.h:211
void SetNodeHot(NodeNum_t nodenum, bool value)
void UpdateVideoCameras(float dt)
Definition GfxActor.cpp:471
std::vector< FlexBody * > & GetFlexbodies()
Definition GfxActor.h:71
SurveyMapEntity & getSurveyMapEntity()
Definition GfxActor.h:153
Ogre::TexturePtr m_help_tex
Definition GfxActor.h:215
bool m_beaconlight_active
Definition GfxActor.h:174
void SetCastShadows(bool value)
std::vector< CParticle > & getCParticles()
Definition GfxActor.h:73
float m_prop_anim_crankfactor_prev
Definition GfxActor.h:175
VideoCamState m_vidcam_state
Definition GfxActor.h:171
void SetRodsVisible(bool visible)
bool IsActorInitialized() const
Temporary TODO: Remove once the spawn routine is fixed.
Definition GfxActor.h:139
void ResetFlexbodies()
Ogre::String GetResourceGroup()
Definition GfxActor.h:146
bool IsActorLive() const
Should the visuals be updated for this actor?
DustPool * m_particles_drip
Definition GfxActor.h:197
void SetCabLightsActive(bool state_on)
Definition GfxActor.cpp:422
void UpdateWheelVisuals()
void SetVideoCamState(VideoCamState state)
Definition GfxActor.cpp:443
void UpdateAeroEngines()
DustPool * m_particles_splash
Definition GfxActor.h:199
void SetWingsVisible(bool visible)
Ogre::MaterialPtr GetHelpMat()
Definition GfxActor.h:150
DustPool * m_particles_sparks
Definition GfxActor.h:201
ActorSB & GetSimDataBuffer()
Definition GfxActor.h:128
void SetWheelsVisible(bool value)
void UpdateRods()
std::vector< BeamGfx > m_gfx_beams
Definition GfxActor.h:185
std::string getWheelRimMeshName(WheelID_t wheel_id)
Definition GfxActor.h:155
FlexObj * m_cab_mesh
Definition GfxActor.h:205
void RegisterCabMesh(Ogre::Entity *ent, Ogre::SceneNode *snode, FlexObj *flexobj)
bool IsDebugViewApplicable(DebugViewType dv)
float UpdateSmoothShift(PropAnim &anim, float dt, float new_target_cstate)
std::vector< VideoCamera > & getVideoCameras()
Definition GfxActor.h:75
SurveyMapEntity m_surveymap_entity
Definition GfxActor.h:216
void UpdateCParticles()
void UpdateExhausts()
int GetActorState() const
Ogre::SceneNode * m_cab_scene_node
Definition GfxActor.h:206
std::vector< std::shared_ptr< Task > > m_flexbody_tasks
Definition GfxActor.h:181
std::vector< Exhaust > m_exhausts
Definition GfxActor.h:194
std::vector< FlareMaterial > m_flare_materials
Definition GfxActor.h:191
DustPool * m_particles_clump
Definition GfxActor.h:202
void FinishFlexbodyTasks()
float m_prop_anim_shift_timer
Definition GfxActor.h:176
RoR::Renderdash * m_renderdash
Definition GfxActor.h:192
std::string m_custom_resource_group
Definition GfxActor.h:165
DebugViewType m_debug_view
Definition GfxActor.h:172
Ogre::Entity * m_cab_entity
Definition GfxActor.h:207
std::vector< Prop > & getProps()
Definition GfxActor.h:72
void UpdateSimDataBuffer()
Copies sim. data from Actor to GfxActor for later update.
void InitializeActor()
Temporary TODO: Remove once the spawn routine is fixed.
Definition GfxActor.h:140
void SetRenderdashActive(bool active)
void UpdatePropAnimations(float dt)
Ogre::MaterialPtr m_cab_mat_visual
Updated in-place from templates.
Definition GfxActor.h:208
VideoCamState GetVideoCamState() const
Definition GfxActor.h:144
ActorPtr GetActor()
Definition GfxActor.cpp:337
void UpdateDebugView()
Definition GfxActor.cpp:724
ActorSB m_simbuf
Definition GfxActor.h:218
std::vector< NodeGfx > m_gfx_nodes
Definition GfxActor.h:184
std::vector< std::shared_ptr< Task > > m_flexwheel_tasks
Definition GfxActor.h:180
Ogre::MaterialPtr m_cab_mat_visual_trans
Definition GfxActor.h:209
void SortFlexbodies()
int m_prop_anim_prev_gear
Definition GfxActor.h:177
std::vector< WheelGfx > m_wheels
Definition GfxActor.h:189
void UpdateAirbrakes()
void UpdateCabMesh()
void UpdateFlares(float dt, bool is_player)
void UpdateProps(float dt, bool is_player_actor)
Ogre::SceneNode * m_gfx_beams_parent_scenenode
Definition GfxActor.h:167
bool HasDriverSeatProp() const
Definition GfxActor.h:151
void CalcPropAnimation(PropAnim &anim, float &cstate, int &div, float dt)
ActorPtr m_actor
Definition GfxActor.h:164
void RemoveBeam(int beam_index)
NodeSB * GetSimNodeBuffer()
Definition GfxActor.h:129
void SetAllMeshesVisible(bool value)
std::vector< Prop > m_props
Definition GfxActor.h:187
void UpdateBeaconFlare(Prop &prop, float dt, bool is_player_actor)
void SetAeroEnginesVisible(bool visible)
WheelSide getWheelSide(WheelID_t wheel_id)
Definition GfxActor.h:154
void SetFlexbodyVisible(bool visible)
std::vector< VideoCamera > m_videocameras
Definition GfxActor.h:190
int m_driverseat_prop_index
Definition GfxActor.h:166
Ogre::MaterialPtr m_cab_mat_template_plain
Definition GfxActor.h:210
void SetDebugView(DebugViewType dv)
DustPool * m_particles_dust
Definition GfxActor.h:198
void SetPropsVisible(bool visible)
std::vector< Exhaust > & getExhausts()
Definition GfxActor.h:74
std::vector< CParticle > m_cparticles
Definition GfxActor.h:193
void UpdateParticles(float dt)
Definition GfxActor.cpp:592
int GetActorId() const
void RegisterCabMaterial(Ogre::MaterialPtr mat, Ogre::MaterialPtr mat_trans)
Definition GfxActor.cpp:406
Ogre::TexturePtr GetHelpTex()
Definition GfxActor.h:149
void ScaleActor(Ogre::Vector3 relpos, float ratio)
void SetFlexbodiesVisible(bool visible)
void CalculateDriverPos(Ogre::Vector3 &out_pos, Ogre::Quaternion &out_rot)
DustPool * m_particles_ripple
Definition GfxActor.h:200
void UpdateRenderdashRTT()
DebugViewType m_last_debug_view
Definition GfxActor.h:173
Ogre::MaterialPtr & GetCabTransMaterial()
Definition GfxActor.h:148
std::vector< AirbrakeGfx > m_gfx_airbrakes
Definition GfxActor.h:186
void FinishWheelUpdates()
void SetMaterialFlareOn(int flare_index, bool state_on)
Definition GfxActor.cpp:342
std::vector< FlexBody * > m_flexbodies
Definition GfxActor.h:188
void CycleDebugViews()
void SetBeaconsEnabled(bool beacon_light_is_active)
void UpdateNetLabels(float dt)
bool m_initialized
Definition GfxActor.h:170
int countBeaconProps() const
void UpdateWingMeshes()
void ToggleDebugView()
DebugViewType GetDebugView() const
Definition GfxActor.h:145
void UpdateFlexbodies()
const ActorPtr & getOwningActor()
Definition GfxActor.h:156
Ogre::MaterialPtr m_help_mat
Definition GfxActor.h:214
'renderdash' is a name of a classic Render-To-Texture animated material with gauges and other dashboa...
Definition Renderdash.h:35
DebugViewType
Definition GfxData.h:102
VideoCamState
Definition GfxData.h:94
WheelSide
Used by rig-def/addonpart/tuneup formats to specify wheel rim mesh orientation.
int WheelID_t
Index to Actor::ar_wheels, use RoR::WHEELID_INVALID as empty value.
uint16_t NodeNum_t
Node position within Actor::ar_nodes; use RoR::NODENUM_INVALID as empty value.
std::vector< NodeSB > simbuf_nodes
Definition SimBuffers.h:134
A mesh attached to vehicle frame via 3 nodes.
Definition GfxData.h:156