This commit is contained in:
ethan merchant 2023-07-19 19:18:51 -04:00
parent 8308529340
commit 99c99dde80
5 changed files with 82 additions and 59 deletions

View file

@ -58,7 +58,7 @@ public class Glove {
if (lift) { if (lift) {
pullPoint = con.pos + -direction * stretch; pullPoint = con.pos + -direction * stretch;
} else { } else {
direction = PR.Direction(con.pos, pullPoint); direction = Vec3.Direction(con.pos, pullPoint);
} }
} else { } else {
pullPoint = con.pos; pullPoint = con.pos;
@ -83,7 +83,7 @@ public class Glove {
case Pull.Backhanded: case Pull.Backhanded:
pullPoint = otherCon.pos; pullPoint = otherCon.pos;
direction = PR.Direction(con.pos, otherCon.pos); direction = Vec3.Direction(con.pos, otherCon.pos);
virtualGlove.orientation = con.ori; virtualGlove.orientation = con.ori;
break; break;
} }

View file

@ -8,6 +8,9 @@ class RollsCursor : Interaction {
// data // data
public Cursor cursor = new Cursor(); public Cursor cursor = new Cursor();
PR.Delta fIdelta = new PR.Delta();
PR.Delta fMdelta = new PR.Delta();
PR.Delta fRdelta = new PR.Delta();
public void Init() { } public void Init() { }
@ -22,12 +25,23 @@ class RollsCursor : Interaction {
float stretch = (fI + fM + fR + fL) / 4f; float stretch = (fI + fM + fR + fL) / 4f;
Vec3 to = Roll(hand, JointId.KnuckleMid, fI, fM, fR, fL); // Vec3 to = Roll(hand, JointId.KnuckleMid, fI, fM, fR, fL);
Vec3 from = Roll(hand, JointId.KnuckleMajor, fI, fM, fR, fL); // Vec3 from = Roll(hand, JointId.KnuckleMajor, fI, fM, fR, fL);
Vec3 dir = PR.Direction(to, from); // Vec3 dir = Vec3.Direction(to, from);
cursor.raw = to + dir * stretch * reach.value; // cursor.raw = to + dir * stretch * reach.value;
if (fL == 0.0f) {
cursor.raw = hand.Get(FingerId.Index, JointId.Tip).position;
}
fIdelta.Update(hand.Get(FingerId.Index, JointId.Tip).position);
fMdelta.Update(hand.Get(FingerId.Middle, JointId.Tip).position);
fRdelta.Update(hand.Get(FingerId.Ring, JointId.Tip).position);
Vec3 delta = (fIdelta.value + fMdelta.value + fRdelta.value) / 3f;
cursor.raw += delta * 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.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.pos, Quat.Identity, 0.01f), new Color(0, 1, 0));
@ -36,7 +50,7 @@ class RollsCursor : Interaction {
} }
// design // design
public Design reach = new Design { str = "1.0", term = "0+m", min = 0 }; public Design reach = new Design { str = "3.0", term = "0+m", min = 0 };
public Vec3 Roll(Hand hand, JointId jointId, float fI, float fM, float fR, float fL) { public Vec3 Roll(Hand hand, JointId jointId, float fI, float fM, float fR, float fL) {
Vec3 i = hand.Get(FingerId.Index, jointId).position; Vec3 i = hand.Get(FingerId.Index, jointId).position;

View file

@ -20,7 +20,7 @@ public class Mono {
// ------------------------------------------------- // -------------------------------------------------
public Interaction[] dofs; public Interaction[] interactions;
public ColorCube colorCube = new ColorCube(); public ColorCube colorCube = new ColorCube();
@ -32,7 +32,7 @@ public class Mono {
// public MonoNet net = new MonoNet(); // public MonoNet net = new MonoNet();
public Mono() { public Mono() {
dofs = new Interaction[] { interactions = new Interaction[] {
new Chiral(new Interaction[] { new Chiral(new Interaction[] {
new WaveCursor() { handed = Handed.Left }, new WaveCursor() { handed = Handed.Left },
new WaveCursor() { handed = Handed.Right } new WaveCursor() { handed = Handed.Right }
@ -51,8 +51,8 @@ public class Mono {
public void Init() { public void Init() {
compositor.Init(); compositor.Init();
for (int i = 0; i < dofs.Length; i++) { for (int i = 0; i < interactions.Length; i++) {
dofs[i].Init(); interactions[i].Init();
} }
matDev = Material.Default.Copy(); matDev = Material.Default.Copy();
@ -104,10 +104,10 @@ public class Mono {
// Input.HandClearOverride(Handed.Right); // Input.HandClearOverride(Handed.Right);
// store hand pre override in rig // store hand pre override in rig
rig.Step(); rig.Step();
Hand h = Input.Hand(Handed.Right); // Hand h = Input.Hand(Handed.Right);
if (h.pinch.IsActive()) { // if (h.pinch.IsActive()) {
Console.WriteLine($"{h.pinchPt}, {Input.Head.orientation * -Vec3.Forward}"); // Console.WriteLine($"{h.pinchPt}, {Input.Head.orientation * -Vec3.Forward}");
} // }
// Hand hand = Input.Hand(Handed.Right); // Hand hand = Input.Hand(Handed.Right);
// Controller con = Input.Controller(Handed.Right); // Controller con = Input.Controller(Handed.Right);
@ -125,30 +125,30 @@ public class Mono {
spatial.Frame(); spatial.Frame();
// pinch-cursor? // pinch-cursor?
{ // {
float deadzone = 0.01f; // float deadzone = 0.01f;
float strength = 6f; // float strength = 6f;
Hand hand = Input.Hand(Handed.Right); // Hand hand = Input.Hand(Handed.Right);
Vec3 indexTip = hand.Get(FingerId.Index, JointId.Tip).position; // Vec3 indexTip = hand.Get(FingerId.Index, JointId.Tip).position;
Vec3 thumbTip = hand.Get(FingerId.Thumb, JointId.Tip).position; // Vec3 thumbTip = hand.Get(FingerId.Thumb, JointId.Tip).position;
Vec3 delta = indexTip - thumbTip; // Vec3 delta = indexTip - thumbTip;
float mag = delta.Magnitude; // float mag = delta.Magnitude;
float pinch = MathF.Max(mag - deadzone, 0); // float pinch = MathF.Max(mag - deadzone, 0);
Vec3 dir = delta.Normalized; // Vec3 dir = delta.Normalized;
cursor.raw = indexTip + dir * pinch * strength; // cursor.raw = indexTip + dir * pinch * strength;
Lines.Add(indexTip, thumbTip, new Color(0, 0, 1), 0.002f); // Lines.Add(indexTip, thumbTip, new Color(0, 0, 1), 0.002f);
Mesh.Sphere.Draw(matHolo, Matrix.TS(cursor.pos, 0.01f), new Color(0.5f, 0.5f, 0.5f)); // Mesh.Sphere.Draw(matHolo, Matrix.TS(cursor.pos, 0.01f), new Color(0.5f, 0.5f, 0.5f));
// V.XYZ(0, 0, ); // // V.XYZ(0, 0, );
drawerA.Frame(cursor, pinch); // drawerA.Frame(cursor, pinch);
drawerB.Frame(cursor, pinch); // drawerB.Frame(cursor, pinch);
drawerC.Frame(cursor, pinch); // drawerC.Frame(cursor, pinch);
} // }
@ -156,17 +156,17 @@ public class Mono {
// ------------------------------------------------- // -------------------------------------------------
for (int i = 0; i < dofs.Length; i++) { for (int i = 0; i < interactions.Length; i++) {
if (dofs[i].Active) { if (interactions[i].Active) {
dofs[i].Frame(); interactions[i].Frame();
} }
} }
// <Heresy> // <Heresy>
WaveCursor lwc = (WaveCursor)((Chiral)dofs[0]).dofs[0]; WaveCursor lwc = (WaveCursor)((Chiral)interactions[0]).dofs[0];
WaveCursor rwc = (WaveCursor)((Chiral)dofs[0]).dofs[1]; WaveCursor rwc = (WaveCursor)((Chiral)interactions[0]).dofs[1];
Trackballer ltb = (Trackballer)((Chiral)dofs[1]).dofs[0]; Trackballer ltb = (Trackballer)((Chiral)interactions[1]).dofs[0];
Trackballer rtb = (Trackballer)((Chiral)dofs[1]).dofs[1]; Trackballer rtb = (Trackballer)((Chiral)interactions[1]).dofs[1];
if (lwc.Active) { if (lwc.Active) {
lwc.Demo(ltb.ori); lwc.Demo(ltb.ori);
@ -249,12 +249,12 @@ public class Mono {
dofIndex--; dofIndex--;
} }
UI.SameLine(); UI.SameLine();
if (UI.Button("next") && dofIndex < dofs.Length - 1) { if (UI.Button("next") && dofIndex < interactions.Length - 1) {
dofIndex++; dofIndex++;
} }
Interaction dof = dofs[dofIndex]; Interaction dof = interactions[dofIndex];
Type type = dof.GetType(); Type type = dof.GetType();
// active toggle // active toggle
Color tint = dof.Active ? new Color(0, 1, 0) : new Color(1, 0, 0); Color tint = dof.Active ? new Color(0, 1, 0) : new Color(1, 0, 0);

View file

@ -49,17 +49,17 @@ public static class PR {
} }
} }
// construct the quaternion that rotates one vector to another // // construct the quaternion that rotates one vector to another
// uses the usual trick to get the half angle // // uses the usual trick to get the half angle
public static Quat Delta(Vec3 to, Vec3 from) { // public static Quat Delta(Vec3 to, Vec3 from) {
Vec3 vec = Vec3.Cross(from, to); // Vec3 vec = Vec3.Cross(from, to);
return new Quat( // return new Quat(
vec.x, // vec.x,
vec.y, // vec.y,
vec.z, // vec.z,
1 + Vec3.Dot(to, from ) // 1 + Vec3.Dot(to, from )
).Normalized; // ).Normalized;
} // }
// Quat q; // Quat q;
// public static void Relative(Quat to) => q = to * q * to.Inverse; // public static void Relative(Quat to) => q = to * q * to.Inverse;
@ -93,12 +93,8 @@ public static class PR {
return r.Next(min, max); return r.Next(min, max);
} }
public static Vec3 Direction(Vec3 to, Vec3 from) {
return (to - from).Normalized;
}
public static Vec3 SnapToLine(this Vec3 v, Vec3 a, Vec3 b, bool clamp, out float t, float tMin = 0, float tMax = 1) { public static Vec3 SnapToLine(this Vec3 v, Vec3 a, Vec3 b, bool clamp, out float t, float tMin = 0, float tMax = 1) {
Quat q = Quat.LookDir(Direction(b, a)); Quat q = Quat.LookDir(Vec3.Direction(b, a));
Vec3 lv = q.Inverse * (v - a); Vec3 lv = q.Inverse * (v - a);
lv.x = lv.y = 0; lv.x = lv.y = 0;
Vec3 r = q * lv + a; Vec3 r = q * lv + a;
@ -306,6 +302,19 @@ public static class PR {
// } // }
// } // }
public class Delta {
public Vec3 value { get; private set; }
Vec3 last;
public Vec3 Update(Vec3 current) {
value = current - last;
last = current;
return value;
}
}
public class PID { public class PID {
public float p, i; public float p, i;
public float value; public float value;

View file

@ -7,7 +7,7 @@ SKSettings settings = new SKSettings {
assetsFolder = "add", assetsFolder = "add",
depthMode = DepthMode.D32, depthMode = DepthMode.D32,
disableUnfocusedSleep = true, disableUnfocusedSleep = true,
displayPreference = DisplayMode.Flatscreen, // displayPreference = DisplayMode.Flatscreen,
// disableFlatscreenMRSim = true, // disableFlatscreenMRSim = true,
}; };
if (!SK.Initialize(settings)) if (!SK.Initialize(settings))