using StereoKit; namespace snake; static class Rig { public static Pose head = Pose.Identity; public static DeltaBool btn_select = new(false); public static DeltaBool btn_grip = new(false); public static DeltaBool btn_back = new(false); public static Vec3 fullstick = Vec3.Up; public static Pose r_con_stick = Pose.Identity; public static XYZi new_dir = new(0, 0, 1); public static void Init() { } public static void Frame() { head = Input.Head; // flatscreen dev controls if (Device.Name == "Simulator") { btn_select.Step(Input.Key(Key.MouseLeft).IsActive()); btn_back.Step(Input.Key(Key.MouseRight).IsActive()); if (Input.Key(Key.A).IsJustActive()) new_dir = new(-1, 0, 0); if (Input.Key(Key.S).IsJustActive()) new_dir = new(+1, 0, 0); if (Input.Key(Key.W).IsJustActive()) new_dir = new(0, 0, -1); if (Input.Key(Key.R).IsJustActive()) new_dir = new(0, 0, +1); if (Input.Key(Key.Shift).IsJustActive()) new_dir = new(0, -1, 0); if (Input.Key(Key.Space).IsJustActive()) new_dir = new(0, +1, 0); fullstick = new_dir.ToVec3; } else { // Hand r_hand = Input.Hand(Handed.Right); // [!] hand input simulates controller... Controller r_con = Input.Controller(Handed.Right); bool con_tracked = r_con.trackedPos > TrackState.Lost; // bool hand_tracked = Input.HandSource(Handed.Right) > HandSource.None; if (con_tracked) { btn_select.Step(r_con.x1.IsActive() || r_con.trigger > 0.5f); btn_grip.Step(r_con.grip > 0.5f); btn_back.Step(r_con.x2.IsActive()); Vec2 stick = r_con.stick; Quat stick_rot = Quat.FromAngles(stick.y * -90, 0, stick.x * +90); float stick_sign = r_con.IsStickClicked ? -1 : +1; r_con_stick = r_con.pose; r_con_stick.position += r_con_stick.orientation * V.XYZ(0.0065f, -0.012f, -0.05f); r_con_stick.orientation *= Quat.FromAngles(-50, 0, 0); fullstick = r_con_stick.orientation * stick_rot * Vec3.Up * stick_sign; // Vec3 fullstick = r_hand.palm.orientation * Vec3.Up; float ax = Maths.abs(fullstick.x); float ay = Maths.abs(fullstick.y); float az = Maths.abs(fullstick.z); if (ax > ay && ax > az) new_dir = new(Maths.sign(fullstick.x), 0, 0); if (ay > ax && ay > az) new_dir = new(0, Maths.sign(fullstick.y), 0); if (az > ax && az > ay) new_dir = new(0, 0, Maths.sign(fullstick.z)); } } } }