It now rains in lighthouse :)

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@7406 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2011-01-14 02:27:14 +00:00
parent 68bd15050b
commit 404bb88703
6 changed files with 129 additions and 13 deletions

33
data/rain.xml Normal file
View File

@ -0,0 +1,33 @@
<?xml version="1.0"?>
<!-- For sky particles, the size of the box is ignored -->
<particles emitter="box">
<spreading angle="3" />
<velocity x="0.0"
y="-0.04"
z="0.0" />
<material file="rain.png"/>
<!-- Amount of particles emitted per second -->
<rate min="800"
max="900" />
<!-- Minimal and maximal lifetime of a particle, in milliseconds. -->
<lifetime min="4000"
max="5000" />
<!-- Size of the particles -->
<size min="16.00"
max="16.00" />
<color min="255 255 255"
max="255 255 255" />
<!-- Distance at which the particles fade out -->
<fade-away start="50"
end="100" />
</particles>

View File

@ -12,12 +12,12 @@
<material file="snowflake.png"/>
<!-- Amount of particles emitted per second -->
<rate min="800"
<rate min="900"
max="900" />
<!-- Minimal and maximal lifetime of a particle, in milliseconds. -->
<lifetime min="5000"
max="6000" />
<lifetime min="9000"
max="9000" />
<!-- Size of the particles -->
<size min="0.40"

View File

@ -26,6 +26,60 @@
#include "io/file_manager.hpp"
#include "utils/constants.hpp"
class FadeAwayAffector : public scene::IParticleAffector
{
/** (Squared) distance from camera at which a particle started being faded out */
int m_start_fading;
/** (Squared) distance from camera at which a particle is completely faded out */
int m_end_fading;
public:
FadeAwayAffector(int start, int end)
{
m_start_fading = start;
m_end_fading = end;
assert(m_end_fading >= m_start_fading);
}
virtual void affect(u32 now, scene::SParticle* particlearray, u32 count)
{
scene::ICameraSceneNode* curr_cam = irr_driver->getSceneManager()->getActiveCamera();
const core::vector3df& cam_pos = curr_cam->getPosition();
for (unsigned int n=0; n<count; n++)
{
scene::SParticle& curr = particlearray[n];
core::vector3df diff = curr.pos - cam_pos;
const float x = diff.X;
const float y = diff.Y;
const float z = diff.Z;
const int distance_squared = x*x + y*y + z*z;
if (distance_squared < m_start_fading)
{
curr.color.setAlpha(255);
}
else if (distance_squared > m_end_fading)
{
curr.color.setAlpha(0);
}
else
{
curr.color.setAlpha((distance_squared - m_start_fading) / (m_end_fading - m_start_fading));
}
}
}
virtual scene::E_PARTICLE_AFFECTOR_TYPE getType() const
{
// FIXME: this method seems to make sense only for built-in affectors
return scene::EPAT_FADE_OUT;
}
};
ParticleEmitter::ParticleEmitter(const ParticleKind* type, core::vector3df position,
scene::ISceneNode* parent) : m_position(position)
{
@ -185,8 +239,8 @@ void ParticleEmitter::setParticleType(const ParticleKind* type)
m_particle_type->getAngleSpread() /* angle */
);
//irr_driver->getSceneManager()->addCubeSceneNode(2.0f, parent, -1, position, core::vector3df(0, 0, 0) /* rotation */,
// core::vector3df(box_size_x, box_size_y, box_size_z));
//irr_driver->getSceneManager()->addCubeSceneNode(2.0f, m_parent, -1, m_position, core::vector3df(0, 0, 0) /* rotation */,
// core::vector3df(box_size_x*2, box_size_y*2, box_size_z*2));
break;
}
@ -217,4 +271,13 @@ void ParticleEmitter::setParticleType(const ParticleKind* type)
m_node->addAffector(gaf);
gaf->drop();
}
const float fas = type->getFadeAwayStart();
const float fae = type->getFadeAwayEnd();
if (fas > 0.0f && fae > 0.0f)
{
FadeAwayAffector* faa = new FadeAwayAffector(fas*fas, fae*fae);
m_node->addAffector(faa);
faa->drop();
}
}

