From bacbd224e2a05d33f877126f5e2bb250f5c11812 Mon Sep 17 00:00:00 2001 From: spatialfree Date: Wed, 5 Oct 2022 22:38:09 -0400 Subject: [PATCH] thumb pad roll --- app/Mono.cs | 20 +++++++++++++++ app/PullRequest.cs | 39 +++++++++++++++++++++++++++-- app/dofs/trackballer/Trackballer.cs | 37 ++++++++++++++++----------- 3 files changed, 79 insertions(+), 17 deletions(-) diff --git a/app/Mono.cs b/app/Mono.cs index 4e22b53..c5d2e4d 100644 --- a/app/Mono.cs +++ b/app/Mono.cs @@ -96,6 +96,26 @@ public class Mono { dofs[3].Frame(); + // turn this into a function + Vec3 vA = new Vec3(-1, 0, 0); + Vec3 vB = new Vec3(1, 1, 1); + + Vec3 vC = Input.Hand(Handed.Right).palm.position; + + Quat q = Quat.LookDir((vB - vA).Normalized); + + // // snap vC to line vA-vB + // Vec3 local = q.Inverse * (vC - vA); + // local.x = 0; + // local.y = 0; + // vC = q * local + vA; + + vC = vC.SnapToLine(vA, vB, true); + + Lines.Add(vA, vB, new Color(1, 1, 1), 0.002f); + Mesh.Cube.Draw(matDev, Matrix.TRS(vC, q, 0.04f)); + + // rGlove.Step(); lGlove.Step(); // rBlock.Step(); lBlock.Step(); diff --git a/app/PullRequest.cs b/app/PullRequest.cs index 33fbb93..8bade5e 100644 --- a/app/PullRequest.cs +++ b/app/PullRequest.cs @@ -92,8 +92,43 @@ public static class PullRequest { return (to - from).Normalized; } - // swizzle - public static Vec3 JustX(this Vec3 v) { + public static Vec3 SnapToLine(this Vec3 v, Vec3 a, Vec3 b, bool clamp) { + Quat q = Quat.LookDir(Direction(b, a)); + Vec3 lv = q.Inverse * (v - a); + lv.x = lv.y = 0; + Vec3 r = q * lv + a; + if (clamp) { + float d = (b - a).Length; + float t = (r - a).Length / d; + if (t < 0) t = 0; + if (t > 1) t = 1; + r = a + (b - a) * t; + } + return r; + } + + /* + // turn this into a function + Vec3 vA = new Vec3(-1, 0, 0); + Vec3 vB = new Vec3(1, 1, 1); + + Vec3 vC = Input.Hand(Handed.Right).palm.position; + + Quat q = Quat.LookDir((vB - vA).Normalized); + + // snap vC to line vA-vB + Vec3 local = q.Inverse * (vC - vA); + local.x = 0; + local.y = 0; + vC = q * local + vA; + + Lines.Add(vA, vB, new Color(1, 1, 1), 0.002f); + Mesh.Cube.Draw(matDev, Matrix.TRS(vC, q, 0.04f)); + + */ + + // swizzle + public static Vec3 JustX(this Vec3 v) { return new Vec3(v.x, 0, 0); } public static Vec3 JustY(this Vec3 v) { diff --git a/app/dofs/trackballer/Trackballer.cs b/app/dofs/trackballer/Trackballer.cs index 16ee8e3..59df5fe 100644 --- a/app/dofs/trackballer/Trackballer.cs +++ b/app/dofs/trackballer/Trackballer.cs @@ -18,10 +18,10 @@ class Trackballer : dof { Matrix mAnchor = Matrix.TR(anchor, hand.palm.orientation); Matrix mAnchorInv = mAnchor.Inverse; - Vec3 pad = Vec3.Lerp( - hand.Get(FingerId.Thumb, JointId.KnuckleMinor).position, + Vec3 pad = anchor.SnapToLine( hand.Get(FingerId.Thumb, JointId.Tip).position, - 0.5f + hand.Get(FingerId.Thumb, JointId.KnuckleMinor).position, + true ); Vec3 localPad = mAnchorInv.Transform(pad); @@ -31,25 +31,32 @@ class Trackballer : dof { } else { btnIn.Step(localPad.Length < layer[0]); } - color = btnIn.held ? new Color(1, 0, 0) : Color.White; + color = btnIn.held ? new Color(1, 0, 0) : color; - - btnOut.Step(localPad.Length > layer[2]); - if (localPad.Length > layer[2]) { - color = new Color(0, 1, 1); + if (btnOut.held) { + btnOut.Step(localPad.Length > layer[1]); + } else { + btnOut.Step(localPad.Length > layer[2]); } + color = btnOut.held ? new Color(0, 1, 0) : color; - if (localPad.Length < layer[1]) { - delta = PullRequest.Relative( - hand.palm.orientation, - PullRequest.Delta(localPad.Normalized, oldLocalPad.Normalized) - ).Normalized; + if (btnIn.held) { + delta = Quat.Identity; + } else { + if (localPad.Length < layer[1]) { + delta = PullRequest.Relative( + hand.palm.orientation, + PullRequest.Delta(localPad.Normalized, oldLocalPad.Normalized) + ).Normalized; + } } oldLocalPad = localPad; // Draw - Mesh.Sphere.Draw(Mono.inst.matDev, Matrix.TRS(anchor, ori, 0.045f), color); + Mesh.Cube.Draw(Mono.inst.matDev, Matrix.TRS(anchor, ori, 0.04f), color); + + Mesh.Sphere.Draw(Mono.inst.matDev, Matrix.TRS(pad, hand.palm.orientation, 0.015f), new Color(0, 1, 0)); } Quat newOri = delta * ori; @@ -66,7 +73,7 @@ class Trackballer : dof { // design public Handed handed = Handed.Left; - public float[] layer = new float[] { 0.015f, 0.03f, 0.055f }; + public float[] layer = new float[] { 0.00333f, 0.02f, 0.0666f };