[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[cinvoke-svn] r121 - trunk/skorpion
From: |
will |
Subject: |
[cinvoke-svn] r121 - trunk/skorpion |
Date: |
13 Nov 2006 02:00:51 -0500 |
Author: vmy
Date: 2006-11-13 02:00:51 -0500 (Mon, 13 Nov 2006)
New Revision: 121
Modified:
trunk/skorpion/ParticleSystem.cs
trunk/skorpion/skorpion.cs
Log:
a crude engine animation uses ParticleSystems new mode
Modified: trunk/skorpion/ParticleSystem.cs
===================================================================
--- trunk/skorpion/ParticleSystem.cs 2006-11-13 04:15:50 UTC (rev 120)
+++ trunk/skorpion/ParticleSystem.cs 2006-11-13 07:00:51 UTC (rev 121)
@@ -8,6 +8,8 @@
{
public class ParticleSystem
{
+ public enum Mode {ballFountain, engineThrob};
+
public struct PointVertex
{
public Vector3 v;
@@ -33,7 +35,8 @@
private float _time;
private int _particleCount;
-
+ private Mode _mode;
+
private float _radius;
public float Radius
{
@@ -70,8 +73,9 @@
private VertexBuffer _vertexBuffer = null;
- public ParticleSystem(int numFlush, int numDiscard)
+ public ParticleSystem(Mode mode, int numFlush, int numDiscard)
{
+ _mode = mode;
_time = 0.0f; // elapsed
since system initialization
_particleCount = 0; // currently in
scene
_radius = 1; // unknown
@@ -113,151 +117,206 @@
{
_time += fSecsPerFrame;
- for(int ii = _particlesList.Count-1; ii >= 0; ii--)
+ switch(_mode)
{
- Particle p = (Particle)_particlesList[ii];
+ 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;
+ // Calculate new position
+ float fT = _time -
p.creationTime;
+ float fGravity;
- if (p.isSpark)
- {
- fGravity = -5.0f;
- p.fadeProgression -= (fSecsPerFrame *
2.25f);
- }
- else
- {
- fGravity = -9.8f;
- p.fadeProgression -= fSecsPerFrame *
0.25f;
- }
+ 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;
+ 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;
+ if (p.fadeProgression < 0.0f)
+ p.fadeProgression =
0.0f;
- // remove particles that are too far from their
emitter
-#if false
- //if(p.positionVector.Length() > 180)
- if(fT > 10 || fT < .01)
- {
- freeParticles.Add(p);
- particlesList.RemoveAt(ii);
+ // 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 (!p.isSpark)
- particles--;
- }
- else
- particlesList[ii] = p;
-#endif
+ if
(_freeParticles.Count > 0)
+ {
+
spark = (Particle)_freeParticles[0];
+
_freeParticles.RemoveAt(0);
+ }
+ else
+ {
+
spark = new Particle();
+ }
- // remove particles... or if they are a spark
that has faded
-#if true
- // Kill old particles
- 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;
+
spark.isSpark = true;
+
spark.initialVelocity = new Vector3();
+
spark.initialPosition = p.positionVector;
+
spark.initialPosition.Y = _radius - 100;
- if
(_freeParticles.Count > 0)
- {
- spark =
(Particle)_freeParticles[0];
-
_freeParticles.RemoveAt(0);
- }
- else
- {
- spark = new
Particle();
- }
+ 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.isSpark = true;
- spark.initialVelocity =
new Vector3();
- spark.initialPosition
= p.positionVector;
- spark.initialPosition.Y
= _radius - 100;
+
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;
- 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.positionVector = spark.initialPosition;
+
spark.velocityVector = spark.initialVelocity;
- 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.diffuseColor = ColorOperator.Lerp(p.fadeColor, p.diffuseColor,
p.fadeProgression);
+
spark.fadeColor = System.Drawing.Color.Black;
+
spark.fadeProgression = 1.0f;
+
spark.creationTime = _time;
- spark.positionVector =
spark.initialPosition;
- spark.velocityVector =
spark.initialVelocity;
+
_particlesList.Add(spark);
+ }
+ }
- spark.diffuseColor =
ColorOperator.Lerp(p.fadeColor, p.diffuseColor, p.fadeProgression);
- spark.fadeColor =
System.Drawing.Color.Black;
- spark.fadeProgression
= 1.0f;
- spark.creationTime =
_time;
+ // Kill particle
+ _freeParticles.Add(p);
+
_particlesList.RemoveAt(ii);
-
_particlesList.Add(spark);
- }
+ if (!p.isSpark)
+
_particleCount--;
+ }
+ else
+ _particlesList[ii] = p;
}
- // Kill particle
- _freeParticles.Add(p);
- _particlesList.RemoveAt(ii);
+ // emit NumParticlesToEmit new
particles, but dont exceed _particlesLimit
+ int particlesEmit = _particleCount +
_numParticlesToEmit;
+ while(_particleCount < _particlesLimit
&& _particleCount < particlesEmit)
+ {
+ Particle particle;
- if (!p.isSpark)
- _particleCount--;
- }
- else
- _particlesList[ii] = p;
-#endif
- }
+ if (_freeParticles.Count > 0)
+ {
+ particle =
(Particle)_freeParticles[0];
+
_freeParticles.RemoveAt(0);
+ }
+ else
+ {
+ particle = new
Particle();
+ }
- // emit NumParticlesToEmit new particles, but dont
exceed _particlesLimit
- int particlesEmit = _particleCount +
_numParticlesToEmit;
- while(_particleCount < _particlesLimit &&
_particleCount < particlesEmit)
- {
- Particle 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;
- if (_freeParticles.Count > 0)
- {
- particle = (Particle)_freeParticles[0];
- _freeParticles.RemoveAt(0);
+ 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;
}
- else
+ case Mode.engineThrob:
{
- particle = new Particle();
- }
+ for(int ii = _particlesList.Count-1; ii
>= 0; ii--)
+ {
+ Particle p =
(Particle)_particlesList[ii];
+
+ // Calculate new position
+ float fRand =
((float)_rand.Next(int.MaxValue)/(float)int.MaxValue) * 1.1f;
+ p.positionVector =
p.initialPosition; // should be random
+ p.positionVector.Scale(fRand);
+
+ if (p.fadeProgression < 0.0f)
+ p.fadeProgression =
0.0f;
- // 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;
+ // remove particles if they
time out
+ _particlesList[ii] = p;
+ }
+
+ // emit NumParticlesToEmit new
particles, but dont exceed _particlesLimit
+ int particlesEmit = _particleCount +
_numParticlesToEmit;
+ while(_particleCount < _particlesLimit
&& _particleCount < particlesEmit)
+ {
+ Particle particle;
- particle.isSpark = false;
+ if (_freeParticles.Count > 0)
+ {
+ particle =
(Particle)_freeParticles[0];
+
_freeParticles.RemoveAt(0);
+ }
+ else
+ {
+ particle = new
Particle();
+ }
- particle.initialPosition = vPosition + new
Vector3(0.0f, _radius, 0.0f);
+ // 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.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.isSpark = false;
- //particle.initialVelocity.Scale(-10);
+ particle.initialPosition =
vPosition + new Vector3(_radius, 0.0f, 0.0f);
- particle.positionVector =
particle.initialPosition;
- particle.velocityVector =
particle.initialVelocity;
+ 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.diffuseColor = clrEmitColor;
- particle.fadeColor = clrFadeColor;
- particle.fadeProgression = 1.0f;
- particle.creationTime = _time;
+
//particle.initialVelocity.Scale(-10);
- _particlesList.Add(particle);
- _particleCount++;
+ 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;
+ }
}
}
@@ -266,7 +325,16 @@
// Set the render states for using point sprites
dev.RenderState.PointSpriteEnable = true;
dev.RenderState.PointScaleEnable = true ;
- dev.RenderState.PointSize = 0.8f; //0.08f;
+ switch(_mode)
+ {
+ case Mode.ballFountain:
+ dev.RenderState.PointSize = 0.8f;
//0.08f;
+ break;
+ case Mode.engineThrob:
+ dev.RenderState.PointSize = 8f; //0.08f;
+ break;
+ }
+
dev.RenderState.PointSizeMin = 0.00f;
dev.RenderState.PointScaleA = 0.00f;
dev.RenderState.PointScaleB = 0.00f;
Modified: trunk/skorpion/skorpion.cs
===================================================================
--- trunk/skorpion/skorpion.cs 2006-11-13 04:15:50 UTC (rev 120)
+++ trunk/skorpion/skorpion.cs 2006-11-13 07:00:51 UTC (rev 121)
@@ -119,11 +119,15 @@
Hashtable iAssets = null;
+ public enum ParticleColors { White, Red, Green, Blue,
NumColors};
+ // thrusters make fire
+ ParticleSystem iThrusterParticleSystem = null;
+ Texture iThrusterParticleTexture = null;
+ ParticleColors iThrusterParticleColor = ParticleColors.Green;
+
// ball is on fire
ParticleSystem iBallParticleSystem = null;
Texture iBallParticleTexture = null;
- int iBallNumberParticlesToEmit =
1;
- public enum ParticleColors { White, Red, Green, Blue,
NumColors};
ParticleColors iBallParticleColor = ParticleColors.White;
public System.Drawing.Color[] g_clrColor =
{
@@ -261,8 +265,27 @@
{
// ship text
+ // thrusters
+ iThrusterParticleSystem = new
ParticleSystem(ParticleSystem.Mode.engineThrob, 512, 2048);
+ iThrusterParticleSystem.Radius = 3;
+ iThrusterParticleSystem.ParticlesLimit = 4;
+ iThrusterParticleSystem.NumParticlesToEmit = 1;
+ iThrusterParticleSystem.EmitVelocity = 1;
+ iThrusterParticleTexture = TextureLoader.FromFile(
iDevice,
+ System.IO.Directory.GetCurrentDirectory() +
"\\assets\\Particle.bmp",
+ D3DX.Default,
+ D3DX.Default,
+ D3DX.Default,
+ 0,
+ Format.Unknown,
+ Pool.Managed,
+ Filter.Triangle|Filter.Mirror,
+ Filter.Triangle|Filter.Mirror,
+ 0);
+ iThrusterParticleSystem.RestoreDeviceObjects(iDevice);
+
// particles
- iBallParticleSystem = new ParticleSystem(512, 2048);
+ iBallParticleSystem = new
ParticleSystem(ParticleSystem.Mode.ballFountain, 512, 2048);
iBallParticleSystem.Radius = 3; //0.03f;
iBallParticleSystem.ParticlesLimit = 1024;
iBallParticleSystem.NumParticlesToEmit = 1;
@@ -523,6 +546,28 @@
iDevice.RenderState.Lighting = true;
iDevice.RenderState.ZBufferEnable = true;
+ // draw pulsating thruster on ship
+ foreach(Entity e2 in
GlobalState.Client.ThisFrame.Values)
+ //foreach(Entity e in
(Entity)GlobalState.Client.Universe.Entities[2])
+ {
+ if (e2.Type == Ship.TYPE)
+ {
+ iDevice.Transform.World =
Matrix.Translation(e2.Position.X, e2.Position.Y, e2.Position.Z);
+ iThrusterParticleSystem.Update(.03F,
+
g_clrColor[(int)iThrusterParticleColor],
+
g_clrColorFade[(int)iThrusterParticleColor],
+ new Vector3(0f, 0f, 0f), new
Vector3(0f, 0f, .1f));
+ iDevice.RenderState.ZBufferWriteEnable
= false;
+ iDevice.RenderState.AlphaBlendEnable =
true;
+ iDevice.RenderState.SourceBlend =
Blend.One;
+ iDevice.RenderState.DestinationBlend =
Blend.One;
+ iDevice.SetTexture(0,
iThrusterParticleTexture);
+ iThrusterParticleSystem.Render(iDevice);
+ iDevice.RenderState.ZBufferWriteEnable
= true;
+ iDevice.RenderState.AlphaBlendEnable =
false;
+ }
+ }
+
// draw sparks erupting from the ball
foreach(Entity e2 in
GlobalState.Client.ThisFrame.Values)
//foreach(Entity e in
(Entity)GlobalState.Client.Universe.Entities[2])
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [cinvoke-svn] r121 - trunk/skorpion,
will <=