Fixed lighting issues by adding ambient lights, and cleaned up more code.

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3264 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2009-03-16 01:23:23 +00:00
parent e3fdeaaa8c
commit 41020d56ac
18 changed files with 51 additions and 367 deletions

View File

@ -151,7 +151,7 @@ void RaceGUI::handle(GameAction ga, int value)
if (race_manager->getNumPlayers() ==1 )
{
Kart* kart = RaceManager::getWorld()->getLocalPlayerKart(0);
kart->setPowerup(POWERUP_BOWLING, 10000);
kart->setPowerup(POWERUP_BUBBLEGUM, 10000);
}
break;
case GA_DEBUG_ADD_MISSILE:

View File

@ -53,7 +53,7 @@ bool Widget::convertToCoord(std::string& x, int* absolute, int* percentage)
bool is_number;
int i;
std::istringstream myStream(x);
is_number = (myStream >> i);
is_number = (myStream >> i)!=0;
if(!is_number) return false;
@ -410,7 +410,7 @@ void RibbonWidget::add()
if(free_h_space < min_free_space) // buttons are too big to fit :( zoom out
{
global_zoom = (float)w / (float)( w - free_h_space + min_free_space );
free_h_space = w - total_needed_space*global_zoom;
free_h_space = (int)(w - total_needed_space*global_zoom);
}
const int one_button_space = (int)round((float)w / (float)subbuttons_amount);
@ -440,12 +440,12 @@ void RibbonWidget::add()
const int needed_space_under_button = has_label ? 30 : 10; // quite arbitrary for now
// if button too high to fit, scale down
float zoom = global_zoom;
while(button_y + m_children[i].h*zoom + needed_space_under_button > h) zoom -= 0.01;
while(button_y + m_children[i].h*zoom + needed_space_under_button > h) zoom -= 0.01f;
// ---- add bitmap button part
const float image_w = m_children[i].w*zoom;
rect<s32> subsize = rect<s32>(widget_x - image_w/2.0, button_y,
widget_x + image_w/2.0, button_y + m_children[i].h*zoom);
rect<s32> subsize = rect<s32>(widget_x - (int)(image_w/2.0f), button_y,
widget_x + (int)(image_w/2.0f), button_y + (int)(m_children[i].h*zoom));
subbtn = new MyGUIButton(GUIEngine::getGUIEnv(), btn, ++id_counter_2, subsize, true);
@ -457,8 +457,8 @@ void RibbonWidget::add()
if(has_label)
{
subsize = rect<s32>(widget_x - one_button_space/2,
(button_y + m_children[i].h)*zoom + 5 /* leave 5 pixels between button and label */,
widget_x + one_button_space/2, h);
(int)((button_y + m_children[i].h)*zoom) + 5 /* leave 5 pixels between button and label */,
widget_x + (int)(one_button_space/2.0f), h);
stringw message = m_children[i].m_properties[PROP_TEXT].c_str();
IGUIStaticText* label = GUIEngine::getGUIEnv()->addStaticText(message.c_str(), subsize, false, true, btn);
@ -501,14 +501,14 @@ void SpinnerWidget::add()
{
int i;
std::istringstream myStream(min_s);
bool is_number = (myStream >> i);
bool is_number = (myStream >> i)!=0;
if(is_number) m_min = i;
else m_min = 0;
}
{
int i;
std::istringstream myStream(max_s);
bool is_number = (myStream >> i);
bool is_number = (myStream >> i)!=0;
if(is_number) m_max = i;
else m_max = 10;
}
@ -675,9 +675,9 @@ void RibbonGridWidget::add()
{
RibbonWidget* ribbon = new RibbonWidget(RIBBON_TOOLBAR);
ribbon->x = x;
ribbon->y = y + n*row_height;
ribbon->y = y + (int)(n*row_height);
ribbon->w = w;
ribbon->h = row_height;
ribbon->h = (int)(row_height);
ribbon->m_type = WTYPE_RIBBON;
ribbon->m_properties[PROP_ID] = this->m_properties[PROP_ID];
ribbon->m_parent = this;

View File

@ -17,12 +17,11 @@
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define _WINSOCKAPI_
#include <plib/ssg.h>
#include "items/attachment.hpp"
#include "stk_config.hpp"
#include "user_config.hpp"
#include "items/attachment.hpp"
#include "graphics/irr_driver.hpp"
#include "items/attachment_manager.hpp"
#include "items/projectile_manager.hpp"
#include "karts/kart.hpp"
@ -36,6 +35,8 @@ Attachment::Attachment(Kart* _kart)
m_time_left = 0.0;
m_kart = _kart;
m_previous_owner = NULL;
m_node = irr_driver->addMesh(NULL);
#ifdef HAVE_IRRLICHT
#else
m_holder = new ssgSelector();
@ -53,15 +54,14 @@ Attachment::Attachment(Kart* _kart)
//-----------------------------------------------------------------------------
Attachment::~Attachment()
{
#ifndef HAVE_IRRLICHT
ssgDeRefDelete(m_holder);
#endif
irr_driver->removeNode(m_node);
} // ~Attachment
//-----------------------------------------------------------------------------
void Attachment::set(attachmentType type, float time, Kart *current_kart)
{
clear();
// m_node->add
#ifndef HAVE_IRRLICHT
m_holder->selectStep(type);
#endif

View File

@ -48,7 +48,9 @@ private:
Kart *m_kart; // kart the attachment is attached to
float m_time_left; // time left till attachment expires
float m_initial_speed; // for parachutes only
ssgSelector *m_holder; // where the attachment is put on the kart
/** Scene node of the attachment, which will be attached to the kart's
* scene node. */
scene::ISceneNode *m_node;
Kart *m_previous_owner; // used by bombs so that it's not passed
// back to previous owner
RandomGenerator m_random;

View File

@ -19,7 +19,8 @@
#include "items/attachment_manager.hpp"
#include "loader.hpp"
#include "callback_manager.hpp"
#include "graphics/irr_driver.hpp"
#include "io/file_manager.hpp"
AttachmentManager *attachment_manager = 0;
@ -45,19 +46,11 @@ struct initAttachmentType {attachmentType attachment; const char *file;};
initAttachmentType iat[]=
{
#ifdef HAVE_IRRLICHT
{ATTACH_PARACHUTE, "parachute.b3d"},
{ATTACH_BOMB, "bomb.b3d"},
{ATTACH_ANVIL, "anvil.b3d"},
{ATTACH_TINYTUX, "tinytux_magnet.b3d"},
{ATTACH_MAX, ""},
#else
{ATTACH_PARACHUTE, "parachute.ac"},
{ATTACH_BOMB, "bomb.ac"},
{ATTACH_ANVIL, "anvil.ac"},
{ATTACH_TINYTUX, "tinytux_magnet.ac"},
{ATTACH_MAX, ""},
#endif
};
//-----------------------------------------------------------------------------
@ -65,7 +58,7 @@ void AttachmentManager::removeTextures()
{
for(int i=0; iat[i].attachment!=ATTACH_MAX; i++)
{
ssgDeRefDelete(m_attachments[iat[i].attachment]);
// FIXME: free attachment textures
} // for
callback_manager->clear(CB_ATTACHMENT);
} // removeTextures
@ -77,11 +70,7 @@ void AttachmentManager::loadModels()
{
// FIXME LEAK: these models are not removed (unimportant, since they
// have to be in memory till the end of the game.
#ifdef HAVE_IRRLICHT
#else
m_attachments[iat[i].attachment]=loader->load(iat[i].file, CB_ATTACHMENT);
m_attachments[iat[i].attachment]->ref();
#endif
m_attachments[iat[i].attachment]=irr_driver->getMesh(iat[i].file);
} // for
} // reInit

View File

@ -19,16 +19,18 @@
#ifndef HEADER_ATTACHMENT_MANAGER_HPP
#define HEADER_ATTACHMENT_MANAGER_HPP
#include <plib/ssg.h>
#include "irrlicht.h"
#include "items/attachment.hpp"
class AttachmentManager
{
private:
ssgEntity *m_attachments[ATTACH_MAX];
scene::IMesh *m_attachments[ATTACH_MAX];
public:
AttachmentManager() {};
ssgEntity *getModel (attachmentType type) {return m_attachments[type];}
/** Returns the mest for a certain attachment.
* \param type Type of the attachment needed. */
scene::IMesh *getMesh(attachmentType type) const {return m_attachments[type]; }
void removeTextures ();
void loadModels ();
};

View File

@ -25,13 +25,8 @@
#include "utils/coord.hpp"
#include "utils/vec3.hpp"
#ifdef HAVE_IRRLICHT
Item::Item(ItemType type, const Vec3& xyz, const Vec3& normal,
scene::IMesh* mesh, unsigned int item_id, bool rotate)
#else
Item::Item(ItemType type, const Vec3& xyz, const Vec3& normal,
ssgEntity* model, unsigned int item_id, bool rotate)
#endif
{
m_rotate = rotate;
m_parent = NULL;
@ -43,29 +38,15 @@ Item::Item(ItemType type, const Vec3& xyz, const Vec3& normal,
m_type = type;
m_collected = false;
m_time_till_return = 0.0f; // not strictly necessary, see isCollected()
#ifdef HAVE_IRRLICHT
m_root = irr_driver->addMesh(mesh);
m_root->setPosition(xyz.toIrrVector());
m_root->grab();
#else
m_root = new ssgTransform();
m_root->ref();
m_root->setTransform(const_cast<sgCoord*>(&m_coord.toSgCoord()));
m_root->addKid(model);
stk_scene->add(m_root);
#endif
m_node = irr_driver->addMesh(mesh);
m_node->setPosition(xyz.toIrrVector());
m_node->grab();
} // Item
//-----------------------------------------------------------------------------
Item::~Item()
{
#ifdef HAVE_IRRLICHT
m_root->drop();
#else
stk_scene->remove(m_root);
ssgDeRefDelete(m_root);
#endif
m_node->drop();
} // ~Item
//-----------------------------------------------------------------------------
@ -74,10 +55,6 @@ void Item::reset()
m_collected = false;
m_time_till_return = 0.0f;
m_deactive_time = 0.0f;
#ifdef HAVE_IRRLICHT
#else
m_root->setTransform(const_cast<sgCoord*>(&m_coord.toSgCoord()));
#endif
} // reset
//-----------------------------------------------------------------------------
void Item::setParent(Kart* parent)
@ -100,11 +77,7 @@ void Item::update(float delta)
hell.setZ( (m_time_till_return>1.0f) ? -1000000.0f
: m_coord.getXYZ().getZ() - m_time_till_return / 2.0f);
#ifdef HAVE_IRRLICHT
m_root->setPosition(hell.toIrrVector());
#else
m_root->setTransform(hell.toFloat());
#endif
m_node->setPosition(hell.toIrrVector());
}
else
{
@ -119,12 +92,8 @@ void Item::update(float delta)
// have it rotate
Vec3 rotation(delta*M_PI, 0, 0);
m_coord.setHPR(m_coord.getHPR()+rotation);
#ifdef HAVE_IRRLICHT
m_root->setRotation(m_coord.getHPR().toIrrHPR());
m_root->setPosition(m_coord.getXYZ().toIrrVector());
#else
m_root->setTransform(const_cast<sgCoord*>(&m_coord.toSgCoord()));
#endif
m_node->setRotation(m_coord.getHPR().toIrrHPR());
m_node->setPosition(m_coord.getXYZ().toIrrVector());
}
} // update

