private bool InitializeParticle(Particle p) { Color4 color; Matrix32 transform; CalcInitialColorAndTransform(out color, out transform); float emitterScaleAmount = 1; Vector2 emitterScale = new Vector2(); emitterScale.X = transform.U.Length; emitterScale.Y = transform.V.Length; float crossProduct = Vector2.CrossProduct(transform.U, transform.V); if (crossProduct < 0.0f) { emitterScale.Y = -emitterScale.Y; } emitterScaleAmount = Mathf.Sqrt(Math.Abs(crossProduct)); float emitterAngle = transform.U.Atan2Deg; NumericRange aspectRatioVariationPair = new NumericRange(0, Math.Max(0.0f, AspectRatio.Dispersion)); float zoom = Zoom.NormalRandomNumber(Rng); float aspectRatio = AspectRatio.Median * (1 + Math.Abs(aspectRatioVariationPair.NormalRandomNumber(Rng))) / (1 + Math.Abs(aspectRatioVariationPair.NormalRandomNumber(Rng))); p.TextureIndex = 0.0f; p.Velocity = Velocity.NormalRandomNumber(Rng) * emitterScaleAmount; p.ScaleInitial = emitterScale * ApplyAspectRatio(zoom, aspectRatio); p.ScaleCurrent = p.ScaleInitial; p.WindDirection = WindDirection.UniformRandomNumber(Rng); p.WindAmount = WindAmount.NormalRandomNumber(Rng) * emitterScaleAmount; p.GravityVelocity = 0.0f; p.GravityAcceleration = 0.0f; p.GravityAmount = GravityAmount.NormalRandomNumber(Rng) * emitterScaleAmount; p.GravityDirection = GravityDirection.NormalRandomNumber(Rng); p.MagnetAmountInitial = MagnetAmount.NormalRandomNumber(Rng); p.Lifetime = Math.Max(Lifetime.NormalRandomNumber(Rng), 0.1f); p.Age = 0.0f; p.AngularVelocity = AngularVelocity.NormalRandomNumber(Rng); p.Angle = Orientation.UniformRandomNumber(Rng) + emitterAngle; p.Spin = Spin.NormalRandomNumber(Rng); p.ColorInitial = color; p.ColorCurrent = color; p.RandomRayDirection = (new NumericRange(0, 360)).UniformRandomNumber(Rng); p.RandomSplineVertex0 = GenerateRandomMotionControlPoint(ref p.RandomRayDirection); p.RandomSplineVertex1 = Vector2.Zero; p.RandomSplineVertex2 = GenerateRandomMotionControlPoint(ref p.RandomRayDirection); p.RandomSplineVertex3 = GenerateRandomMotionControlPoint(ref p.RandomRayDirection); p.RandomMotionSpeed = RandomMotionSpeed.NormalRandomNumber(Rng); p.RandomSplineOffset = 0; Vector2 position; switch (Shape) { case EmitterShape.Point: position = 0.5f * Size; p.RegularDirection = Direction.UniformRandomNumber(Rng) + emitterAngle - 90.0f; break; case EmitterShape.Line: position = new Vector2(Rng.RandomFloat() * Size.X, Size.Y * 0.5f); p.RegularDirection = Direction.UniformRandomNumber(Rng) + emitterAngle - 90.0f; break; case EmitterShape.Ellipse: float angle = Rng.RandomFloat(0, 360); Vector2 sincos = Vector2.CosSinRough(angle * Mathf.DegToRad); position = 0.5f * ((sincos + Vector2.One) * Size); p.RegularDirection = Direction.UniformRandomNumber(Rng) + emitterAngle - 90 + angle; break; case EmitterShape.Area: position.X = Rng.RandomFloat() * Size.X; position.Y = Rng.RandomFloat() * Size.Y; p.RegularDirection = Direction.UniformRandomNumber(Rng) + emitterAngle - 90.0f; break; case EmitterShape.Custom: position = GetPointInCustomShape(); p.RegularDirection = Direction.UniformRandomNumber(Rng) + emitterAngle - 90.0f; break; default: throw new Lime.Exception("Invalid particle emitter shape"); } p.RegularPosition = transform.TransformVector(position); if (!TryGetRandomModifier(out p.Modifier)) { return(false); } var animationDuration = AnimationUtils.FramesToSeconds(p.Modifier.Animators.GetOverallDuration()); p.AgeToAnimationTime = (float)(animationDuration / p.Lifetime); if (EmissionType == EmissionType.Inner) { p.RegularDirection += 180; } else if ((EmissionType & EmissionType.Inner) != 0) { if (Rng.RandomInt(2) == 0) { p.RegularDirection += 180; } } else if (EmissionType == 0) { return(false); } p.FullDirection = p.RegularDirection; p.FullPosition = p.RegularPosition; return(true); }