/// <summary>
        /// Updates the projectile.
        /// </summary>
        public bool Update(TimeEntity timeEntity)
        {
            elapsedTime = (float)timeEntity.ElapsedTime.TotalSeconds;

            // Simple projectile physics.
            position += velocity * elapsedTime;
            velocity.Y -= elapsedTime * gravity;
            age += elapsedTime;

            // Update the particle emitter, which will create our particle trail.
            trailEmitter.Update(timeEntity, position);

            // If enough time has passed, explode! Note how we pass our velocity
            // in to the AddParticle method: this lets the explosion be influenced
            // by the speed and direction of the projectile which created it.
            if (age > projectileLifespan)
            {
                for (int i = 0; i < numExplosionParticles; i++)
                    explosionParticles.QuerieNewParticle(position, velocity);

                for (int i = 0; i < numExplosionSmokeParticles; i++)
                    explosionSmokeParticles.QuerieNewParticle(position, velocity);

                return false;
            }

            return true;
        }
 private void MainLoop()
 {
     long newTime = stopwatch.ElapsedTicks;
     delta = newTime - currentTimeEntity.TotalTime.Ticks;
     currentTimeEntity = new TimeEntity(TimeSpan.FromTicks(delta), TimeSpan.FromTicks(newTime));
     RaiseUpdate(new TimedEventArgs { TimeEntity = currentTimeEntity });
     Dispatcher.CurrentDispatcher.BeginInvoke(new EmptyEventHandler(MainLoop), DispatcherPriority.ApplicationIdle, null);
 }
        private void MainLoop()
        {
            long newTime = stopwatch.ElapsedTicks;

            delta             = newTime - currentTimeEntity.TotalTime.Ticks;
            currentTimeEntity = new TimeEntity(TimeSpan.FromTicks(delta), TimeSpan.FromTicks(newTime));
            RaiseUpdate(new TimedEventArgs {
                TimeEntity = currentTimeEntity
            });
            Dispatcher.CurrentDispatcher.BeginInvoke(new EmptyEventHandler(MainLoop), DispatcherPriority.ApplicationIdle, null);
        }
 public override void Update(Microsoft.Research.Visualization3D.MainLoops.TimeEntity timeEntity)
 {
     for (int i = 0; i < numProjectiles; i++)
     {
         if (!projectiles[i].Update(timeEntity))
         {
             projectiles[i] = new Projectile(
                 explosionParticleSystem,
                 smokeParticleSystem,
                 projectileParticleSystem,
                 GeneratePosition(),
                 (float)r.NextDouble());
         }
     }
     this.projectileParticleSystem.Update(timeEntity);
     this.explosionParticleSystem.Update(timeEntity);
     this.smokeParticleSystem.Update(timeEntity);
 }
        /// <summary>
        /// Updates the emitter, creating the appropriate number of particles
        /// in the appropriate positions.
        /// </summary>
        public void Update(TimeEntity timeEntity, Vector3 newPosition)
        {
            // Work out how much time has passed since the previous update.
            elapsedTime = (float)timeEntity.ElapsedTime.TotalSeconds;

            if (elapsedTime > 0)
            {
                // Work out how fast we are moving.
                Vector3 velocity = (newPosition - previousPosition) / elapsedTime;

                // If we had any time left over that we didn't use during the
                // previous update, add that to the current elapsed time.
                float timeToSpend = timeLeftOver + elapsedTime;

                // Counter for looping over the time interval.
                float currentTime = -timeLeftOver;

                // Create particles as long as we have a big enough time interval.
                while (timeToSpend > timeBetweenParticles)
                {
                    currentTime += timeBetweenParticles;
                    timeToSpend -= timeBetweenParticles;

                    // Work out the optimal position for this particle. This will produce
                    // evenly spaced particles regardless of the object speed, particle
                    // creation frequency, or game update rate.
                    float mu = currentTime / elapsedTime;

                    Vector3 position = Vector3.Lerp(previousPosition, newPosition, mu);

                    // Create the particle.
                    particleSystem.QuerieNewParticle(position, velocity * 5);
                }

                // Store any time we didn't use, so it can be part of the next update.
                timeLeftOver = timeToSpend;
            }

            previousPosition = newPosition;
        }
        public override void Draw(TimeEntity timeEntity)
        {
            if (particlesList.Count > 0)
            {
                SetupDevice();

                // Set the particle vertex buffer and vertex declaration.
                device.SetStreamSource(0, vertexBuffer, 0, ParticleVertex.SizeInBytes);
                device.VertexFormat = ParticleVertex.Format;


                // Activate the particle effect.
                int numPasses = effect.Begin();

                for (int i = 0; i < numPasses; i++)
                {
                    effect.BeginPass(i);

                    device.DrawPrimitives(PrimitiveType.PointList, 0, particlesList.Count);

                    effect.EndPass();
                }



                effect.End();

                // Reset a couple of the more unusual renderstates that we changed,
                // so as not to mess up any other subsequent drawing.
                device.SetRenderState(RenderState.AlphaFunc, Compare.Always);
                device.SetRenderState(RenderState.PointSpriteEnable, false);
                device.SetRenderState(RenderState.ZWriteEnable, true);
            }

            drawCounter++;
        }
 public TimeManager()
 {
     currentTimeEntity = new TimeEntity(TimeSpan.FromMilliseconds(0), TimeSpan.FromMilliseconds(0));
 }
 public override void Draw(TimeEntity timeEntity)
 {
     this.projectileParticleSystem.Draw(timeEntity);
     this.explosionParticleSystem.Draw(timeEntity);
     this.smokeParticleSystem.Draw(timeEntity);
 }
        private void DrawRayCasting(TimeEntity timeEntity)
        {
            effect.SetValue("g_ObjectToClip", world * camera.ViewMatrix * camera.ProjectionMatrix);
            effect.SetValue("g_ObjectToWorld", world);
            effect.SetValue("g_ObjectToView", world * camera.ViewMatrix);

            effect.SetValue("g_ViewToTex", Matrix.Invert(tex * world * camera.ViewMatrix));
            effect.SetValue("g_SamplingParams", new Vector4(intensitiveInterval, intensitiveScale, (float)1.0f / camera.ProjectionMatrix.M11, (float)1.0f / camera.ProjectionMatrix.M22));
            effect.SetValue("g_TextureSize", new Vector4(textureSizeX, textureSizeY, textureSizeZ, 0));
            effect.SetValue("g_TexCoordOffset", new Vector4((float)timeEntity.TotalTime.TotalMilliseconds * 0.002f, (float)timeEntity.TotalTime.TotalMilliseconds * 0.001f, densityMod, 0));
            effect.SetValue("denValueRange", new Vector4((CurrentValue - dataSource.Minimum) / (dataSource.Maximum - dataSource.Minimum), 0, 0, step));
            effect.SetValue("EnableSlicing", EnableSlicing);

            Vector4 pixelOffset = new Vector4(0.5f / resolutionX, -0.5f / resolutionY, 0f, 0f);
            pixelOffset *= (float)volumeShorterring;

            effect.SetValue("g_PixelOffset", pixelOffset);
            effect.SetTexture(new EffectHandle("g_EmiAbsTexture"), texture);
            effect.SetTexture(new EffectHandle("g_DensityModTexture"), denModTex);
            effect.SetTexture(new EffectHandle("g_DepthBufferTexture"), solidDepthRT);
            effect.SetTexture(new EffectHandle("g_EmiAbsAccuBufferTexture"), volumeAccuRT);
            effect.SetTexture(new EffectHandle("g_EmiAbsDepthBufferTexture"), volumeDepthRT);

            device.VertexFormat = VertexFormat.Position;
            int numPasses = effect.Begin();
            for (int i = 0; i < numPasses; i++)
            {
                effect.BeginPass(i);
                device.SetStreamSource(0, cube, 0, Vertex.SizeInBytes);
                device.Indices = cubeIndices;
                device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, 8, 0, 12);
                effect.EndPass();
            }
            effect.End();

        }
 public override void Update(TimeEntity timeEntity)
 {
     //Nothing to do here
 }
 public abstract void Update(TimeEntity timeEntity);
 public abstract void Draw(TimeEntity timeEntity);
 public TimeManager()
 {
     currentTimeEntity = new TimeEntity(TimeSpan.FromMilliseconds(0), TimeSpan.FromMilliseconds(0));
 }
