Skip to content
0.2.0-dev Download ZIP
35 lines ·1.2 KB Raw
1namespace EvilEngine.GenerativeMotion;
2
3internal static class Kinematics
4{
5 public static Double3[] World(ReadOnlySpan<Rigid> poses, int frames)
6 {
7 var joints = SomaSkeleton.JointCount;
8 var parents = SomaSkeleton.Parents;
9 var world = new Double3[frames * joints];
10 var rotation = new DoubleQuat[joints];
11 for (var frame = 0; frame < frames; frame++)
12 {
13 var pose = poses.Slice(frame * joints, joints);
14 var position = world.AsSpan(frame * joints, joints);
15 for (var joint = 0; joint < joints; joint++)
16 {
17 var q = pose[joint].Rotation;
18 var local = new DoubleQuat(q.X, q.Y, q.Z, q.W).Normalized();
19 var offset = Ground.Of(pose[joint].Position);
20 var parent = parents[joint];
21 if (parent < 0)
22 {
23 rotation[joint] = local;
24 position[joint] = offset;
25 continue;
26 }
27
28 rotation[joint] = rotation[parent] * local;
29 position[joint] = position[parent] + rotation[parent].Apply(offset);
30 }
31 }
32
33 return world;
34 }
35}