using System.Numerics; using Raylib_cs; namespace Smoll.Ex2 { class ArrowComponent : Smoll.Component { Complex offset; public Complex rawValue; Transform2DComponent? ownerTransform; public ArrowComponent(int offset_x = 0, int offset_y = 0) { this.offset = offset_x + Complex.ImaginaryOne*offset_y; } public override void OnAttached() { ownerTransform = owner.GetComponent(); } public Complex Origin() { ownerTransform ??= owner.GetComponent(); ownerTransform ??= new Transform2DComponent(); var tr = ownerTransform.AbsoluteTransform(); return tr.position + offset*Complex.Exp(Complex.ImaginaryOne * tr.angle) * tr.scale; } public Complex Vector() { ownerTransform ??= owner.GetComponent(); ownerTransform ??= new Transform2DComponent(); var tr = ownerTransform.AbsoluteTransform(); return rawValue*Complex.Exp(Complex.ImaginaryOne * tr.angle) * tr.scale; } public Tuple OriginAndVector() { ownerTransform ??= owner.GetComponent(); ownerTransform ??= new Transform2DComponent(); var tr = ownerTransform.AbsoluteTransform(); return Tuple.Create(tr.position + offset*Complex.Exp(Complex.ImaginaryOne * tr.angle) * tr.scale, rawValue*Complex.Exp(Complex.ImaginaryOne * tr.angle) * tr.scale); } public override void Draw(Smoll.Layer.DrawMode drawMode) { if(drawMode == Layer.DrawMode.Debug) { var data = OriginAndVector(); Complex start = data.Item1; Complex end = data.Item1 + data.Item2; Raylib.DrawLineEx(new Vector2((float)start.Real, (float)start.Imaginary),new Vector2((float)end.Real, (float)end.Imaginary),2f, Color.Red); } } } }