From ba6fc33a4002f32c19305bfa1086a18d4def1a33 Mon Sep 17 00:00:00 2001 From: spatialfree Date: Sat, 7 Dec 2024 19:49:15 -0500 Subject: [PATCH] con mesh and snap to hand --- Assets/meshes/assets.glb | 4 ++-- Platforms/Android/AndroidManifest.xml | 4 ++-- src/Arts.cs | 10 ++++++---- src/Data.cs | 18 ++++++++++++++---- src/Dofs.cs | 4 ++-- 5 files changed, 26 insertions(+), 14 deletions(-) diff --git a/Assets/meshes/assets.glb b/Assets/meshes/assets.glb index 4bb875f..5ff1115 100644 --- a/Assets/meshes/assets.glb +++ b/Assets/meshes/assets.glb @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:253c75378db0b495c212ddfc6181dce32432d7df5f3875e20f55bee6617a030d -size 6844 +oid sha256:d14a38f568ecca9c13cfd7698720c4c8dbff855e3c4fd0f79f76d527042ee776 +size 53500 diff --git a/Platforms/Android/AndroidManifest.xml b/Platforms/Android/AndroidManifest.xml index c955c1d..83f5f54 100644 --- a/Platforms/Android/AndroidManifest.xml +++ b/Platforms/Android/AndroidManifest.xml @@ -2,8 +2,8 @@ diff --git a/src/Arts.cs b/src/Arts.cs index 8a2b3a7..ac1570a 100644 --- a/src/Arts.cs +++ b/src/Arts.cs @@ -76,13 +76,15 @@ static class Arts // stretch_cursor { - Mesh.Cube.Draw( + 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(5 * U.cm) + Stretch.to_grab.pose.ToMatrix(V.XYZ(flip_x, 1, 1) * 1.5f * U.cm) ); - Mesh.Cube.Draw( + 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(4 * U.cm) + Stretch.from_grab.pose.ToMatrix(V.XYZ(flip_x, 1, 1) * 1.5f * U.cm) ); Mesh.Cube.Draw( diff --git a/src/Data.cs b/src/Data.cs index 0700e15..c65ded8 100644 --- a/src/Data.cs +++ b/src/Data.cs @@ -13,14 +13,16 @@ public class Grab public Pose pose; private Vec3 pos_offset; private Quat ori_offset; - private Hand? held_by; + public Hand? held_by; + private bool snap_to_hand = false; - public Grab(float x, float y, float z) + public Grab(float x, float y, float z, bool snap_to_hand = false) { pose = new Pose(x, y, z); pos_offset = Vec3.Zero; ori_offset = Quat.Identity; held_by = null; + this.snap_to_hand = snap_to_hand; } public bool OnGrab(ref Hand hand, ref Grab grab_ref) @@ -50,8 +52,16 @@ public class Grab { if (Held) { - pose.orientation = held_by.palm.orientation * ori_offset; - pose.position = held_by.palm.position - held_by.palm.orientation * pos_offset; + if (snap_to_hand) + { + pose.orientation = held_by.palm.orientation; + pose.position = held_by.palm.position; + } + else + { + pose.orientation = held_by.palm.orientation * ori_offset; + pose.position = held_by.palm.position - held_by.palm.orientation * pos_offset; + } } } } \ No newline at end of file diff --git a/src/Dofs.cs b/src/Dofs.cs index fea5c97..3b8fbaf 100644 --- a/src/Dofs.cs +++ b/src/Dofs.cs @@ -14,8 +14,8 @@ static class Stretch public static void Init() { - to_grab = new(-0.3f, 0, 0); - from_grab = new(-0.3f, 0, 0.1f); + to_grab = new(-0.3f, 0, 0, true); + from_grab = new(-0.3f, 0, 0.1f, true); } public static void Frame()