1) Added new water splash effect (though it needs a proper texture, and

better tweaked parameters).
2) Water and smoke special effects can now be triggered depending on
   terrain (default is off for everything). For testing purposes the
   lighthouse track has smoke for sand, and water splashed for sea
   (i.e. it is currently possible to drive on the water ... for
   testing purposes only :)  )


git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3605 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
hikerstk 2009-06-11 05:57:46 +00:00
parent 807e0dd011
commit 2eceacbd70
10 changed files with 240 additions and 35 deletions

View File

@ -60,6 +60,8 @@ supertuxkart_SOURCES = \
graphics/skid_marks.hpp \
graphics/smoke.cpp \
graphics/smoke.hpp \
graphics/water_splash.hpp \
graphics/water_splash.cpp \
gui/credits.cpp \
gui/credits.hpp \
gui/engine.cpp \

View File

@ -48,18 +48,29 @@ Material::Material(const XMLNode *node, int index)
node->get("clampU", &b); if(b) m_clamp_tex +=UCLAMP;
b=false;
node->get("clampV", &b); if(b) m_clamp_tex +=VCLAMP;
node->get("transparency", &m_transparency );
node->get("alpha", &m_alpha_blending );
node->get("light", &m_lighting );
node->get("sphere", &m_sphere_map );
node->get("friction", &m_friction );
node->get("ignore", &m_ignore );
node->get("zipper", &m_zipper );
node->get("reset", &m_resetter );
node->get("collide", &m_collideable );
node->get("maxSpeed", &m_max_speed_fraction);
node->get("slowdownTime", &m_slowdown );
node->get("transparency", &m_transparency );
node->get("alpha", &m_alpha_blending );
node->get("light", &m_lighting );
node->get("sphere", &m_sphere_map );
node->get("friction", &m_friction );
node->get("ignore", &m_ignore );
node->get("zipper", &m_zipper );
node->get("reset", &m_resetter );
node->get("collide", &m_collideable );
node->get("maxSpeed", &m_max_speed_fraction);
node->get("slowdownTime", &m_slowdown );
std::string s("");
node->get("graphical-effect", &s );
if(s=="water")
m_graphical_effect = GE_WATER;
else if(s=="smoke")
m_graphical_effect = GE_SMOKE;
else if (s!="")
fprintf(stderr,
"Invalid graphical effect specification: '%s' - ignored.\n",
s.c_str());
else
m_graphical_effect = GE_NONE;
install(/*is_full_path*/false);
} // Material
@ -87,19 +98,20 @@ Material::~Material()
//-----------------------------------------------------------------------------
void Material::init(unsigned int index)
{
m_index = index ;
m_clamp_tex = 0 ;
m_transparency = false ;
m_alpha_blending = false ;
m_lighting = true ;
m_sphere_map = false ;
m_friction = 1.0f ;
m_ignore = false ;
m_zipper = false ;
m_resetter = false ;
m_collideable = true ;
m_index = index;
m_clamp_tex = 0;
m_transparency = false;
m_alpha_blending = false;
m_lighting = true;
m_sphere_map = false;
m_friction = 1.0f;
m_ignore = false;
m_zipper = false;
m_resetter = false;
m_collideable = true;
m_max_speed_fraction = 1.0f;
m_slowdown = stk_config->m_slowdown_factor;
m_graphical_effect = GE_NONE;
}
//-----------------------------------------------------------------------------

View File

@ -21,7 +21,7 @@
#define HEADER_MATERIAL_HPP
#include <string>
#define _WINSOCKAPI_
#include "irrlicht.h"
using namespace irr;
@ -29,10 +29,14 @@ class XMLNode;
class Material
{
public:
enum GraphicalEffect {GE_NONE, GE_SMOKE, GE_WATER};
private:
video::ITexture *m_texture;
unsigned int m_index;
std::string m_texname;
GraphicalEffect m_graphical_effect;
bool m_collideable;
bool m_zipper;
bool m_resetter;
@ -73,6 +77,10 @@ public:
/** Returns the slowdown that happens if a kart is
* faster than the maximum speed. */
float getSlowDown () const { return m_slowdown; }
/** Returns true if this material should have smoke effect. */
bool hasSmoke () const { return m_graphical_effect==GE_SMOKE;}
/** Returns true if this material should have water splashes. */
bool hasWaterSplash () const { return m_graphical_effect==GE_WATER;}
} ;

View File