View File

@ -20,18 +20,11 @@
#ifndef HEADER_ITEM_HPP
#define HEADER_ITEM_HPP
#define _WINSOCKAPI_
#include <plib/sg.h>
#ifdef HAVE_IRRLICHT
#include "irrlicht.h"
using namespace irr;
#endif
#include "karts/kart.hpp"
#include "utils/coord.hpp"
#ifndef HAVE_IRRLICHT
class ssgtransform;
class ssgEntity;
#endif
// -----------------------------------------------------------------------------
class Item
@ -54,12 +47,8 @@ private:
float m_time_till_return; // time till a collected item reappears
Coord m_coord; // Original coordinates, used mainly when
// collected items reappear.
#ifdef HAVE_IRRLICHT
/** Scene node of this item. */
scene::ISceneNode *m_root;
#else
ssgTransform* m_root; // The actual root of the item
#endif
scene::ISceneNode *m_node;
unsigned int m_item_id; // index in item_manager field
bool m_rotate; // set to false if item should not rotate
@ -72,15 +61,9 @@ private:
float m_deactive_time;
public:
#ifdef HAVE_IRRLICHT
Item (ItemType type, const Vec3& xyz, const Vec3& normal,
scene::IMesh* mesh, unsigned int item_id,
bool rotate=true);
#else
Item (ItemType type, const Vec3& xyz, const Vec3& normal,
ssgEntity* model, unsigned int item_id,
bool rotate=true);
#endif
virtual ~Item ();
void update (float delta);
virtual void isCollected(float t=2.0f);
@ -105,10 +88,6 @@ public:
void deactivate(float t) { m_deactive_time=t; }
// ------------------------------------------------------------------------
unsigned int getItemId() const { return m_item_id; }
#ifdef HAVE_IRRLICHT
#else
ssgTransform* getRoot() const { return m_root; }
#endif
ItemType getType() const { return m_type; }
bool wasCollected() const { return m_collected;}
void setParent(Kart* parent);

