Exemplo n.º 1
0
        public void ZeroWidth()
        {
            var random = new Random(123456);
              var d = new BoxDistribution { MinValue = new Vector3F(1, 2, 3), MaxValue = new Vector3F(1, 2, 3) };

              Assert.AreEqual(new Vector3F(1, 2, 3), d.Next(random));
              Assert.AreEqual(new Vector3F(1, 2, 3), d.Next(random));
              Assert.AreEqual(new Vector3F(1, 2, 3), d.Next(random));
        }
Exemplo n.º 2
0
        public void ZeroWidth()
        {
            var random = new Random(123456);
            var d      = new BoxDistribution {
                MinValue = new Vector3(1, 2, 3), MaxValue = new Vector3(1, 2, 3)
            };

            Assert.AreEqual(new Vector3(1, 2, 3), d.Next(random));
            Assert.AreEqual(new Vector3(1, 2, 3), d.Next(random));
            Assert.AreEqual(new Vector3(1, 2, 3), d.Next(random));
        }
Exemplo n.º 3
0
        public void Values()
        {
            var random = new Random(123456);
            var d      = new BoxDistribution();

            for (int i = 0; i < 100; i++)
            {
                d.MinValue = RandomHelper.Random.NextVector3(-1, 1);
                d.MaxValue = RandomHelper.Random.NextVector3(-1, 1);

                var value = d.Next(random);

                Assert.IsTrue(d.MinValue.X <= value.X && value.X <= d.MaxValue.X || d.MaxValue.X <= value.X && value.X <= d.MinValue.X);
                Assert.IsTrue(d.MinValue.Y <= value.Y && value.Y <= d.MaxValue.Y || d.MaxValue.Y <= value.Y && value.Y <= d.MinValue.Y);
                Assert.IsTrue(d.MinValue.Z <= value.Z && value.Z <= d.MaxValue.Z || d.MaxValue.Z <= value.Z && value.Z <= d.MinValue.Z);
            }
        }
Exemplo n.º 4
0
        public void Values()
        {
            var random = new Random(123456);
              var d = new BoxDistribution();

              for (int i = 0; i < 100; i++)
              {
            d.MinValue = RandomHelper.Random.NextVector3F(-1, 1);
            d.MaxValue = RandomHelper.Random.NextVector3F(-1, 1);

            var value = d.Next(random);

            Assert.IsTrue(d.MinValue.X <= value.X && value.X <= d.MaxValue.X || d.MaxValue.X <= value.X && value.X <= d.MinValue.X);
            Assert.IsTrue(d.MinValue.Y <= value.Y && value.Y <= d.MaxValue.Y || d.MaxValue.Y <= value.Y && value.Y <= d.MinValue.Y);
            Assert.IsTrue(d.MinValue.Z <= value.Z && value.Z <= d.MaxValue.Z || d.MaxValue.Z <= value.Z && value.Z <= d.MinValue.Z);
              }
        }
Exemplo n.º 5
0
        public override void Update(GameTime gameTime)
        {
            _waitTime -= gameTime.ElapsedGameTime;

            if (_waitTime < TimeSpan.Zero)
            {
                // Time to start the next effect at a random position.
                var position = _boxDistribution.Next(RandomHelper.Random);

                // Create teleport effect (the effect comes from a resource pool).
                var teleport = _pool.Obtain();
                teleport.Initialize(ContentManager);
                teleport.Pose = new Pose(position);

                // Add the teleport effect to the particle system service and the scene.
                ParticleSystemService.ParticleSystems.Add(teleport.ParticleSystem);
                GraphicsScreen.Scene.Children.Add(teleport.ParticleSystemNode);
                _teleportEffects.Add(teleport);

                _waitTime = TimeSpan.FromSeconds(1);
            }

            // Update teleport effects and recycle them if they are dead.
            for (int i = _teleportEffects.Count - 1; i >= 0; i--)
            {
                var  teleport = _teleportEffects[i];
                bool isAlive  = teleport.Update(GraphicsService);
                if (!isAlive)
                {
                    ParticleSystemService.ParticleSystems.Remove(teleport.ParticleSystem);
                    GraphicsScreen.Scene.Children.Remove(teleport.ParticleSystemNode);
                    _teleportEffects.RemoveAt(i);

                    _pool.Recycle(teleport);
                }
            }

            Profiler.AddValue("ParticleCount", ParticleHelper.CountNumberOfParticles(ParticleSystemService.ParticleSystems));
        }
Exemplo n.º 6
0
        protected override void OnUpdateParticles(TimeSpan deltaTime, int startIndex, int count)
        {
            if (_positionParameter == null ||
                _targetPositionParameter == null ||
                _speedParameter == null ||
                _sizeXParameter == null)
            {
                return;
            }

            Vector3F[] positions       = _positionParameter.Values;
            Vector3F[] targetPositions = _targetPositionParameter.Values;
            float[]    speeds          = _speedParameter.Values;
            float[]    sizes           = _sizeXParameter.Values;
            Pose       cameraPose      = (_cameraPoseParameter != null) ? _cameraPoseParameter.DefaultValue : Pose.Identity;

            if (positions == null || targetPositions == null || speeds == null)
            {
                // This effector only works with varying parameters.
                return;
            }

            Random   random = ParticleSystem.Random;
            Vector3F center = ParticleSystem.Pose.Position;
            float    dt     = (float)deltaTime.TotalSeconds;

            for (int i = startIndex; i < startIndex + count; i++)
            {
                Vector3F targetPosition = targetPositions[i];
                Vector3F lineSegment    = targetPosition - positions[i];
                float    distance       = lineSegment.Length;
                if (Numeric.IsZero(distance))
                {
                    // The bee has reached the target position. Choose a new direction and distance.
                    Vector3F d = _distribution.Next(random);

                    // Keep the new target position within a certain range.
                    if (Math.Abs(targetPosition.X + d.X - center.X) > MaxRange)
                    {
                        d.X = -d.X;
                    }
                    if (Math.Abs(targetPosition.Y + d.Y - center.Y) > MaxRange)
                    {
                        d.Y = -d.Y;
                    }
                    if (Math.Abs(targetPosition.Z + d.Z - center.Z) > MaxRange)
                    {
                        d.Z = -d.Z;
                    }

                    targetPositions[i] = targetPosition + d;
                }
                else
                {
                    // Move bee towards target position.
                    Vector3F movementDirection = lineSegment / distance;
                    float    movementDistance  = speeds[i] * dt;
                    if (movementDistance > distance)
                    {
                        movementDistance = distance;
                    }

                    positions[i] += movementDirection * movementDistance;

                    // The bee should look in the direction it is flying. Transform the direction
                    // into the view space and check the sign of x-component.
                    movementDirection = cameraPose.ToLocalDirection(movementDirection);
                    float sign = (movementDirection.X >= 0) ? +1 : -1;
                    if (InvertLookDirection)
                    {
                        sign *= -1;
                    }

                    if (Math.Sign(sizes[i]) != (int)sign)
                    {
                        sizes[i] *= -1;
                    }
                }
            }
        }