Esempio n. 1
0
        public override void Update(GameTime gameTime)
        {
            if (InputService.IsPressed(MouseButtons.Left, true) || InputService.IsPressed(Buttons.RightTrigger, true, LogicalPlayerIndex.One))
            {
                var     cameraPose      = GraphicsScreen.CameraNode.PoseWorld;
                Vector3 cameraPosition  = cameraPose.Position;
                Vector3 cameraDirection = cameraPose.ToWorldDirection(Vector3.Forward);

                // Create a ray for picking.
                RayShape ray = new RayShape(cameraPosition, cameraDirection, 1000);

                // The ray should stop at the first hit. We only want the first object.
                ray.StopsAtFirstHit = true;

                // The collision detection requires a CollisionObject.
                CollisionObject rayCollisionObject = new CollisionObject(new GeometricObject(ray, Pose.Identity));

                // Get the first object that has contact with the ray.
                ContactSet contactSet = Simulation.CollisionDomain.GetContacts(rayCollisionObject).FirstOrDefault();
                if (contactSet != null && contactSet.Count > 0)
                {
                    // The ray has hit something.

                    // The contact set contains all detected contacts between the ray and the rigid body.
                    // Get the first contact in the contact set. (A ray hit usually contains exactly 1 contact.)
                    Contact contact     = contactSet[0];
                    var     hitPosition = contact.Position;
                    var     normal      = contact.Normal;
                    if (contactSet.ObjectA == rayCollisionObject)
                    {
                        normal = -normal;
                    }

                    // The particle parameter arrays are circular buffers. Get the particle array index
                    // where the next particle is created:
                    int particleIndex = (_decals.ParticleStartIndex + _decals.NumberOfActiveParticles) % _decals.MaxNumberOfParticles;

                    // Add 1 particle.
                    int numberOfCreatedParticles = _decals.AddParticles(1, null);
                    if (numberOfCreatedParticles > 0)
                    {
                        // We initialize the particle parameters Position, Normal and Axis manually using
                        // the results of the collision detection:
                        var positionParameter = _decals.Parameters.Get <Vector3>(ParticleParameterNames.Position);
                        positionParameter.Values[particleIndex] = hitPosition + normal * 0.01f; // We add a slight 1 cm offset to avoid z-fighting.

                        var normalParameter = _decals.Parameters.Get <Vector3>("Normal");
                        normalParameter.Values[particleIndex] = normal;

                        var axisParameter = _decals.Parameters.Get <Vector3>("Axis");
                        axisParameter.Values[particleIndex] = (normal == Vector3.Up) ? Vector3.Backward : Vector3.Up;
                    }
                }
            }

            // Synchronize particles <-> graphics.
            _particleSystemNode.Synchronize(GraphicsService);

            Profiler.AddValue("ParticleCount", ParticleHelper.CountNumberOfParticles(ParticleSystemService.ParticleSystems));
        }
Esempio n. 2
0
        public override void Update(GameTime gameTime)
        {
            // Synchronize particles <-> graphics.
            _particleSystemNode.Synchronize(GraphicsService);

            Profiler.AddValue("ParticleCount", ParticleHelper.CountNumberOfParticles(ParticleSystemService.ParticleSystems));
        }
Esempio n. 3
0
        public override void Update(GameTime gameTime)
        {
            // Move the particle system with the camera.
            _particleSystem.Pose = new Pose(GraphicsScreen.CameraNode.PoseWorld.Position);

            // Synchronize particles <-> graphics.
            _particleSystemNode.Synchronize(GraphicsService);

            Profiler.AddValue("ParticleCount", ParticleHelper.CountNumberOfParticles(ParticleSystemService.ParticleSystems));
        }
        public override void Update(GameTime gameTime)
        {
            // The bee swarm effect needs the CameraPose to determine the bee texture orientation.
            _beeSwarm.Parameters.Get <Pose>("CameraPose").DefaultValue = GraphicsScreen.CameraNode.PoseWorld;

            // Synchronize particles <-> graphics.
            _particleSystemNode.Synchronize(GraphicsService);

            Profiler.AddValue("ParticleCount", ParticleHelper.CountNumberOfParticles(ParticleSystemService.ParticleSystems));
        }
