twist lift

This commit is contained in:
spatialfree 2022-01-15 15:23:32 -05:00
parent b55d97a8a3
commit 6788b46a10
2 changed files with 63 additions and 39 deletions

View file

@ -14,14 +14,21 @@ public class Glove {
} }
public Pose virtualGlove; public Pose virtualGlove;
Vec3 direction; Quat projection = Quat.Identity;
Vec3 direction {
get { return projection * new Vec3(0, 0, -1); }
set { projection = Quat.LookDir(value); }
}
public Pull? pulling = null; public Pull? pulling = null;
float stretch; float stretch;
float stretchDeadzone = 0; float stretchDeadzone = 0;
Vec3 pullPoint; Vec3 pullPoint;
Vec3 twistPoint;
float twist;
bool twistOut; bool twistOut;
Quat twistOffset;
Quat oldOri;
int firstFace; int firstFace;
@ -37,8 +44,8 @@ public class Glove {
} }
if (!con.device.IsX1Pressed && !con.device.IsX2Pressed) { firstFace = 0; } if (!con.device.IsX1Pressed && !con.device.IsX2Pressed) { firstFace = 0; }
bool twist = firstFace == 1; bool twisting = firstFace == 1;
bool reach = firstFace == 2; bool reaching = firstFace == 2;
bool lift = false; bool lift = false;
if (firstFace == 1 && con.device.IsX2Pressed) { lift = true; } if (firstFace == 1 && con.device.IsX2Pressed) { lift = true; }
@ -46,7 +53,7 @@ public class Glove {
// exclusive states? // exclusive states?
if (reach) { if (reaching) {
// shoulder stuff // shoulder stuff
// pullPoint = (shoulder.orientation * origin) + shoulder.position; // pullPoint = (shoulder.orientation * origin) + shoulder.position;
// shoulder.orientation.Inverse * (con.pose.position - shoulder.position) // shoulder.orientation.Inverse * (con.pose.position - shoulder.position)
@ -72,7 +79,7 @@ public class Glove {
case Pull.Stretch: case Pull.Stretch:
pullPoint = otherCon.pos; pullPoint = otherCon.pos;
direction = con.ori * Vec3.Forward; projection = con.ori;
virtualGlove.orientation = otherCon.ori; virtualGlove.orientation = otherCon.ori;
break; break;
@ -87,21 +94,35 @@ public class Glove {
pulling = null; pulling = null;
} }
stretch = Math.Max(Vec3.Distance(pullPoint, con.pos) - stretchDeadzone, 0); if (!twisting) {
stretch = Math.Max(Vec3.Distance(pullPoint, con.pos) - stretchDeadzone, 0);
twist = 0;
twistOffset = Quat.Identity;
}
if (!twist) { twistPoint = con.ori * Vec3.Up; } float twistDelta = MathF.Acos(Vec3.Dot(con.ori * projection * Vec3.Up, oldOri * projection * Vec3.Up)) / SKMath.Pi;
Quat twistFrom = Quat.LookAt(Vec3.Zero, con.ori * Vec3.Forward, twistPoint); twistOut = Vec3.Dot(con.ori * projection * Vec3.Up, oldOri * projection * Vec3.Right * (chirality ? 1 : -1)) > 0;
if (twist) { twistDelta *= twistOut ? -1 : 1;
stretch = (float)(Math.Acos(Vec3.Dot(twistFrom * Vec3.Up, con.ori * Vec3.Up)) / Math.PI); if (!float.IsFinite(twistDelta)) { twistDelta = 0; }
twistOut = Vec3.Dot(twistFrom * Vec3.Up, con.ori * Vec3.Right * (chirality ? 1 : -1)) > 0; if (twisting) {
stretch = 0;
direction = con.ori * Vec3.Forward; if (lift) {
virtualGlove.orientation = twistFrom; twistOffset = con.ori.Inverse * projection;
} else {
twist = twist + twistDelta;
projection = con.ori * twistOffset;
}
virtualGlove.orientation = con.ori;
} }
oldOri = con.ori;
virtualGlove.position = con.pos + direction * stretch * 3; virtualGlove.position = con.pos + direction * (stretch + Math.Abs(twist)) * 3;
Render(con.Pose(), virtualGlove, wrist, twist, stretch, twistOut, twistFrom); Render(con.Pose(), virtualGlove, wrist, stretch, twist, chirality);
} }
// decouple the rendering // decouple the rendering
@ -109,26 +130,29 @@ public class Glove {
// that way we can render the same way for all peers // that way we can render the same way for all peers
static Mesh mesh = Default.MeshCube; static Mesh mesh = Default.MeshCube;
static Material mat = Default.Material; static Material mat = Default.Material;
public void Render(Pose glove, Pose virtualGlove, Pose wrist, bool twist, float stretch, bool twistOut, Quat twistFrom) { public void Render(Pose glove, Pose virtualGlove, Pose wrist, float stretch, float twist, bool chirality) {
Lines.Add(pullPoint, glove.position, new Color(1, 0, 1), 0.005f); 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); Lines.Add(glove.position, virtualGlove.position, new Color(0, 1, 1), 0.005f);
// Twist // Twist
float twistValue = twist ? stretch : 0; float twistAbs = Math.Abs(twist);
Lines.Add( Vec3 twistStuff = glove.position + projection * glove.orientation.Inverse * (wrist.position - glove.position);
wrist.position + glove.orientation * Vec3.Up * 0.04f, int segments = twistAbs == 0 ? -1 : 6 + (int)(twistAbs * 10);
wrist.position + glove.orientation * Vec3.Up * 0.05f, LinePoint[] linePoints = new LinePoint[segments + 2];
new Color(1, 1, 0), 0.005f linePoints[0] = new LinePoint(twistStuff, new Color(1, 1, 0), 0.005f);
); for (int i = 0; i <= segments; i++) {
Vec3 lastPos = wrist.position; float tw = twistAbs * Math.Min(i / (float)(segments - 1), 1);
for (int i = 0; i < 32; i++) { tw *= chirality ? 1 : -1;
float tw = twistValue * (i / 31f); tw *= twist > 0 ? 1 : -1;
tw *= twistOut ? -1 : 1; // spiral 3
Vec3 nextPos = wrist.position + twistFrom * new Vec3(SKMath.Sin(tw * SKMath.Pi), SKMath.Cos(tw * SKMath.Pi), 0) * 0.05f; float tighten = Math.Max(1 - (twistAbs / 9), 0);
float radius = i == segments ? 0.06f : 0.05f * (1 - (1 - i / (float)segments) * (1 - tighten));
Vec3 nextPos = twistStuff + projection * new Vec3(SKMath.Sin(tw * SKMath.Pi), SKMath.Cos(tw * SKMath.Pi), 0) * radius;
Lines.Add(lastPos, nextPos, new Color(1, 1, 0), 0.005f); // convert to LinePoints ? // Lines.Add(lastPos, nextPos, new Color(1, 1, 0), 0.005f);
lastPos = nextPos; linePoints[i + 1] = new LinePoint(nextPos, new Color(1, 1, 0), 0.005f);
} }
Lines.Add(linePoints);
mesh.Draw(mat, glove.ToMatrix(new Vec3(0.025f, 0.1f, 0.1f) / 3)); 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))); mesh.Draw(mat, virtualGlove.ToMatrix(new Vec3(0.025f, 0.1f, 0.1f)));

