cinvoke-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cinvoke-svn] r146 - trunk/skorpion


From: will
Subject: [cinvoke-svn] r146 - trunk/skorpion
Date: 22 Mar 2007 01:47:50 -0400

Author: vmy
Date: 2007-03-22 01:47:49 -0400 (Thu, 22 Mar 2007)
New Revision: 146

Modified:
   trunk/skorpion/ParticleSystem.cs
   trunk/skorpion/skorpion.cs
Log:
modularized/oo-ized ParticleSystem for ease of extension

Modified: trunk/skorpion/ParticleSystem.cs
===================================================================
--- trunk/skorpion/ParticleSystem.cs    2007-03-19 07:22:43 UTC (rev 145)
+++ trunk/skorpion/ParticleSystem.cs    2007-03-22 05:47:49 UTC (rev 146)
@@ -6,10 +6,8 @@
     
 namespace skorpion
 {
-       public class ParticleSystem
+       public abstract class ParticleSystem
        {
-               public enum Mode {ballFountain, engineThrob};
-
                public struct PointVertex
                {
                        public Vector3 v;
@@ -33,49 +31,38 @@
                        public float fadeProgression;
                };
 
-               private float _time;
-               private int _particleCount;
-               private Mode _mode;
+               protected float _time;
+               protected int _particleCount;
 
-               private float _radius;
-               public float Radius
-               {
-                       set{ _radius = value; }
-               }
+               protected float _radius;
+               public float Radius { set{ _radius = value; } }
 
-               private int _particlesLimit;
-               public int ParticlesLimit
-               {
-                       set {_particlesLimit = value;}
-               }
+               protected int _particlesLimit;
+               public int ParticlesLimit { set {_particlesLimit = value;} }
 
-               private int _numParticlesToEmit;
+               protected int _numParticlesToEmit;
                public int NumParticlesToEmit
-               {
-                       set{ _numParticlesToEmit = value; }
-               }
+               { set{ _numParticlesToEmit = value; } }
 
-               private float _emitVelocity;
-               public float EmitVelocity
-               {
-                       set{ _emitVelocity = value; }
-               }
+               protected float _emitVelocity;
+               public float EmitVelocity { set{ _emitVelocity = value; } }
                
+               protected float _pointSize;
+               
                // has to do with streaming VertexBuffers
-               private int _baseParticle = 0;
-               private int _flush = 0;
-               private int _discard = 0;
+               protected int _baseParticle = 0;
+               protected int _flush = 0;
+               protected int _discard = 0;
 
-               private System.Collections.ArrayList _particlesList;
-               private System.Collections.ArrayList _freeParticles;
+               protected System.Collections.ArrayList _particlesList;
+               protected System.Collections.ArrayList _freeParticles;
 
-               private System.Random _rand;
+               protected System.Random _rand;
 
-               private VertexBuffer _vertexBuffer = null;
+               protected VertexBuffer _vertexBuffer = null;
 
-               public ParticleSystem(Mode mode, int numFlush, int numDiscard)
+               public ParticleSystem(float pointSize, int numFlush, int 
numDiscard)
                {
-                       _mode = mode;
                        _time = 0.0f;                           // elapsed 
since system initialization
                        _particleCount = 0;                     // currently in 
scene
                        _radius = 1;                            // unknown
@@ -83,6 +70,8 @@
                        _numParticlesToEmit = 1;        // per frame
                        _emitVelocity = 32.0f;          // straight up
 
+                       _pointSize = pointSize;
+
                        // used for streaming via VertexBuffer
                        _baseParticle = numDiscard;
                        _flush = numFlush;
@@ -111,254 +100,16 @@
                }
 
                // update the time and the position/velocity of the emitter
-               public void Update(float fSecsPerFrame,
+               public abstract void Update(float fSecsPerFrame,
                        System.Drawing.Color clrEmitColor, System.Drawing.Color 
clrFadeColor,
-                       Vector3 vPosition, Vector3 vVelocity)
-               {
-                       _time += fSecsPerFrame;
+                       Vector3 vPosition, Vector3 vVelocity);
                        
-                       switch(_mode)
-                       {
-                               case Mode.ballFountain:
-                               {
-                                       for(int ii = _particlesList.Count-1; ii 
>= 0; ii--)
-                                       {
-                                               Particle p = 
(Particle)_particlesList[ii];
-                               
-                                               // Calculate new position
-                                               float fT = _time - 
p.creationTime;
-                                               float fGravity;
-
-                                               if (p.isSpark)
-                                               {
-                                                       fGravity = -0.05f;
-                                                       p.fadeProgression -= 
(fSecsPerFrame * 2.25f);
-                                               }
-                                               else
-                                               {
-                                                       fGravity = -9.8f;
-                                                       p.fadeProgression -= 
fSecsPerFrame * 0.25f;
-                                               }
-
-                                               p.positionVector    = 
p.initialVelocity * fT + p.initialPosition;
-                                               p.positionVector.Y += (0.5f * 
fGravity) * (fT * fT);
-                                               p.velocityVector.Y  = 
p.initialVelocity.Y + fGravity * fT;
-
-                                               if (p.fadeProgression < 0.0f)
-                                                       p.fadeProgression = 
0.0f;
-
-                                               // remove particles... or if 
they are a spark that has faded
-                                               if (p.positionVector.Y + 100 < 
_radius || p.isSpark && p.fadeProgression <= 0.0f)
-                                               {
-                                                       // Emit sparks
-                                                       if (!p.isSpark)
-                                                       {
-                                                               for (int i=0; 
i<4; i++)
-                                                               {
-                                                                       
Particle spark;
-
-                                                                       if 
(_freeParticles.Count > 0)
-                                                                       {
-                                                                               
spark = (Particle)_freeParticles[0];
-                                                                               
_freeParticles.RemoveAt(0);
-                                                                       }
-                                                                       else
-                                                                       {
-                                                                               
spark = new Particle();
-                                                                       }
-
-                                                                       
spark.isSpark  = true;
-                                                                       
spark.initialVelocity = new Vector3();
-                                                                       
spark.initialPosition   = p.positionVector;
-                                                                       
spark.initialPosition.Y = _radius - 100;
-
-                                                                       float 
fRand1 = ((float)_rand.Next(int.MaxValue)/(float)int.MaxValue) * (float)Math.PI 
* 2.00f;
-                                                                       float 
fRand2 = ((float)_rand.Next(int.MaxValue)/(float)int.MaxValue) * (float)Math.PI 
* 0.25f;
-
-                                                                       
spark.initialVelocity.X  = p.velocityVector.X * 0.25f + (float)Math.Cos(fRand1) 
* (float)Math.Sin(fRand2);
-                                                                       
spark.initialVelocity.Z  = p.velocityVector.Z * 0.25f + (float)Math.Sin(fRand1) 
* (float)Math.Sin(fRand2);
-                                                                       
spark.initialVelocity.Y  = (float)Math.Cos(fRand2);
-                                                                       
spark.initialVelocity.Y *= 
((float)_rand.Next(int.MaxValue)/(float)int.MaxValue) * 1.5f;
-
-                                                                       
spark.positionVector = spark.initialPosition;
-                                                                       
spark.velocityVector = spark.initialVelocity;
-
-                                                                       
spark.diffuseColor = ColorOperator.Lerp(p.fadeColor, p.diffuseColor, 
p.fadeProgression);
-                                                                       
spark.fadeColor = System.Drawing.Color.Black;
-                                                                       
spark.fadeProgression   = 1.0f;
-                                                                       
spark.creationTime  = _time;
-
-                                                                       
_particlesList.Add(spark);
-                                                               }
-                                                       }
-
-                                                       // Kill particle
-                                                       _freeParticles.Add(p);
-                                                       
_particlesList.RemoveAt(ii);
-
-                                                       if (!p.isSpark)
-                                                               
_particleCount--;
-                                               }                       
-                                               else
-                                                       _particlesList[ii] = p;
-                                       }
-
-                                       // emit NumParticlesToEmit new 
particles, but dont exceed _particlesLimit 
-                                       int particlesEmit = _particleCount + 
_numParticlesToEmit;
-                                       while(_particleCount < _particlesLimit 
&& _particleCount < particlesEmit)
-                                       {
-                                               Particle particle;
-
-                                               if (_freeParticles.Count > 0)
-                                               {
-                                                       particle = 
(Particle)_freeParticles[0];
-                                                       
_freeParticles.RemoveAt(0);
-                                               }
-                                               else
-                                               {
-                                                       particle = new 
Particle();
-                                               }
-
-                                               // Emit new particle
-                                               float fRand1 = 
((float)_rand.Next(int.MaxValue)/(float)int.MaxValue) * (float)Math.PI * 2.0f;
-                                               float fRand2 = 
((float)_rand.Next(int.MaxValue)/(float)int.MaxValue) * (float)Math.PI * 0.25f;
-
-                                               particle.isSpark = false;
-
-                                               particle.initialPosition = 
vPosition + new Vector3(0.0f, _radius, 0.0f);
-
-                                               particle.initialVelocity.X  = 
(float)Math.Cos(fRand1) * (float)Math.Sin(fRand2) * 2.5f;
-                                               particle.initialVelocity.Z  = 
(float)Math.Sin(fRand1) * (float)Math.Sin(fRand2) * 2.5f;
-                                               particle.initialVelocity.Y  = 
(float)Math.Cos(fRand2);
-                                               particle.initialVelocity.Y *= 
((float)_rand.Next(int.MaxValue)/(float)int.MaxValue) * _emitVelocity;
-                                               //particle.initialVelocity = 
vVelocity;
-                                               particle.initialVelocity.X += 
(float)Math.Cos(fRand1) * (float)Math.Sin(fRand2) * .5f;
-                                               particle.initialVelocity.Y += 
(float)Math.Sin(fRand1) * (float)Math.Sin(fRand2) * .5f;
-                                               particle.initialVelocity.Z += 
(float)Math.Sin(fRand1) * (float)Math.Cos(fRand2) * .5f;
-
-                                               
//particle.initialVelocity.Scale(-10);
-
-                                               particle.positionVector = 
particle.initialPosition;
-                                               particle.velocityVector = 
particle.initialVelocity;
-
-                                               particle.diffuseColor = 
clrEmitColor;
-                                               particle.fadeColor    = 
clrFadeColor;
-                                               particle.fadeProgression      = 
1.0f;
-                                               particle.creationTime     = 
_time;
-
-                                               _particlesList.Add(particle);
-                                               _particleCount++;
-                                       }
-                                       break;
-                               }
-                               case Mode.engineThrob:
-                               {
-                                       for(int ii = _particlesList.Count-1; ii 
>= 0; ii--)
-                                       {
-                                               Particle p = 
(Particle)_particlesList[ii];
-                               
-                                               // Calculate new position
-                                               // Calculate new position
-                                               float fT = _time - 
p.creationTime;
-                                               float fGravity;
-
-                                               if (p.isSpark)
-                                               {
-                                                       fGravity = -0.05f;
-                                                       p.fadeProgression -= 
(fSecsPerFrame * 2.25f);
-                                               }
-                                               else
-                                               {
-                                                       fGravity = -9.8f;
-                                                       p.fadeProgression -= 
fSecsPerFrame * 0.25f;
-                                               }
-
-                                               p.positionVector    = 
p.initialVelocity * fT + p.initialPosition;
-                                               p.positionVector.Y += (0.5f * 
fGravity) * (fT * fT);
-                                               p.velocityVector.Y  = 
p.initialVelocity.Y + fGravity * fT;
-               
-                                               if (p.fadeProgression < 0.0f)
-                                                       p.fadeProgression = 
0.0f;
-
-                                               // remove particles... or if 
they are a spark that has faded
-                                               //if (p.positionVector.Y + 100 
< _radius || p.isSpark && p.fadeProgression <= 0.0f)
-                                               if(fT > .03f  || p.isSpark && 
p.fadeProgression <= 0.0f)
-                                               {
-                                                       // Kill particle
-                                                       _freeParticles.Add(p);
-                                                       
_particlesList.RemoveAt(ii);
-
-                                                       if (!p.isSpark)
-                                                               
_particleCount--;
-                                               }                       
-                                               else
-                                                       _particlesList[ii] = p; 
                                
-                                       }
-                                       
-                                       // emit NumParticlesToEmit new 
particles, but dont exceed _particlesLimit 
-                                       int particlesEmit = _particleCount + 
_numParticlesToEmit;
-                                       while(_particleCount < _particlesLimit 
&& _particleCount < particlesEmit)
-                                       {
-                                               Particle particle;
-
-                                               if (_freeParticles.Count > 0)
-                                               {
-                                                       particle = 
(Particle)_freeParticles[0];
-                                                       
_freeParticles.RemoveAt(0);
-                                               }
-                                               else
-                                               {
-                                                       particle = new 
Particle();
-                                               }
-
-                                               // Emit new particle
-                                               float fRand1 = 
((float)_rand.Next(int.MaxValue)/(float)int.MaxValue) * (float)Math.PI * 2.0f;
-                                               float fRand2 = 
((float)_rand.Next(int.MaxValue)/(float)int.MaxValue) * (float)Math.PI * 0.25f;
-
-                                               particle.isSpark = false;
-
-                                               particle.initialPosition = 
vPosition + new Vector3(_radius, 0.0f, 0.0f);
-
-                                               particle.initialVelocity = 
vVelocity;
-                                               
particle.initialVelocity.Scale(-1);
-
-                                               particle.initialVelocity.X  += 
(float)Math.Cos(fRand1) * (float)Math.Sin(fRand2) * 2.5f;
-                                               particle.initialVelocity.Z  += 
(float)Math.Sin(fRand1) * (float)Math.Sin(fRand2) * 2.5f;
-                                               particle.initialVelocity.Y  += 
(float)Math.Cos(fRand2);
-                                               particle.initialVelocity.X += 
(float)Math.Cos(fRand1) * (float)Math.Sin(fRand2) * .5f;
-                                               particle.initialVelocity.Y += 
(float)Math.Sin(fRand1) * (float)Math.Sin(fRand2) * .5f;
-                                               particle.initialVelocity.Z += 
(float)Math.Sin(fRand1) * (float)Math.Cos(fRand2) * .5f;
-
-                                               particle.positionVector = 
particle.initialPosition;
-                                               particle.velocityVector = 
particle.initialVelocity;
-
-                                               particle.diffuseColor = 
clrEmitColor;
-                                               particle.fadeColor    = 
clrFadeColor;
-                                               particle.fadeProgression      = 
1.0f;
-                                               particle.creationTime     = 
_time;
-
-                                               _particlesList.Add(particle);
-                                               _particleCount++;
-                                       }
-                                       break;
-                               }
-                       }
-               }
-
                public void Render(Device dev)
                {
                        // Set the render states for using point sprites
                        dev.RenderState.PointSpriteEnable = true;
                        dev.RenderState.PointScaleEnable = true ;
-                       switch(_mode)
-                       {
-                               case Mode.ballFountain:
-                                       dev.RenderState.PointSize = 0.8f; 
//0.08f;
-                                       break;
-                               case Mode.engineThrob:
-                                       dev.RenderState.PointSize = 2f; //0.08f;
-                                       break;
-                       }
+                       dev.RenderState.PointSize = _pointSize;
 
                        dev.RenderState.PointSizeMin = 0.00f;
                        dev.RenderState.PointScaleA = 0.00f;
@@ -450,4 +201,433 @@
                        dev.RenderState.PointScaleEnable = false;
                }
        }
