braille_xr/sk_demo/src/Rig.cs
2024-02-04 01:23:13 -05:00

47 lines
No EOL
1.3 KiB
C#

public class Rig {
public Vec3 head_pos = Vec3.Zero;
public Quat head_ori = Quat.Identity;
public Vec3 view_pos = Vec3.Zero;
public Hand hand_0 = new();
public Hand hand_1 = new();
public Vec3 palm_pos = Vec3.Zero;
public Quat palm_ori = Quat.Identity;
public Vec3 perch_pos = Vec3.Zero;
public void Init() {
}
public void Run() {
hand_0 = Input.Hand(Handed.Left);
hand_1 = Input.Hand(Handed.Right);
head_pos = Main.Mono.dev && Time.Totalf > 0.5f ? head_pos : Input.Head.position;
head_ori = Main.Mono.dev && Time.Totalf > 0.5f ? head_ori : Input.Head.orientation;
view_pos = head_pos + V.XYZ(0, -6*U.cm, 0);
// Position is specifically defined as the middle of the middle finger's root (metacarpal) bone.
palm_pos = hand_1.palm.position;
// For orientation, Forward is the direction the flat of the palm is facing, "Iron Man" style. X+ is to the outside of the right hand, and to the inside of the left hand.
palm_ori = hand_1.palm.orientation;
perch_pos = palm_pos + Vec3.Up * 8 * U.cm;
}
public struct Btn {
public bool frameDown, held, frameUp;
public void Frame(bool down, bool? up = null) {
if (up != null && held) {
down = !(bool)up;
}
frameDown = down && !held;
frameUp = !down && held;
held = down;
}
}
}