View file

@ -192,23 +192,23 @@ public class SupineCursor : SpatialCursor {
} }
float calibStr; float calibStr;
Quat calibQuat; Quat calibQuat;
Pose dom, sub; Pose rCon, lCon;
public override void Step(Pose[] poses, float scalar) { public override void Step(Pose[] poses, float scalar) {
dom = poses[0]; rCon = poses[0];
sub = poses[1]; lCon = poses[1];
Quat rel = Quat.LookAt(Vec3.Zero, sub.orientation * Vec3.Forward); Quat rel = Quat.LookAt(Vec3.Zero, lCon.orientation * Vec3.Forward);
float twist = (Vec3.Dot(rel * -Vec3.Right, sub.orientation * Vec3.Up) + 1) / 2; float twist = (Vec3.Dot(rel * -Vec3.Right, lCon.orientation * Vec3.Up) + 1) / 2;
p0 = dom.position + dom.orientation * calibQuat * Vec3.Forward * calibStr * twist; p0 = rCon.position + rCon.orientation * calibQuat * Vec3.Forward * calibStr * twist;
model.Draw(Matrix.TS(p0, 0.06f)); model.Draw(Matrix.TS(p0, 0.06f));
} }
public override void Calibrate() { public override void Calibrate() {
Vec3 target = Input.Head.position + Input.Head.Forward; Vec3 target = Input.Head.position + Input.Head.Forward;
calibStr = Vec3.Distance(dom.position, target) * 2; calibStr = Vec3.Distance(rCon.position, target) * 2;
Quat calibAlign = Quat.LookAt(dom.position, target); Quat calibAlign = Quat.LookAt(rCon.position, target);
calibQuat = dom.orientation.Inverse * calibAlign; calibQuat = rCon.orientation.Inverse * calibAlign;
} }
} }