View File

@ -48,6 +48,8 @@ ParticleKind::ParticleKind(const std::string file) : m_min_start_color(255,255,2
m_velocity_y = 0.001f;
m_velocity_z = 0.001f;
m_gravity_strength = 0.0f;
m_fade_away_start = -1.0f;
m_fade_away_end = -1.0f;
m_force_lost_to_gravity_time = 1000;
@ -193,6 +195,7 @@ ParticleKind::ParticleKind(const std::string file) : m_min_start_color(255,255,2
//std::cout << "m_fadeout_time = " << m_fadeout_time << "\n";
// ------------------------------------------------------------------------
const XMLNode* gravity = xml->getNode("gravity");
if (gravity != NULL)
{
@ -202,5 +205,14 @@ ParticleKind::ParticleKind(const std::string file) : m_min_start_color(255,255,2
// ------------------------------------------------------------------------
const XMLNode* fadeaway = xml->getNode("fade-away");
if (fadeaway != NULL)
{
fadeaway->get("start", &m_fade_away_start);
fadeaway->get("end", &m_fade_away_end);
}
// ------------------------------------------------------------------------
delete xml;
}

View File

@ -80,6 +80,9 @@ private:
/** For box emitters only */
float m_box_x, m_box_y, m_box_z;
/** Distance from camera at which particles start fading out, or negative if disabled */
float m_fade_away_start, m_fade_away_end;
public:
/**
@ -125,9 +128,12 @@ public:
/** Get the time it takes for gravity to completely replace the emission force. Meaningless if gravity is disabled. */
int getForceLostToGravityTime() const { return m_force_lost_to_gravity_time; }
void setBoxSizeX (float newVal) { m_box_x = newVal; }
void setBoxSizeY (float newVal) { m_box_y = newVal; }
void setBoxSizeZ (float newVal) { m_box_z = newVal; }
float getFadeAwayStart() const { return m_fade_away_start; }
float getFadeAwayEnd () const { return m_fade_away_end; }
void setBoxSizeX (float newVal) { m_box_x = newVal; }
void setBoxSizeY (float newVal) { m_box_y = newVal; }
void setBoxSizeZ (float newVal) { m_box_z = newVal; }
};
#endif

View File

@ -133,6 +133,9 @@ void Track::cleanup()
}
m_all_nodes.clear();
if (m_sky_particles_emitter) delete m_sky_particles_emitter;
m_sky_particles_emitter = NULL;
// The meshes stored in the scene nodes are dropped now.
// But to really remove all track meshes from memory
// they have to be removed from the cache.
@ -988,12 +991,11 @@ void Track::loadTrackModel(World* parent, unsigned int mode_id)
const float z = (m_aabb_max.getZ() + m_aabb_min.getZ())/2.0f;
const float size_x = m_aabb_max.getX() - m_aabb_min.getX();
const float size_z = m_aabb_max.getZ() - m_aabb_min.getZ();
m_sky_particles->setBoxSizeX(size_x);
m_sky_particles->setBoxSizeZ(size_z);
m_sky_particles->setBoxSizeX(size_x*0.5f); // FIXME: don't hardcode size reduction. We need to set the emission area in blender
m_sky_particles->setBoxSizeZ(size_z*0.5f);
// FIXME: don't hardcode height
printf("&&&& %f %f\n", m_aabb_min.getY(), m_aabb_max.getY());
m_sky_particles_emitter = new ParticleEmitter(m_sky_particles, core::vector3df(x, 25.0f, z));
// FIXME: don't hardcode height We need to set the emission area in blender
m_sky_particles_emitter = new ParticleEmitter(m_sky_particles, core::vector3df(x, m_aabb_max.getY()*0.75f, z));
}
// Only print warning if not in battle mode, since battle tracks don't have