Esempio n. 5
0
        public override void Update(GameTime gameTime)
        {
            // Move the model and the particle system with the rigid body.
            _modelNode.PoseWorld = _rigidBody.Pose;
            _particleSystem.Pose = _rigidBody.Pose;

            // Synchronize particles <-> graphics.
            _particleSystemNode.Synchronize(GraphicsService);

            Profiler.AddValue("ParticleCount", ParticleHelper.CountNumberOfParticles(ParticleSystemService.ParticleSystems));
        }
Esempio n. 6
0
        public override void Update(GameTime gameTime)
        {
            if (InputService.IsDown(MouseButtons.Left) || InputService.IsDown(Buttons.RightTrigger, LogicalPlayerIndex.One))
            {
                _flameJet.AddParticles(6);
            }

            // Synchronize particles <-> graphics.
            _particleSystemNode.Synchronize(GraphicsService);

            Profiler.AddValue("ParticleCount", ParticleHelper.CountNumberOfParticles(ParticleSystemService.ParticleSystems));
        }
Esempio n. 7
0
        public bool Update(IGraphicsService graphicsService)
        {
            // The effect lasts for 3 seconds.
            if (ParticleSystem.Time >= TimeSpan.FromSeconds(3))
            {
                return(false);
            }

            // Synchronize particles <-> graphics.
            ParticleSystemNode.Synchronize(graphicsService);
            return(true);
        }
Esempio n. 8
0
        public override void Update(GameTime gameTime)
        {
            _graphicsScreen.DebugRenderer.Clear();

            // Synchronize particle data and graphics data.
            _particleCloud0.Synchronize(GraphicsService);
            _particleCloud1.Synchronize(GraphicsService);
            _particleCloud2.Synchronize(GraphicsService);

            // Update color of clouds.
            var cloudColor = (_dynamicSkyObject.AmbientLight + _dynamicSkyObject.SunLight) * 2;

            _particleCloud0.ParticleSystem.Parameters.Get <Vector3>(ParticleParameterNames.Color).DefaultValue = cloudColor;
            _particleCloud1.ParticleSystem.Parameters.Get <Vector3>(ParticleParameterNames.Color).DefaultValue = cloudColor;
            _particleCloud2.ParticleSystem.Parameters.Get <Vector3>(ParticleParameterNames.Color).DefaultValue = cloudColor;
        }
Esempio n. 9
0
        public override void Update(GameTime gameTime)
        {
            // If enough time has passed, trigger the explosion sound and the explosion effect.
            _timeUntilExplosion -= gameTime.ElapsedGameTime;
            if (_timeUntilExplosion <= TimeSpan.Zero)
            {
                _explosion.Explode();
                _explosionSound.Play(0.2f, 0, 0);
                _timeUntilExplosion = ExplosionInterval;
            }

            // Synchronize particles <-> graphics.
            _particleSystemNode.Synchronize(GraphicsService);

            Profiler.AddValue("ParticleCount", ParticleHelper.CountNumberOfParticles(ParticleSystemService.ParticleSystems));
        }
Esempio n. 10
0
        public override void Update(GameTime gameTime)
        {
            // Add 2 new particles in each frame.
            _particleSystem.AddParticles(2);

            // Particles are added and simulated when the particle system service is updated.
            // In this example the service is updated in Game1.Update(). The service is updated
            // after all GameComponents, before Game1.Draw().

            // The ParticleSystemNode needs to be synchronized with the ParticleSystem.
            // The Synchronize() method takes a snapshot of the current particles which
            // is then rendered by the graphics service.
            // (This explicit synchronization is necessary because the particle system
            // service and the graphics service may run in parallel on multiple threads.)
            _particleSystemNode.Synchronize(GraphicsService);

            Profiler.AddValue("ParticleCount", ParticleHelper.CountNumberOfParticles(ParticleSystemService.ParticleSystems));
        }
