initial hand tracking support

This commit is contained in:
ethan merchant 2024-12-08 01:51:09 -05:00
parent 81def53f8c
commit 2d7f92e5a0
2 changed files with 44 additions and 26 deletions

View file

@ -2,8 +2,8 @@
<manifest <manifest
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
package="com.dofdev.snake" package="com.dofdev.snake"
android:versionCode="50" android:versionCode="51"
android:versionName="1.55" android:versionName="1.56"
android:installLocation="auto" android:installLocation="auto"
> >
<uses-sdk android:minSdkVersion="29" android:targetSdkVersion="32" /> <uses-sdk android:minSdkVersion="29" android:targetSdkVersion="32" />

View file

@ -40,33 +40,51 @@ static class Rig
} }
else else
{ {
// Hand r_hand = Input.Hand(Handed.Right); if (Input.HandSource(Handed.Right) == HandSource.Articulated)
// [!] 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); Hand r_hnd = Input.Hand(Handed.Right);
btn_grip.Step(r_con.grip > 0.5f); if (r_hnd.IsTracked)
btn_back.Step(r_con.x2.IsActive()); {
btn_select.Step(r_hnd.IsPinched);
btn_grip.Step(r_hnd.IsGripped);
// btn_back.Step(); // [!] todo
Vec2 stick = r_con.stick; Vec3 thumb_tip = r_hnd.Get(FingerId.Thumb, JointId.Tip).position;
Quat stick_rot = Quat.FromAngles(stick.y * -90, 0, stick.x * +90); Vec3 index_tip = r_hnd.Get(FingerId.Index, JointId.Tip).position;
float stick_sign = r_con.IsStickClicked ? -1 : +1; r_con_stick.position = thumb_tip;
r_con_stick = r_con.aim;
// 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; fullstick = Vec3.Direction(index_tip, thumb_tip);
float ax = Maths.abs(fullstick.x);
float ay = Maths.abs(fullstick.y); float ax = Maths.abs(fullstick.x);
float az = Maths.abs(fullstick.z); float ay = Maths.abs(fullstick.y);
if (ax > ay && ax > az) new_dir = new(Maths.sign(fullstick.x), 0, 0); float az = Maths.abs(fullstick.z);
if (ay > ax && ay > az) new_dir = new(0, Maths.sign(fullstick.y), 0); if (ax > ay && ax > az) new_dir = new(Maths.sign(fullstick.x), 0, 0);
if (az > ax && az > ay) new_dir = new(0, 0, Maths.sign(fullstick.z)); 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));
}
}
else
{
Controller r_con = Input.Controller(Handed.Right);
if (r_con.IsTracked)
{
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.aim;
fullstick = r_con_stick.orientation * stick_rot * Vec3.Up * stick_sign;
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));
}
} }
} }
} }