using System.Numerics; namespace EvilEngine.GenerativeMotion; public static class TargetPlacement { private const int Joints = SomaSkeleton.JointCount; public static void Place(ReadOnlySpan window, int poses, GroundPoint goal, double turn, int anchor, UpAxis up, Span output) { var ground = new Ground(up); var rotation = ground.Rotation(turn); var shifted = ground.Point(ground.Turn(Ground.Of(window[anchor * Joints].Position), turn)); var shift = goal - shifted; window[..(poses * Joints)].CopyTo(output); for (var pose = 0; pose < poses; pose++) { var root = window[pose * Joints]; var position = ground.Turn(Ground.Of(root.Position), turn); var moved = ground.Compose( new GroundPoint(ground.Point(position).U + shift.U, ground.Point(position).V + shift.V), ground.Height(position)); var q = root.Rotation; var turned = (rotation * new DoubleQuat(q.X, q.Y, q.Z, q.W).Normalized()).Normalized(); output[pose * Joints] = new Rigid(new Vector3((float)moved.X, (float)moved.Y, (float)moved.Z), new Quaternion((float)turned.X, (float)turned.Y, (float)turned.Z, (float)turned.W)); } } }