@ -1,8 +1,7 @@
// $Id: dust_cloud.cpp 1681 2008-04-09 13:52:48Z hikerstk $
// $Id: smoke.cpp 1681 2008-04-09 13:52:48Z hikerstk $
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2006 SuperTuxKart-Team
// 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
@ -74,7 +73,7 @@ void Smoke::update(float t)
return;
static int left=1;
left = 1-left;
const btWheelInfo &wi = m_kart->getVehicle()->getWheelInfo(left ? 3 : 2);
const btWheelInfo &wi = m_kart->getVehicle()->getWheelInfo(2+left);
Vec3 c=wi.m_raycastInfo.m_contactPointWS;
// FIXME: the X position is not yet always accurate.

View File

@ -1,7 +1,7 @@
// $Id: dust_cloud.hpp 1681 2008-04-09 13:52:48Z hikerstk $
//
// SuperTuxKart - a fun racing game with go-kart
// Copyright (C) 2006 SuperTuxKart-Team
// 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

View File

@ -0,0 +1,110 @@
// $Id$
//
// 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.
#include "water_splash.hpp"
#include "graphics/material_manager.hpp"
#include "graphics/irr_driver.hpp"
#include "io/file_manager.hpp"
#include "karts/kart.hpp"
#include "physics/btKart.hpp"
#include "utils/constants.hpp"
WaterSplash::WaterSplash(Kart* kart) : m_kart(kart), m_particle_size(0.33f)
{
m_node = irr_driver->addParticleNode();
// Note: the smoke system is NOT child of the kart, since bullet
// gives the position of the wheels on the ground in world coordinates.
// So it's easier not to move the particle system with the kart, and set
// the position directly from the wheel coordinates.
m_node->setPosition(core::vector3df(-m_kart->getKartWidth()*0.35f,
m_particle_size*0.25f,
-m_kart->getKartLength()*0.5f));
Material *m= material_manager->getMaterial("water_light.png");
m->setMaterialProperties(&(m_node->getMaterial(0)));
m_node->setMaterialTexture(0, m->getTexture());
m_emitter = m_node->createPointEmitter(core::vector3df(0, 0, 0), // velocity in m/ms
5, 10,
video::SColor(255,0,0,0),
video::SColor(255,255,255,255),
300, 500,
20 // max angle
);
m_emitter->setMinStartSize(core::dimension2df(m_particle_size/1.5f, m_particle_size/1.5f));
m_emitter->setMaxStartSize(core::dimension2df(m_particle_size*1.5f, m_particle_size*1.5f));
m_node->setEmitter(m_emitter); // this grabs the emitter
scene::IParticleFadeOutAffector *fade_af =
m_node->createFadeOutParticleAffector(video::SColor(0, 255, 0, 0), 500);
m_node->addAffector(fade_af);
fade_af->drop();
scene::IParticleGravityAffector *gaf =
m_node->createGravityAffector();
m_node->addAffector(gaf);
gaf->drop();
} // KartParticleSystem
//-----------------------------------------------------------------------------
/** Destructor, removes
*/
WaterSplash::~WaterSplash()
{
irr_driver->removeNode(m_node);
} // ~WaterSplash
//-----------------------------------------------------------------------------
void WaterSplash::update(float t)
{
// No particles to emit, no need to change the speed
if(m_emitter->getMinParticlesPerSecond()==0)
return;
// Cycle through all four wheels
static int left=1;
static int rear=1;
left = 1-left;
if(left==0) rear = 1-rear;
const btWheelInfo &wi = m_kart->getVehicle()->getWheelInfo(rear*2+left);
Vec3 c=wi.m_raycastInfo.m_contactPointWS;
// FIXME: the X position is not yet always accurate.
m_node->setPosition(core::vector3df(c.getX()+ m_particle_size*0.25f * (left?+1:-1),
c.getZ()+m_particle_size*0.25f,
c.getY()));
// There seems to be no way to randomise the velocity for particles,
// so we have to do this manually, by changing the default velocity.
// Irrlicht expects velocity (called 'direction') in m/ms!!
float f=m_kart->getSpeed();
if(f<1) return; // avoid problem with modulo 0
Vec3 dir((rand()%int(f))*(left?-1:1)*0.004f,
sin(DEGREE_TO_RAD(rand()%180))*0.004f,
sin(DEGREE_TO_RAD(rand()%100))*0.004f);
m_emitter->setDirection(dir.toIrrVector());
} // update
//-----------------------------------------------------------------------------
void WaterSplash::setCreationRate(float f)
{
m_emitter->setMinParticlesPerSecond(int(f));
m_emitter->setMaxParticlesPerSecond(int(f));
} // setCreationRate

View File

