thumb pad roll

This commit is contained in:
spatialfree 2022-10-05 22:38:09 -04:00
parent f3f62b4eb7
commit bacbd224e2
3 changed files with 79 additions and 17 deletions

View file

@ -96,6 +96,26 @@ public class Mono {
dofs[3].Frame(); 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(); // rGlove.Step(); lGlove.Step();
// rBlock.Step(); lBlock.Step(); // rBlock.Step(); lBlock.Step();

View file

@ -92,6 +92,41 @@ public static class PullRequest {
return (to - from).Normalized; return (to - from).Normalized;
} }
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 // swizzle
public static Vec3 JustX(this Vec3 v) { public static Vec3 JustX(this Vec3 v) {
return new Vec3(v.x, 0, 0); return new Vec3(v.x, 0, 0);

View file

@ -18,10 +18,10 @@ class Trackballer : dof {
Matrix mAnchor = Matrix.TR(anchor, hand.palm.orientation); Matrix mAnchor = Matrix.TR(anchor, hand.palm.orientation);
Matrix mAnchorInv = mAnchor.Inverse; Matrix mAnchorInv = mAnchor.Inverse;
Vec3 pad = Vec3.Lerp( Vec3 pad = anchor.SnapToLine(
hand.Get(FingerId.Thumb, JointId.KnuckleMinor).position,
hand.Get(FingerId.Thumb, JointId.Tip).position, hand.Get(FingerId.Thumb, JointId.Tip).position,
0.5f hand.Get(FingerId.Thumb, JointId.KnuckleMinor).position,
true
); );
Vec3 localPad = mAnchorInv.Transform(pad); Vec3 localPad = mAnchorInv.Transform(pad);
@ -31,25 +31,32 @@ class Trackballer : dof {
} else { } else {
btnIn.Step(localPad.Length < layer[0]); 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;
if (btnOut.held) {
btnOut.Step(localPad.Length > layer[1]);
} else {
btnOut.Step(localPad.Length > layer[2]); btnOut.Step(localPad.Length > layer[2]);
if (localPad.Length > layer[2]) {
color = new Color(0, 1, 1);
} }
color = btnOut.held ? new Color(0, 1, 0) : color;
if (btnIn.held) {
delta = Quat.Identity;
} else {
if (localPad.Length < layer[1]) { if (localPad.Length < layer[1]) {
delta = PullRequest.Relative( delta = PullRequest.Relative(
hand.palm.orientation, hand.palm.orientation,
PullRequest.Delta(localPad.Normalized, oldLocalPad.Normalized) PullRequest.Delta(localPad.Normalized, oldLocalPad.Normalized)
).Normalized; ).Normalized;
} }
}
oldLocalPad = localPad; oldLocalPad = localPad;
// Draw // 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; Quat newOri = delta * ori;
@ -66,7 +73,7 @@ class Trackballer : dof {
// design // design
public Handed handed = Handed.Left; 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 };