Пример #1
0
        public void AffectRotation(ParticleForce force, float ratio, CPos origin)
        {
            var random = ParticleUtils.Random;

            var angle = Angle.Cast((origin - Position).FlatAngle - Rotation.CastToAngleRange().Z);

            var zFloat = 0f;

            switch (force.Type)
            {
            case ParticleForceType.FORCE:
                zFloat = Math.Sign(-angle) * force.Strength * ratio * 0.1f;
                zFloat = Math.Min(0.628f, zFloat);
                break;

            case ParticleForceType.TURBULENCE:
                angle  = Angle.RandomAngle(random);
                zFloat = Math.Sign(-angle) * force.Strength * ratio * 0.1f;
                zFloat = Math.Min(0.628f, zFloat);
                break;

            case ParticleForceType.DRAG:
                zFloat = -force.Strength * ratio * rotate_velocity.Z * 0.1f;
                if (Math.Abs(zFloat) > Math.Abs(rotate_velocity.Z))
                {
                    zFloat = -rotate_velocity.Z * ratio;
                }
                break;

            case ParticleForceType.VORTEX:
                zFloat = Math.Sign(-angle - MathF.PI / 2) * force.Strength * 0.1f;
                zFloat = Math.Min(0.628f, zFloat);
                break;
            }

            rotate_velocity = new VAngle(0, 0, zFloat);
        }
Пример #2
0
        public void AffectVelocity(ParticleForce force, float ratio, CPos origin, int originHeight)
        {
            var random = ParticleUtils.Random;

            var useZ    = force.UseHeight && Height != originHeight;
            var zinvert = Height > originHeight;

            var angle  = (Position - origin).FlatAngle;
            var xFloat = 0f;
            var yFloat = 0f;
            var zFloat = 0f;

            switch (force.Type)
            {
            case ParticleForceType.FORCE:
                xFloat = (force.Strength * MathF.Cos(angle)) * ratio;
                yFloat = (force.Strength * MathF.Sin(angle)) * ratio;
                if (useZ)
                {
                    zFloat = (zinvert ? -1 : 1) * force.Strength * ratio;
                }
                break;

            case ParticleForceType.TURBULENCE:
                angle  = Angle.RandomAngle(random);
                xFloat = (force.Strength * MathF.Cos(angle)) * ratio;
                yFloat = (force.Strength * MathF.Sin(angle)) * ratio;
                if (useZ)
                {
                    zFloat = (zinvert ? -1 : 1) * ((float)random.NextDouble() - 0.5f) * force.Strength * ratio;
                }
                break;

            case ParticleForceType.DRAG:
                xFloat = -force.Strength * ratio * velocity.X / 256;
                if (Math.Abs(xFloat) > Math.Abs(velocity.X))
                {
                    xFloat = -velocity.X * ratio;
                }

                yFloat = -force.Strength * ratio * velocity.Y / 256;
                if (Math.Abs(yFloat) > Math.Abs(velocity.Y))
                {
                    yFloat = -velocity.Y * ratio;
                }

                if (useZ)
                {
                    zFloat = force.Strength * ratio * velocity.Z / 256;
                    if (Math.Abs(zFloat) > Math.Abs(velocity.Z))
                    {
                        zFloat = -velocity.Z * ratio;
                    }
                }
                break;

            case ParticleForceType.VORTEX:
                angle -= MathF.PI / 2;                         // Rotate 90°
                xFloat = (force.Strength * MathF.Cos(angle)) * ratio;
                yFloat = (force.Strength * MathF.Sin(angle)) * ratio;
                zFloat = 0;                         // Vortex is only 2D
                break;
            }

            xFloat += velocity_left.X;
            yFloat += velocity_left.Y;
            zFloat += velocity_left.Z;

            var x = (int)Math.Round(xFloat);
            var y = (int)Math.Round(yFloat);
            var z = (int)Math.Round(zFloat);

            velocity_left = new Vector(xFloat - x, yFloat - y, zFloat - z);
            velocity     += new CPos(x, y, z);
        }