public static void CreateLightning(BoltArgs a, ref LightningData data, Random r)
        {
            // Find Displacement
            Vector2 d = a.End - a.Start;
            float dist = d.Length();
            d /= dist;
            Vector2 n = new Vector2(-d.Y, d.X);

            // Get Range Of Lightning Displacements
            float range = a.LineMaxLength - a.LineMinLength;

            // Add Startpoint
            data.Lines.Add(a.Start);

            // Add Jags
            while(dist > a.LineMaxLength) {
                float disp = (float)r.NextDouble() * range + a.LineMinLength;
                a.Start += disp * d;
                dist -= disp;
                Vector2 nl = a.Start + ((float)r.NextDouble() * 2 - 1) * a.JagDisplacement * n;
                data.Lines.Add(nl);
                data.Lines.Add(nl);
            }

            // Add Endpoint
            data.Lines.Add(a.End);
        }
Пример #2
0
        public static void CreateLightning(BoltArgs a, ref LightningData data, Random r)
        {
            // Find Displacement
            Vector2 d    = a.End - a.Start;
            float   dist = d.Length();

            d /= dist;
            Vector2 n = new Vector2(-d.Y, d.X);

            // Get Range Of Lightning Displacements
            float range = a.LineMaxLength - a.LineMinLength;

            // Add Startpoint
            data.Lines.Add(a.Start);

            // Add Jags
            while (dist > a.LineMaxLength)
            {
                float disp = (float)r.NextDouble() * range + a.LineMinLength;
                a.Start += disp * d;
                dist    -= disp;
                Vector2 nl = a.Start + ((float)r.NextDouble() * 2 - 1) * a.JagDisplacement * n;
                data.Lines.Add(nl);
                data.Lines.Add(nl);
            }

            // Add Endpoint
            data.Lines.Add(a.End);
        }
Пример #3
0
 public BranchArgs(BoltArgs a, float slope, Vector2 minB, Vector2 maxB)
 {
     Start           = a.Start;
     End             = a.End;
     JagDisplacement = a.JagDisplacement;
     LineMinLength   = a.LineMinLength;
     LineMaxLength   = a.LineMaxLength;
     BranchSlope     = slope;
     MinBounds       = minB;
     MaxBounds       = maxB;
     Color           = a.Color;
 }
 public BranchArgs(BoltArgs a, float slope, Vector2 minB, Vector2 maxB)
 {
     Start = a.Start;
     End = a.End;
     JagDisplacement = a.JagDisplacement;
     LineMinLength = a.LineMinLength;
     LineMaxLength = a.LineMaxLength;
     BranchSlope = slope;
     MinBounds = minB;
     MaxBounds = maxB;
     Color = a.Color;
 }