[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

C.4.18.3 Snow

To convert the old snow particle system to new particles you can use a box emitter which is oriented at the top where the snow drops should appear and which is very thin. You can use a force effector with random acceleration on the XZ plane to get the effect that snowflakes drift. Here you see an example of a snow particle system in the world file:

  <meshfact name="snowFact">
      <particlesize x="0.17" y="0.17" />
        <min x="-5" y="-0.3" z="-5" />
        <max x="10" y="6" z="10" />
      <emitter type="box">
        <mass min="5" max="7.5" />
          <min x="-5" y="6" z="-5" />
          <max x="10" y="6" z="10" />
        <uniformvelocity />
        <initialvelocity x="0" y="-1.42" z="0" />
        <initialttl min="5" max="5" />
      <effector type="lincolor">
        <color red="0" green="0" blue="1" time="5" />
      <effector type="force">
	<randomacceleration x="2.5" y="0" z="2.5" />
  <meshobj name="snowfall">
    <ztest />
        <add />
      <v x="10" y="0" z="10" />

Here is how this could work in code:

  csRef<iMeshFactoryWrapper> mfw = engine->CreateMeshFactory (
      "crystalspace.mesh.object.particles", "snow");
  if (!mfw) return;

  csRef<iMeshWrapper> exp = engine->CreateMeshWrapper (mfw, "custom snow",
	sector, csVector3 (0, 0, 0));

  exp->GetMeshObject()->SetMixMode (CS_FX_ADD);
  exp->GetMeshObject()->SetMaterialWrapper (mat);

  csRef<iParticleBuiltinEmitterFactory> emit_factory = 
      csLoadPluginCheck<iParticleBuiltinEmitterFactory> (
        Sys->object_reg, "crystalspace.mesh.object.particles.emitter", false);
  csRef<iParticleBuiltinEffectorFactory> eff_factory = 
      csLoadPluginCheck<iParticleBuiltinEffectorFactory> (
        Sys->object_reg, "crystalspace.mesh.object.particles.effector", false);

  csRef<iParticleBuiltinEmitterBox> boxemit = emit_factory->CreateBox ();
  boxemit->SetBox (bbox);
  boxemit->SetParticlePlacement (CS_PARTICLE_BUILTIN_VOLUME);
  boxemit->SetEmissionRate (num / 5f);
  boxemit->SetInitialMass (5.0f, 7.5f);
  boxemit->SetUniformVelocity (true);
  boxemit->SetInitialTTL (5f, 5f);
  boxemit->SetInitialVelocity (csVector3 (0, -1.42f, 0), csVector3 (0));

  csRef<iParticleBuiltinEffectorLinColor> lincol = eff_factory->
    CreateLinColor ();
  lincol->AddColor (csColor4 (.25,.25,.25,1), 2.5f);

  csRef<iParticleBuiltinEffectorForce> force = eff_factory->
    CreateForce ();
  force->SetRandomAcceleration (csVector3 (1.5f, 0.0f, 1.5f));

  csRef<iParticleSystem> partstate =
  	scfQueryInterface<iParticleSystem> (exp->GetMeshObject ());
  partstate->SetMinBoundingBox (bbox);
  partstate->SetParticleSize (csVector2 (0.07f, 0.07f));
  partstate->AddEmitter (boxemit);
  partstate->AddEffector (lincol);
  partstate->AddEffector (force);

This document was generated using texi2html 1.76.