+
+       public class BallFountainParticleSystem : ParticleSystem
+       {
+               public BallFountainParticleSystem(float pointSize, int 
numFlush, int numDiscard) : base(pointSize, numFlush, numDiscard) {}
+
+               public override void Update(float fSecsPerFrame,
+                       System.Drawing.Color clrEmitColor, System.Drawing.Color 
clrFadeColor,
+                       Vector3 vPosition, Vector3 vVelocity)
+               {
+                       _time += fSecsPerFrame;
+                       
+                       for(int ii = _particlesList.Count-1; ii >= 0; ii--)
+                       {
+                               Particle p = (Particle)_particlesList[ii];
+                               
+                               // Calculate new position
+                               float fT = _time - p.creationTime;
+                               float fGravity;
+
+                               if (p.isSpark)
+                               {
+                                       fGravity = -0.05f;
+                                       p.fadeProgression -= (fSecsPerFrame * 
2.25f);
+                               }
+                               else
+                               {
+                                       fGravity = -9.8f;
+                                       p.fadeProgression -= fSecsPerFrame * 
0.25f;
+                               }
+
+                               p.positionVector    = p.initialVelocity * fT + 
p.initialPosition;
+                               p.positionVector.Y += (0.5f * fGravity) * (fT * 
fT);
+                               p.velocityVector.Y  = p.initialVelocity.Y + 
fGravity * fT;
+
+                               if (p.fadeProgression < 0.0f)
+                                       p.fadeProgression = 0.0f;
+
+                               // remove particles... or if they are a spark 
that has faded
+                               if (p.positionVector.Y + 100 < _radius || 
p.isSpark && p.fadeProgression <= 0.0f)
+                               {
+                                       // Emit sparks
+                                       if (!p.isSpark)
+                                       {
+                                               for (int i=0; i<4; i++)
+                                               {
+                                                       Particle spark;
+
+                                                       if 
(_freeParticles.Count > 0)
+                                                       {
+                                                               spark = 
(Particle)_freeParticles[0];
+                                                               
_freeParticles.RemoveAt(0);
+                                                       }
+                                                       else
+                                                       {
+                                                               spark = new 
Particle();
+                                                       }
+
+                                                       spark.isSpark  = true;
+                                                       spark.initialVelocity = 
new Vector3();
+                                                       spark.initialPosition   
= p.positionVector;
+                                                       spark.initialPosition.Y 
= _radius - 100;
+
+                                                       float fRand1 = 
((float)_rand.Next(int.MaxValue)/(float)int.MaxValue) * (float)Math.PI * 2.00f;
+                                                       float fRand2 = 
((float)_rand.Next(int.MaxValue)/(float)int.MaxValue) * (float)Math.PI * 0.25f;
+
+                                                       spark.initialVelocity.X 
 = p.velocityVector.X * 0.25f + (float)Math.Cos(fRand1) * 
(float)Math.Sin(fRand2);
+                                                       spark.initialVelocity.Z 
 = p.velocityVector.Z * 0.25f + (float)Math.Sin(fRand1) * 
(float)Math.Sin(fRand2);
+                                                       spark.initialVelocity.Y 
 = (float)Math.Cos(fRand2);
+                                                       spark.initialVelocity.Y 
*= ((float)_rand.Next(int.MaxValue)/(float)int.MaxValue) * 1.5f;
+
+                                                       spark.positionVector = 
spark.initialPosition;
+                                                       spark.velocityVector = 
spark.initialVelocity;
+
+                                                       spark.diffuseColor = 
ColorOperator.Lerp(p.fadeColor, p.diffuseColor, p.fadeProgression);
+                                                       spark.fadeColor = 
System.Drawing.Color.Black;
+                                                       spark.fadeProgression   
= 1.0f;
+                                                       spark.creationTime  = 
_time;
+
+                                                       
_particlesList.Add(spark);
+                                               }
+                                       }
+
+                                       // Kill particle
+                                       _freeParticles.Add(p);
+                                       _particlesList.RemoveAt(ii);
+
+                                       if (!p.isSpark)
+                                               _particleCount--;
+                               }                       
+                               else
+                                       _particlesList[ii] = p;
+                       }
+
+                       // emit NumParticlesToEmit new particles, but dont 
exceed _particlesLimit 
+                       int particlesEmit = _particleCount + 
_numParticlesToEmit;
+                       while(_particleCount < _particlesLimit && 
_particleCount < particlesEmit)
+                       {
+                               Particle particle;
+
+                               if (_freeParticles.Count > 0)
+                               {
+                                       particle = (Particle)_freeParticles[0];
+                                       _freeParticles.RemoveAt(0);
+                               }
+                               else
+                               {
+                                       particle = new Particle();
+                               }
+
+                               // Emit new particle
+                               float fRand1 = 
((float)_rand.Next(int.MaxValue)/(float)int.MaxValue) * (float)Math.PI * 2.0f;
+                               float fRand2 = 
((float)_rand.Next(int.MaxValue)/(float)int.MaxValue) * (float)Math.PI * 0.25f;
+
+                               particle.isSpark = false;
+
+                               particle.initialPosition = vPosition + new 
Vector3(0.0f, _radius, 0.0f);
+
+                               particle.initialVelocity.X  = 
(float)Math.Cos(fRand1) * (float)Math.Sin(fRand2) * 2.5f;
+                               particle.initialVelocity.Z  = 
(float)Math.Sin(fRand1) * (float)Math.Sin(fRand2) * 2.5f;
+                               particle.initialVelocity.Y  = 
(float)Math.Cos(fRand2);
+                               particle.initialVelocity.Y *= 
((float)_rand.Next(int.MaxValue)/(float)int.MaxValue) * _emitVelocity;
+                               //particle.initialVelocity = vVelocity;
+                               particle.initialVelocity.X += 
(float)Math.Cos(fRand1) * (float)Math.Sin(fRand2) * .5f;
+                               particle.initialVelocity.Y += 
(float)Math.Sin(fRand1) * (float)Math.Sin(fRand2) * .5f;
+                               particle.initialVelocity.Z += 
(float)Math.Sin(fRand1) * (float)Math.Cos(fRand2) * .5f;
+
+                               //particle.initialVelocity.Scale(-10);
+
+                               particle.positionVector = 
particle.initialPosition;
+                               particle.velocityVector = 
particle.initialVelocity;
+
+                               particle.diffuseColor = clrEmitColor;
+                               particle.fadeColor    = clrFadeColor;
+                               particle.fadeProgression      = 1.0f;
+                               particle.creationTime     = _time;
+
+                               _particlesList.Add(particle);
+                               _particleCount++;
+                       }
+               }
+
+       }
+
+       public class EngineThrobParticleSystem : ParticleSystem
+       {
+               public EngineThrobParticleSystem(float pointSize, int numFlush, 
int numDiscard) : base(pointSize, numFlush, numDiscard) {}
+
+               public override void Update(float fSecsPerFrame,
+                       System.Drawing.Color clrEmitColor, System.Drawing.Color 
clrFadeColor,
+                       Vector3 vPosition, Vector3 vVelocity)
+               {
+                       _time += fSecsPerFrame;
+                       
+                       
+                       for(int ii = _particlesList.Count-1; ii >= 0; ii--)
+                       {
+                               Particle p = (Particle)_particlesList[ii];
+                               
+                               // Calculate new position
+                               // Calculate new position
+                               float fT = _time - p.creationTime;
+                               float fGravity;
+
+                               if (p.isSpark)
+                               {
+                                       fGravity = -0.05f;
+                                       p.fadeProgression -= (fSecsPerFrame * 
2.25f);
+                               }
+                               else
+                               {
+                                       fGravity = -9.8f;
+                                       p.fadeProgression -= fSecsPerFrame * 
0.25f;
+                               }
+
+                               p.positionVector    = p.initialVelocity * fT + 
p.initialPosition;
+                               p.positionVector.Y += (0.5f * fGravity) * (fT * 
fT);
+                               p.velocityVector.Y  = p.initialVelocity.Y + 
fGravity * fT;
+               
+                               if (p.fadeProgression < 0.0f)
+                                       p.fadeProgression = 0.0f;
+
+                               // remove particles... or if they are a spark 
that has faded
+                               //if (p.positionVector.Y + 100 < _radius || 
p.isSpark && p.fadeProgression <= 0.0f)
+                               if(fT > .03f  || p.isSpark && p.fadeProgression 
<= 0.0f)
+                               {
+                                       // Kill particle
+                                       _freeParticles.Add(p);
+                                       _particlesList.RemoveAt(ii);
+
+                                       if (!p.isSpark)
+                                               _particleCount--;
+                               }                       
+                               else
+                                       _particlesList[ii] = p;                 
                
+                       }
+                                       
+                       // emit NumParticlesToEmit new particles, but dont 
exceed _particlesLimit 
+                       int particlesEmit = _particleCount + 
_numParticlesToEmit;
+                       while(_particleCount < _particlesLimit && 
_particleCount < particlesEmit)
+                       {
+                               Particle particle;
+
+                               if (_freeParticles.Count > 0)
+                               {
+                                       particle = (Particle)_freeParticles[0];
+                                       _freeParticles.RemoveAt(0);
+                               }
+                               else
+                               {
+                                       particle = new Particle();
+                               }
+
+                               // Emit new particle
+                               float fRand1 = 
((float)_rand.Next(int.MaxValue)/(float)int.MaxValue) * (float)Math.PI * 2.0f;
+                               float fRand2 = 
((float)_rand.Next(int.MaxValue)/(float)int.MaxValue) * (float)Math.PI * 0.25f;
+
+                               particle.isSpark = false;
+
+                               particle.initialPosition = vPosition + new 
Vector3(_radius, 0.0f, 0.0f);
+
+                               particle.initialVelocity = vVelocity;
+                               particle.initialVelocity.Scale(-1);
+
+                               particle.initialVelocity.X  += 
(float)Math.Cos(fRand1) * (float)Math.Sin(fRand2) * 2.5f;
+                               particle.initialVelocity.Z  += 
(float)Math.Sin(fRand1) * (float)Math.Sin(fRand2) * 2.5f;
+                               particle.initialVelocity.Y  += 
(float)Math.Cos(fRand2);
+                               particle.initialVelocity.X += 
(float)Math.Cos(fRand1) * (float)Math.Sin(fRand2) * .5f;
+                               particle.initialVelocity.Y += 
(float)Math.Sin(fRand1) * (float)Math.Sin(fRand2) * .5f;
+                               particle.initialVelocity.Z += 
(float)Math.Sin(fRand1) * (float)Math.Cos(fRand2) * .5f;
+
+                               particle.positionVector = 
particle.initialPosition;
+                               particle.velocityVector = 
particle.initialVelocity;
+
+                               particle.diffuseColor = clrEmitColor;
+                               particle.fadeColor    = clrFadeColor;
+                               particle.fadeProgression      = 1.0f;
+                               particle.creationTime     = _time;
+
+                               _particlesList.Add(particle);
+                               _particleCount++;
+                       }
+               }
+       
+       }
+
+       public class BackgroundWhirlParticleSystem : ParticleSystem
+       {
+               public BackgroundWhirlParticleSystem(float pointSize, int 
numFlush, int numDiscard) : base(pointSize, numFlush, numDiscard) {}
+
+               public override void Update(float fSecsPerFrame,
+                       System.Drawing.Color clrEmitColor, System.Drawing.Color 
clrFadeColor,
+                       Vector3 vPosition, Vector3 vVelocity)
+               {
+                       _time += fSecsPerFrame;
+                       
+                       for(int ii = _particlesList.Count-1; ii >= 0; ii--)
+                       {
+                               Particle p = (Particle)_particlesList[ii];
+                               
+                               // Calculate new position
+                               // Calculate new position
+                               float fT = _time - p.creationTime;
+                               //float fGravity;
+
+                               //if (p.isSpark)
+                       {
+                               //fGravity = -0.05f;
+                               //p.fadeProgression -= (fSecsPerFrame * 2.25f);
+                       }
+                               //else
+                       {
+                               //fGravity = -9.8f;
+                               //p.fadeProgression -= fSecsPerFrame * 0.25f;
+                       }
+
+                               float pX = (float)(1000F * Math.Cos(fT) * 
Math.Sin(fT * ii));
+                               float pY = (float)(1000F * Math.Sin(fT) * 
Math.Sin(fT * ii));
+                               float pZ = (float)(1000F * Math.Cos(fT * ii));
+                               //p.positionVector.X += 1f;
+                               p.positionVector.X = -100 + pX;
+                               p.positionVector.Y = -100 + pY;
+                               p.positionVector.Z = -100 + pZ;
+                               //System.Console.WriteLine(fT + " " + 
p.positionVector);                
+                               //if (p.fadeProgression < 0.0f)
+                               //      p.fadeProgression = 0.0f;
+
+                               // remove particles... or if they are a spark 
that has faded
+                               //if (p.positionVector.Y + 100 < _radius || 
p.isSpark && p.fadeProgression <= 0.0f)
+                               if(fT > .5f  || p.isSpark && p.fadeProgression 
<= 0.0f)
+                               {
+                                       // Kill particle
+                                       //_freeParticles.Add(p);
+                                       //_particlesList.RemoveAt(ii);
+
+                                       //if (!p.isSpark)
+                                       //      _particleCount--;
+                               }                       
+                               //else
+                               _particlesList[ii] = p;                         
        
+                       }
+                                       
+                       // emit NumParticlesToEmit new particles, but dont 
exceed _particlesLimit 
+                       int particlesEmit = _particleCount + 
_numParticlesToEmit;
+                       //while(_particleCount < _particlesLimit && 
_particleCount < particlesEmit)
+                       while(_particlesList.Count < 10)
+                       {
+                               Particle particle;
+
+                               if (_freeParticles.Count > 0)
+                               {
+                                       particle = (Particle)_freeParticles[0];
+                                       _freeParticles.RemoveAt(0);
+                               }
+                               else
+                               {
+                                       particle = new Particle();
+                               }
+
+                               // Emit new particle
+                               float fRand1 = 
((float)_rand.Next(int.MaxValue)/(float)int.MaxValue) * (float)Math.PI * 2.0f;
+                               float fRand2 = 
((float)_rand.Next(int.MaxValue)/(float)int.MaxValue) * (float)Math.PI * 0.25f;
+
+                               particle.isSpark = false;
+
+                               particle.initialPosition = vPosition + new 
Vector3(_radius, 0.0f, 0.0f);
+
+                               particle.initialVelocity = vVelocity;
+                               particle.initialVelocity.Scale(-1);
+
+                               particle.initialVelocity.X  += 
(float)Math.Cos(fRand1) * (float)Math.Sin(fRand2) * 2.5f;
+                               particle.initialVelocity.Z  += 
(float)Math.Sin(fRand1) * (float)Math.Sin(fRand2) * 2.5f;
+                               particle.initialVelocity.Y  += 
(float)Math.Cos(fRand2);
+                               particle.initialVelocity.X += 
(float)Math.Cos(fRand1) * (float)Math.Sin(fRand2) * .5f;
+                               particle.initialVelocity.Y += 
(float)Math.Sin(fRand1) * (float)Math.Sin(fRand2) * .5f;
+                               particle.initialVelocity.Z += 
(float)Math.Sin(fRand1) * (float)Math.Cos(fRand2) * .5f;
+
+                               particle.positionVector = 
particle.initialPosition;
+                               particle.velocityVector = 
particle.initialVelocity;
+
+                               particle.diffuseColor = clrEmitColor;
+                               particle.fadeColor    = clrFadeColor;
+                               particle.fadeProgression      = 1.0f;
+                               particle.creationTime     = _time;
+
+                               _particlesList.Add(particle);
+                               _particleCount++;
+                       }
+               }
+
+       }
+
+       public class AtomosBodyParticleSystem : ParticleSystem
+       {
+               public AtomosBodyParticleSystem(float pointSize, int numFlush, 
int numDiscard) : base(pointSize, numFlush, numDiscard) {}
+
+               public override void Update(float fSecsPerFrame,
+                       System.Drawing.Color clrEmitColor, System.Drawing.Color 
clrFadeColor,
+                       Vector3 vPosition, Vector3 vVelocity)
+               {
+                       _time += fSecsPerFrame;
+                       
+                       
+                       for(int ii = _particlesList.Count-1; ii >= 0; ii--)
+                       {
+                               Particle p = (Particle)_particlesList[ii];
+                               
+                               float fT = _time - p.creationTime;
+
+                               // compute gravitational force and apply that 
acceleration to velocity
+                               float g = .0000000000667f;
+                               float force = g * 99999.0f * 90.0f / 
(float)Math.Pow((vPosition - p.positionVector).Length(), 2.0f);
+                               Vector3 r = vPosition - p.positionVector;
+                               r.Scale(-1 * force / 10000000);
+                               p.velocityVector += r;
+                               p.positionVector += p.velocityVector;
+                               
//System.Console.Out.WriteLine(p.positionVector);
+                       }
+                                       
+                       // emit NumParticlesToEmit new particles, but dont 
exceed _particlesLimit 
+                       int particlesEmit = _particleCount + 
_numParticlesToEmit;
+                       while(_particlesList.Count < 1)
+                       {
+                               Particle particle;
+
+                               if (_freeParticles.Count > 0)
+                               {
+                                       particle = (Particle)_freeParticles[0];
+                                       _freeParticles.RemoveAt(0);
+                               }
+                               else
+                               {
+                                       particle = new Particle();
+                               }
+
+                               // Emit new particle
+                               float fRand1 = 
((float)_rand.Next(int.MaxValue)/(float)int.MaxValue) * (float)Math.PI * 2.0f;
+                               float fRand2 = 
((float)_rand.Next(int.MaxValue)/(float)int.MaxValue) * (float)Math.PI * 0.25f;
+                               float fRand3 = 
((float)_rand.Next(int.MaxValue)/(float)int.MaxValue) * (float)Math.PI * 0.25f;
+
+                               particle.isSpark = false;
+
+                               particle.initialPosition = vPosition;
+
+                               particle.initialVelocity = vVelocity;
+                                               
+                               particle.initialVelocity.X  += 
(float)Math.Cos(fRand1) * (float)Math.Sin(fRand2) * 2.5f;
+                               particle.initialVelocity.Z  += 
(float)Math.Sin(fRand1) * (float)Math.Sin(fRand2) * 2.5f;
+                               particle.initialVelocity.Y  += 
(float)Math.Cos(fRand2);
+                               particle.initialVelocity.X += 
(float)Math.Cos(fRand1) * (float)Math.Sin(fRand2) * .5f;
+                               particle.initialVelocity.Y += 
(float)Math.Sin(fRand1) * (float)Math.Sin(fRand2) * .5f;
+                               particle.initialVelocity.Z += 
(float)Math.Sin(fRand1) * (float)Math.Cos(fRand2) * .5f;
+                               particle.initialVelocity.Scale(90);
+                               particle.positionVector = 
particle.initialPosition;
+                               particle.velocityVector = 
particle.initialVelocity;
+                               particle.velocityVector.X += fRand1;
+                               particle.velocityVector.Y += fRand2;
+                               particle.velocityVector.Z += fRand3;
+
+                               particle.diffuseColor = clrEmitColor;
+                               particle.fadeColor    = clrFadeColor;
+                               particle.fadeProgression      = 1.0f;
+                               particle.creationTime     = _time;
+
+                               _particlesList.Add(particle);
+                               _particleCount++;
+                       }
+               }
+
+       }
 }
