Almost fix Nolok wheel issue in 3 strikes mode. Note, my fix is not complete and will result in segfaults in 3 strikes mode

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@10044 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria
2011-10-26 15:18:46 +00:00
parent 5d6f1ed4a4
commit 953e8cf1ef
7 changed files with 75 additions and 50 deletions

View File

@@ -19,7 +19,9 @@
#include <string>
#include <IMeshSceneNode.h>
#include <IMeshManipulator.h>
#include <ISceneManager.h>
#include <SMesh.h>
#include "audio/music_manager.hpp"
#include "io/file_manager.hpp"
@@ -239,7 +241,7 @@ void ThreeStrikesBattle::update(float dt)
std::string tire;
float scale = 0.5f;
float radius = 0.5f;
PhysicalObject::bodyTypes tire_model;
PhysicalObject::bodyTypes tire_physics_shape;
// insert blown away tire(s) now if was requested
while (m_insert_tire > 0)
@@ -250,12 +252,12 @@ void ThreeStrikesBattle::update(float dt)
tire = file_manager->getModelFile("tire.b3d");
scale = 0.5f;
radius = 0.5f;
tire_model = PhysicalObject::MP_CYLINDER_Y;
tire_physics_shape = PhysicalObject::MP_CYLINDER_Y;
}
else
{
scale = 1.0f;
tire_model = PhysicalObject::MP_CYLINDER_X;
tire_physics_shape = PhysicalObject::MP_CYLINDER_X;
radius = m_tire_radius[m_insert_tire-2];
tire_offset = m_tire_offsets[m_insert_tire-2];
if (m_insert_tire == 2)
@@ -268,25 +270,44 @@ void ThreeStrikesBattle::update(float dt)
tire = m_tire_dir+"/wheel-rear-right.b3d";
}
TrackObjectManager* tom = m_track->getTrackObjectManager();
PhysicalObject* obj =
tom->insertObject(tire,
tire_model,
15 /* mass */,
radius /* radius */,
core::vector3df(800.0f,0,m_tire_rotation
/ M_PI * 180 + 180) ,
m_tire_position + tire_offset,
core::vector3df(scale,scale,scale) /* scale */);
TrackObjectManager* tom = m_track->getTrackObjectManager();
scene::IMesh* tire_mesh = NULL;
if (file_manager->fileExists(tire))
{
tire_mesh = irr_driver->getMesh(tire);
}
if (!tire_mesh)
{
fprintf(stderr, "Warning: '%s' not found and is ignored.\n",
tire.c_str());
}
else
{
scene::IMeshManipulator* manipulator = irr_driver->getSceneManager()->getMeshManipulator();
scene::IMesh* tire_mesh_copy = manipulator->createMeshCopy(tire_mesh);
PhysicalObject* obj =
tom->insertObject(tire_mesh_copy,
tire_physics_shape,
15 /* mass */,
radius /* radius */,
core::vector3df(800.0f,0,m_tire_rotation
/ M_PI * 180 + 180) ,
m_tire_position + tire_offset,
core::vector3df(scale,scale,scale) /* scale */);
tire_mesh_copy->drop(); // PhysicalObject grabbed it
// FIXME: orient the force relative to kart orientation
obj->getBody()->applyCentralForce(btVector3(60.0f, 0.0f, 0.0f));
m_tires.push_back(obj);
}
// FIXME: orient the force relative to kart orientation
obj->getBody()->applyCentralForce(btVector3(60.0f, 0.0f, 0.0f));
m_insert_tire--;
if(m_insert_tire == 1)
m_insert_tire = 0;
m_tires.push_back(obj);
}
} // update

View File

