internal virtual void InitializeBolt(LightningBolt inBolt) { Vector3 source = FXSource.GameObj.Transform.Pos + FXSource.GetPoint(FrozenCore.FastRandom); Vector3 target = FXTarget.GameObj.Transform.Pos + FXTarget.GetPoint(FrozenCore.FastRandom); inBolt.SetData(Sway, _jaggedness, source, target, Color, Thickness, BoltLifeTime); }
void ICmpRenderer.Draw(IDrawDevice device) { if (_inEditor) { if (FXSource != null && FXTarget != null) { Canvas c = new Canvas(device); FXSource.DrawInEditor(c); FXTarget.DrawInEditor(c); Vector3 src = FXSource.GameObj.Transform.Pos; Vector3 tar = FXTarget.GameObj.Transform.Pos; c.PushState(); Vector3 line = tar - src; Vector2 normal = line.Xy.PerpendicularLeft; Vector3 p1 = line * 0.33f; Vector3 p2 = line * 0.33f; Vector3 p3 = line * 0.67f; Vector3 p4 = line * 0.67f; p1 += src + new Vector3(normal * .04f, p1.Z); p2 += src + new Vector3(normal * -.02f, p2.Z); p3 += src + new Vector3(normal * .02f, p3.Z); p4 += src + new Vector3(normal * -.04f, p4.Z); c.State.ColorTint = Colors.Pink; c.DrawLine(src.X, src.Y, src.Z, p1.X, p1.Y, p1.Z); c.DrawLine(p1.X, p1.Y, p1.Z, p2.X, p2.Y, p2.Z); c.DrawLine(p2.X, p2.Y, p2.Z, p3.X, p3.Y, p3.Z); c.DrawLine(p3.X, p3.Y, p3.Z, p4.X, p4.Y, p4.Z); c.DrawLine(p4.X, p4.Y, p4.Z, tar.X, tar.Y, tar.Z); c.PopState(); } } else { foreach (LightningBolt bolt in _bolts) { if (bolt.IsAlive) { if (!bolt.BatchInfos.ContainsKey(device) || !bolt.BatchInfos[device].IsReady) { bolt.PrepareTextureForDrawDevice(device); } LightningBolt.BoltData bd = bolt.BatchInfos[device]; float scaleAtStart = device.GetScaleAtZ(FXSource.GameObj.Transform.Pos.Z); float scaleAtEnd = device.GetScaleAtZ(FXTarget.GameObj.Transform.Pos.Z); Vector2 axis = (bd.End - bd.Start).Xy; Vector2 normal = axis.PerpendicularLeft.Normalized; VertexC1P3T2[] v = new VertexC1P3T2[4]; v[0] = new VertexC1P3T2(); v[0].Pos = bd.Start - new Vector3(normal * Sway * scaleAtStart, 0); v[0].TexCoord = new Vector2(0, 0); v[0].Color = bolt.CurrentColor; v[1] = new VertexC1P3T2(); v[1].Pos = bd.Start + new Vector3(normal * Sway * scaleAtStart, 0); v[1].TexCoord = new Vector2(0, 1); v[1].Color = bolt.CurrentColor; v[2] = new VertexC1P3T2(); v[2].Pos = bd.End + new Vector3(normal * Sway * scaleAtEnd, 0); v[2].TexCoord = new Vector2(1, 1); v[2].Color = bolt.CurrentColor; v[3] = new VertexC1P3T2(); v[3].Pos = bd.End - new Vector3(normal * Sway * scaleAtEnd, 0); v[3].TexCoord = new Vector2(1, 0); v[3].Color = bolt.CurrentColor; device.AddVertices(bd.BatchInfo, VertexMode.Quads, v); } } } }