\ No newline at end of file

Modified: trunk/skorpion/skorpion.cs
===================================================================
--- trunk/skorpion/skorpion.cs  2007-03-19 07:22:43 UTC (rev 145)
+++ trunk/skorpion/skorpion.cs  2007-03-22 05:47:49 UTC (rev 146)
@@ -325,7 +325,7 @@
                        // thrusters
                        if(ClientConfig.Thrusters)
                        {
-                               iThrusterParticleSystem = new 
ParticleSystem(ParticleSystem.Mode.engineThrob, 512, 2048);
+                               iThrusterParticleSystem = new 
EngineThrobParticleSystem(2f, 512, 2048);
                                iThrusterParticleSystem.Radius = .1f;
                                iThrusterParticleSystem.ParticlesLimit = 512;
                                iThrusterParticleSystem.NumParticlesToEmit = 1;
@@ -344,7 +344,7 @@
                                
iThrusterParticleSystem.RestoreDeviceObjects(iDevice);
                        }
                        // particles
-                       iBallParticleSystem = new 
ParticleSystem(ParticleSystem.Mode.ballFountain, 512, 2048);
+                       iBallParticleSystem = new 
BallFountainParticleSystem(.8f, 512, 2048);
                        iBallParticleSystem.Radius = 3; //0.03f;
                        iBallParticleSystem.ParticlesLimit = 1024;
                        iBallParticleSystem.NumParticlesToEmit = 1;     





reply via email to

[Prev in Thread] Current Thread [Next in Thread]