diff --git a/src/Data.cs b/src/Data.cs new file mode 100644 index 0000000..bb9e2f3 --- /dev/null +++ b/src/Data.cs @@ -0,0 +1,60 @@ +using StereoKit; + +namespace dofdemo; + + +public static class Data +{ + +} + +public class Grab +{ + public Pose pose; + private Vec3 pos_offset; + private Quat ori_offset; + private Hand? held_by; + + public Grab() + { + pose = new Pose(); + pos_offset = Vec3.Zero; + ori_offset = Quat.Identity; + held_by = null; + } + + public bool OnGrab(ref Hand hand, ref Grab grab_ref) + { + if (!Held) // Allow only one hand at a time to grab + { + if (Vec3.Distance(hand.palm.position, pose.position) < 0.1f) + { + held_by = hand; + grab_ref = this; + pos_offset = hand.palm.position - pose.position; + ori_offset = hand.palm.orientation.Inverse * pose.orientation; + return true; + } + } + return false; + } + + public bool Held => held_by != null; + + public void OnRelease() + { + held_by = null; + } + + public void Frame() + { + if (Held) + { + Log.Info(held_by.palm.position.ToString()); + + // Apply position and rotation logic here + pose.position = held_by.palm.position - pos_offset; + pose.orientation = held_by.palm.orientation * ori_offset; + } + } +} \ No newline at end of file