@@ -35,6 +35,7 @@ using namespace irr;
#include <ISceneManager.h>
#include <IMeshManipulator.h>
#include <IMeshSceneNode.h>
// -----------------------------------------------------------------------------
PhysicalObject::PhysicalObject(const XMLNode &xml_node)
@@ -87,7 +88,7 @@ PhysicalObject::PhysicalObject(const XMLNode &xml_node)
// -----------------------------------------------------------------------------
PhysicalObject::PhysicalObject(const std::string& model,
PhysicalObject::PhysicalObject(scene::IMesh* model,
bodyTypes shape, float mass, float radius,
const core::vector3df& hpr,
const core::vector3df& pos,
@@ -123,11 +124,20 @@ void PhysicalObject::init()
// 1. Determine size of the object
// -------------------------------
Vec3 min, max;
scene::IAnimatedMesh *mesh
= ((scene::IAnimatedMeshSceneNode*)m_node)->getMesh();
scene::IMesh *mesh = NULL;
if (m_node->getType() == scene::ESNT_ANIMATED_MESH)
{
mesh = ((scene::IAnimatedMeshSceneNode*)m_node)->getMesh();
}
else
{
mesh = ((scene::IMeshSceneNode*)m_node)->getMesh();
}
MeshTools::minMax3D(mesh, &min, &max);
Vec3 extend = max-min;
// Adjust the mesth of the graphical object so that its center is where it
// Adjust the mesh of the graphical object so that its center is where it
// is in bullet (usually at (0,0,0)). It can be changed in the case clause
// if this is not correct for a particular shape.
Vec3 offset_from_center = -0.5f*(max+min);

View File

@@ -79,7 +79,7 @@ private:
public:
PhysicalObject (const XMLNode &node);
PhysicalObject(const std::string& model,
PhysicalObject(scene::IMesh* model,
bodyTypes shape, float mass, float radius,
const core::vector3df& hpr,
const core::vector3df& pos,

View File

@@ -28,6 +28,8 @@
#include "modes/world.hpp"
#include "tracks/track.hpp"
#include <IMeshSceneNode.h>
/** A track object: any additional object on the track. This object implements
* a graphics-only representation, i.e. there is no physical representation.
* Derived classes can implement a physical representation (see
@@ -117,7 +119,7 @@ TrackObject::TrackObject(const XMLNode &xml_node)
m_mesh->grab();
irr_driver->grabAllTextures(m_mesh);
scene::IAnimatedMeshSceneNode *node =
irr_driver->addAnimatedMesh(m_mesh);
irr_driver->addAnimatedMesh( (scene::IAnimatedMesh*)m_mesh );
m_node = node;
#ifdef DEBUG
std::string debug_name = model_name+" (track-object)";
@@ -142,7 +144,7 @@ TrackObject::TrackObject(const XMLNode &xml_node)
// ----------------------------------------------------------------------------
TrackObject::TrackObject(const core::vector3df& pos, const core::vector3df& hpr,
const core::vector3df& scale, const std::string& model_name)
const core::vector3df& scale, scene::IMesh* model)
{
m_init_xyz = pos;
m_init_hpr = hpr;
@@ -151,35 +153,26 @@ TrackObject::TrackObject(const core::vector3df& pos, const core::vector3df& hpr,
m_is_looped = false;
m_sound = NULL;
// Some animated objects (billboards, sound emitters) don't use this scene node
if (model_name == "")
// Some animated objects (billboards, sound emitters) don't use the mesh
// scene node
if (model == NULL)
{
m_node = NULL;
m_mesh = NULL;
}
else
{
if(file_manager->fileExists(model_name))
{
m_mesh = irr_driver->getAnimatedMesh(model_name);
}
if(!m_mesh)
{
fprintf(stderr, "Warning: '%s' not found and is ignored.\n",
model_name.c_str());
return;
}
m_mesh = model;
m_mesh->grab();
irr_driver->grabAllTextures(m_mesh);
scene::IAnimatedMeshSceneNode *node=irr_driver->addAnimatedMesh(m_mesh);
scene::IMeshSceneNode *node = irr_driver->addMesh(model);
m_node = node;
#ifdef DEBUG
std::string debug_name = model_name+" (track-object)";
std::string debug_name = "(track-object)";
m_node->setName(debug_name.c_str());
#endif
m_frame_start = node->getStartFrame();
m_frame_end = node->getEndFrame();
m_frame_start = 0;
m_frame_end = 0;
if(!m_enabled)
m_node->setVisible(false);
@@ -226,9 +219,6 @@ void TrackObject::reset()
scene::IAnimatedMeshSceneNode *a_node =
(scene::IAnimatedMeshSceneNode*)m_node;
a_node->setPosition(m_init_xyz);
a_node->setRotation(m_init_hpr);
a_node->setScale(m_init_scale);
a_node->setLoopMode(m_is_looped);
if(m_is_looped)
@@ -236,6 +226,10 @@ void TrackObject::reset()
a_node->setFrameLoop(m_frame_start, m_frame_end);
}
}
m_node->setPosition(m_init_xyz);
m_node->setRotation(m_init_hpr);
m_node->setScale(m_init_scale);
} // reset
// ----------------------------------------------------------------------------
/** Enables or disables this object. This affects the visibility, i.e.

View File

@@ -70,7 +70,7 @@ protected:
/** The mesh used here. It needs to be stored so that it can be
* removed from irrlicht's mesh cache when it is deleted. */
scene::IAnimatedMesh *m_mesh;
scene::IMesh *m_mesh;
/** The initial XYZ position of the object. */
core::vector3df m_init_xyz;
@@ -87,7 +87,7 @@ protected:
public:
TrackObject(const XMLNode &xml_node);
TrackObject(const core::vector3df& pos, const core::vector3df& hpr,
const core::vector3df& scale, const std::string& model);
const core::vector3df& scale, scene::IMesh* model);
~TrackObject();
virtual void update(float dt);
virtual void reset();

View File

@@ -189,7 +189,7 @@ void TrackObjectManager::enableFog(bool enable)
// ----------------------------------------------------------------------------
PhysicalObject* TrackObjectManager::insertObject(const std::string& model,
PhysicalObject* TrackObjectManager::insertObject(scene::IMesh* model,
PhysicalObject::bodyTypes shape,
float mass, float radius,
const core::vector3df& hpr,

View File

@@ -54,7 +54,7 @@ public:
/** Enable or disable fog on objects */
void enableFog(bool enable);
PhysicalObject* insertObject(const std::string& model,
PhysicalObject* insertObject(scene::IMesh* model,
PhysicalObject::bodyTypes shape,
float mass, float radius,
const core::vector3df& hpr,