57 lines
No EOL
1.2 KiB
C#
57 lines
No EOL
1.2 KiB
C#
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(float x, float y, float z)
|
|
{
|
|
pose = new Pose(x, y, z);
|
|
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.orientation.Inverse * (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)
|
|
{
|
|
pose.orientation = held_by.palm.orientation * ori_offset;
|
|
pose.position = held_by.palm.position - held_by.palm.orientation * pos_offset;
|
|
}
|
|
}
|
|
} |