Irrlicht only:

1) Added better support for reading XML files.
2) Fixed keyboard handling (for some keys only
   key releases were recognised).
3) #ifdef-ed out more plib parts that would cause a 
   crash with irrlicht.


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@3164 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2009-02-17 02:57:28 +00:00
parent 70b9dd6545
commit 0267f7630c
25 changed files with 591 additions and 79 deletions

View File

@ -91,6 +91,10 @@ supertuxkart_SOURCES = \
graphics/skid_marks.hpp \
graphics/smoke.cpp \
graphics/smoke.hpp \
io/xml_node.cpp \
io/xml_node.hpp \
io/xml_reader.cpp \
io/xml_reader.hpp\`
items/attachment.cpp \
items/attachment.hpp \
items/attachment_manager.cpp \

View File

@ -215,6 +215,14 @@ FileManager::~FileManager()
#endif
} // ~FileManager
//-----------------------------------------------------------------------------
#ifdef HAVE_IRRLICHT
XMLReader *FileManager::getXMLReader(const std::string &f)
{
io::IXMLReader *r = m_file_system->createXMLReader(f.c_str());
return new XMLReader(r);
} // getXMLReader
#endif
//-----------------------------------------------------------------------------
void FileManager::pushModelSearchPath(const std::string& path)
{

View File

@ -26,6 +26,7 @@
#ifdef HAVE_IRRLICHT
# include "irrlicht.h"
using namespace irr;
#include "io/xml_reader.hpp"
#endif
class FileManager
@ -53,11 +54,15 @@ private:
const std::string& fname) const;
public:
FileManager();
~FileManager();
FileManager();
~FileManager();
#ifdef HAVE_IRRLICHT
void setDevice(IrrlichtDevice *device);
void dropFileSystem();
void setDevice(IrrlichtDevice *device);
void dropFileSystem();
XMLReader *getXMLReader(const std::string &f);
// io::IXMLWriter *getXMLWriter(const std::string &f)
//{ return m_file_system->createXMLWriter(f.c_str());}
#endif
std::string getHomeDir () const;
@ -91,6 +96,7 @@ public:
void popTextureSearchPath () {m_texture_search_path.pop_back(); }
void popModelSearchPath () {m_model_search_path.pop_back(); }
void popMusicSearchPath () {m_music_search_path.pop_back(); }
};
extern FileManager* file_manager;

View File

@ -20,8 +20,10 @@
#include "graphics/camera.hpp"
#ifndef HAVE_IRRLICHT
#define _WINSOCKAPI_
#include <plib/ssg.h>
#endif
#include "user_config.hpp"
#include "audio/sound_manager.hpp"
#include "graphics/irr_driver.hpp"
@ -236,7 +238,11 @@ void Camera::update(float dt)
// The reverse mode and the cam used in follow the leader mode (when a
// kart has been eliminated) are facing backwards:
bool reverse = m_kart->getControls().m_look_back || m_mode==CM_LEADER_MODE;
#ifdef HAVE_IRRLICHT
Vec3 cam_rel_pos(0.f, reverse ? m_distance : -m_distance, 1.5f);
#else
Vec3 cam_rel_pos(0.f, reverse ? m_distance : -m_distance, 1.5f);
#endif
// Set the camera rotation
// -----------------------

View File

@ -133,7 +133,6 @@ scene::ICameraSceneNode *IrrDriver::addCamera()
*/
void IrrDriver::update(float dt)
{
m_device->getVideoDriver()->beginScene(true, true, video::SColor(255,100,101,140));
m_scene_manager->drawAll();
m_device->getVideoDriver()->endScene();
@ -143,6 +142,30 @@ void IrrDriver::update(float dt)
// Irrlicht Event handler.
bool IrrDriver::OnEvent(const irr::SEvent &event)
{
switch (event.EventType)
{
case irr::EET_KEY_INPUT_EVENT: {
printf("key input event\n");
break;
} // keyboard
case irr::EET_GUI_EVENT: {
return false; }
case irr::EET_MOUSE_INPUT_EVENT: {
return false; }
case irr::EET_LOG_TEXT_EVENT:
{
// Ignore 'normal' messages
if(event.LogEvent.Level>=0)
{
printf("Level %d: %s\n",
event.LogEvent.Level,event.LogEvent.Text);
}
return true;
}
default:
printf("Event: %d -> ",event.EventType);
return false;
} // switch
return false;
} // OnEvent

View File

@ -32,12 +32,12 @@ void MeshTools::minMax3D(scene::IMesh* mesh, Vec3 *min, Vec3 *max) {
continue;
}
u16 *mbIndices = mb->getIndices();
irr::video::S3DVertex* mbVertices=(irr::video::S3DVertex*)mb->getVertices();
video::S3DVertex* mbVertices=(irr::video::S3DVertex*)mb->getVertices();
for(unsigned int j=0; j<mb->getIndexCount(); j+=1) {
int indx=mbIndices[j];
Vec3 c(mbVertices[indx].Pos.X,
mbVertices[indx].Pos.Y,
mbVertices[indx].Pos.Z );
mbVertices[indx].Pos.Z,
mbVertices[indx].Pos.Y );
min->min(c);
max->max(c);
} // for j

View File

@ -99,12 +99,11 @@ void Scene::draw(float dt)
glEnable ( GL_DEPTH_TEST ) ;
const Track* TRACK = RaceManager::getTrack();
#ifndef HAVE_IRRLICHT
ssgGetLight ( 0 ) -> setPosition ( TRACK->getSunPos() ) ;
ssgGetLight ( 0 ) -> setColour ( GL_AMBIENT , TRACK->getAmbientCol() ) ;
ssgGetLight ( 0 ) -> setColour ( GL_DIFFUSE , TRACK->getDiffuseCol() ) ;
ssgGetLight ( 0 ) -> setColour ( GL_SPECULAR, TRACK->getSpecularCol() ) ;
if (TRACK->useFog())
{
glEnable ( GL_FOG ) ;
@ -130,6 +129,7 @@ void Scene::draw(float dt)
TRACK->getSkyColor()[2],
TRACK->getSkyColor()[3]);
}
#endif
glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ) ;

View File

@ -18,8 +18,8 @@ Global
Release|Win32 = Release|Win32
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B1BC2764-1A43-4800-A654-788B0D05EDA2}.Debug|Win32.ActiveCfg = Release|Win32
{B1BC2764-1A43-4800-A654-788B0D05EDA2}.Debug|Win32.Build.0 = Release|Win32
{B1BC2764-1A43-4800-A654-788B0D05EDA2}.Debug|Win32.ActiveCfg = Debug|Win32
{B1BC2764-1A43-4800-A654-788B0D05EDA2}.Debug|Win32.Build.0 = Debug|Win32
{B1BC2764-1A43-4800-A654-788B0D05EDA2}.irrlicht-debug|Win32.ActiveCfg = irrlicht-debug|Win32
{B1BC2764-1A43-4800-A654-788B0D05EDA2}.irrlicht-debug|Win32.Build.0 = irrlicht-debug|Win32
{B1BC2764-1A43-4800-A654-788B0D05EDA2}.Release|Win32.ActiveCfg = Release|Win32

View File

@ -837,6 +837,18 @@
>
</File>
</Filter>
<Filter
Name="io"
>
<File
RelativePath="..\..\io\xml_node.cpp"
>
</File>
<File
RelativePath="..\..\io\xml_reader.cpp"
>
</File>
</Filter>
</Filter>
<Filter
Name="Headerdateien"
@ -1507,6 +1519,18 @@
>
</File>
</Filter>
<Filter
Name="io"
>
<File
RelativePath="..\..\io\xml_node.hpp"
>
</File>
<File
RelativePath="..\..\io\xml_reader.hpp"
>
</File>
</Filter>
</Filter>
<Filter
Name="Ressourcendateien"

162
src/io/xml_node.cpp Executable file
View File

@ -0,0 +1,162 @@
// $Id: xml_reader.hpp 694 2006-08-29 07:42:36Z hiker $
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2009 Joerg Henrichs
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifdef HAVE_IRRLICHT
#include "io/xml_node.hpp"
#include "utils/string_utils.hpp"
#include "utils/vec3.hpp"
XMLNode::XMLNode(io::IXMLReader *xml)
{
for(unsigned int i=0; i<xml->getAttributeCount(); i++)
{
std::string name = core::stringc(xml->getAttributeName(i)).c_str();
core::stringw value = xml->getAttributeValue(i);
m_attributes[name] = value;
} // for i
} // XMLNode
// ----------------------------------------------------------------------------
/** If 'attribute' was defined, set 'value' to the value of the
* attribute and return true, otherwise return false and do not
* change value.
* \param attribute Name of the attribute.
* \param value Value of the attribute.
*/
bool XMLNode::get(const std::string &attribute, std::string *value)
{
std::map<std::string, core::stringw>::iterator o;
o = m_attributes.find(attribute);
if(o==m_attributes.end()) return false;
*value=core::stringc(o->second).c_str();
return true;
} // get
// ----------------------------------------------------------------------------
bool XMLNode::get(const std::string &attribute, core::vector3df *value)
{
std::string s = "";
if(!get(attribute, &s)) return false;
std::vector<std::string> v = StringUtils::split(s,' ');
if(v.size()!=3) return false;
value->X = (float)atof(v[0].c_str());
value->Y = (float)atof(v[1].c_str());
value->Z = (float)atof(v[2].c_str());
return true;
} // get(vector3df)
// ----------------------------------------------------------------------------
bool XMLNode::get(const std::string &attribute, Vec3 *value)
{
std::string s = "";
if(!get(attribute, &s)) return false;
std::vector<std::string> v = StringUtils::split(s,' ');
if(v.size()!=3) return false;
value->setX((float)atof(v[0].c_str()));
value->setY((float)atof(v[1].c_str()));
value->setZ((float)atof(v[2].c_str()));
return true;
} // get(Vec3)
// ----------------------------------------------------------------------------
bool XMLNode::get(const std::string &attribute, video::SColorf *color)
{
std::string s;
if(!get(attribute, &s)) return false;
std::vector<std::string> v = StringUtils::split(s,' ');
if(v.size()!=4) return false;
color->set((float)atof(v[0].c_str()),
(float)atof(v[1].c_str()),
(float)atof(v[2].c_str()),
(float)atof(v[3].c_str()));
return true;
} // get(SColor)
// ----------------------------------------------------------------------------
bool XMLNode::get(const std::string &attribute, int *value)
{
std::string s;
if(!get(attribute, &s)) return false;
*value = atoi(s.c_str());
return true;
} // get(int)
// ----------------------------------------------------------------------------
bool XMLNode::get(const std::string &attribute, float *value)
{
std::string s;
if(!get(attribute, &s)) return false;
*value = (float)atof(s.c_str());
return true;
} // get(int)
// ----------------------------------------------------------------------------
bool XMLNode::get(const std::string &attribute, bool *value)
{
std::string s;
if(!get(attribute, &s)) return false;
*value = s=="" || s[0]=='T' || s[0]=='t' ||
s=="true" || s=="TRUE" || s=="#t" || s=="#T";
return true;
} // get(bool)
// ----------------------------------------------------------------------------
bool XMLNode::get(const std::string &attribute, std::vector<std::string> *value)
{
std::string s;
if(!get(attribute, &s)) return false;
*value = StringUtils::split(s,' ');
return true;
} // get(vector<string>)
// ----------------------------------------------------------------------------
bool XMLNode::get(const std::string &attribute, std::vector<float> *value)
{
std::string s;
if(!get(attribute, &s)) return false;
std::vector<std::string> v = StringUtils::split(s,' ');
value->clear();
for(unsigned int i=0; i<v.size(); i++)
{
value->push_back((float)atof(v[i].c_str()));
}
return true;
} // get(vector<float>)
// ----------------------------------------------------------------------------
bool XMLNode::get(const std::string &attribute, std::vector<int> *value)
{
std::string s;
if(!get(attribute, &s)) return false;
std::vector<std::string> v = StringUtils::split(s,' ');
value->clear();
for(unsigned int i=0; i<v.size(); i++)
{
value->push_back(atoi(v[i].c_str()));
}
return true;
} // get(vector<int>)
// ----------------------------------------------------------------------------
#endif

51
src/io/xml_node.hpp Executable file
View File

@ -0,0 +1,51 @@
// $Id: xml_reader.hpp 694 2006-08-29 07:42:36Z hiker $
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2009 Joerg Henrichs
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifdef HAVE_IRRLICHT
#ifndef HEADER_XML_NODE_HPP
#define HEADER_XML_NODE_HPP
#include <string>
#include <map>
#include <vector>
#include "irrlicht.h"
using namespace irr;
class Vec3;
class XMLNode
{
private:
std::map<std::string, core::stringw> m_attributes;
public:
XMLNode(io::IXMLReader *xml);
bool get(const std::string &attribute, std::string *value);
bool get(const std::string &attribute, core::vector3df *value);
bool get(const std::string &attribute, Vec3 *value);
bool get(const std::string &attribute, video::SColorf *value);
bool get(const std::string &attribute, std::vector<std::string> *value);
bool get(const std::string &attribute, std::vector<float> *value);
bool get(const std::string &attribute, std::vector<int> *value);
bool get(const std::string &attribute, int *value);
bool get(const std::string &attribute, float *value);
bool get(const std::string &attribute, bool *value);
}; // XMLNode
#endif
#endif

57
src/io/xml_reader.cpp Executable file
View File

@ -0,0 +1,57 @@
// $Id: xml_reader.hpp 694 2006-08-29 07:42:36Z hiker $
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2009 Joerg Henrichs
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifdef HAVE_IRRLICHT
#include "io/xml_reader.hpp"
#include "io/xml_node.hpp"
XMLReader::XMLReader(io::IXMLReader *xml)
{
while(xml->read())
{
switch (xml->getNodeType())
{
case io::EXN_ELEMENT:
{
// FIXME: is there an easier way to convert
// stringw to std::string?
std::string s = core::stringc(xml->getNodeName()).c_str();
XMLNode *node = new XMLNode(xml);
m_all_nodes[s] = node;
break;
}
case io::EXN_ELEMENT_END: // Ignore all other types
case io::EXN_UNKNOWN:
case io::EXN_COMMENT:
case io::EXN_TEXT: break;
} // switch
} // while
} // XMLReader
// ----------------------------------------------------------------------------
XMLNode *XMLReader::getNode(const std::string &node_name)
{
std::map<std::string, XMLNode *>::iterator node;
node = m_all_nodes.find(node_name);
if(node==m_all_nodes.end()) return NULL;
return node->second;
} // getNode
#endif

43
src/io/xml_reader.hpp Executable file
View File

@ -0,0 +1,43 @@
// $Id: xml_reader.hpp 694 2006-08-29 07:42:36Z hiker $
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2009 Joerg Henrichs
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 3
// of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#ifdef HAVE_IRRLICHT
#ifndef HEADER_XML_READER_HPP
#define HEADER_XML_READER_HPP
#include <string>
#include <map>
#include "irrlicht.h"
using namespace irr;
class XMLNode;
class XMLReader
{
private:
io::IXMLReader *m_reader;
std::map<std::string, XMLNode *> m_all_nodes;
public:
XMLReader(io::IXMLReader *r);
XMLNode *getNode(const std::string &node_name);
}; // XMLReader
#endif
#endif

View File

@ -62,7 +62,9 @@ Attachment::~Attachment()
void Attachment::set(attachmentType type, float time, Kart *current_kart)
{
clear();
#ifndef HAVE_IRRLICHT
m_holder->selectStep(type);
#endif
m_type = type;
m_time_left = time;
m_previous_owner = current_kart;

View File

@ -275,7 +275,7 @@ void KartModel::setDefaultPhysicsPosition(const Vec3 &center_shift,
void KartModel::adjustWheels(float rotation, float steer,
const float suspension[4])
{
#ifdef HAVE_IRRLICHT
float clamped_suspension[4];
// Clamp suspension to minimum and maximum suspension length, so that
// the graphical wheel models don't look too wrong.
@ -293,10 +293,23 @@ void KartModel::adjustWheels(float rotation, float steer,
ratio = sign * fabsf(ratio*(2-ratio)); // expanded form of 1 - (1 - x)^2, i.e. making suspension display quadratic and not linear
clamped_suspension[i] = ratio*suspension_length;
} // for i<4
core::vector3df wheel_rot (RAD_TO_DEGREE(-rotation), 0, 0);
//core::vector3df wheel_steer(0, wheel_steer, 0);
//core::vector3df wheel_front = wheel_rot+wheel_steer;
#ifdef HAVE_IRRLICHT
core::vector3df wheel_rear (RAD_TO_DEGREE(-rotation), 0, 0);
core::vector3df wheel_steer(0, RAD_TO_DEGREE(steer), 0);
core::vector3df wheel_front = wheel_rear+wheel_steer;
for(unsigned int i=0; i<4; i++)
{
core::vector3df pos = m_wheel_graphics_position[i].toIrrVector();
pos.Z += clamped_suspension[i];
m_wheel_node[i]->setPosition(pos);
}
m_wheel_node[0]->setRotation(wheel_front);
m_wheel_node[1]->setRotation(wheel_front);
m_wheel_node[2]->setRotation(wheel_rear );
m_wheel_node[3]->setRotation(wheel_rear );
#ifdef FIXME
sgCopyVec3(wheel_front[3], m_wheel_graphics_position[0].toFloat());
wheel_front[3][2] += clamped_suspension[0];
@ -319,24 +332,6 @@ void KartModel::adjustWheels(float rotation, float steer,
sgMat4 wheel_steer;
sgMat4 wheel_rot;
float clamped_suspension[4];
// Clamp suspension to minimum and maximum suspension length, so that
// the graphical wheel models don't look too wrong.
for(unsigned int i=0; i<4; i++)
{
const float suspension_length = (m_max_suspension[i]-m_min_suspension[i])/2;
// limit amplitude between set limits, first dividing it by a
// somewhat arbitrary constant to reduce visible wheel movement
clamped_suspension[i] = std::min(std::max(suspension[i]/m_dampen_suspension_amplitude[i],
m_min_suspension[i]),
m_max_suspension[i]);
float ratio = clamped_suspension[i] / suspension_length;
const int sign = ratio < 0 ? -1 : 1;
ratio = sign * fabsf(ratio*(2-ratio)); // expanded form of 1 - (1 - x)^2, i.e. making suspension display quadratic and not linear
clamped_suspension[i] = ratio*suspension_length;
} // for i<4
sgMakeRotMat4( wheel_rot, 0, RAD_TO_DEGREE(-rotation), 0);
sgMakeRotMat4( wheel_steer, steer , 0, 0);
sgMultMat4(wheel_front, wheel_steer, wheel_rot);

View File

@ -57,9 +57,7 @@ void Moveable::updateGraphics(const Vec3& off_xyz, const Vec3& off_hpr)
sgCoord c=Coord(xyz, hpr).toSgCoord();
#ifdef HAVE_IRRLICHT
m_root->setPosition(xyz.toIrrVector());
hpr*=180.0f/3.14159f;
core::vector3df f(hpr.getZ(), -hpr.getX(), hpr.getY());
m_root->setRotation(f);
m_root->setRotation(hpr.toIrrHPR());
#else
m_model_transform->setTransform(&c);
#endif

View File

@ -161,6 +161,7 @@ void PlayerKart::action(KartAction action, int value)
m_controls.m_look_back = (value!=0);
break;
case KA_DRIFT:
printf("Drifting: value %d\n",value);
m_controls.m_drift = (value!=0);
break;
}

View File

@ -24,6 +24,9 @@
#include <vector>
#define _WINSOCKAPI_
#include <plib/sg.h>
#ifdef HAVE_IRRLICHT
#include "irrlicht.h"
#endif
#include "utils/vec3.hpp"
namespace lisp
@ -147,6 +150,32 @@ namespace lisp
}
return true;
}
#ifdef HAVE_IRRLICHT
bool get(const char* name, core::vector3df& val) const
{
const Lisp* lisp = getLisp(name);
if(!lisp)
return false;
lisp = lisp->getCdr();
if(!lisp) return false;
const Lisp* m_car = lisp->getCar();
if(!m_car) return false;
m_car->get(val.X);
lisp = lisp->getCdr();
m_car = lisp->getCar();
if(!m_car) return false;
m_car->get(val.Y);
lisp = lisp->getCdr();
m_car = lisp->getCar();
if(!m_car) return false;
m_car->get(val.Z);
lisp = lisp->getCdr();
return true;
}
#endif
bool get(const char* name, Vec3& val) const
{
const Lisp* lisp = getLisp(name);

View File

@ -206,7 +206,8 @@ void MainLoop::run()
sound_manager->update(dt);
#ifdef HAVE_IRRLICHT
irr_driver->update(dt);
if(!user_config->m_bullet_debug)
irr_driver->update(dt);
#else
glFlush();
SDL_GL_SwapBuffers();

View File

@ -498,7 +498,20 @@ void SDLDriver::input()
ev.key.keysym.unicode);
}
input(Input::IT_KEYBOARD, ev.key.keysym.sym,
ev.key.keysym.unicode, 0, 32768);
#ifdef HAVE_IRRLICHT
// FIXME: not sure why this happens: with plib the unicode
// value is 0. Since all values defined in user_config
// assume that the unicode value is 0, it does not work
// with irrlicht, which has proper unicode values defined
// (keydown is not recognised, but keyup is). So for now
// (till user_config is migrated to ful lirrlicht support)
// we pass the 0 here artifically so that keyboard handling
// works.
0,
#else
ev.key.keysym.unicode,
#endif
0, 32768);
break;
@ -510,8 +523,10 @@ void SDLDriver::input()
if (!m_mode)
{
BaseGUI* menu = menu_manager->getCurrentMenu();
#ifndef HAVE_IRRLICHT
if (menu != NULL)
menu->inputPointer(ev.motion.x, m_main_surface->h - ev.motion.y);
#endif
}
// If sensing input mouse movements are made less sensitive in order
// to avoid it being detected unwantedly.

View File

@ -37,6 +37,7 @@
#include "graphics/irr_driver.hpp"
#include "graphics/mesh_tools.hpp"
#include "graphics/scene.hpp"
#include "io/xml_node.hpp"
#include "items/item.hpp"
#include "items/item_manager.hpp"
#include "lisp/lisp.hpp"
@ -58,7 +59,7 @@ const int Track::UNKNOWN_SECTOR = -1;
Track::Track( std::string filename_, float w, float h, bool stretch )
{
m_filename = filename_;
m_item_style = "";
m_item_style = "";
m_track_2d_width = w;
m_track_2d_height = h;
m_do_stretch = stretch;
@ -837,26 +838,71 @@ void Track::draw2Dview (float x_offset, float y_offset) const
//-----------------------------------------------------------------------------
void Track::loadTrack(const std::string &filename)
{
m_filename = filename;
m_filename = filename;
m_ident = StringUtils::basename(StringUtils::without_extension(m_filename));
std::string path = StringUtils::without_extension(m_filename);
// Default values
m_use_fog = false;
sgSetVec4 ( m_fog_color , 0.3f, 0.7f, 0.9f, 1.0f ) ;
m_fog_density = 1.0f/100.0f;
m_fog_start = 0.0f;
m_fog_end = 1000.0f;
m_gravity = 9.80665f;
m_use_fog = false;
m_fog_density = 1.0f/100.0f;
m_fog_start = 0.0f;
m_fog_end = 1000.0f;
m_gravity = 9.80665f;
#ifdef HAVE_IRRLICHT
m_sun_position = core::vector3df(0.4f, 0.4f, 0.4f);
m_sky_color = video::SColorf(0.3f, 0.7f, 0.9f, 1.0f);
m_fog_color = video::SColorf(0.3f, 0.7f, 0.9f, 1.0f);
m_ambient_color = video::SColorf(0.5f, 0.5f, 0.5f, 1.0f);
m_specular_color = video::SColorf(1.0f, 1.0f, 1.0f, 1.0f);
m_diffuse_color = video::SColorf(1.0f, 1.0f, 1.0f, 1.0f);
XMLReader *xml = file_manager->getXMLReader(m_filename);
XMLNode *node = xml->getNode("track");
node->get("name", &m_name);
node->get("description", &m_description);
node->get("designer", &m_designer);
node->get("version", &m_version);
std::vector<std::string> filenames;
node->get("music", &filenames);
getMusicInformation(filenames, m_music);
node->get("item", &m_item_style);
node->get("screenshot", &m_screenshot);
node->get("topview", &m_top_view);
node->get("item", &m_item_style);
node->get("screenshot", &m_screenshot);
node->get("topview", &m_top_view);
node->get("sky-color", &m_sky_color);
node->get("start-x", &m_start_x);
node->get("start-y", &m_start_y);
node->get("start-z", &m_start_z);
node->get("start-heading", &m_start_heading);
node->get("use-fog", &m_use_fog);
node->get("fog-color", &m_fog_color);
node->get("fog-density", &m_fog_density);
node->get("fog-start", &m_fog_start);
node->get("fog-end", &m_fog_end);
node->get("sun-position", &m_sun_position);
node->get("sun-ambient", &m_ambient_color);
node->get("sun-specular", &m_specular_color);
node->get("sun-diffuse", &m_diffuse_color);
node->get("gravity", &m_gravity);
node->get("arena", &m_is_arena);
node->get("groups", &m_groups);
if(m_groups.size()==0)
m_groups.push_back("standard");
// if both camera position and rotation are defined,
// set the flag that the track has final camera position
m_has_final_camera = node->get("camera-final-position", &m_camera_final_position);
m_has_final_camera &= node->get("camera-final-hpr", &m_camera_final_hpr);
m_camera_final_hpr.degreeToRad();
#else
sgSetVec3 ( m_sun_position, 0.4f, 0.4f, 0.4f );
sgSetVec4 ( m_sky_color, 0.3f, 0.7f, 0.9f, 1.0f );
sgSetVec4 ( m_fog_color, 0.3f, 0.7f, 0.9f, 1.0f );
sgSetVec4 ( m_ambient_col, 0.5f, 0.5f, 0.5f, 1.0f );
sgSetVec4 ( m_specular_col, 1.0f, 1.0f, 1.0f, 1.0f );
sgSetVec4 ( m_diffuse_col, 1.0f, 1.0f, 1.0f, 1.0f );
lisp::Parser parser;
const lisp::Lisp* const ROOT = parser.parse(m_filename);
@ -903,12 +949,12 @@ void Track::loadTrack(const std::string &filename)
m_has_final_camera = LISP->get("camera-final-position", m_camera_final_position);
m_has_final_camera &= LISP->get("camera-final-hpr", m_camera_final_hpr);
m_camera_final_hpr.degreeToRad();
delete ROOT;
#endif
// Set the correct paths
m_screenshot = file_manager->getTrackFile(m_screenshot, getIdent());
m_top_view = file_manager->getTrackFile(m_top_view, getIdent());
delete ROOT;
} // loadTrack
//-----------------------------------------------------------------------------
@ -1146,7 +1192,7 @@ void Track::convertTrackToBullet()
u16 *mbIndices = mb->getIndices();
btVector3 vertices[3];
irr::video::S3DVertex* mbVertices=(irr::video::S3DVertex*)mb->getVertices();
irr::video::S3DVertex* mbVertices=(video::S3DVertex*)mb->getVertices();
for(unsigned int j=0; j<mb->getIndexCount(); j+=3) {
for(unsigned int k=0; k<3; k++) {
int indx=mbIndices[j+k];
@ -1154,11 +1200,12 @@ void Track::convertTrackToBullet()
// (STK: Z up, irrlicht: Y up). We might want to change
// this as well, makes it easier to work with bullet and
// irrlicht together, without having to swap indices.
vertices[k] = btVector3( mbVertices[indx].Pos.X,
mbVertices[indx].Pos.Z,
mbVertices[indx].Pos.Y );
vertices[k] = btVector3(mbVertices[indx].Pos.X,
mbVertices[indx].Pos.Z,
mbVertices[indx].Pos.Y );
} // for k
m_track_mesh->addTriangle(vertices[0], vertices[1], vertices[2], material);
m_track_mesh->addTriangle(vertices[0], vertices[1],
vertices[2], material );
} // for j
} // for i<getMeshBufferCount
} // for obj in children
@ -1505,6 +1552,11 @@ void Track::loadTrackModel()
#ifdef HAVE_IRRLICHT
// FIXME: for now assume that mesh 0 is the actual track.
MeshTools::minMax3D(m_all_meshes[0], &min, &max);
const core::vector3df &sun_pos = getSunPos();
m_light = irr_driver->getSceneManager()->addLightSceneNode(0, sun_pos);
video::SLight light;
m_light->setLightData(light);
#else
SSGHelp::MinMax(m_model, &min, &max);
#endif

View File

@ -59,6 +59,7 @@ private:
#ifdef HAVE_IRRLICHT
std::vector<scene::ISceneNode*> m_all_nodes;
std::vector<scene::IMesh*> m_all_meshes;
scene::ILightSceneNode *m_light;
#else
ssgBranch *m_model;
#endif
@ -93,17 +94,26 @@ public:
) : segment(_segment), triangle(_triangle) {};
};
std::string m_name;
sgVec4 m_sky_color;
bool m_use_fog;
sgVec4 m_fog_color;
float m_fog_density;
float m_fog_start;
float m_fog_end;
sgVec3 m_sun_position; /** Position of the sun */
sgVec4 m_ambient_col;
sgVec4 m_specular_col;
sgVec4 m_diffuse_col;
std::string m_name;
bool m_use_fog;
float m_fog_density;
float m_fog_start;
float m_fog_end;
#ifdef HAVE_IRRLICHT
core::vector3df m_sun_position;
video::SColorf m_ambient_color;
video::SColorf m_specular_color;
video::SColorf m_diffuse_color;
video::SColorf m_sky_color;
video::SColorf m_fog_color;
#else
sgVec4 m_sky_color;
sgVec4 m_fog_color;
sgVec3 m_sun_position; /** Position of the sun */
sgVec4 m_ambient_col;
sgVec4 m_specular_col;
sgVec4 m_diffuse_col;
#endif
//FIXME: Maybe the next 4 vectors should be inside an struct and be used
//from a vector of structs?
@ -177,16 +187,25 @@ public:
getGroups () const {return m_groups; }
void startMusic () const;
const std::string& getFilename () const {return m_filename; }
#ifdef HAVE_IRRLICHT
const core::vector3df& getSunPos () const {return m_sun_position; }
const video::SColorf& getAmbientCol () const {return m_ambient_color; }
const video::SColorf& getDiffuseCol () const {return m_diffuse_color; }
const video::SColorf& getSpecularCol () const {return m_specular_color; }
const video::SColorf& getFogColor () const {return m_fog_color; }
const video::SColorf& getSkyColor () const {return m_sky_color; }
#else
const sgVec3& getSunPos () const {return m_sun_position; }
const sgVec4& getAmbientCol () const {return m_ambient_col; }
const sgVec4& getDiffuseCol () const {return m_diffuse_col; }
const sgVec4& getSpecularCol () const {return m_specular_col; }
const bool& useFog () const {return m_use_fog; }
const sgVec4& getFogColor () const {return m_fog_color; }
const sgVec4& getSkyColor () const {return m_sky_color; }
#endif
const bool& useFog () const {return m_use_fog; }
const float& getFogDensity () const {return m_fog_density; }
const float& getFogStart () const {return m_fog_start; }
const float& getFogEnd () const {return m_fog_end; }
const sgVec4& getSkyColor () const {return m_sky_color; }
const std::string& getDescription () const {return m_description; }
const std::string& getDesigner () const {return m_designer; }
const std::string& getTopviewFile () const {return m_top_view; }

View File

@ -132,7 +132,7 @@ void TrackManager::loadTrackList ()
{
// getTrackFile appends dir, so it's opening: *dir/*dir.track
#ifdef HAVE_IRRLICHT
config_file = file_manager->getTrackFile((*dir)+".irrtrack");
config_file = file_manager->getTrackFile((*dir)+".scene");
#else
config_file = file_manager->getTrackFile((*dir)+".track");
#endif

View File

@ -101,4 +101,26 @@ void Vec3::setPitchRoll(const Vec3 &normal)
// line, so to compute the actual angles 90 degrees must be subtracted.
m_y = acosf(pitch) - NINETY_DEGREE_RAD;
m_z = acosf(roll) - NINETY_DEGREE_RAD;
} // setPitchRoll
} // setPitchRoll
// ----------------------------------------------------------------------------
/** Converts a bullet HPR value into an irrlicht HPR value.
* FIXME: this function should be inlined, but while debugging it's
* easier (compile-time wise) to modify it here :)
*/
#ifdef HAVE_IRRLICHT
const core::vector3df Vec3::toIrrHPR() const
{
core::vector3df r(RAD_TO_DEGREE( getZ()),
RAD_TO_DEGREE(-getX()),
RAD_TO_DEGREE( getY()) );
return r;
} // toIrrHPR
// ----------------------------------------------------------------------------
const core::vector3df Vec3::toIrrVector() const
{
core::vector3df v(m_x, m_z, m_y);
return v;
} // toIrrVector
#endif

View File

@ -32,9 +32,6 @@ using namespace irr;
class Vec3 : public btVector3
{
private:
#ifdef HAVE_IRRLICHT
core::vector3df m_irr_vector;
#endif
inline float clampToUnity(float f) {return f<-1?f:(f>1?1:f);}
void setPitchRoll(const Vec3 &normal);
@ -63,11 +60,8 @@ public:
float* toFloat() const {return (float*)this; }
#ifdef HAVE_IRRLICHT
/** Converts a Vec3 to an irrlicht 3d floating point vector. */
const core::vector3df &toIrrVector()
{
m_irr_vector.set(m_x, m_z, m_y);
return m_irr_vector;
}
const core::vector3df toIrrVector() const;
const core::vector3df toIrrHPR() const;
#endif
void degreeToRad();
Vec3& operator=(const btVector3& a) {*(btVector3*)this=a; return *this;}