From 99c99dde80ec32143ac2e550372f9b270f7345d5 Mon Sep 17 00:00:00 2001 From: spatialfree Date: Wed, 19 Jul 2023 19:18:51 -0400 Subject: [PATCH] roll out --- src/Glove.cs | 4 +- src/Interactions/rolls-cursor/RollsCursor.cs | 24 +++++-- src/Mono.cs | 70 ++++++++++---------- src/PR.cs | 41 +++++++----- src/_Init.cs | 2 +- 5 files changed, 82 insertions(+), 59 deletions(-) diff --git a/src/Glove.cs b/src/Glove.cs index bef4ae0..146a48c 100644 --- a/src/Glove.cs +++ b/src/Glove.cs @@ -58,7 +58,7 @@ public class Glove { if (lift) { pullPoint = con.pos + -direction * stretch; } else { - direction = PR.Direction(con.pos, pullPoint); + direction = Vec3.Direction(con.pos, pullPoint); } } else { pullPoint = con.pos; @@ -83,7 +83,7 @@ public class Glove { case Pull.Backhanded: pullPoint = otherCon.pos; - direction = PR.Direction(con.pos, otherCon.pos); + direction = Vec3.Direction(con.pos, otherCon.pos); virtualGlove.orientation = con.ori; break; } diff --git a/src/Interactions/rolls-cursor/RollsCursor.cs b/src/Interactions/rolls-cursor/RollsCursor.cs index 324deba..886fd0d 100644 --- a/src/Interactions/rolls-cursor/RollsCursor.cs +++ b/src/Interactions/rolls-cursor/RollsCursor.cs @@ -8,6 +8,9 @@ class RollsCursor : Interaction { // data public Cursor cursor = new Cursor(); + PR.Delta fIdelta = new PR.Delta(); + PR.Delta fMdelta = new PR.Delta(); + PR.Delta fRdelta = new PR.Delta(); public void Init() { } @@ -22,12 +25,23 @@ class RollsCursor : Interaction { float stretch = (fI + fM + fR + fL) / 4f; - Vec3 to = Roll(hand, JointId.KnuckleMid, fI, fM, fR, fL); - Vec3 from = Roll(hand, JointId.KnuckleMajor, fI, fM, fR, fL); + // Vec3 to = Roll(hand, JointId.KnuckleMid, fI, fM, fR, fL); + // Vec3 from = Roll(hand, JointId.KnuckleMajor, fI, fM, fR, fL); - Vec3 dir = PR.Direction(to, from); + // Vec3 dir = Vec3.Direction(to, from); - cursor.raw = to + dir * stretch * reach.value; + // cursor.raw = to + dir * stretch * reach.value; + + if (fL == 0.0f) { + cursor.raw = hand.Get(FingerId.Index, JointId.Tip).position; + } + + fIdelta.Update(hand.Get(FingerId.Index, JointId.Tip).position); + fMdelta.Update(hand.Get(FingerId.Middle, JointId.Tip).position); + fRdelta.Update(hand.Get(FingerId.Ring, JointId.Tip).position); + + Vec3 delta = (fIdelta.value + fMdelta.value + fRdelta.value) / 3f; + cursor.raw += delta * reach.value; Mesh.Sphere.Draw(Mono.inst.matHoloframe, Matrix.TRS(cursor.raw, Quat.Identity, 0.01f), new Color(1, 0, 0)); Mesh.Sphere.Draw(Mono.inst.matHoloframe, Matrix.TRS(cursor.pos, Quat.Identity, 0.01f), new Color(0, 1, 0)); @@ -36,7 +50,7 @@ class RollsCursor : Interaction { } // design - public Design reach = new Design { str = "1.0", term = "0+m", min = 0 }; + public Design reach = new Design { str = "3.0", term = "0+m", min = 0 }; public Vec3 Roll(Hand hand, JointId jointId, float fI, float fM, float fR, float fL) { Vec3 i = hand.Get(FingerId.Index, jointId).position; diff --git a/src/Mono.cs b/src/Mono.cs index 0eb8119..3287d93 100644 --- a/src/Mono.cs +++ b/src/Mono.cs @@ -20,7 +20,7 @@ public class Mono { // ------------------------------------------------- - public Interaction[] dofs; + public Interaction[] interactions; public ColorCube colorCube = new ColorCube(); @@ -32,7 +32,7 @@ public class Mono { // public MonoNet net = new MonoNet(); public Mono() { - dofs = new Interaction[] { + interactions = new Interaction[] { new Chiral(new Interaction[] { new WaveCursor() { handed = Handed.Left }, new WaveCursor() { handed = Handed.Right } @@ -51,8 +51,8 @@ public class Mono { public void Init() { compositor.Init(); - for (int i = 0; i < dofs.Length; i++) { - dofs[i].Init(); + for (int i = 0; i < interactions.Length; i++) { + interactions[i].Init(); } matDev = Material.Default.Copy(); @@ -104,10 +104,10 @@ public class Mono { // Input.HandClearOverride(Handed.Right); // store hand pre override in rig rig.Step(); - Hand h = Input.Hand(Handed.Right); - if (h.pinch.IsActive()) { - Console.WriteLine($"{h.pinchPt}, {Input.Head.orientation * -Vec3.Forward}"); - } + // Hand h = Input.Hand(Handed.Right); + // if (h.pinch.IsActive()) { + // Console.WriteLine($"{h.pinchPt}, {Input.Head.orientation * -Vec3.Forward}"); + // } // Hand hand = Input.Hand(Handed.Right); // Controller con = Input.Controller(Handed.Right); @@ -125,30 +125,30 @@ public class Mono { spatial.Frame(); // pinch-cursor? - { - float deadzone = 0.01f; - float strength = 6f; + // { + // float deadzone = 0.01f; + // float strength = 6f; - Hand hand = Input.Hand(Handed.Right); - Vec3 indexTip = hand.Get(FingerId.Index, JointId.Tip).position; - Vec3 thumbTip = hand.Get(FingerId.Thumb, JointId.Tip).position; + // Hand hand = Input.Hand(Handed.Right); + // Vec3 indexTip = hand.Get(FingerId.Index, JointId.Tip).position; + // Vec3 thumbTip = hand.Get(FingerId.Thumb, JointId.Tip).position; - Vec3 delta = indexTip - thumbTip; - float mag = delta.Magnitude; - float pinch = MathF.Max(mag - deadzone, 0); + // Vec3 delta = indexTip - thumbTip; + // float mag = delta.Magnitude; + // float pinch = MathF.Max(mag - deadzone, 0); - Vec3 dir = delta.Normalized; + // Vec3 dir = delta.Normalized; - cursor.raw = indexTip + dir * pinch * strength; + // cursor.raw = indexTip + dir * pinch * strength; - Lines.Add(indexTip, thumbTip, new Color(0, 0, 1), 0.002f); - Mesh.Sphere.Draw(matHolo, Matrix.TS(cursor.pos, 0.01f), new Color(0.5f, 0.5f, 0.5f)); - // V.XYZ(0, 0, ); + // Lines.Add(indexTip, thumbTip, new Color(0, 0, 1), 0.002f); + // Mesh.Sphere.Draw(matHolo, Matrix.TS(cursor.pos, 0.01f), new Color(0.5f, 0.5f, 0.5f)); + // // V.XYZ(0, 0, ); - drawerA.Frame(cursor, pinch); - drawerB.Frame(cursor, pinch); - drawerC.Frame(cursor, pinch); - } + // drawerA.Frame(cursor, pinch); + // drawerB.Frame(cursor, pinch); + // drawerC.Frame(cursor, pinch); + // } @@ -156,17 +156,17 @@ public class Mono { // ------------------------------------------------- - for (int i = 0; i < dofs.Length; i++) { - if (dofs[i].Active) { - dofs[i].Frame(); + for (int i = 0; i < interactions.Length; i++) { + if (interactions[i].Active) { + interactions[i].Frame(); } } // - WaveCursor lwc = (WaveCursor)((Chiral)dofs[0]).dofs[0]; - WaveCursor rwc = (WaveCursor)((Chiral)dofs[0]).dofs[1]; - Trackballer ltb = (Trackballer)((Chiral)dofs[1]).dofs[0]; - Trackballer rtb = (Trackballer)((Chiral)dofs[1]).dofs[1]; + WaveCursor lwc = (WaveCursor)((Chiral)interactions[0]).dofs[0]; + WaveCursor rwc = (WaveCursor)((Chiral)interactions[0]).dofs[1]; + Trackballer ltb = (Trackballer)((Chiral)interactions[1]).dofs[0]; + Trackballer rtb = (Trackballer)((Chiral)interactions[1]).dofs[1]; if (lwc.Active) { lwc.Demo(ltb.ori); @@ -249,12 +249,12 @@ public class Mono { dofIndex--; } UI.SameLine(); - if (UI.Button("next") && dofIndex < dofs.Length - 1) { + if (UI.Button("next") && dofIndex < interactions.Length - 1) { dofIndex++; } - Interaction dof = dofs[dofIndex]; + Interaction dof = interactions[dofIndex]; Type type = dof.GetType(); // active toggle Color tint = dof.Active ? new Color(0, 1, 0) : new Color(1, 0, 0); diff --git a/src/PR.cs b/src/PR.cs index 921d09e..8dbce5e 100644 --- a/src/PR.cs +++ b/src/PR.cs @@ -49,17 +49,17 @@ public static class PR { } } - // construct the quaternion that rotates one vector to another - // uses the usual trick to get the half angle - public static Quat Delta(Vec3 to, Vec3 from) { - Vec3 vec = Vec3.Cross(from, to); - return new Quat( - vec.x, - vec.y, - vec.z, - 1 + Vec3.Dot(to, from ) - ).Normalized; - } + // // construct the quaternion that rotates one vector to another + // // uses the usual trick to get the half angle + // public static Quat Delta(Vec3 to, Vec3 from) { + // Vec3 vec = Vec3.Cross(from, to); + // return new Quat( + // vec.x, + // vec.y, + // vec.z, + // 1 + Vec3.Dot(to, from ) + // ).Normalized; + // } // Quat q; // public static void Relative(Quat to) => q = to * q * to.Inverse; @@ -93,12 +93,8 @@ public static class PR { return r.Next(min, max); } - public static Vec3 Direction(Vec3 to, Vec3 from) { - return (to - from).Normalized; - } - public static Vec3 SnapToLine(this Vec3 v, Vec3 a, Vec3 b, bool clamp, out float t, float tMin = 0, float tMax = 1) { - Quat q = Quat.LookDir(Direction(b, a)); + Quat q = Quat.LookDir(Vec3.Direction(b, a)); Vec3 lv = q.Inverse * (v - a); lv.x = lv.y = 0; Vec3 r = q * lv + a; @@ -306,6 +302,19 @@ public static class PR { // } // } + public class Delta { + public Vec3 value { get; private set; } + + Vec3 last; + public Vec3 Update(Vec3 current) { + value = current - last; + last = current; + return value; + } + } + + + public class PID { public float p, i; public float value; diff --git a/src/_Init.cs b/src/_Init.cs index 2919029..820feb5 100644 --- a/src/_Init.cs +++ b/src/_Init.cs @@ -7,7 +7,7 @@ SKSettings settings = new SKSettings { assetsFolder = "add", depthMode = DepthMode.D32, disableUnfocusedSleep = true, - displayPreference = DisplayMode.Flatscreen, + // displayPreference = DisplayMode.Flatscreen, // disableFlatscreenMRSim = true, }; if (!SK.Initialize(settings))