hand input

This commit is contained in:
ethan merchant 2024-12-07 15:33:33 -05:00
parent d2b4bc5b85
commit 3ee827ad1f

View file

@ -6,10 +6,17 @@ static class Rig
{
public static Pose head = Pose.Identity;
public static Hand l_hnd;
public static Hand r_hnd;
public static DeltaBool btn_select = new(false);
public static DeltaBool btn_grip = new(false);
public static DeltaBool btn_l_grip = new(false);
public static DeltaBool btn_r_grip = new(false);
public static DeltaBool btn_back = new(false);
public static Grab? l_held = null;
public static Grab? r_held = null;
public static Pose l_hld, l_aim, r_hld, r_aim;
public static Vec3 fullstick = Vec3.Up;
@ -27,47 +34,56 @@ static class Rig
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 (Device.Name == "Simulator")
// {
// btn_select.Step(Input.Key(Key.MouseLeft).IsActive());
// btn_back.Step(Input.Key(Key.MouseRight).IsActive());
r_hld = new Pose(
V.XYZ(SKMath.Sin(Time.Totalf * 1f) * 0.1f, 0.5f, 1.0f),
Quat.FromAngles(0, 0, SKMath.Sin(Time.Totalf * 6f) * 30f)
);
l_aim = new Pose(
V.XYZ(SKMath.Sin(Time.Totalf * 2f) * 0.6f, 0.5f, 0.5f),
Quat.Identity
);
// r_hld = new Pose(
// V.XYZ(SKMath.Sin(Time.Totalf * 1f) * 0.1f, 0.5f, 1.0f),
// Quat.FromAngles(0, 0, SKMath.Sin(Time.Totalf * 6f) * 30f)
// );
// l_aim = new Pose(
// V.XYZ(SKMath.Sin(Time.Totalf * 2f) * 0.6f, 0.5f, 0.5f),
// Quat.Identity
// );
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
{
// 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);
r_hld = r_con.pose;
r_aim = r_con.aim;
l_hnd = Input.Hand(Handed.Left);
Controller l_con = Input.Controller(Handed.Left);
l_hld = l_con.pose;
l_aim = l_con.aim;
// l_hld = l_con.pose;
l_hld = l_hnd.palm;
// l_aim = l_con.aim;
r_hnd = Input.Hand(Handed.Right);
Controller r_con = Input.Controller(Handed.Right);
// r_hld = r_con.pose;
r_hld = r_hnd.palm;
// r_aim = r_con.aim;
btn_l_grip.Step(l_con.grip > 0.5f || l_hnd.IsGripped);
btn_r_grip.Step(r_con.grip > 0.5f || r_hnd.IsGripped);
btn_select.Step(r_con.x1.IsActive() || r_con.trigger > 0.5f);
btn_back.Step(r_con.x2.IsActive());
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);
@ -85,6 +101,6 @@ static class Rig
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));
}
}
// }
}
}