Exemple #14
0
 public override void Draw(TimeEntity timeEntity)
 {
     if (primitiveCount > 0)
     {
         effect.Technique = new EffectHandle("PerPixelDiffuseAndPhongMetaball");
         device.SetStreamSource(0, vb, 0, MetaballVertex.SizeInBytes);
         device.VertexFormat = MetaballVertex.Format;
         int passes = effect.Begin();
         for (int i = 0; i < passes; i++)
         {
             effect.BeginPass(i);
             device.DrawPrimitives(PrimitiveType.TriangleList, 0, primitiveCount);
             effect.EndPass();
         }
         effect.End();
     }
 }
        public override void Draw(TimeEntity timeEntity)
        {
            device.SetRenderTarget(0, solidDepthSurface);
            ClearRenderTarget(new Vector4(1000, 0, 0, 0));

            

            device.SetRenderTarget(0, volumeDepthSurface);
            ClearRenderTarget(new Vector4(camera.NearPlane, 0, 0, 0));
            effect.Technique = new EffectHandle("Depth");
            DrawRayCasting(timeEntity);

            device.SetRenderTarget(0, volumeAccuSurface);
            device.Clear(ClearFlags.Target, new Color4(1.0f, 0, 0, 0), 1.0f, 0);
            effect.Technique = new EffectHandle("EmiAbs_Accu");
            DrawRayCasting(timeEntity);


            device.SetRenderTarget(0, backBufferSurface);
            effect.Technique = new EffectHandle("EmiAbs_Compose");
            DrawRayCasting(timeEntity);
        }
