Fixed compilation problem on non-irrlicht compilation (missing files,

missing ifdef - sorry for that).
In irrlicht karts have now (non-rotating) wheels, and the camera
points correctly at the kart.


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/trunk/supertuxkart@3116 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2009-02-10 11:11:39 +00:00
parent 3b7bfd5367
commit be6b0f8085
11 changed files with 155 additions and 8 deletions

View File

@ -195,7 +195,7 @@ void Camera::setInitialTransform()
} // updateKartPosition
//-----------------------------------------------------------------------------
void Camera::update (float dt)
void Camera::update(float dt)
{
if(m_mode==CM_FINAL) return finalCamera(dt);
@ -262,7 +262,7 @@ void Camera::update (float dt)
m_hpr = c.getHPR();
#ifdef HAVE_IRRLICHT
m_camera->setPosition(m_xyz.toIrrVector());
//m_camera->setTarget(kart_xyz.toIrrVector());
m_camera->setTarget(kart_xyz.toIrrVector());
#else
m_context -> setCamera(&c.toSgCoord());
#endif

View File

@ -80,6 +80,17 @@ scene::IAnimatedMesh *IrrDriver::getAnimatedMesh(const std::string &filename)
return m_scene_manager->getMesh(filename.c_str());
} // getAnimatedMesh
// ----------------------------------------------------------------------------
/** Loads a non-animated mesh and returns a pointer to it.
* \param filename File to load.
*/
scene::IMesh *IrrDriver::getMesh(const std::string &filename)
{
scene::IAnimatedMesh *m = m_scene_manager->getMesh(filename.c_str());
if(!m) return NULL;
return m->getMesh(0);
} // getMesh
// ----------------------------------------------------------------------------
/** Adds a mesh that will be optimised using an oct tree.
* \param mesh Mesh to add.

View File

@ -40,6 +40,7 @@ public:
IrrlichtDevice *getDevice() const { return m_device; }
scene::ISceneManager *getSceneManager() const { return m_scene_manager; }
scene::IAnimatedMesh *getAnimatedMesh(const std::string &name);
scene::IMesh *getMesh(const std::string &name);
bool OnEvent(const irr::SEvent &event);
scene::ISceneNode *addOctTree(scene::IMesh *mesh);
scene::ISceneNode *addMesh(scene::IMesh *mesh);

47
src/graphics/mesh_tools.cpp Executable file
View File

@ -0,0 +1,47 @@
// $Id: mesh_tools.hpp 3001 2009-01-20 13:51:08Z hikerstk $
//
// 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 "graphics/mesh_tools.hpp"
void MeshTools::minMax3D(scene::IMesh* mesh, Vec3 *min, Vec3 *max) {
Vec3 extend;
*min = Vec3( 999999.9f);
*max = Vec3(-999999.9f);
for(unsigned int i=0; i<mesh->getMeshBufferCount(); i++) {
scene::IMeshBuffer *mb = mesh->getMeshBuffer(i);
if(mb->getVertexType()!=video::EVT_STANDARD) {
fprintf(stderr, "Tools::minMax3D: Ignoring type '%d'!",
mb->getVertexType());
continue;
}
u16 *mbIndices = mb->getIndices();
irr::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 );
min->min(c);
max->max(c);
} // for j
} // for i<getMeshBufferCount
} // minMax3D
#endif

35
src/graphics/mesh_tools.hpp Executable file
View File

@ -0,0 +1,35 @@
// $Id: mesh_tools.hpp 3001 2009-01-20 13:51:08Z hikerstk $
//
// 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_MESH_TOOLS_HPP
#define HEADER_MESH_TOOLS_HPP
#include "irrlicht.h"
using namespace irr;
#include "utils/vec3.hpp"
namespace MeshTools
{
void minMax3D(scene::IMesh* mesh, Vec3 *min, Vec3 *max);
} // MeshTools
#endif
#endif // HAVE_IRRLICHT

View File

@ -53,7 +53,9 @@ Attachment::Attachment(Kart* _kart)
//-----------------------------------------------------------------------------
Attachment::~Attachment()
{
#ifndef HAVE_IRRLICHT
ssgDeRefDelete(m_holder);
#endif
} // ~Attachment
//-----------------------------------------------------------------------------

View File

@ -266,7 +266,9 @@ void ItemManager::cleanup()
for(AllItemTypes::iterator i =m_all_items.begin();
i!=m_all_items.end(); i++)
{
#ifndef HAVE_IRRLICHT
delete *i;
#endif
}
m_all_items.clear();

View File

@ -256,10 +256,13 @@ Kart::~Kart()
delete m_tuning;
delete m_vehicle_raycaster;
delete m_uprightConstraint;
#ifdef HAVE_IRRLICHT
#else
for(int i=0; i<m_kart_chassis.getNumChildShapes(); i++)
{
delete m_kart_chassis.getChildShape(i);
}
#endif
} // ~Kart
//-----------------------------------------------------------------------------

View File

@ -94,15 +94,18 @@ KartModel::~KartModel()
/** Attach the kart model and wheels to the scene node.
* \param node Node to attach the models to.
*/
#ifdef HAVE_IRRLICHT
void KartModel::attachModel(scene::ISceneNode **node)
{
*node = irr_driver->addMesh(m_mesh);
for(unsigned int i=0; i<4; i++)
{
// *node->addChild(m_wh
m_wheel_node[i] = irr_driver->addMesh(m_wheel_model[i]);
m_wheel_node[i]->setPosition(m_wheel_graphics_position[i].toIrrVector());
(*node)->addChild(m_wheel_node[i]);
}
} // attachModel
#endif
// ----------------------------------------------------------------------------
/** Loads the 3d model and all wheels.
@ -111,7 +114,7 @@ void KartModel::loadModels(const std::string &kart_ident)
{
#ifdef HAVE_IRRLICHT
std::string full_path = file_manager->getKartFile(m_model_filename);
m_mesh = irr_driver->getAnimatedMesh(full_path)->getMesh(0);
m_mesh = irr_driver->getMesh(full_path);
Vec3 min, max;
MeshTools::minMax3D(m_mesh, &min, &max);
Vec3 size = max-min;
@ -170,7 +173,7 @@ void KartModel::loadModels(const std::string &kart_ident)
#ifdef HAVE_IRRLICHT
std::string full_wheel = file_manager->getKartFile(m_wheel_filename[i],
kart_ident);
m_wheel_model[i] = irr_driver->getAnimatedMesh(full_wheel)->getMesh(0);
m_wheel_model[i] = irr_driver->getMesh(full_wheel);
// FIXME: wheel handling still missing.
#else
m_wheel_model[i] = loader->load(m_wheel_filename[i], CB_KART);
@ -273,7 +276,44 @@ void KartModel::adjustWheels(float rotation, float steer,
const float suspension[4])
{
#ifdef HAVE_IRRLICHT
// FIXME: missing
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
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 FIXME
sgCopyVec3(wheel_front[3], m_wheel_graphics_position[0].toFloat());
wheel_front[3][2] += clamped_suspension[0];
m_wheel_transform[0]->setTransform(wheel_front);
sgCopyVec3(wheel_front[3], m_wheel_graphics_position[1].toFloat());
wheel_front[3][2] += clamped_suspension[1];
m_wheel_transform[1]->setTransform(wheel_front);
sgCopyVec3(wheel_rot[3], m_wheel_graphics_position[2].toFloat());
wheel_rot[3][2] += clamped_suspension[2];
m_wheel_transform[2]->setTransform(wheel_rot);
sgCopyVec3(wheel_rot[3], m_wheel_graphics_position[3].toFloat());
wheel_rot[3][2] += clamped_suspension[3];
m_wheel_transform[3]->setTransform(wheel_rot);
#endif
#else
sgMat4 wheel_front;
sgMat4 wheel_steer;

View File

@ -59,6 +59,9 @@ private:
#ifdef HAVE_IRRLICHT
/** The four wheel models. */
scene::IMesh *m_wheel_model[4];
/** The four scene nodes the wheels are attached to */
scene::ISceneNode *m_wheel_node[4];
#else
/** The four wheel models. */
ssgEntity *m_wheel_model[4];

View File

@ -57,6 +57,9 @@ 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);
#else
m_model_transform->setTransform(&c);
#endif