View File

@ -21,8 +21,8 @@
#include <string>
#include <sstream>
#include "callback_manager.hpp"
#include "user_config.hpp"
#include "loader.hpp"
#include "material_manager.hpp"
#include "material.hpp"
#include "graphics/irr_driver.hpp"

View File

@ -23,6 +23,7 @@
#include <stdexcept>
#include <sstream>
#include "callback_manager.hpp"
#include "material_manager.hpp"
#include "material.hpp"
#include "graphics/irr_driver.hpp"
@ -30,7 +31,6 @@
#include "items/bowling.hpp"
#include "items/cake.hpp"
#include "items/plunger.hpp"
#include "loader.hpp"
typedef struct
@ -75,7 +75,6 @@ void PowerupManager::removeTextures()
} // for
#endif
callback_manager->clear(CB_COLLECTABLE);
} // removeTextures
//-----------------------------------------------------------------------------

View File

@ -28,7 +28,6 @@
#include "bullet/Demos/OpenGL/GL_ShapeDrawer.h"
#include "loader.hpp"
#include "user_config.hpp"
#include "material_manager.hpp"
#include "audio/sound_manager.hpp"

View File

@ -19,7 +19,6 @@
#include "karts/kart_model.hpp"
#include "loader.hpp"
#include "stk_config.hpp"
#include "user_config.hpp"
#include "graphics/irr_driver.hpp"
@ -46,20 +45,11 @@ KartModel::KartModel()
m_max_suspension[i] = 1.3f;
m_dampen_suspension_amplitude[i] = 2.5f;
}
#ifdef HAVE_IRRLICHT
m_wheel_filename[0] = "wheel-front-right.3ds";
m_wheel_filename[1] = "wheel-front-left.3ds";
m_wheel_filename[2] = "wheel-rear-right.3ds";
m_wheel_filename[3] = "wheel-rear-left.a3ds";
m_mesh = NULL;
#else
m_wheel_filename[0] = "wheel-front-right.ac";
m_wheel_filename[1] = "wheel-front-left.ac";
m_wheel_filename[2] = "wheel-rear-right.ac";
m_wheel_filename[3] = "wheel-rear-left.ac";
m_root = NULL;
#endif
} // KartModel
// ----------------------------------------------------------------------------
@ -80,21 +70,12 @@ void KartModel::loadInfo(const lisp::Lisp* lisp)
*/
KartModel::~KartModel()
{
// This automatically frees the wheels and the kart model.
// m_root can be zero in case of STKConfig, which has a kart_properties
// attribute (for the default values) as well.
#ifdef HAVE_IRRLICHT
#else
if(m_root) m_root->removeAllKids();
ssgDeRefDelete(m_root);
#endif
} // ~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);
@ -105,14 +86,12 @@ void KartModel::attachModel(scene::ISceneNode **node)
(*node)->addChild(m_wheel_node[i]);
}
} // attachModel
#endif
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
/** Loads the 3d model and all wheels.
*/
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->getMesh(full_path);
Vec3 min, max;
@ -127,27 +106,6 @@ void KartModel::loadModels(const std::string &kart_ident)
// node). m_z_offset should probably be made available to kart.
// Vec3 move_kart_to_0_z(0, 0, m_z_offset);
// m_root->setTransform(move_kart_to_0_z);
#else
ssgEntity *obj = loader->load(m_model_filename, CB_KART);
if(!obj)
{
fprintf(stderr, "Can't find kart model '%s'.\n",m_model_filename.c_str());
return;
}
m_root = new ssgTransform();
m_root->ref();
m_root->addKid(obj);
ssgStripify(obj);
Vec3 min, max;
SSGHelp::MinMax(obj, &min, &max);
m_z_offset = min.getZ();
m_kart_width = max.getX()-min.getX();
m_kart_length = max.getY()-min.getY();
m_kart_height = max.getZ()-min.getZ();
sgVec3 move_kart_to_0_z;
sgSetVec3(move_kart_to_0_z, 0, 0, m_z_offset);
m_root->setTransform(move_kart_to_0_z);
#endif
// Now set default some default parameters (if not defined) that
// depend on the size of the kart model (wheel position, center
@ -170,33 +128,10 @@ void KartModel::loadModels(const std::string &kart_ident)
// depend on the size of the model.
for(unsigned int i=0; i<4; i++)
{
#ifdef HAVE_IRRLICHT
std::string full_wheel = file_manager->getKartFile(m_wheel_filename[i],
kart_ident);
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);
m_wheel_transform[i]= new ssgTransform();
#ifdef DEBUG
m_wheel_transform[i]->setName("wheeltransform");
#endif
if(m_wheel_model[i])
{
m_wheel_transform[i]->addKid(m_wheel_model[i]);
m_root->addKid(m_wheel_transform[i]);
Vec3 min_wheel, max_wheel;
SSGHelp::MinMax(m_wheel_model[i], &min_wheel, &max_wheel);
m_wheel_graphics_radius[i] = (max_wheel.getZ()-min_wheel.getZ())*0.5f;
sgMat4 wheel_loc;
sgVec3 hpr;
sgZeroVec3(hpr);
sgMakeCoordMat4(wheel_loc, m_wheel_graphics_position[i].toFloat(),
hpr);
m_wheel_transform[i]->setTransform(wheel_loc);
} // if m_wheel_model[i]
#endif
} // for i<4
if(!m_wheel_model[0])
{
@ -294,7 +229,6 @@ void KartModel::adjustWheels(float rotation, float steer,
clamped_suspension[i] = ratio*suspension_length;
} // for i<4
#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;
@ -327,31 +261,6 @@ void KartModel::adjustWheels(float rotation, float steer,
wheel_rot[3][2] += clamped_suspension[3];
m_wheel_transform[3]->setTransform(wheel_rot);
#endif
#else
sgMat4 wheel_front;
sgMat4 wheel_steer;
sgMat4 wheel_rot;
sgMakeRotMat4( wheel_rot, 0, RAD_TO_DEGREE(-rotation), 0);
sgMakeRotMat4( wheel_steer, steer , 0, 0);
sgMultMat4(wheel_front, wheel_steer, wheel_rot);
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
} // adjustWheels
// ----------------------------------------------------------------------------

View File

@ -23,7 +23,6 @@
#include <stdexcept>
#include <plib/ssg.h>
#include "material_manager.hpp"
#include "loader.hpp"
#include "stk_config.hpp"
#include "user_config.hpp"
#include "karts/kart_model.hpp"

View File

@ -46,7 +46,6 @@
#include "user_config.hpp"
#include "race_manager.hpp"
#include "loader.hpp"
#include "main_loop.hpp"
#include "material_manager.hpp"
#include "sdldrv.hpp"
@ -439,7 +438,6 @@ void InitTuxkart()
unlock_manager = new UnlockManager();
user_config = new UserConfig();
irr_driver = new IrrDriver();
loader = new Loader();
sound_manager = new SoundManager();
sfx_manager = new SFXManager();
// The order here can be important, e.g. KartPropertiesManager needs
@ -503,7 +501,6 @@ void CleanTuxKart()
if(sound_manager) delete sound_manager;
if(user_config) delete user_config;
if(unlock_manager) delete unlock_manager;
if(loader) delete loader;
if(translations) delete translations;
if(file_manager) delete file_manager;
if(stk_scene) delete stk_scene;

View File

@ -21,12 +21,8 @@
#include <string>
#include <vector>
#ifdef HAVE_IRRLICHT
#include "irrlicht.h"
using namespace irr;
#endif
#define _WINSOCKAPI_
#include <plib/sg.h>
#include "graphics/irr_driver.hpp"
#include "graphics/mesh_tools.hpp"
@ -40,7 +36,6 @@ using namespace irr;
#include "utils/string_utils.hpp"
// -----------------------------------------------------------------------------
#ifdef HAVE_IRRLICHT
MovingPhysics::MovingPhysics(const XMLNode *xml_node)
{
std::string model_name;
@ -96,55 +91,6 @@ MovingPhysics::MovingPhysics(const XMLNode *xml_node)
else if(shape=="box" ) m_body_type = MP_BOX;
else if(shape=="sphere" ) m_body_type = MP_SPHERE;
} // MovingPhysics
#else
MovingPhysics::MovingPhysics(const std::string data)
: ssgTransform(), Callback()
{
m_shape = NULL;
m_body = NULL;
m_motion_state = NULL;
m_mass = 1;
setUserData(new ssgBase()); // prevent tree optimisations to remove this node
std::vector<std::string> parameters = StringUtils::split(data, ' ');
if(parameters.size()<2)
{
fprintf(stderr, "Invalid physics specification: '%s'\n",data.c_str());
}
parameters.erase(parameters.begin());
std::string &shape=parameters[0];
m_body_type = MP_NONE;
if(shape=="cone" ) m_body_type = MP_CONE;
else if(shape=="box" ) m_body_type = MP_BOX;
else if(shape=="sphere" ) m_body_type = MP_SPHERE;
parameters.erase(parameters.begin());
// Scan for additional parameters, which are in the form of keyword=value
// (without any spaces). Currently only mass=... is supported.
while(parameters.size()>0)
{
// Split the parameter string by '=' to get the keyword and value
std::vector<std::string> p=StringUtils::split(parameters[0],'=');
if(p.size()!=2)
{
fprintf(stderr, "Invalid physics parameter string: '%s'\n",data.c_str());
break;
}
if(p[0]=="mass")
{
StringUtils::from_string<float>(p[1], m_mass);
}
else
{
fprintf(stderr, "Invalid physics parameter string: '%s'\n",
data.c_str());
break;
}
parameters.erase(parameters.begin());
}
} // MovingPhysics
#endif
// -----------------------------------------------------------------------------
MovingPhysics::~MovingPhysics()
@ -153,86 +99,17 @@ MovingPhysics::~MovingPhysics()
delete m_body;
delete m_motion_state;
delete m_shape;
#ifdef HAVE_IRRLICHT
#else
stk_scene->remove(this);
#endif
} // ~MovingPhysics
// -----------------------------------------------------------------------------
/** Additional initialisation after loading of the model is finished.
*/
/* Main problem is that the loader (see world::loadTrack) adds a
ssgTransform->ssgRangeSelector->MovingPhysics, and that this ssgTransform M
contains the actual position. So, if the physic position P would be set
immediately, the transform M causes the position the object is drawn to be
wrong (M*P is drawn instead of P). So, to correct this, the body has to be
attached to the root of the scene graph. The body is therefore removed from
its old place, and appended to the root. The original position has to be
recomputed by going up in the scene graph and multiplying the transforms. */
void MovingPhysics::init()
{
#ifdef HAVE_IRRLICHT
#else
// 1. Remove the object from the graph and attach it to the root
// -------------------------------------------------------------
if(getNumParents()>1)
{
fprintf(stderr, "WARNING: physical object with more than one parent!!\n");
return;
}
ssgBranch *parent = getParent(0);
stk_scene->add(this);
parent->removeKid(this);
// 2. Determine the original position of the object
// ------------------------------------------------
ssgEntity *p=parent;
sgMat4 pos;
sgMakeIdentMat4(pos);
while(p->getNumParents())
{
if(p->getNumParents()!=1)
{
// FIXME: Not sure if this is needed: if one object has more than
// one parent (--> this object appears more than once in the
// scene), we have to follow all possible ways up to the
// root, and for each way add one instance to the root.
// For now this is unsupported, and we abort here.
fprintf(stderr, "MovingPhysics: init: %d parents found, ignored.\n",
p->getNumParents());
return;
} // if numparents!=1
if(p->isAKindOf(ssgTypeTransform()))
{
ssgBaseTransform *trans=(ssgBaseTransform*)p;
sgMat4 change_position;
trans->getTransform(change_position);
sgPostMultMat4(pos, change_position);
}
if(p->getNumKids()==0)
{
ssgBranch *new_parent=p->getParent(0);
new_parent->removeKid(p);
p = new_parent;
}
else
{
p=p->getParent(0);
}
} // while
#endif
// 3. Determine size of the object
// 1. Determine size of the object
// -------------------------------
Vec3 min, max;
#ifdef HAVE_IRRLICHT
MeshTools::minMax3D(m_mesh, &min, &max);
#else
SSGHelp::MinMax(this, &min, &max);
#endif
Vec3 extend = max-min;
m_half_height = 0.5f*(extend.getZ());
switch (m_body_type)
@ -240,41 +117,25 @@ void MovingPhysics::init()
case MP_CONE: {
float radius = 0.5f*std::max(extend.getX(), extend.getY());
m_shape = new btConeShapeZ(radius, extend.getZ());
#ifdef HAVE_IRRLICHT
#else
setName("cone");
#endif
break;
}
case MP_BOX: m_shape = new btBoxShape(0.5*extend);
#ifndef HAVE_IRRLICHT
setName("box");
#endif
break;
case MP_SPHERE: {
float radius = std::max(extend.getX(), extend.getY());
radius = 0.5f*std::max(radius, extend.getZ());
m_shape = new btSphereShape(radius);
#ifndef HAVE_IRRLICHT
setName("sphere");
#endif
break;
}
case MP_NONE: fprintf(stderr, "WARNING: Uninitialised moving shape\n");
break;
break;
}
// 4. Create the rigid object
// 2. Create the rigid object
// --------------------------
#ifdef HAVE_IRRLICHT
Vec3 pos = m_init_pos.getOrigin();
pos.setZ(m_init_pos.getOrigin().getZ()+m_half_height);
m_init_pos.setOrigin(pos);
#else
m_init_pos.setIdentity();
m_init_pos.setOrigin(btVector3(pos[3][0],pos[3][1],pos[3][2]+m_half_height));
#endif
m_motion_state = new btDefaultMotionState(m_init_pos);
btVector3 inertia;
m_shape->calculateLocalInertia(m_mass, inertia);
@ -299,14 +160,10 @@ void MovingPhysics::update(float dt)
m_body->setCenterOfMassTransform(m_init_pos);
c.setXYZ(m_init_pos.getOrigin());
}
#ifdef HAVE_IRRLICHT
m_node->setPosition(c.getXYZ().toIrrVector());
m_node->setRotation(c.getHPR().toIrrHPR());
#else
setTransform(const_cast<sgCoord*>(&c.toSgCoord()));
#endif
} // update
// -----------------------------------------------------------------------------
void MovingPhysics::reset()
{

View File

@ -20,27 +20,18 @@
#ifndef HEADER_MOVING_PHYSICS_HPP
#define HEADER_MOVING_PHYSICS_HPP
#include <string>
#ifdef HAVE_IRRLICHT
#include "irrlicht.h"
using namespace irr;
#endif
#define _WINSOCKAPI_
#include <plib/ssg.h>
#include "btBulletDynamicsCommon.h"
#include "callback.hpp"
#include "user_pointer.hpp"
class Vec3;
#ifdef HAVE_IRRLICHT
class scene::IAnimatedMesh;
class XMLNode;
#endif
#ifdef HAVE_IRRLICHT
class MovingPhysics : public Callback
#else
class MovingPhysics : public ssgTransform, public Callback
#endif
{
public:
enum bodyTypes {MP_NONE, MP_CONE, MP_BOX, MP_SPHERE};
@ -54,16 +45,10 @@ protected:
float m_mass;
UserPointer m_user_pointer;
btTransform m_init_pos;
#ifdef HAVE_IRRLICHT
scene::IMesh *m_mesh;
scene::ISceneNode *m_node;
#endif
public:
#ifdef HAVE_IRRLICHT
MovingPhysics (const XMLNode *node);
#else
MovingPhysics (const std::string data);
#endif
~MovingPhysics ();
void update (float dt);
void init ();

View File

@ -33,7 +33,6 @@
#include "user_config.hpp"
#include "material_manager.hpp"
#include "main_loop.hpp"
#include "loader.hpp"
#include "player.hpp"
#include "user_config.hpp"
#include "items/item_manager.hpp"
@ -257,9 +256,7 @@ void SDLDriver::setVideoMode(bool resetTextures)
#if defined(WIN32) || defined(__APPLE__)
if(resetTextures)
{
// Clear plib internal texture cache
loader->endLoad();
// FIXME: clear texture cache here
// Windows needs to reload all textures, display lists, ... which means
// that all models have to be reloaded. So first, free all textures,
// models, then reload the textures from materials.dat, then reload

View File

@ -26,9 +26,9 @@
#include <plib/ssgAux.h>
#include "irrlicht.h"
#include "loader.hpp"
#include "stk_config.hpp"
#include "material_manager.hpp"
#include "callback_manager.hpp"
#include "isect.hpp"
#include "user_config.hpp"
#include "audio/sound_manager.hpp"
@ -1443,7 +1443,7 @@ void Track::loadTrackModel()
}
} // if need_hat
ssgEntity *obj = loader->load(file_manager->getModelFile(fname),
ssgEntity *obj = load(file_manager->getModelFile(fname),
CB_TRACK,
/* optimise */ true,
/*is_full_path*/ true);
@ -1487,6 +1487,7 @@ void Track::loadTrackModel()
m_light = irr_driver->getSceneManager()->addLightSceneNode(0, sun_pos);
video::SLight light;
m_light->setLightData(light);
//irr_driver->getSceneManager()->setAmbientLight(video::SColorf(1.0f,1.0f,1.0f,1.0f));
// Note: the physics world for irrlicht is created in loadMainTrack
createPhysicsModel();
} // loadTrack