use controller pose instead
This commit is contained in:
parent
041ceea867
commit
741f2ee713
5 changed files with 24 additions and 32 deletions
BIN
Assets/meshes/assets.glb
(Stored with Git LFS)
BIN
Assets/meshes/assets.glb
(Stored with Git LFS)
Binary file not shown.
|
@ -79,15 +79,13 @@ static class Arts
|
|||
|
||||
// stretch_cursor
|
||||
{
|
||||
float flip_x = Stretch.to_grab.Held && Stretch.to_grab.held_by.handed == Handed.Left ? -1 : 1;
|
||||
meshes["con"].Draw(
|
||||
mat_mono,
|
||||
Stretch.to_grab.pose.ToMatrix(V.XYZ(flip_x, 1, 1) * 1.5f * U.cm)
|
||||
Stretch.to_grab.pose.ToMatrix(1.5f * U.cm)
|
||||
);
|
||||
flip_x = Stretch.from_grab.Held && Stretch.from_grab.held_by.handed == Handed.Left ? -1 : 1;
|
||||
meshes["con"].Draw(
|
||||
mat_mono,
|
||||
Stretch.from_grab.pose.ToMatrix(V.XYZ(flip_x, 1, 1) * 1.5f * U.cm)
|
||||
Stretch.from_grab.pose.ToMatrix(1.5f * U.cm)
|
||||
);
|
||||
|
||||
Mesh.Cube.Draw(
|
||||
|
|
20
src/Data.cs
20
src/Data.cs
|
@ -13,7 +13,7 @@ public class Grab
|
|||
public Pose pose;
|
||||
private Vec3 pos_offset;
|
||||
private Quat ori_offset;
|
||||
public Hand? held_by;
|
||||
public Controller? held_by;
|
||||
private bool snap_to_hand = false;
|
||||
|
||||
public Grab(float x, float y, float z, bool snap_to_hand = false)
|
||||
|
@ -25,16 +25,16 @@ public class Grab
|
|||
this.snap_to_hand = snap_to_hand;
|
||||
}
|
||||
|
||||
public bool OnGrab(ref Hand hand, ref Grab grab_ref)
|
||||
public bool OnGrab(ref Controller con, ref Grab grab_ref)
|
||||
{
|
||||
if (!Held) // Allow only one hand at a time to grab
|
||||
{
|
||||
if (Vec3.Distance(hand.palm.position, pose.position) < 0.14f)
|
||||
if (Vec3.Distance(con.pose.position, pose.position) < 0.14f)
|
||||
{
|
||||
held_by = hand;
|
||||
held_by = con;
|
||||
grab_ref = this;
|
||||
pos_offset = hand.palm.orientation.Inverse * (hand.palm.position - pose.position);
|
||||
ori_offset = hand.palm.orientation.Inverse * pose.orientation;
|
||||
pos_offset = con.pose.orientation.Inverse * (con.pose.position - pose.position);
|
||||
ori_offset = con.pose.orientation.Inverse * pose.orientation;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -54,13 +54,13 @@ public class Grab
|
|||
{
|
||||
if (snap_to_hand)
|
||||
{
|
||||
pose.orientation = held_by.palm.orientation;
|
||||
pose.position = held_by.palm.position;
|
||||
pose.orientation = held_by.pose.orientation;
|
||||
pose.position = held_by.pose.position;
|
||||
}
|
||||
else
|
||||
{
|
||||
pose.orientation = held_by.palm.orientation * ori_offset;
|
||||
pose.position = held_by.palm.position - held_by.palm.orientation * pos_offset;
|
||||
pose.orientation = held_by.pose.orientation * ori_offset;
|
||||
pose.position = held_by.pose.position - held_by.pose.orientation * pos_offset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -111,7 +111,7 @@ static class Mono
|
|||
{
|
||||
if (Rig.btn_l_grip.delta == +1)
|
||||
{
|
||||
grab.OnGrab(ref Rig.l_hnd, ref Rig.l_held);
|
||||
grab.OnGrab(ref Rig.l_con, ref Rig.l_held);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -132,7 +132,7 @@ static class Mono
|
|||
{
|
||||
if (Rig.btn_r_grip.delta == +1)
|
||||
{
|
||||
grab.OnGrab(ref Rig.r_hnd, ref Rig.r_held);
|
||||
grab.OnGrab(ref Rig.r_con, ref Rig.r_held);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
22
src/Rig.cs
22
src/Rig.cs
|
@ -6,8 +6,8 @@ static class Rig
|
|||
{
|
||||
public static Pose head = Pose.Identity;
|
||||
|
||||
public static Hand l_hnd;
|
||||
public static Hand r_hnd;
|
||||
public static Hand l_hnd, r_hnd;
|
||||
public static Controller l_con, r_con;
|
||||
|
||||
public static DeltaBool btn_select = new(false);
|
||||
public static DeltaBool btn_l_grip = new(false);
|
||||
|
@ -17,8 +17,6 @@ static class Rig
|
|||
public static Grab? l_held = null;
|
||||
public static Grab? r_held = null;
|
||||
|
||||
public static Pose l_hld, l_aim, r_hld, r_aim;
|
||||
|
||||
public static Vec3 fullstick = Vec3.Up;
|
||||
public static Pose r_con_stick = Pose.Identity;
|
||||
|
||||
|
@ -26,7 +24,8 @@ static class Rig
|
|||
|
||||
public static void Init()
|
||||
{
|
||||
|
||||
l_con = new();
|
||||
r_con = new();
|
||||
}
|
||||
|
||||
public static void Frame()
|
||||
|
@ -62,21 +61,16 @@ static class Rig
|
|||
// [!] hand input simulates controller...
|
||||
|
||||
l_hnd = Input.Hand(Handed.Left);
|
||||
Controller l_con = Input.Controller(Handed.Left);
|
||||
// l_hld = l_con.pose;
|
||||
l_hld = l_hnd.palm;
|
||||
// l_aim = l_con.aim;
|
||||
l_con = Input.Controller(Handed.Left);
|
||||
|
||||
r_hnd = Input.Hand(Handed.Right);
|
||||
Controller r_con = Input.Controller(Handed.Right);
|
||||
// r_hld = r_con.pose;
|
||||
r_hld = r_hnd.palm;
|
||||
// r_aim = r_con.aim;
|
||||
|
||||
r_con = Input.Controller(Handed.Right);
|
||||
|
||||
btn_l_grip.Step(l_con.grip > 0.5f || l_hnd.IsGripped);
|
||||
btn_r_grip.Step(r_con.grip > 0.5f || r_hnd.IsGripped);
|
||||
|
||||
// double grip?
|
||||
|
||||
btn_select.Step(r_con.x1.IsActive() || r_con.trigger > 0.5f);
|
||||
btn_back.Step(r_con.x2.IsActive());
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue