Make more particle parameters configurable

git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@7292 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
auria 2011-01-06 01:25:46 +00:00
parent aa6c225684
commit b6b9f2810d
5 changed files with 52 additions and 14 deletions

View File

@ -1,7 +1,14 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<particles emitter="box" box_x="0.5" box_y="0.1" box_z="0.5"> <particles emitter="box" box_x="0.5" box_y="0.1" box_z="0.5">
<spreading value="0.002" /> <spreading x="120"
y="100"
z="120" />
<velocity x="0.002"
y="0.002"
z="0.002" />
<material file="nitro-particle.png" /> <material file="nitro-particle.png" />
<!-- Amount of particles emitted per second --> <!-- Amount of particles emitted per second -->

View File

@ -1,7 +1,14 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<particles emitter="point"> <particles emitter="point">
<spreading value="0.003" /> <spreading x="120"
y="180"
z="120" />
<velocity x="0.003"
y="0.003"
z="0.003" />
<material file="smoke.png" /> <material file="smoke.png" />
<!-- Amount of particles emitted per second --> <!-- Amount of particles emitted per second -->

View File

@ -130,15 +130,13 @@ void ParticleEmitter::update()
{ {
// No particles to emit, no need to change the speed // No particles to emit, no need to change the speed
if (m_emitter->getMinParticlesPerSecond() == 0) return; if (m_emitter->getMinParticlesPerSecond() == 0) return;
const float spreading = m_particle_type->getSpreadFactor();
// There seems to be no way to randomise the velocity for particles, // There seems to be no way to randomise the velocity for particles,
// so we have to do this manually, by changing the default velocity. // so we have to do this manually, by changing the default velocity.
// Irrlicht expects velocity (called 'direction') in m/ms!! // Irrlicht expects velocity (called 'direction') in m/ms!!
Vec3 dir(cos(DEGREE_TO_RAD*(rand()%180))*spreading, Vec3 dir(cos(DEGREE_TO_RAD*(rand()%m_particle_type->getAngleSpreadX()))*m_particle_type->getVelocityX(),
sin(DEGREE_TO_RAD*(rand()%100))*spreading, sin(DEGREE_TO_RAD*(rand()%m_particle_type->getAngleSpreadY()))*m_particle_type->getVelocityY(),
sin(DEGREE_TO_RAD*(rand()%180))*spreading); sin(DEGREE_TO_RAD*(rand()%m_particle_type->getAngleSpreadZ()))*m_particle_type->getVelocityZ());
m_emitter->setDirection(dir.toIrrVector()); m_emitter->setDirection(dir.toIrrVector());
} // update } // update

View File

@ -33,7 +33,6 @@ ParticleKind::ParticleKind(const std::string file) : m_min_start_color(255,255,2
// ---- Initial values to prevent readin uninitialized values // ---- Initial values to prevent readin uninitialized values
m_max_size = 0.5f; m_max_size = 0.5f;
m_min_size = 0.5f; m_min_size = 0.5f;
m_spread_factor = 0.001f;
m_shape = EMITTER_POINT; m_shape = EMITTER_POINT;
m_material = NULL; m_material = NULL;
m_min_rate = 10; m_min_rate = 10;
@ -44,6 +43,12 @@ ParticleKind::ParticleKind(const std::string file) : m_min_start_color(255,255,2
m_box_x = 0.5f; m_box_x = 0.5f;
m_box_y = 0.5f; m_box_y = 0.5f;
m_box_z = 0.5f; m_box_z = 0.5f;
m_angle_spread_x = 90;
m_angle_spread_y = 90;
m_angle_spread_z = 90;
m_velocity_x = 0.001f;
m_velocity_y = 0.001f;
m_velocity_z = 0.001f;
// ----- Read XML file // ----- Read XML file
@ -88,10 +93,19 @@ ParticleKind::ParticleKind(const std::string file) : m_min_start_color(255,255,2
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
const XMLNode* spreading = xml->getNode("spreading"); const XMLNode* spreading = xml->getNode("spreading");
spreading->get("value", &m_spread_factor); spreading->get("x", &m_angle_spread_x);
spreading->get("y", &m_angle_spread_y);
spreading->get("z", &m_angle_spread_z);
//std::cout << "m_spread_factor = " << m_spread_factor << "\n"; //std::cout << "m_spread_factor = " << m_spread_factor << "\n";
// ------------------------------------------------------------------------
const XMLNode* velocity = xml->getNode("velocity");
velocity->get("x", &m_velocity_x);
velocity->get("y", &m_velocity_y);
velocity->get("z", &m_velocity_z);
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
const XMLNode* material = xml->getNode("material"); const XMLNode* material = xml->getNode("material");

View File

@ -47,8 +47,14 @@ private:
float m_max_size; float m_max_size;
float m_min_size; float m_min_size;
float m_spread_factor; int m_angle_spread_x;
int m_angle_spread_y;
int m_angle_spread_z;
float m_velocity_x;
float m_velocity_y;
float m_velocity_z;
EmitterShape m_shape; EmitterShape m_shape;
Material* m_material; Material* m_material;
@ -83,8 +89,6 @@ public:
int getMinRate () const { return m_min_rate; } int getMinRate () const { return m_min_rate; }
int getMaxRate () const { return m_max_rate; } int getMaxRate () const { return m_max_rate; }
float getSpreadFactor() const { return m_spread_factor; }
EmitterShape getShape () const { return m_shape; } EmitterShape getShape () const { return m_shape; }
Material* getMaterial () const { return m_material; } Material* getMaterial () const { return m_material; }
@ -100,6 +104,14 @@ public:
float getBoxSizeX () const { return m_box_x; } float getBoxSizeX () const { return m_box_x; }
float getBoxSizeY () const { return m_box_y; } float getBoxSizeY () const { return m_box_y; }
float getBoxSizeZ () const { return m_box_z; } float getBoxSizeZ () const { return m_box_z; }
int getAngleSpreadX() const { return m_angle_spread_x; }
int getAngleSpreadY() const { return m_angle_spread_y; }
int getAngleSpreadZ() const { return m_angle_spread_z; }
float getVelocityX () const { return m_velocity_x; }
float getVelocityY () const { return m_velocity_y; }
float getVelocityZ () const { return m_velocity_z; }
}; };
#endif #endif