SuperTuxKart
Loading...
Searching...
No Matches
track_object_presentation.hpp
1// SuperTuxKart - a fun racing game with go-kart
2//
3// Copyright (C) 2013-2015 Joerg Henrichs, Marianne Gagnon
4//
5// This program is free software; you can redistribute it and/or
6// modify it under the terms of the GNU General Public License
7// as published by the Free Software Foundation; either version 3
8// of the License, or (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program; if not, write to the Free Software
17// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19
20#ifndef HEADER_TRACK_OBJECT_PRESENTATION_HPP
21#define HEADER_TRACK_OBJECT_PRESENTATION_HPP
22
23#include "graphics/lod_node.hpp"
24#include "utils/cpp2011.hpp"
25#include "utils/no_copy.hpp"
26#include "utils/log.hpp"
27#include "utils/leak_check.hpp"
28#include "utils/time.hpp"
29#include "utils/vec3.hpp"
30
31#include <vector3d.h>
32
33#include <memory>
34#include <limits>
35#include <string>
36
37class SFXBase;
38class ParticleEmitter;
39class PhysicalObject;
40class ThreeDAnimation;
42namespace GE { class GERenderInfo; }
43class STKInstancedSceneNode;
44class XMLNode;
45class TrackObject;
46
47namespace irr
48{
49 namespace scene { class IAnimatedMesh; class IMesh; class IMeshSceneNode; class ISceneNode; }
50}
51using namespace irr;
52
57{
58protected:
60 core::vector3df m_init_xyz;
61
63 core::vector3df m_init_hpr;
64
66 core::vector3df m_init_scale;
67
68
69public:
70
71 TrackObjectPresentation(const XMLNode& xml_node);
72
73 TrackObjectPresentation(const core::vector3df& xyz,
74 const core::vector3df& hpr = core::vector3df(0,0,0),
75 const core::vector3df& scale = core::vector3df(0,0,0))
76 {
77 m_init_xyz = xyz;
78 m_init_hpr = hpr;
79 m_init_scale = scale;
80 } // TrackObjectPresentation
81
82 // ------------------------------------------------------------------------
83 virtual ~TrackObjectPresentation() {}
84 // ------------------------------------------------------------------------
85
86 virtual void reset() {}
87 virtual void setEnable(bool enabled)
88 {
89 Log::warn("TrackObjectPresentation", "setEnable unimplemented for this presentation type");
90 }
91 virtual void updateGraphics(float dt) {}
92 virtual void update(float dt) {}
93 virtual void move(const core::vector3df& xyz, const core::vector3df& hpr,
94 const core::vector3df& scale, bool isAbsoluteCoord) {}
95
96 // ------------------------------------------------------------------------
98 virtual const core::vector3df& getPosition() const { return m_init_xyz; }
99 // ------------------------------------------------------------------------
102 virtual const core::vector3df getAbsolutePosition() const
103 {
104 return m_init_xyz;
105 } // getAbsolutePosition
106 // ------------------------------------------------------------------------
107 virtual const core::vector3df getAbsoluteCenterPosition() const
108 {
109 return m_init_xyz;
110 }
111 // ------------------------------------------------------------------------
113 virtual const core::vector3df& getRotation() const { return m_init_hpr; }
114 // ------------------------------------------------------------------------
116 virtual const core::vector3df& getScale() const { return m_init_scale; }
117
118 LEAK_CHECK()
119};
120
121// ============================================================================
127{
128protected:
130 scene::ISceneNode* m_node;
131
132 bool m_force_always_hidden;
133public:
134
138 {
139 m_node = NULL;
140 m_force_always_hidden = false;
141 } // TrackObjectPresentationSceneNode
142 // ------------------------------------------------------------------------
144 TrackObjectPresentationSceneNode(const core::vector3df& xyz,
145 const core::vector3df& hpr,
146 const core::vector3df& scale,
147 scene::ISceneNode* node = NULL) :
148 TrackObjectPresentation(xyz, hpr, scale)
149 {
150 m_node = node;
151 m_force_always_hidden = false;
152 } // TrackObjectPresentationSceneNode
153
154 // ------------------------------------------------------------------------
155 virtual const core::vector3df& getPosition() const OVERRIDE;
156 virtual const core::vector3df getAbsolutePosition() const OVERRIDE;
157 virtual const core::vector3df getAbsoluteCenterPosition() const OVERRIDE;
158 virtual const core::vector3df& getRotation() const OVERRIDE;
159 virtual const core::vector3df& getScale() const OVERRIDE;
160 virtual void move(const core::vector3df& xyz, const core::vector3df& hpr,
161 const core::vector3df& scale, bool isAbsoluteCoord) OVERRIDE;
162 virtual void setEnable(bool enabled) OVERRIDE;
163 virtual void reset() OVERRIDE;
164
165 // ------------------------------------------------------------------------
167 scene::ISceneNode* getNode() { return m_node; }
168 // ------------------------------------------------------------------------
170 const scene::ISceneNode* getNode() const { return m_node; }
171 // ------------------------------------------------------------------------
172 bool isAlwaysHidden() const { return m_force_always_hidden; }
173}; // class TrackObjectPresentationSceneNode
174
175// ============================================================================
181{
182public:
183 TrackObjectPresentationEmpty(const XMLNode& xml_node);
185}; // class TrackObjectPresentationEmpty
186
187// ============================================================================
192{
193 TrackObject* m_parent;
194 using TrackObjectPresentationSceneNode::move;
195 std::string m_name;
196 bool m_start_executed, m_reset_executed;
197public:
199 const XMLNode& xml_node,
200 ModelDefinitionLoader& model_def_loader);
202 virtual void update(float dt) OVERRIDE;
203 virtual void reset() OVERRIDE
204 {
205 m_reset_executed = false;
206 TrackObjectPresentationSceneNode::reset();
207 }
208 virtual void move(const core::vector3df& xyz, const core::vector3df& hpr,
209 const core::vector3df& scale, bool isAbsoluteCoord) OVERRIDE;
210}; // TrackObjectPresentationLibraryNode
211
212// ============================================================================
217{
218public:
219
220 TrackObjectPresentationLOD(const XMLNode& xml_node,
221 scene::ISceneNode* parent,
222 ModelDefinitionLoader& model_def_loader,
223 std::shared_ptr<GE::GERenderInfo> ri);
225 virtual void reset() OVERRIDE;
226};
227
228// ============================================================================
233{
234private:
237 scene::IMesh *m_mesh;
238
241
244
245 std::string m_model_file;
246
247 std::shared_ptr<GE::GERenderInfo> m_render_info;
248
249 void init(const XMLNode* xml_node, scene::ISceneNode* parent, bool enabled);
250
251public:
252 TrackObjectPresentationMesh(const XMLNode& xml_node, bool enabled,
253 scene::ISceneNode* parent,
254 std::shared_ptr<GE::GERenderInfo> render_info);
255
256 TrackObjectPresentationMesh(const std::string& model_file,
257 const core::vector3df& xyz,
258 const core::vector3df& hpr,
259 const core::vector3df& scale);
260 TrackObjectPresentationMesh(scene::IAnimatedMesh* mesh,
261 const core::vector3df& xyz,
262 const core::vector3df& hpr,
263 const core::vector3df& scale);
265 virtual void reset() OVERRIDE;
266 // ------------------------------------------------------------------------
268 const std::string& getModelFile() const { return m_model_file; }
269}; // class TrackObjectPresentationMesh
270
271// ============================================================================
276{
277private:
278
282
285
286 core::vector3df m_xyz;
287
288 bool m_enabled;
289
290public:
291
293 scene::ISceneNode* parent,
294 bool disable_for_multiplayer);
296 void onTriggerItemApproached(int kart_id);
297 virtual void updateGraphics(float dt) OVERRIDE;
298 virtual void move(const core::vector3df& xyz, const core::vector3df& hpr,
299 const core::vector3df& scale, bool isAbsoluteCoord) OVERRIDE;
300 void triggerSound(bool loop);
301 void stopSound();
302
303 virtual void setEnable(bool enabled) OVERRIDE;
304
305 // ------------------------------------------------------------------------
307 const std::string& getTriggerCondition() const { return m_trigger_condition; }
308}; // TrackObjectPresentationSound
309
310// ============================================================================
315{
321 float m_fade_out_start;
322 float m_fade_out_end;
323public:
325 scene::ISceneNode* parent);
327 virtual void updateGraphics(float dt) OVERRIDE;
328}; // TrackObjectPresentationBillboard
329
330
331// ============================================================================
336{
337private:
338 ParticleEmitter* m_emitter;
339 LODNode* m_lod_emitter_node;
340 std::string m_trigger_condition;
341 bool m_delayed_stop;
342 double m_delayed_stop_time;
343
344public:
346 scene::ISceneNode* parent);
348
349 virtual void updateGraphics(float dt) OVERRIDE;
350 void triggerParticles();
351 void stop();
352 void stopIn(double delay);
353 void setRate(float rate);
354 // ------------------------------------------------------------------------
356 std::string& getTriggerCondition() { return m_trigger_condition; }
357}; // TrackObjectPresentationParticles
358
359// ============================================================================
364{
365private:
366 video::SColor m_color;
367 float m_distance;
368 float m_energy;
369public:
371 scene::ISceneNode* parent);
373 float getEnergy() const { return m_energy; }
374 virtual void setEnable(bool enabled) OVERRIDE;
375 void setEnergy(float energy);
376}; // TrackObjectPresentationLight
377
378// ============================================================================
379
380enum ActionTriggerType
381{
382 TRIGGER_TYPE_POINT = 0,
383 TRIGGER_TYPE_CYLINDER = 1
384};
385
390{
391private:
393 std::string m_action, m_library_id, m_triggered_object, m_library_name;
394
395 float m_xml_reenable_timeout;
396
397 uint64_t m_reenable_timeout;
398
399 ActionTriggerType m_type;
400
401public:
403 TrackObject* parent);
404 TrackObjectPresentationActionTrigger(const core::vector3df& xyz,
405 const std::string& scriptname,
406 float distance);
407
409
410 void onTriggerItemApproached(int kart_id);
411 // ------------------------------------------------------------------------
413 virtual void reset() OVERRIDE
414 { m_reenable_timeout = StkTime::getMonoTimeMs(); }
415 // ------------------------------------------------------------------------
418 virtual void setEnable(bool status) OVERRIDE
419 {
420 m_reenable_timeout = status ? StkTime::getMonoTimeMs() :
421 std::numeric_limits<uint64_t>::max();
422 }
423 // ------------------------------------------------------------------------
424 void setReenableTimeout(float time)
425 {
426 m_reenable_timeout =
427 StkTime::getMonoTimeMs() + (uint64_t)(time * 1000.0f);
428 }
429}; // class TrackObjectPresentationActionTrigger
430
431
432#endif // TRACKOBJECTPRESENTATION_HPP
433
manages level-of-detail
Definition: lod_node.hpp:50
Utility class to load level-of-detail nodes and library nodes.
Definition: model_definition_loader.hpp:81
manages smoke particle effects
Definition: particle_emitter.hpp:42
Definition: physical_object.hpp:40
The base class for sound effects.
Definition: sfx_base.hpp:43
static uint64_t getMonoTimeMs()
Returns a time based since the starting of stk (monotonic clock).
Definition: time.hpp:106
A virtual base class for all animations.
Definition: three_d_animation.hpp:45
A track object representation that consists of an action trigger.
Definition: track_object_presentation.hpp:390
virtual void setEnable(bool status) OVERRIDE
Sets the trigger to be enabled or disabled.
Definition: track_object_presentation.hpp:418
virtual void reset() OVERRIDE
Reset the trigger (i.e.
Definition: track_object_presentation.hpp:413
std::string m_action
For action trigger objects.
Definition: track_object_presentation.hpp:393
A track object representation that consists of a billboard scene node.
Definition: track_object_presentation.hpp:315
bool m_fade_out_when_close
To make the billboard disappear when close to the camera.
Definition: track_object_presentation.hpp:320
A track object representation that is invisible and only consists of a location, rotation and scale.
Definition: track_object_presentation.hpp:181
A track object representation that consists of a level-of-detail scene node.
Definition: track_object_presentation.hpp:217
A track object representation that is a library node.
Definition: track_object_presentation.hpp:192
A track object representation that consists of a light emitter.
Definition: track_object_presentation.hpp:364
A track object representation that consists of a mesh scene node.
Definition: track_object_presentation.hpp:233
bool m_is_in_skybox
True if the object is in the skybox.
Definition: track_object_presentation.hpp:243
const std::string & getModelFile() const
Returns the mode file name.
Definition: track_object_presentation.hpp:268
scene::IMesh * m_mesh
The mesh used here.
Definition: track_object_presentation.hpp:237
bool m_is_looped
True if it is a looped animation.
Definition: track_object_presentation.hpp:240
A track object representation that consists of a particle emitter.
Definition: track_object_presentation.hpp:336
std::string & getTriggerCondition()
Returns the trigger condition for this object.
Definition: track_object_presentation.hpp:356
Base class for all track object presentation classes using a scene node as presentation.
Definition: track_object_presentation.hpp:127
virtual const core::vector3df getAbsolutePosition() const OVERRIDE
Returns a copy of the initial position.
Definition: track_object_presentation.cpp:87
scene::ISceneNode * getNode()
Returns a pointer to the scene node.
Definition: track_object_presentation.hpp:167
virtual const core::vector3df & getScale() const OVERRIDE
Returns the initial scale.
Definition: track_object_presentation.cpp:112
TrackObjectPresentationSceneNode(const XMLNode &xml_node)
Constructor based on data from xml.
Definition: track_object_presentation.hpp:136
virtual const core::vector3df & getRotation() const OVERRIDE
Returns the initial rotation.
Definition: track_object_presentation.cpp:105
const scene::ISceneNode * getNode() const
Returns a pointer to the scene node, const version.
Definition: track_object_presentation.hpp:170
virtual const core::vector3df & getPosition() const OVERRIDE
Returns the position of this TrackObjectPresentation.
Definition: track_object_presentation.cpp:80
TrackObjectPresentationSceneNode(const core::vector3df &xyz, const core::vector3df &hpr, const core::vector3df &scale, scene::ISceneNode *node=NULL)
Constructor based on a transform.
Definition: track_object_presentation.hpp:144
scene::ISceneNode * m_node
A pointer to the scene node of this object.
Definition: track_object_presentation.hpp:130
A track object representation that consists of a sound emitter.
Definition: track_object_presentation.hpp:276
const std::string & getTriggerCondition() const
Currently used for sound effects only, in cutscenes only atm.
Definition: track_object_presentation.hpp:307
SFXBase * m_sound
If a sound is attached to this object and/or this is a sound emitter object.
Definition: track_object_presentation.hpp:281
std::string m_trigger_condition
Currently used for sound effects only, in cutscenes only atm.
Definition: track_object_presentation.hpp:284
Base class for all track object presentation classes.
Definition: track_object_presentation.hpp:57
core::vector3df m_init_xyz
The initial XYZ position of the object.
Definition: track_object_presentation.hpp:60
core::vector3df m_init_hpr
The initial hpr of the object.
Definition: track_object_presentation.hpp:63
core::vector3df m_init_scale
The initial scale of the object.
Definition: track_object_presentation.hpp:66
virtual const core::vector3df & getPosition() const
Returns the position of this TrackObjectPresentation.
Definition: track_object_presentation.hpp:98
virtual const core::vector3df getAbsolutePosition() const
Returns a copy of the initial position.
Definition: track_object_presentation.hpp:102
virtual const core::vector3df & getRotation() const
Returns the initial rotation.
Definition: track_object_presentation.hpp:113
virtual const core::vector3df & getScale() const
Returns the initial scale.
Definition: track_object_presentation.hpp:116
This is a base object for any separate object on the track, which might also have a skeletal animatio...
Definition: track_object.hpp:56
utility class used to parse XML files
Definition: xml_node.hpp:48