diff --git a/app/Mono.cs b/app/Mono.cs index 6acb304..86d0550 100644 --- a/app/Mono.cs +++ b/app/Mono.cs @@ -44,18 +44,18 @@ public class Mono { Renderer.SetClip(0.02f, 1000f); dofs = new dof[] { - new Chiral() { - dofs = new dof[] { - new WaveCursor() { handed = Handed.Left }, - new WaveCursor() { handed = Handed.Right } - } - }, - new Chiral() { - dofs = new dof[] { - new Trackballer() { handed = Handed.Left }, - new Trackballer() { handed = Handed.Right } - } - }, + new Chiral(new dof[] { + new RollsCursor() { handed = Handed.Left }, + new RollsCursor() { handed = Handed.Right } + }), + new Chiral(new dof[] { + new WaveCursor() { handed = Handed.Left }, + new WaveCursor() { handed = Handed.Right } + }), + new Chiral(new dof[] { + new Trackballer() { handed = Handed.Left }, + new Trackballer() { handed = Handed.Right } + }), }; } @@ -122,30 +122,31 @@ public class Mono { } // - 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)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]; - if (lwc.Active) { - lwc.Demo(ltb.ori); - } - if (rwc.Active) { - rwc.Demo(rtb.ori); - } + // if (lwc.Active) { + // lwc.Demo(ltb.ori); + // } + // if (rwc.Active) { + // rwc.Demo(rtb.ori); + // } - if (rtb.Active) { - rtb.Demo(); - } + // if (rtb.Active) { + // rtb.Demo(); + // } - if (!shapeHeld) { - shapeHeld = rtb.btnPush.frameDown; - } - if (shapeHeld) { - shape.position = rwc.cursor.smooth; - shape.orientation = rtb.ori; - shapeHeld = !rtb.btnPull.frameDown; - } + // if (!shapeHeld) { + // shapeHeld = rtb.btnPush.frameDown; + // } + // if (shapeHeld) { + // shape.position = rwc.cursor.smooth; + // shape.orientation = rtb.ori; + // shapeHeld = !rtb.btnPull.frameDown; + // } + // I'd rather have it be pose.pos & pose.ori // as it's a bit of space hog @@ -261,6 +262,7 @@ public class Mono { // Chiral : handedness implies symmetry public class Chiral : dof { + public Chiral(dof[] dofs) => this.dofs = dofs; private bool active; public bool Active { get { return this.active; } diff --git a/app/Rig/Rig.cs b/app/Rig/Rig.cs index ed9f20b..8775dd8 100644 --- a/app/Rig/Rig.cs +++ b/app/Rig/Rig.cs @@ -83,6 +83,21 @@ public class Rig { lWrist = new Pose(lCon.pos + lCon.ori * new Vec3(0, 0, 0.052f), lCon.ori); } + public float Flexion(Hand hand, FingerId finger, float deadzone = 0.3f) { + float flexion = (Vec3.Dot( + PullRequest.Direction( + hand.Get(finger, JointId.Tip).position, + hand.Get(finger, JointId.KnuckleMinor).position + ), + PullRequest.Direction( + hand.Get(finger, JointId.KnuckleMid).position, + hand.Get(finger, JointId.KnuckleMajor).position + ) + ) + 1f) / 2; + + return Math.Max(flexion - deadzone, 0f) / (1 - deadzone); + } + public Vec3 Fullstick(bool chirality) { Controller con = Con(chirality).device; Quat rot = Quat.FromAngles(con.stick.y * -90, 0, con.stick.x * 90); diff --git a/app/Space.cs b/app/Space.cs index 7335f90..8053049 100644 --- a/app/Space.cs +++ b/app/Space.cs @@ -183,52 +183,53 @@ public class Space { float r; // damage float g; // resources float b; // peak + Vec3 pos; + float angle; // color(r, max(g, b), b) // height = b public void Frame() { } - - /* - - sapling - e - - e = lerp(e, g * lft, lft / x) - r += e - g -= e - b -= min(g, 0) - reliant on ideal conditions being there to ease off of the seed dependency - (scrappy can outlast the g) - - tree - r += min(g, 0) + background radiation * lft - g += b * lft - b += - r 0->b - g = clamp(g, 0, 1) - b = clamp(b, 0, 1) - - e = (r / neighbors) * lft - g -= e - - if g > 1 - r - seed(g) - g = 0 - - tilt towards best spot - * rand.dir * r * smoothstart (r * r * r * r * r) ? - - if r > b - b += lft - - if b > 1 - poof - - seed - g = what was passed down - pos = parent.pos + Quat.FromAngles(0, noise.value * 360f, 0) * parent.r // lol - */ } -} \ No newline at end of file +} + + +/* + COMMENTS + + sapling + e + + e = lerp(e, g * lft, lft / x) + r += e + g -= e + b -= min(g, 0) + reliant on ideal conditions being there to ease off of the seed dependency + (scrappy can outlast the g) + + tree + r += min(g, 0) + background radiation * lft + g += b * lft + b += + r 0->b + g = clamp(g, 0, 1) + b = clamp(b, 0, 1) + + e = (r / neighbors) * lft + g -= e + + if g > 1 - r + seed(g, pos + Quat.FromAngles(0, noise.value * 360f, 0) * b) + g = 0 + + tilt towards best spot + * rand.dir * r * smoothstart (r * r * r * r * r) ? + + if r > b + b += lft + + if b > 1 + poof + +*/ \ No newline at end of file diff --git a/app/dofs/rolls-cursor/RollsCursor.cs b/app/dofs/rolls-cursor/RollsCursor.cs new file mode 100644 index 0000000..770a374 --- /dev/null +++ b/app/dofs/rolls-cursor/RollsCursor.cs @@ -0,0 +1,73 @@ +namespace Oriels; + +class RollsCursor : dof { + public bool Active { get; set; } + + // input + public Handed handed = Handed.Left; + + // data + public Cursor cursor = new Cursor(); + + public void Init() { } + + public void Frame() { + Rig rig = Mono.inst.rig; + Hand hand = Input.Hand(handed); + if (hand.tracked.IsActive() && !hand.tracked.IsJustActive()) { + float fI = rig.Flexion(hand, FingerId.Index); + float fM = rig.Flexion(hand, FingerId.Middle); + float fR = rig.Flexion(hand, FingerId.Ring); + float fL = rig.Flexion(hand, FingerId.Little); + + // Biased by finger length + float stretch = (fI + fI + fM + fM + fM + fR + fR + fL) / 8f; + + Vec3 to = Roll(hand, JointId.Tip, fI, fM, fR, fL); + Vec3 from = Roll(hand, JointId.KnuckleMajor, fI, fM, fR, fL); + + Vec3 dir = PullRequest.Direction(to, from); + + cursor.raw = to + dir * stretch * 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)); + Mesh.Sphere.Draw(Mono.inst.matHoloframe, Matrix.TRS(cursor.smooth, Quat.Identity, 0.01f), new Color(0, 0, 1)); + } + } + + // design + public Design reach = new Design { str = "1.0", term = "0+m", min = 0 }; + + // Roll + // based on flexion + // with a "recursive" lerp + // i - m - r - l + // im - mr - rl + // imr - mrl + // imrl + public Vec3 Roll(Hand hand, JointId jointId, float fI, float fM, float fR, float fL) { + Vec3 i = hand.Get(FingerId.Index, jointId).position; + Vec3 m = hand.Get(FingerId.Middle, jointId).position; + Vec3 r = hand.Get(FingerId.Ring, jointId).position; + Vec3 l = hand.Get(FingerId.Little, jointId).position; + + Vec3 im = Vec3.Lerp(i , m , fM / (fM + fI)); + Vec3 mr = Vec3.Lerp( m , r , fR / (fR + fM)); + Vec3 rl = Vec3.Lerp( r, l, fL / (fL + fR)); + + Vec3 imr = Vec3.Lerp(im , mr , fR / (fR + fM + fI)); + Vec3 mrl = Vec3.Lerp( mr, rl, fL / (fL + fR + fM)); + + Vec3 imrl = Vec3.Lerp(imr, mrl, fL / (fL + fR + fM + fI)); + + return imrl; + } +} + + + +/* + COMMENTS + +*/ \ No newline at end of file diff --git a/app/dofs/stretch-cursor/wave/WaveCursor.cs b/app/dofs/stretch-cursor/wave/WaveCursor.cs index ef862a2..3f9d144 100644 --- a/app/dofs/stretch-cursor/wave/WaveCursor.cs +++ b/app/dofs/stretch-cursor/wave/WaveCursor.cs @@ -12,52 +12,38 @@ class WaveCursor : dof { public void Init() {} public void Frame() { + Rig rig = Mono.inst.rig; Hand hand = Input.Hand(handed); if (hand.tracked.IsActive() && !hand.tracked.IsJustActive()) { - 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 fI = rig.Flexion(hand, FingerId.Index); + float fM = rig.Flexion(hand, FingerId.Middle); + float fR = rig.Flexion(hand, FingerId.Ring); + float fL = rig.Flexion(hand, FingerId.Little); // Biased by finger length - float stretch = (fI + fI + fM + fM + fM + fR + fR + fL) / 8f; + float stretch = (fI + fI + fM + fM + fM + fR + fR + fL) / 8f; - Vec3 dir = PullRequest.Direction( - hand.Get(FingerId.Index, JointId.Tip).position, - hand.Get(FingerId.Index, JointId.KnuckleMajor).position - ); + Vec3 to = hand.Get(FingerId.Index, JointId.Tip).position; + Vec3 from = hand.Get(FingerId.Index, JointId.KnuckleMajor).position; - cursor.raw = hand.Get(FingerId.Index, JointId.Tip).position + dir * stretch * reach.value; + Vec3 dir = PullRequest.Direction(to, from); - 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)); + cursor.raw = to + dir * stretch * 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)); Mesh.Sphere.Draw(Mono.inst.matHoloframe, Matrix.TRS(cursor.smooth, Quat.Identity, 0.01f), new Color(0, 0, 1)); } } // design - public Design deadzone = new Design { str="0.3", term="0+1t", min=0, max=1 }; - public Design reach = new Design { str="1.0", term="0+m", min=0 }; + public Design reach = new Design { str="1.0", term="0+m", min=0 }; - float Flexion(Hand hand, FingerId finger) { - float flexion = (Vec3.Dot( - PullRequest.Direction( - hand.Get(finger, JointId.Tip).position, - hand.Get(finger, JointId.KnuckleMinor).position - ), - PullRequest.Direction( - hand.Get(finger, JointId.KnuckleMid).position, - hand.Get(finger, JointId.KnuckleMajor).position - ) - ) + 1f) / 2; - - return Math.Max(flexion - deadzone.value, 0f) / (1 - deadzone.value); - } // demo - public Design snakeLength = new Design { str="0.5", term="0+1t", min=0, max=1 }; - public Design snakeScale = new Design { str="0.333", term=">0", min=0.01f }; - public Design snakeRadius = new Design { str="4", term="0+cm", unit=U.cm, min=0 }; + public Design snakeLength = new Design { str="0.5", term="0+1t", min=0, max=1 }; + public Design snakeScale = new Design { str="0.333", term=">0", min=0.01f }; + public Design snakeRadius = new Design { str="4", term="0+cm", unit=U.cm, min=0 }; Vec3[] mm = new Vec3[128]; public void Demo(Quat ori) {