grab class

This commit is contained in:
ethan merchant 2024-12-07 13:42:10 -05:00
parent 9c7b1f35b3
commit d2b4bc5b85

60
src/Data.cs Normal file
View file

@ -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;
}
}
}