Esempio n. 11
0
        public override void Update(GameTime gameTime)
        {
            bool wasDepthSorted = _brownOut.IsDepthSorted;

            _brownOut.IsDepthSorted = !(InputService.IsDown(MouseButtons.Left) || InputService.IsDown(Buttons.RightTrigger, LogicalPlayerIndex.One));
            if (wasDepthSorted != _brownOut.IsDepthSorted)
            {
                // DigitalRune Graphics caches states like IsDepthSorted. To delete the cached data,
                // we can delete the current ParticleSystem.RenderData.
                _brownOut.RenderData = null;
                foreach (var child in _brownOut.Children)
                {
                    child.RenderData = null;
                }
            }

            // Synchronize particles <-> graphics.
            _particleSystemNode.Synchronize(GraphicsService);

            Profiler.AddValue("ParticleCount", ParticleHelper.CountNumberOfParticles(ParticleSystemService.ParticleSystems));
        }
Esempio n. 12
0
        public override void Update(GameTime gameTime)
        {
            // Toggle fire distortion.
            if (InputService.IsPressed(Keys.H, false))
            {
                bool isEnabled = _fireDistortionParticleSystemNode.IsEnabled;
                _fireDistortionParticleSystemNode.IsEnabled = !isEnabled;
                _fireDistortionParticleSystemNode.ParticleSystem.Enabled = !isEnabled;
            }

            // Trigger explosion.
            if (InputService.IsPressed(Keys.J, false))
            {
                _explosionDistortionParticleSystemNode.ParticleSystem.AddParticles(20);
            }

            // Trigger nova
            if (InputService.IsPressed(Keys.K, false))
            {
                _novaDistortionParticleSystemNode.ParticleSystem.AddParticles(40);
            }

            // Synchronize particle data and render data.
            _fireDistortionParticleSystemNode.Synchronize(GraphicsService);
            _explosionDistortionParticleSystemNode.Synchronize(GraphicsService);
            _novaDistortionParticleSystemNode.Synchronize(GraphicsService);

            var debugRenderer = _graphicsScreen.DebugRenderer;

            debugRenderer.Clear();

            //debugRenderer.DrawObject(_fireDistortionParticleSystemNode, Color.Red, true, false);
            //debugRenderer.DrawObject(_explosionDistortionParticleSystemNode, Color.Green, true, false);
            //debugRenderer.DrawObject(_novaDistortionParticleSystemNode, Color.Blue, true, false);

            // Draw distortion texture in lower right corner.
            int height = GraphicsService.GraphicsDevice.PresentationParameters.BackBufferHeight;

            debugRenderer.DrawTexture(_distortionFilter.DistortionTexture, new Rectangle(0, height - 200, 200, 200));
        }
Esempio n. 13
0
        // OnUpdate() is called once per frame.
        protected override void OnUpdate(TimeSpan deltaTime)
        {
            if (!IsEnabled)
            {
                return;
            }

            // Let the light flicker every ~0.1 seconds.
            _elapsed += (float)deltaTime.TotalSeconds;
            if (_elapsed > 0.1f)
            {
                var light = (PointLight)_light.Light;
                light.HdrScale = _random.NextFloat(16, 24);
                _elapsed       = 0;
            }

            // Synchronize particle data and render data. Needs to be called once per frame!
            // (The method basically takes a snapshot of the particle system, which is then
            // rendered in the current frame.)
            _fireParticles.Synchronize(_graphicsService);
            _smokeParticles.Synchronize(_graphicsService);
        }
Esempio n. 14
0
        public override void Update(GameTime gameTime)
        {
            // Update SceneNode.LastPoseWorld (required for optional effects, like motion blur).
            _meshNode0.SetLastPose(true);
            _meshNode1.SetLastPose(true);

            // Synchronize pose of rigid body and model.
            _meshNode0.PoseWorld = _rigidBody0.Pose;
            _meshNode1.PoseWorld = _rigidBody1.Pose;

            // The particle system nodes are attached to the mesh nodes. Their pose is
            // updated automatically.

            // _particleSystem0 is relative to world space, we need to update its
            // pose explicitly.
            _particleSystem0.Pose = _rigidBody0.Pose;

            // Synchronize particles <-> graphics.
            _particleSystemNode0.Synchronize(GraphicsService);
            _particleSystemNode1.Synchronize(GraphicsService);

            Profiler.AddValue("ParticleCount", ParticleHelper.CountNumberOfParticles(ParticleSystemService.ParticleSystems));
        }