@ -0,0 +1,47 @@
// $Id$
//
// 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.
#ifndef HEADER_WATER_SPLASH_HPP
#define HEADER_WATER_SPLASH_HPP
#include "irrlicht.h"
using namespace irr;
class Kart;
class WaterSplash
{
private:
/** The kart to which this smoke belongs. */
const Kart *m_kart;
/** Irrlicht's particle systems. */
scene::IParticleSystemSceneNode *m_node; /* left wheel */
/** The emitters. Access to these is needed to adjust the number of
* particles per second. */
scene::IParticleEmitter *m_emitter;
/** Size of the particles. */
const float m_particle_size;
public:
WaterSplash (Kart* kart);
virtual ~WaterSplash();
virtual void update (float t);
void setCreationRate(float f);
}; // WaterSplash
#endif

View File

@ -536,6 +536,10 @@
RelativePath="..\..\graphics\smoke.cpp"
>
</File>
<File
RelativePath="..\..\graphics\water_splash.cpp"
>
</File>
</Filter>
<Filter
Name="network"
@ -1186,6 +1190,10 @@
RelativePath="..\..\graphics\smoke.hpp"
>
</File>
<File
RelativePath="..\..\graphics\water_splash.hpp"
>
</File>
</Filter>
<Filter
Name="tracks"

View File

@ -35,6 +35,7 @@
#include "graphics/shadow.hpp"
#include "graphics/skid_marks.hpp"
#include "graphics/smoke.hpp"
#include "graphics/water_splash.hpp"
#include "modes/world.hpp"
#include "io/file_manager.hpp"
#include "items/item_manager.hpp"
@ -74,6 +75,7 @@ Kart::Kart (const std::string& kart_name, int position,
m_shadow_enabled = false;
m_shadow = NULL;
m_smoke_system = NULL;
m_water_splash_system = NULL;
m_nitro = NULL;
m_skidmarks = NULL;
m_animated_node = NULL;
@ -242,8 +244,9 @@ Kart::~Kart()
sfx_manager->deleteSFX(m_skid_sound );
sfx_manager->deleteSFX(m_goo_sound );
if(m_smoke_system) delete m_smoke_system;
if(m_nitro) delete m_nitro;
if(m_smoke_system) delete m_smoke_system;
if(m_water_splash_system) delete m_water_splash_system;
if(m_nitro) delete m_nitro;
m_animated_node->removeChild(m_shadow->getSceneNode());
delete m_shadow;
@ -556,6 +559,7 @@ void Kart::update(float dt)
if ( user_config->m_graphical_effects )
{
m_smoke_system->update(dt);
m_water_splash_system->update(dt);
m_nitro->update(dt);
} // user_config->m_graphical_effects
updatePhysics(dt);
@ -1007,8 +1011,9 @@ void Kart::loadData()
createPhysics();
// Attach Particle System
m_smoke_system = new Smoke(this);
m_nitro = new Nitro(this);
m_smoke_system = new Smoke(this);
m_water_splash_system = new WaterSplash(this);
m_nitro = new Nitro(this);
if(m_kart_properties->hasSkidmarks())
m_skidmarks = new SkidMarks(*this);
@ -1065,9 +1070,19 @@ void Kart::updateGraphics(const Vec3& off_xyz, const Vec3& off_hpr)
if(m_smoke_system)
{
float f = fabsf(m_controls.m_steer) > 0.8 ? 250.0f : 0.0f;
float f=0.0f;
if(getMaterial()->hasSmoke() && fabsf(m_controls.m_steer) > 0.8 &&
isOnGround())
f=250.0f;
m_smoke_system->setCreationRate((m_skidding-1)*f);
}
if(m_water_splash_system)
{
float f = getMaterial()->hasWaterSplash() &&isOnGround()
? sqrt(getSpeed())*40.0f
: 0.0f;
m_water_splash_system->setCreationRate(f);
}
if(m_nitro)
m_nitro->setCreationRate(m_controls.m_nitro && m_collected_energy>0
? (10.0f + getSpeed()*20.0f) : 0);

View File

@ -35,6 +35,7 @@ class SkidMarks;
class Shadow;
class Item;
class Smoke;
class WaterSplash;
class Nitro;
class SFXBase;
class btUprightConstraint;
@ -82,7 +83,10 @@ private:
/** If a kart is flying, the shadow is disabled (since it is
* stuck to the kart, i.e. the shadow would be flying, too). */
bool m_shadow_enabled;
Smoke *m_smoke_system; /**<Smoke from skidding. */
/** Smoke from skidding. */
Smoke *m_smoke_system;
/** Water splash when driving in water. */
WaterSplash *m_water_splash_system;
/** Fire when using a nitro. */
Nitro *m_nitro;