diff --git a/app/Mono.cs b/app/Mono.cs index 5998dc7..4e22b53 100644 --- a/app/Mono.cs +++ b/app/Mono.cs @@ -13,7 +13,7 @@ public class Mono { // ------------------------------------------------- - dof[] dofs; + public dof[] dofs; int dofIndex = 0; dof dof => dofs[dofIndex]; @@ -44,9 +44,10 @@ public class Mono { dofs = new dof[] { // new StretchFinger(), - // new Trackballer(), - new WaveCursor() { handId = 0, deadzone = 0.01f, strength = 3f }, - new WaveCursor() { handId = 1, deadzone = 0.01f, strength = 3f }, + new WaveCursor() { handed = Handed.Left, deadzone = 0.01f, strength = 3f }, + new WaveCursor() { handed = Handed.Right, deadzone = 0.01f, strength = 3f }, + new Trackballer() { handed = Handed.Left }, + new Trackballer() { handed = Handed.Right }, // new StretchCursor() { deadzone = 0.01f, strength = 3f }, // new StretchCursor() { deadzone = 0.01f, strength = 3f }, }; @@ -55,8 +56,8 @@ public class Mono { public void Init() { - dofs[0].Init(); - dofs[1].Init(); + // dofs[0].Init(); + // dofs[1].Init(); // spaceMono.Init(); @@ -91,6 +92,9 @@ public class Mono { // dof.Frame(); dofs[0].Frame(); dofs[1].Frame(); + dofs[2].Frame(); + dofs[3].Frame(); + // rGlove.Step(); lGlove.Step(); @@ -100,19 +104,19 @@ public class Mono { // colorCube.Palm(lCon.device); - // oriel.Frame(); + oriel.Frame(); scene.Step(); // after! (render scene after oriel) // ------------------------------------------------- // spaceMono.Frame(); - // greenyard.Frame(); + greenyard.Frame(); // board.Frame(); // ------------------------------------------------- - // oriel.Render(); + oriel.Render(); net.me.Step(); net.send = true; diff --git a/app/Oriel.cs b/app/Oriel.cs index e12106b..895d54c 100644 --- a/app/Oriel.cs +++ b/app/Oriel.cs @@ -95,16 +95,28 @@ public class Oriel { Glove rGlove = Mono.inst.rGlove; // Vec3 lGlovePos = rig.lGlove.virtualGlove.position; - bool onpress = rig.rCon.triggerBtn.frameDown; - bool held = rig.rCon.triggerBtn.held; - bool onlift = rig.rCon.triggerBtn.frameUp; - cursor = rGlove.virtualGlove.position; - cursorOri = rGlove.virtualGlove.orientation; + // glove + // bool frameDown = rig.rCon.triggerBtn.frameDown; + // bool held = rig.rCon.triggerBtn.held; + // bool frameUp = rig.rCon.triggerBtn.frameUp; + // cursor = rGlove.virtualGlove.position; + // cursorOri = rGlove.virtualGlove.orientation; + + // hand + Trackballer tb = (Trackballer)Mono.inst.dofs[3]; + bool frameDown = tb.btnIn.frameDown; + bool held = tb.btnIn.held; + bool frameUp = tb.btnIn.frameUp; + + WaveCursor wc = (WaveCursor)Mono.inst.dofs[1]; + cursor = wc.cursor.position; + cursorOri = wc.cursor.orientation; + // debug - // bool onpress = Input.Key(Key.Space).IsJustActive(); + // bool frameDown = Input.Key(Key.Space).IsJustActive(); // bool held = Input.Key(Key.Space).IsActive(); - // bool onlift = Input.Key(Key.Space).IsJustInactive(); + // bool frameUp = Input.Key(Key.Space).IsJustInactive(); // if (!Input.Key(Key.Shift).IsActive()) { // Vec3 input = new Vec3( // (Input.Key(Key.S).IsActive() ? 1 : 0) - (Input.Key(Key.A).IsActive() ? 1 : 0), @@ -147,7 +159,7 @@ public class Oriel { qOffset = (ori.Inverse * cursorOri).Normalized; mOffset = matrix; - interacting = onpress; + interacting = frameDown; scaling = false; cornerDetect = Vec3.Zero; } @@ -185,7 +197,7 @@ public class Oriel { anchorOffset = localCursor - LocalAnchor; - scaling = onlift; + scaling = frameUp; } if (scaling) { diff --git a/app/dofs/dof.cs b/app/dofs/dof.cs index af900da..ba7a865 100644 --- a/app/dofs/dof.cs +++ b/app/dofs/dof.cs @@ -1,4 +1,4 @@ -interface dof { // ? +public interface dof { // ? void Init(); void Frame(); // void Drop(); diff --git a/app/dofs/stretch-cursor/og/StretchCursor.cs b/app/dofs/stretch-cursor/og/StretchCursor.cs index 78ca36b..5fa8e55 100644 --- a/app/dofs/stretch-cursor/og/StretchCursor.cs +++ b/app/dofs/stretch-cursor/og/StretchCursor.cs @@ -2,24 +2,29 @@ namespace Oriels; class StretchCursor : dof { // input - public Vec3 vTo, vFrom; + Vec3 vTo; + Vec3 vFrom; // data - public Vec3 cursor; + float stretch; + Vec3 cursor; public void Init() {} - public void Frame() { - float mag = (vTo - vFrom).Magnitude; - float stretch = Math.Max(mag - deadzone, 0f); + public void Frame() { + float mag = (vTo - vFrom).Magnitude; + stretch = MathF.Max(mag - deadzone, 0); - Vec3 dir = PullRequest.Direction(vTo, vFrom); - cursor = vTo + dir * stretch * strength; + Vec3 dir = PullRequest.Direction(vTo, vFrom); + cursor = vTo + dir * stretch * strength; - Mesh.Cube.Draw(Material.Default, Matrix.TS(cursor, 0.01f)); - } + // draw + Lines.Add(vFrom, vTo, new Color(1, 1, 1), 0.002f); + Lines.Add(vTo, cursor, new Color(1, 0, 0), 0.002f); + Mesh.Cube.Draw(Material.Default, Matrix.TRS(cursor, Quat.Identity, 0.04f)); + } // design - public float deadzone = 0.1f; - public float strength = 3f; + float deadzone = 0.1f; + float strength = 3f; } diff --git a/app/dofs/stretch-cursor/wave/WaveCursor.cs b/app/dofs/stretch-cursor/wave/WaveCursor.cs index b4d69fe..2c15799 100644 --- a/app/dofs/stretch-cursor/wave/WaveCursor.cs +++ b/app/dofs/stretch-cursor/wave/WaveCursor.cs @@ -1,113 +1,39 @@ namespace Oriels; class WaveCursor : dof { - public WaveCursor() { - } - - Vec3 oldLocalPad; - Quat delta; + // data public Pose cursor = Pose.Identity; - Material mat; - public void Init() { - mat = Material.Default.Copy(); - mat.SetTexture("diffuse", Tex.DevTex); - } + + public void Init() {} - bool isTracking = false; public void Frame() { - Hand hand = Input.Hand(handId); - + Hand hand = Input.Hand(handed); if (hand.tracked.IsActive() && !hand.tracked.IsJustActive()) { - // p0.position = hand.Get(FingerId.Index, JointId.KnuckleMajor).position; - // p1.position = hand.Get(FingerId.Index, JointId.Tip).position; + float fI = Flexion(hand, FingerId.Index); + float fM = Flexion(hand, FingerId.Middle); + float fR = Flexion(hand, FingerId.Ring); + float fL = Flexion(hand, FingerId.Little); + + float stretch = (fI + fI + fM + fM + fM + fR + fR + fL) / 8f; // based on finger length + + Vec3 dir = PullRequest.Direction( + hand.Get(FingerId.Index, JointId.Tip).position, + hand.Get(FingerId.Index, JointId.KnuckleMajor).position + ); + + Vec3 rawPos = hand.Get(FingerId.Index, JointId.Tip).position + dir * stretch * strength * Mono.inst.stretchStr; + cursor.position = Vec3.Lerp(cursor.position, rawPos, Time.Elapsedf * 6f); + cursor.orientation = hand.palm.orientation; - isTracking = true; } - float fI = Flexion(hand, FingerId.Index); - float fM = Flexion(hand, FingerId.Middle); - float fR = Flexion(hand, FingerId.Ring); - float fL = Flexion(hand, FingerId.Little); - - float stretch = (fI + fI + fM + fM + fM + fR + fR + fL) / 8f; // based on finger length - - Vec3 dir = PullRequest.Direction( - hand.Get(FingerId.Index, JointId.Tip).position, - hand.Get(FingerId.Index, JointId.KnuckleMajor).position - ); - - cursor.position = hand.Get(FingerId.Index, JointId.Tip).position + dir * stretch * strength * Mono.inst.stretchStr; - - - // thumb trackballer - float d = Vec3.Distance( - hand.Get(FingerId.Index, JointId.KnuckleMid).position, - hand.Get(FingerId.Index, JointId.KnuckleMajor).position - ); - Vec3 anchor = hand.Get(FingerId.Index, JointId.KnuckleMajor).position; - anchor = anchor + hand.palm.orientation * Vec3.Forward * d; - Matrix mAnchor = Matrix.TR(anchor, hand.palm.orientation); - Matrix mAnchorInv = mAnchor.Inverse; - - - Vec3 pad = Vec3.Lerp( - hand.Get(FingerId.Thumb, JointId.KnuckleMinor).position, - hand.Get(FingerId.Thumb, JointId.Tip).position, - 0.5f - ); - Vec3 localPad = mAnchorInv.Transform(pad); - - Color color = Color.White; - if (localPad.Length < 0.015f) { - color = new Color(1, 0, 0); - } - if (localPad.Length > 0.055f) { - color = new Color(0, 1, 1); - } - - if (localPad.Length < 0.03f && isTracking) { - delta = PullRequest.Relative( - hand.palm.orientation, - PullRequest.Delta(localPad.Normalized, oldLocalPad.Normalized) - ).Normalized; - } - - if (isTracking) { - Quat newOri = delta * cursor.orientation; - if (new Vec3(newOri.x, newOri.y, newOri.z).LengthSq > 0) { - cursor.orientation = newOri; - } - } - - // Lines.Add( - // mAnchor.Transform(padIn), - // mAnchor.Transform(padOut), - // new Color(1, 1, 1), 0.004f - // ); - - // show that you are about to boolean in and out - - // trackballer demo - // fly around a "ship" with the cursor - // and turn it with the thumb trackballer - - - oldLocalPad = localPad; - - - - Mesh.Sphere.Draw(mat, Matrix.TRS(anchor, cursor.orientation, 0.045f), color); - // Mesh.Cube.Draw(Material.Default, Matrix.TRS(anchor, cursor.orientation, 0.02f)); - - - if (isTracking) { Demo(); } + Demo(); } - public bool backhand = true; public float deadzone = 0.1f; public float strength = 3f; - public int handId = 0; + public Handed handed = Handed.Left; float Flexion(Hand hand, FingerId finger) { @@ -126,11 +52,27 @@ class WaveCursor : dof { } - Vec3 smoothPos; - Vec3[] points = new Vec3[64]; + Vec3[] mm = new Vec3[64]; + + Vec3[] xL = new Vec3[64]; + Vec3[] xR = new Vec3[64]; + Vec3[] yL = new Vec3[64]; + Vec3[] yR = new Vec3[64]; + Vec3[] zL = new Vec3[64]; + Vec3[] zR = new Vec3[64]; void Demo() { - points[0] = smoothPos = Vec3.Lerp(smoothPos, cursor.position, Time.Elapsedf * 6f); + Trail(mm, cursor.position); + // Trail(xL, smoothPos + cursor.orientation * new Vec3(-1, 0, 0) * 0.1f); + // Trail(xR, smoothPos + cursor.orientation * new Vec3( 1, 0, 0) * 0.1f); + // Trail(yL, smoothPos + cursor.orientation * new Vec3(0, -1, 0) * 0.1f); + // Trail(yR, smoothPos + cursor.orientation * new Vec3(0, 1, 0) * 0.1f); + // Trail(zL, smoothPos + cursor.orientation * new Vec3(0, 0, -1) * 0.1f); + // Trail(zR, smoothPos + cursor.orientation * new Vec3(0, 0, 1) * 0.1f); + } + + void Trail(Vec3[] points, Vec3 nextPos) { + points[0] = nextPos; int len = (int)(points.Length * Mono.inst.trailLen); for (int i = 0; i < len; i++) { if (i > 0) { @@ -141,13 +83,17 @@ class WaveCursor : dof { points[i] = points[i - 1] + dir * 0.02f * Mono.inst.trailScl; } - Vec3 from = i > 0 ? points[i - 1] : smoothPos; + Vec3 from = i > 0 ? points[i - 1] : nextPos; Mesh.Cube.Draw( Material.Default, - Matrix.TRS(points[i], Quat.LookDir(PullRequest.Direction(points[i], from)), 0.01f * Mono.inst.trailScl), + Matrix.TRS( + points[i], + Quat.LookDir(PullRequest.Direction(points[i], from)), + new Vec3(0.01f, 0.01f, 0.02f) * Mono.inst.trailScl + ), Color.HSV(i / (float)len, 1, 1) ); } - } + } } \ No newline at end of file diff --git a/app/dofs/trackballer/Trackballer.cs b/app/dofs/trackballer/Trackballer.cs index a1466ad..0c1b2da 100644 --- a/app/dofs/trackballer/Trackballer.cs +++ b/app/dofs/trackballer/Trackballer.cs @@ -1,54 +1,70 @@ namespace Oriels; class Trackballer : dof { - Pose anchor = Pose.Identity; - Quat ori = Quat.Identity; - Quat qDelta = Quat.Identity; - Vec2 oldMouse; - public void Init() { + // data + public Btn btnIn, btnOut; + public Quat ori = Quat.Identity; + Vec3 oldLocalPad; + Quat delta = Quat.Identity; - } + public void Init() {} public void Frame() { - // apply the qDelta to the current orientation relative to the head orientation - // Quat headOri = Input.Head.orientation; - // ori = (headOri * qDelta * headOri.Inverse * ori).Normalized; - // PullRequest.Relative(headOri, qDelta) * ori; + Hand hand = Input.Hand(handed); + if (hand.tracked.IsActive() && !hand.tracked.IsJustActive()) { + Vec3 anchor = hand.Get(FingerId.Index, JointId.KnuckleMajor).position; + anchor = anchor + hand.palm.orientation * Vec3.Forward * 0.045f; + Matrix mAnchor = Matrix.TR(anchor, hand.palm.orientation); + Matrix mAnchorInv = mAnchor.Inverse; - Vec2 mouse = Input.Mouse.pos; - mouse = new Vec2( - (mouse.x / 1280 * 2) - 1f, - (mouse.y / 720 * 2) - 1f - ) * 4f; + Vec3 pad = Vec3.Lerp( + hand.Get(FingerId.Thumb, JointId.KnuckleMinor).position, + hand.Get(FingerId.Thumb, JointId.Tip).position, + 0.5f + ); + Vec3 localPad = mAnchorInv.Transform(pad); - ori = PullRequest.Delta( - new Vec3(mouse.x, mouse.y, 1).Normalized, - new Vec3(oldMouse.x, oldMouse.y, 1).Normalized - ) * ori; + Color color = Color.White; + btnIn.Step(localPad.Length < layer[0]); + if (localPad.Length < layer[0]) { + color = new Color(1, 0, 0); + } + btnOut.Step(localPad.Length > layer[2]); + if (localPad.Length > layer[2]) { + color = new Color(0, 1, 1); + } - oldMouse = mouse; + if (localPad.Length < layer[1]) { + delta = PullRequest.Relative( + hand.palm.orientation, + PullRequest.Delta(localPad.Normalized, oldLocalPad.Normalized) + ).Normalized; + } + oldLocalPad = localPad; - Lines.Add( - anchor.position - ori * new Vec3(-1, 0, 0) * 0.1f, - anchor.position - ori * new Vec3( 1, 0, 0) * 0.1f, - new Color(1, 0, 0), 0.002f - ); - Lines.Add( - anchor.position - ori * new Vec3( 0,-1, 0) * 0.1f, - anchor.position - ori * new Vec3( 0, 1, 0) * 0.1f, - new Color(0, 1, 0), 0.002f - ); - Lines.Add( - anchor.position - ori * new Vec3( 0, 0,-1) * 0.1f, - anchor.position - ori * new Vec3( 0, 0, 1) * 0.1f, - new Color(0, 0, 1), 0.002f - ); - Mesh.Cube.Draw(Material.Default, Matrix.TRS(anchor.position, ori, 0.04f)); + // Draw + Mesh.Sphere.Draw(Mono.inst.matDev, Matrix.TRS(anchor, ori, 0.045f), color); + } + + Quat newOri = delta * ori; + if (new Vec3(newOri.x, newOri.y, newOri.z).LengthSq > 0) { + ori = newOri; + } + + // show that you are about to boolean in and out + + // trackballer demo + // fly around a "ship" with the cursor + // and turn it with the thumb trackballer } - Vec2 fromMouse = new Vec2(0, 0); + // design + public Handed handed = Handed.Left; + public float[] layer = new float[] { 0.015f, 0.03f, 0.055f }; - public float deadzone = 0.1f; + + + public float scale = 1; } diff --git a/oriels.csproj b/oriels.csproj index 8e78513..7470993 100644 --- a/oriels.csproj +++ b/oriels.csproj @@ -7,7 +7,7 @@ - +