momentum and pad curve
This commit is contained in:
parent
bacbd224e2
commit
fb2725f61e
3 changed files with 33 additions and 33 deletions
20
app/Mono.cs
20
app/Mono.cs
|
@ -96,26 +96,6 @@ 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();
|
||||||
|
|
|
@ -92,16 +92,16 @@ 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) {
|
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(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;
|
||||||
if (clamp) {
|
|
||||||
float d = (b - a).Length;
|
float d = (b - a).Length;
|
||||||
float t = (r - a).Length / d;
|
t = (r - a).Length / d;
|
||||||
if (t < 0) t = 0;
|
if (clamp) {
|
||||||
if (t > 1) t = 1;
|
t = t < tMin ? tMin : (t > tMax ? tMax : t);
|
||||||
r = a + (b - a) * t;
|
r = a + (b - a) * t;
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
|
|
|
@ -5,8 +5,9 @@ class Trackballer : dof {
|
||||||
// data
|
// data
|
||||||
public Btn btnIn, btnOut;
|
public Btn btnIn, btnOut;
|
||||||
public Quat ori = Quat.Identity;
|
public Quat ori = Quat.Identity;
|
||||||
Vec3 oldLocalPad;
|
Quat momentum = Quat.Identity;
|
||||||
Quat delta = Quat.Identity;
|
Quat delta = Quat.Identity;
|
||||||
|
Vec3 oldLocalPad;
|
||||||
|
|
||||||
public void Init() {}
|
public void Init() {}
|
||||||
|
|
||||||
|
@ -18,13 +19,21 @@ 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 thumbTip = hand.Get(FingerId.Thumb, JointId.Tip).position;
|
||||||
|
Vec3 thumbKnuckle = hand.Get(FingerId.Thumb, JointId.KnuckleMinor).position;
|
||||||
Vec3 pad = anchor.SnapToLine(
|
Vec3 pad = anchor.SnapToLine(
|
||||||
hand.Get(FingerId.Thumb, JointId.Tip).position,
|
thumbKnuckle, thumbTip,
|
||||||
hand.Get(FingerId.Thumb, JointId.KnuckleMinor).position,
|
true,
|
||||||
true
|
out float t, 0, 0.666f
|
||||||
);
|
);
|
||||||
|
t = 1 - t;
|
||||||
|
t = t * t;
|
||||||
|
// t = 1 - t;
|
||||||
|
pad += hand.Get(FingerId.Thumb, JointId.Tip).orientation * -Vec3.Up * 0.00666f * t;
|
||||||
Vec3 localPad = mAnchorInv.Transform(pad);
|
Vec3 localPad = mAnchorInv.Transform(pad);
|
||||||
|
|
||||||
|
Lines.Add(thumbTip, thumbKnuckle, Color.White, 0.002f);
|
||||||
|
|
||||||
Color color = Color.White;
|
Color color = Color.White;
|
||||||
if (btnIn.held) {
|
if (btnIn.held) {
|
||||||
btnIn.Step(localPad.Length < layer[1]);
|
btnIn.Step(localPad.Length < layer[1]);
|
||||||
|
@ -41,13 +50,15 @@ class Trackballer : dof {
|
||||||
color = btnOut.held ? new Color(0, 1, 0) : color;
|
color = btnOut.held ? new Color(0, 1, 0) : color;
|
||||||
|
|
||||||
if (btnIn.held) {
|
if (btnIn.held) {
|
||||||
delta = Quat.Identity;
|
delta = momentum = Quat.Identity;
|
||||||
} else {
|
} 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;
|
||||||
|
|
||||||
|
momentum = Quat.Slerp(momentum, delta, Time.Elapsedf * 10f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,7 +70,16 @@ class Trackballer : dof {
|
||||||
Mesh.Sphere.Draw(Mono.inst.matDev, Matrix.TRS(pad, hand.palm.orientation, 0.015f), new Color(0, 1, 0));
|
Mesh.Sphere.Draw(Mono.inst.matDev, Matrix.TRS(pad, hand.palm.orientation, 0.015f), new Color(0, 1, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
Quat newOri = delta * ori;
|
|
||||||
|
|
||||||
|
// pad momentum!
|
||||||
|
// like we did w/ vader life alyx immortal
|
||||||
|
// all the difference in the world!
|
||||||
|
// and makes for the third iteration of the trackballer
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Quat newOri = momentum * ori;
|
||||||
if (new Vec3(newOri.x, newOri.y, newOri.z).LengthSq > 0) {
|
if (new Vec3(newOri.x, newOri.y, newOri.z).LengthSq > 0) {
|
||||||
ori = newOri;
|
ori = newOri;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue