From 0de5825654d43794611f04db787e9d2d9f8e83ea Mon Sep 17 00:00:00 2001 From: spatialfree Date: Tue, 11 Jan 2022 12:35:00 -0500 Subject: [PATCH] no lift, new twist --- README.md | 10 ++++++++++ app/Glove.cs | 40 +++++++++++++++++++++++++++++++++++++--- app/SpatialCursor.cs | 4 ++-- 3 files changed, 49 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c471840..41a1945 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,16 @@ exec(vlai)   +# bookmark(next page) +lift for all + +glove visuals +*pull points +*mesh + +  + + # m-- unity diff --git a/app/Glove.cs b/app/Glove.cs index 1ccfae8..3b1dea5 100644 --- a/app/Glove.cs +++ b/app/Glove.cs @@ -20,14 +20,20 @@ public class Glove { float stretch; float stretchDeadzone = 0; Vec3 pullPoint; - + Vec3 twistPoint; + bool twistOut; public void Step() { Pose shoulder = mono.Shoulder(chirality); + Pose wrist = mono.Wrist(chirality); Con con = mono.Con(chirality), otherCon = mono.Con(!chirality); bool reach = con.device.IsX2Pressed; bool pull = otherCon.gripBtn.frameDown; bool lift = con.device.IsX1Pressed; + lift = false; + bool twist = con.device.IsX1Pressed; + + // exclusive states? if (reach) { // shoulder stuff @@ -71,9 +77,20 @@ public class Glove { } stretch = Math.Max(Vec3.Distance(pullPoint, con.pos) - stretchDeadzone, 0); + + if (!twist) { twistPoint = con.ori * Vec3.Up; } + Quat twistFrom = Quat.LookAt(Vec3.Zero, con.ori * Vec3.Forward, twistPoint); + if (twist) { + stretch = (float)(Math.Acos(Vec3.Dot(twistFrom * Vec3.Up, con.ori * Vec3.Up)) / Math.PI); + twistOut = Vec3.Dot(twistFrom * Vec3.Up, con.ori * Vec3.Right * (chirality ? 1 : -1)) > 0; + + direction = con.ori * Vec3.Forward; + virtualGlove.orientation = twistFrom; + } + virtualGlove.position = con.pos + direction * stretch * 3; - Render(con.Pose(), virtualGlove); + Render(con.Pose(), virtualGlove, wrist, twist, stretch, twistOut, twistFrom); } // decouple the rendering @@ -81,10 +98,27 @@ public class Glove { // that way we can render the same way for all peers static Mesh mesh = Default.MeshCube; static Material mat = Default.Material; - public void Render(Pose glove, Pose virtualGlove) { + public void Render(Pose glove, Pose virtualGlove, Pose wrist, bool twist, float stretch, bool twistOut, Quat twistFrom) { Lines.Add(pullPoint, glove.position, new Color(1, 0, 1), 0.005f); Lines.Add(glove.position, virtualGlove.position, new Color(0, 1, 1), 0.005f); + // Twist + float twistValue = twist ? stretch : 0; + Lines.Add( + wrist.position + glove.orientation * Vec3.Up * 0.04f, + wrist.position + glove.orientation * Vec3.Up * 0.05f, + new Color(1, 1, 0), 0.005f + ); + Vec3 lastPos = wrist.position; + for (int i = 0; i < 32; i++) { + float tw = twistValue * (i / 31f); + tw *= twistOut ? -1 : 1; + Vec3 nextPos = wrist.position + twistFrom * new Vec3(SKMath.Sin(tw * SKMath.Pi), SKMath.Cos(tw * SKMath.Pi), 0) * 0.05f; + + Lines.Add(lastPos, nextPos, new Color(1, 1, 0), 0.005f); // convert to LinePoints ? + lastPos = nextPos; + } + mesh.Draw(mat, glove.ToMatrix(new Vec3(0.025f, 0.1f, 0.1f) / 3)); mesh.Draw(mat, virtualGlove.ToMatrix(new Vec3(0.025f, 0.1f, 0.1f))); } diff --git a/app/SpatialCursor.cs b/app/SpatialCursor.cs index 6d9ad73..190342a 100644 --- a/app/SpatialCursor.cs +++ b/app/SpatialCursor.cs @@ -87,9 +87,9 @@ public class TwistCursor : SpatialCursor { outty = Vec3.Dot(from * Vec3.Up, quat * Vec3.Right * (chirality ? 1 : -1)) > 0; p0 = pos + quat * Vec3.Forward * twist * str; - // model.Draw(Matrix.TS(p0, 0.02f)); - // Lines.Add(pos, pos + from * Vec3.Up * 0.1f, new Color(1, 0, 1), 0.005f); + // Render + // model.Draw(Matrix.TS(p0, 0.02f)); Lines.Add(pos, pos + quat * Vec3.Up * 0.1f, new Color(1, 0, 1), 0.005f); Lines.Add(pos, p0, new Color(0, 1, 1), 0.005f); // draw the twist (angle)