private void Create(Vector2 start, Vector2 end)
        {
            var mainBolt = new LightningBolt(start, end);
            bolts.Add(mainBolt);

            int numBranches = rand.Next(3, 6);
            Vector2 diff = end - start;

            float[] branchPoints = Enumerable.Range(0, numBranches)
                .Select(x => Rand(0, 1f))
                .OrderBy(x => x).ToArray();

            for (int i = 0; i < branchPoints.Length; i++)
            {
                Vector2 boltStart = mainBolt.GetPoint(branchPoints[i]);
                Quaternion rot = Quaternion.CreateFromAxisAngle(Vector3.UnitZ, MathHelper.ToRadians(30 * ((i & 1) == 0 ? 1 : -1)));
                Vector2 boltEnd = Vector2.Transform(diff * (1 - branchPoints[i]), rot) + boltStart;
                bolts.Add(new LightningBolt(boltStart, boltEnd));
            }
        }
Beispiel #2
0
        private void Create(Vector2 start, Vector2 end)
        {
            var mainBolt = new LightningBolt(start, end);

            bolts.Add(mainBolt);

            int     numBranches = rand.Next(3, 6);
            Vector2 diff        = end - start;

            float[] branchPoints = Enumerable.Range(0, numBranches)
                                   .Select(x => Rand(0, 1f))
                                   .OrderBy(x => x).ToArray();

            for (int i = 0; i < branchPoints.Length; i++)
            {
                Vector2    boltStart = mainBolt.GetPoint(branchPoints[i]);
                Quaternion rot       = Quaternion.CreateFromAxisAngle(Vector3.UnitZ, MathHelper.ToRadians(30 * ((i & 1) == 0 ? 1 : -1)));
                Vector2    boltEnd   = Vector2.Transform(diff * (1 - branchPoints[i]), rot) + boltStart;
                bolts.Add(new LightningBolt(boltStart, boltEnd));
            }
        }