Exemple #16
0
        public override void Update(TimeEntity timeEntity)
        {
            effect.SetValue("world", Matrix.Identity);
            effect.SetValue("view", camera.ViewMatrix);
            effect.SetValue("projection", camera.ProjectionMatrix);

            effect.SetValue("cameraPosition", camera.Location);
            effect.SetValue("lightPosition", camera.Location);
        }
        public override void Update(TimeEntity timeEntity)
        {
            currentTime = (float)timeEntity.TotalTime.TotalMilliseconds / 10000.0f;

            //if (particlesList.Count > settings.MaxParticles)
            //    particlesList.Clear();

            int oldCount = particlesList.Count;
            for (int i = 0; i < oldCount; i++)
            {
                Vector3 newPosition = ComputeNewPosition(startPositions[i], particlesList[i].Velocity, (currentTime - times[i]) * (1 + settings.DurationRandomness));
                if (MathHelper.CheckPosition(newPosition, dataSource.DisplayData, dataSource.MissingValue) && (particlesList[i].Time < settings.Duration.TotalSeconds + times[i]))
                {
                    float value = MathHelper.GetValue(newPosition, dataSource.DisplayData, dataSource.MissingValue);
                    particlesList.Add(new ParticleVertex(newPosition, particlesList[i].Velocity, (int)RgbPalette.ColorARGB(RgbPalette.GetColor(value, dataSource.Maximum, dataSource.Minimum, dataSource.MissingValue)), particlesList[i].Time + (float)timeEntity.ElapsedTime.TotalSeconds));
                    startPositions.Add(startPositions[i]);
                    times.Add(times[i]);
                }
            }
            particlesList.RemoveRange(0, oldCount);
            startPositions.RemoveRange(0, oldCount);
            times.RemoveRange(0, oldCount);

            if (particlesList.Count > 0)
            {
                if (vertexBuffer != null)
                    vertexBuffer.Dispose();

                vertexBuffer = new VertexBuffer(device, ParticleVertex.SizeInBytes * Math.Max(10, particlesList.Count), Usage.WriteOnly | Usage.Points, ParticleVertex.Format, Pool.Default);
                
                using (DataStream ds = vertexBuffer.Lock(0, 0, LockFlags.None))
                {
                    ds.WriteRange(particlesList.ToArray());
                }
                vertexBuffer.Unlock();
            }

            effect.SetValue("View", camera.ViewMatrix);
            effect.SetValue("Projection", camera.ProjectionMatrix);

        }