1
// $Id: track_object.cpp 4308 2009-12-17 00:22:29Z hikerstk $
3
// SuperTuxKart - a fun racing game with go-kart
4
// Copyright (C) 2009 Joerg Henrichs
6
// This program is free software; you can redistribute it and/or
7
// modify it under the terms of the GNU General Public License
8
// as published by the Free Software Foundation; either version 3
9
// of the License, or (at your option) any later version.
11
// This program is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
// GNU General Public License for more details.
16
// You should have received a copy of the GNU General Public License
17
// along with this program; if not, write to the Free Software
18
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20
#include "tracks/track_object.hpp"
22
#include "graphics/irr_driver.hpp"
23
#include "io/file_manager.hpp"
24
#include "io/xml_node.hpp"
25
#include "modes/world.hpp"
26
#include "tracks/track.hpp"
28
/** A track object: any additional object on the track. This object implements
29
* a graphics-only representation, i.e. there is no physical representation.
30
* Derived classes can implement a physical representation (see
31
* physics/physical_object) or animations.
32
* \param xml_node The xml node from which the initial data is taken. This is
33
* for now: initial position, initial rotation, name of the
34
* model, enable/disable status, timer information.
36
TrackObject::TrackObject(const XMLNode &xml_node)
39
std::string model_name;
40
xml_node.get("model", &model_name);
41
std::string full_path = World::getWorld()->getTrack()->getTrackFile(model_name);
42
m_animated_mesh = irr_driver->getAnimatedMesh(full_path);
45
// If the model isn't found in the track directory, look
46
// in STK's model directory.
47
full_path = file_manager->getModelFile(model_name);
48
m_animated_mesh = irr_driver->getAnimatedMesh(full_path);
51
fprintf(stderr, "Warning: '%s' in '%s' not found and is ignored.\n",
52
xml_node.getName().c_str(), model_name.c_str());
54
} // if(!m_animated_mesh)
56
m_animated_node = irr_driver->addAnimatedMesh(m_animated_mesh);
58
std::string debug_name = model_name+" (track-object)";
59
m_animated_node->setName(debug_name.c_str());
62
// Get the information from the xml node.
64
xml_node.get("enabled", &m_enabled);
67
xml_node.get("looped", &m_is_looped);
69
m_frame_start = m_animated_node->getStartFrame();
70
xml_node.get("frame-start", &m_frame_start);
72
m_frame_end = m_animated_node->getEndFrame();
73
xml_node.get("frame-end", &m_frame_end);
76
m_animated_node->setVisible(false);
78
m_init_xyz = core::vector3df(0,0,0);
79
int result = xml_node.get("xyz", &m_init_xyz);
80
m_init_hpr = core::vector3df(0,0,0);
81
result = xml_node.get("hpr", &m_init_hpr);
82
m_init_scale = core::vector3df(1,1,1);
83
result = xml_node.get("scale", &m_init_scale);
84
if(!XMLNode::hasP(result) ||
85
!XMLNode::hasR(result)) // Needs perhaps pitch and roll
88
m_animated_node->setPosition(m_init_xyz);
89
m_animated_node->setRotation(m_init_hpr);
90
m_animated_node->setScale(m_init_scale);
91
m_animated_node->setMaterialFlag(video::EMF_LIGHTING, false);
95
// ----------------------------------------------------------------------------
96
TrackObject::~TrackObject()
98
irr_driver->removeNode(m_animated_node);
99
irr_driver->removeMesh(m_animated_mesh);
102
// ----------------------------------------------------------------------------
103
/** Initialises an object before a race starts.
105
void TrackObject::reset()
107
m_animated_node->setPosition(m_init_xyz);
108
m_animated_node->setRotation(m_init_hpr);
109
m_animated_node->setScale(m_init_scale);
110
m_animated_node->setLoopMode(m_is_looped);
114
m_animated_node->setFrameLoop(m_frame_start, m_frame_end);
117
// ----------------------------------------------------------------------------
118
/** Enables or disables this object. This affects the visibility, i.e.
119
* disabled objects will not be displayed anymore.
120
* \param mode Enable (true) or disable (false) this object.
122
void TrackObject::setEnable(bool mode)
125
m_animated_node->setVisible(m_enabled);
127
// ----------------------------------------------------------------------------
128
/** This function is called from irrlicht when a (non-looped) animation ends.
130
void TrackObject::OnAnimationEnd(scene::IAnimatedMeshSceneNode* node)
134
// ----------------------------------------------------------------------------
135
void TrackObject::update(float dt)
138
// ----------------------------------------------------------------------------