grab class
This commit is contained in:
parent
9c7b1f35b3
commit
d2b4bc5b85
1 changed files with 60 additions and 0 deletions
60
src/Data.cs
Normal file
60
src/Data.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue