}
virtual void update ( Controller * controller,
float curTime );
static MetaClass classlnstance;
protected:
virtual void createParticle ( float curTime ) ,-
} ;

Приведем пример задания фонтана в sc-файле.

fountain f {
pos ( 12, 1, 16 )
texture ". .\\TexturesWelectricprtl.bmp" particles-per-second 100 dispersion 0.05 life-time 30
dir ( 0, 0.2, 0 ) color ( 0.2, 1, 0, 1 )
}

Еще одним интересным примером системы частиц является огонь. В нем новые частицы создаются в окрестности заданной точки и движутся вверх, постепенно изменяя свой цвет. Для простоты будем считать, что цвет изменяется линейно от начального значения до конечного с течением времени.

class Fire : public ParticleSystem {
private:
Texture * texture;
float startRadius;
float speed;
Vector4D startColor;
Vector4D endColor;
float lastUpdateTime;
float lifeTime;
float dispersion;
float minSize;
float maxSize; public:
Fire ( const char * theName, const Vector3D& thePos, int particlesPerSecond, float theLifeTime, float radius, float theSpeed, Texture * theTexture, const Vector4D& color1, const Vector4D& color2 ) ,-
-Fire ();
virtual void update ( Controller * controller,
float curTime );
static MetaClass classlnstance;
protected:
virtual void createParticle ( float curTime );
void setParticleColor ( Particle * cur, float curTime ) {
float t = (curTime - cur -> timeOfBirth) / lifeTime; cur -> color = startColor * ( 1 - t ) + endColor * t ,-
}
} ;

Добавляем эффекты

s
void Fire :: update ( Controller * controller,
float curTime )
{
if ( lastUpdateTime < 0 )
lastUpdateTime = curTime;
float delta = curTime - lastUpdateTime;
ParticleSystem :: update ( controller, curTime );
for ( Particle * cur = start; cur != NULL; ) {
float delta = curTime - cur -> lastUpdateTime;
cur -> pos += cur -> velocity * (speed * delta); cur -> velocity.x *= 0.9f; cur -> velocity.z *= 0.9f;
setParticleColor ( cur, curTime );

⇐ Предыдущая| |Следующая ⇒