SuperTuxKart
Loading...
Searching...
No Matches
track_object.hpp
1//
2// SuperTuxKart - a fun racing game with go-kart
3// Copyright (C) 2009-2015 Joerg Henrichs
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#ifndef HEADER_TRACK_OBJECT_HPP
20#define HEADER_TRACK_OBJECT_HPP
21
22#include <vector3d.h>
23
24#include "physics/physical_object.hpp"
25#include "scriptengine/scriptvec3.hpp"
26#include "tracks/track_object_presentation.hpp"
27#include "utils/cpp2011.hpp"
28#include "utils/vec3.hpp"
29#include <string>
30#include "animations/three_d_animation.hpp"
31
32#include <memory>
33
35namespace GE { class GERenderInfo; }
36class ThreeDAnimation;
37class XMLNode;
38
39namespace irr
40{
41 namespace scene
42 {
43 class IAnimatedMeshSceneNode;
44 }
45}
46
47using namespace irr;
48
56{
57//public:
58 // The different type of track objects: physical objects, graphical
59 // objects (without a physical representation) - the latter might be
60 // eye candy (to reduce work for physics), ...
61 //enum TrackObjectType {TO_PHYSICAL, TO_GRAPHICAL};
62
63private:
66
67 TrackObjectPresentation* m_presentation;
68
69 std::string m_name;
70
71 std::string m_id;
72
73 std::shared_ptr<GE::GERenderInfo> m_render_info;
74
75protected:
76
78 core::vector3df m_init_xyz;
79
81 core::vector3df m_init_hpr;
82
84 core::vector3df m_init_scale;
85
87 std::string m_lod_group;
88
89 std::string m_interaction;
90
91 std::string m_type;
92
93 bool m_soccer_ball;
94
97
98 std::shared_ptr<PhysicalObject> m_physical_object;
99
100 ThreeDAnimation* m_animator;
101
102 TrackObject* m_parent_library;
103
104 std::vector<TrackObject*> m_movable_children;
105 std::vector<TrackObject*> m_children;
106
107 bool m_initially_visible;
108
109 std::string m_visibility_condition;
110
111 void init(const XMLNode &xml_node, scene::ISceneNode* parent,
112 ModelDefinitionLoader& model_def_loader,
113 TrackObject* parent_library);
114
115public:
116 TrackObject(const XMLNode &xml_node,
117 scene::ISceneNode* parent,
118 ModelDefinitionLoader& model_def_loader,
119 TrackObject* parent_library);
120
121 TrackObject(const core::vector3df& xyz,
122 const core::vector3df& hpr,
123 const core::vector3df& scale,
124 const char* interaction,
125 TrackObjectPresentation* presentation,
126 bool is_dynamic,
127 const PhysicalObject::Settings* physicsSettings);
128 virtual ~TrackObject();
129 virtual void update(float dt);
130 virtual void updateGraphics(float dt);
131 virtual void resetAfterRewind();
132 void move(const core::vector3df& xyz, const core::vector3df& hpr,
133 const core::vector3df& scale, bool updateRigidBody,
134 bool isAbsoluteCoord);
135
136 virtual void reset();
137 const core::vector3df& getPosition() const;
138 const core::vector3df getAbsolutePosition() const;
139 const core::vector3df getAbsoluteCenterPosition() const;
140 const core::vector3df& getRotation() const;
141 const core::vector3df& getScale() const;
142 bool castRay(const btVector3 &from,
143 const btVector3 &to, btVector3 *hit_point,
144 const Material **material, btVector3 *normal,
145 bool interpolate_normal) const;
146
147 TrackObject* getParentLibrary()
148 {
149 return m_parent_library;
150 }
151
152 // ------------------------------------------------------------------------
155 virtual void onWorldReady();
156 // ------------------------------------------------------------------------
159 virtual void handleExplosion(const Vec3& pos, bool directHit) {};
160 void setID(std::string obj_id) { m_id = obj_id; }
161
162 // ------------------------------------------------------------------------
163 const std::string& getLodGroup() const { return m_lod_group; }
164 // ------------------------------------------------------------------------
165 const std::string& getType() const { return m_type; }
166 // ------------------------------------------------------------------------
167 const std::string getName() const { return m_name; }
168 // ------------------------------------------------------------------------
169 const std::string getID() const { return m_id; }
170 // ------------------------------------------------------------------------
171 const std::string getInteraction() const { return m_interaction; }
172 // ------------------------------------------------------------------------
173 bool isEnabled() const { return m_enabled; }
174 // ------------------------------------------------------------------------
175 bool isSoccerBall() const { return m_soccer_ball; }
176 // ------------------------------------------------------------------------
177 const PhysicalObject* getPhysicalObject() const
178 { return m_physical_object.get(); }
179 // ------------------------------------------------------------------------
180 PhysicalObject* getPhysicalObject() { return m_physical_object.get(); }
181 // ------------------------------------------------------------------------
182 const core::vector3df getInitXYZ() const { return m_init_xyz; }
183 // ------------------------------------------------------------------------
184 const core::vector3df getInitRotation() const { return m_init_hpr; }
185 // ------------------------------------------------------------------------
186 const core::vector3df getInitScale() const { return m_init_scale; }
187 // ------------------------------------------------------------------------
188 template<typename T>
189 T* getPresentation() { return dynamic_cast<T*>(m_presentation); }
190 // ------------------------------------------------------------------------
191 template<typename T>
192 const T* getPresentation() const { return dynamic_cast<T*>(m_presentation); }
193 // ------------------------------------------------------------------------
194 // Methods usable by scripts
206 scene::IAnimatedMeshSceneNode* getMesh();
210 TrackObjectPresentationParticles* getParticleEmitter() { return getPresentation<TrackObjectPresentationParticles>(); }
214 TrackObjectPresentationSound* getSoundEmitter(){ return getPresentation<TrackObjectPresentationSound>(); }
218 TrackObjectPresentationLight* getLight() { return getPresentation<TrackObjectPresentationLight>(); }
219 // For angelscript. Needs to be named something different than getAnimator since it's overloaded.
223 ThreeDAnimation* getIPOAnimator() { return m_animator; }
224 // For angelscript. Needs to be named something different than getPhysicalObject since it's overloaded.
228 PhysicalObject* getPhysics() { return m_physical_object.get(); }
230 void setEnabled(bool mode);
231
232 void moveTo(const Scripting::SimpleVec3* pos, bool isAbsoluteCoord);
233 /* @} */
234 /* @} */
235 /* @} */
236
237 void resetEnabled();
238 // ------------------------------------------------------------------------
239 ThreeDAnimation* getAnimator() { return m_animator; }
240 // ------------------------------------------------------------------------
241 const ThreeDAnimation* getAnimator() const { return m_animator; }
242 // ------------------------------------------------------------------------
243 /* Return true if it has animator or its parent library has */
244 bool hasAnimatorRecursively() const
245 {
246 if (m_animator)
247 return true;
248 if (!m_parent_library)
249 return false;
250 return m_parent_library->hasAnimatorRecursively();
251 }
252 // ------------------------------------------------------------------------
253 void setPaused(bool mode){ m_animator->setPaused(mode); }
254 // ------------------------------------------------------------------------
255 void setInitiallyVisible(bool val) { m_initially_visible = val; }
256 // ------------------------------------------------------------------------
258 bool isDriveable() const { return m_is_driveable; }
259 // ------------------------------------------------------------------------
263 void addMovableChild(TrackObject* child);
264 // ------------------------------------------------------------------------
265 void addChild(TrackObject* child);
266 // ------------------------------------------------------------------------
267 std::vector<TrackObject*>& getMovableChildren() { return m_movable_children; }
268 // ------------------------------------------------------------------------
269 std::vector<TrackObject*>& getChildren() { return m_children; }
270 // ------------------------------------------------------------------------
271 void movePhysicalBodyToGraphicalNode(const core::vector3df& xyz, const core::vector3df& hpr);
272 // ------------------------------------------------------------------------
273 bool joinToMainTrack();
274 // ------------------------------------------------------------------------
275 TrackObject* cloneToChild();
276 LEAK_CHECK()
277}; // TrackObject
278
279#endif
Definition: material.hpp:48
Utility class to load level-of-detail nodes and library nodes.
Definition: model_definition_loader.hpp:81
Definition: physical_object.hpp:49
Definition: physical_object.hpp:40
A virtual base class for all animations.
Definition: three_d_animation.hpp:45
A track object representation that consists of a light emitter.
Definition: track_object_presentation.hpp:364
A track object representation that consists of a particle emitter.
Definition: track_object_presentation.hpp:336
A track object representation that consists of a sound emitter.
Definition: track_object_presentation.hpp:276
Base class for all track object presentation classes.
Definition: track_object_presentation.hpp:57
This is a base object for any separate object on the track, which might also have a skeletal animatio...
Definition: track_object.hpp:56
void init(const XMLNode &xml_node, scene::ISceneNode *parent, ModelDefinitionLoader &model_def_loader, TrackObject *parent_library)
Initialises the track object based on the specified XML data.
Definition: track_object.cpp:103
virtual void reset()
Initialises an object before a race starts.
Definition: track_object.cpp:462
core::vector3df m_init_hpr
The initial hpr of the object.
Definition: track_object.hpp:81
bool castRay(const btVector3 &from, const btVector3 &to, btVector3 *hit_point, const Material **material, btVector3 *normal, bool interpolate_normal) const
Does a raycast against the track object.
Definition: track_object.cpp:576
virtual void resetAfterRewind()
This reset all physical object moved by 3d animation back to current ticks.
Definition: track_object.cpp:551
bool m_is_driveable
True if a kart can drive on this object.
Definition: track_object.hpp:96
std::string m_lod_group
LOD group this object is part of, if it is LOD.
Definition: track_object.hpp:87
bool m_enabled
True if the object is currently being displayed.
Definition: track_object.hpp:65
virtual void updateGraphics(float dt)
This updates all only graphical elements.
Definition: track_object.cpp:529
core::vector3df m_init_scale
The initial scale of the object.
Definition: track_object.hpp:84
core::vector3df m_init_xyz
The initial XYZ position of the object.
Definition: track_object.hpp:78
virtual void update(float dt)
This updates once per physics time step.
Definition: track_object.cpp:540
virtual void handleExplosion(const Vec3 &pos, bool directHit)
Called when an explosion happens.
Definition: track_object.hpp:159
A wrapper around bullets btVector3 to include conventient conversion functions (e....
Definition: vec3.hpp:35
utility class used to parse XML files
Definition: xml_node.hpp:48
ThreeDAnimation * getIPOAnimator()
Should only be used on TrackObjects that use curve-based animation.
Definition: track_object.hpp:223
PhysicalObject * getPhysics()
Get the physics representation of an object.
Definition: track_object.hpp:228
scene::IAnimatedMeshSceneNode * getMesh()
Should only be used on mesh track objects.
Definition: track_object.cpp:708
TrackObjectPresentationLight * getLight()
Should only be used on sound emitter track objects.
Definition: track_object.hpp:218
TrackObjectPresentationParticles * getParticleEmitter()
Should only be used on particle emitter track objects.
Definition: track_object.hpp:210
bool isDriveable() const
Returns if a kart can drive on this object.
Definition: track_object.hpp:258
TrackObjectPresentationSound * getSoundEmitter()
Should only be used on sound emitter track objects.
Definition: track_object.hpp:214
Definition: scriptvec3.hpp:29