0.2.0-dev Download ZIP
30 lines ·1.3 KB Raw
| 1 | using System.Numerics; |
| 2 | |
| 3 | namespace EvilEngine.GenerativeMotion; |
| 4 | |
| 5 | public static class TargetPlacement |
| 6 | { |
| 7 | private const int Joints = SomaSkeleton.JointCount; |
| 8 | |
| 9 | public static void Place(ReadOnlySpan<Rigid> window, int poses, GroundPoint goal, double turn, int anchor, |
| 10 | UpAxis up, Span<Rigid> output) |
| 11 | { |
| 12 | var ground = new Ground(up); |
| 13 | var rotation = ground.Rotation(turn); |
| 14 | var shifted = ground.Point(ground.Turn(Ground.Of(window[anchor * Joints].Position), turn)); |
| 15 | var shift = goal - shifted; |
| 16 | window[..(poses * Joints)].CopyTo(output); |
| 17 | for (var pose = 0; pose < poses; pose++) |
| 18 | { |
| 19 | var root = window[pose * Joints]; |
| 20 | var position = ground.Turn(Ground.Of(root.Position), turn); |
| 21 | var moved = ground.Compose( |
| 22 | new GroundPoint(ground.Point(position).U + shift.U, ground.Point(position).V + shift.V), |
| 23 | ground.Height(position)); |
| 24 | var q = root.Rotation; |
| 25 | var turned = (rotation * new DoubleQuat(q.X, q.Y, q.Z, q.W).Normalized()).Normalized(); |
| 26 | output[pose * Joints] = new Rigid(new Vector3((float)moved.X, (float)moved.Y, (float)moved.Z), |
| 27 | new Quaternion((float)turned.X, (float)turned.Y, (float)turned.Z, (float)turned.W)); |
| 28 | } |
| 29 | } |
| 30 | } |