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();
|
||||
|
||||
|
||||
// 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();
|
||||
|
||||
// rBlock.Step(); lBlock.Step();
|
||||
|
|
|
@ -92,16 +92,16 @@ public static class PullRequest {
|
|||
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));
|
||||
Vec3 lv = q.Inverse * (v - a);
|
||||
lv.x = lv.y = 0;
|
||||
Vec3 r = q * lv + a;
|
||||
|
||||
float d = (b - a).Length;
|
||||
t = (r - a).Length / d;
|
||||
if (clamp) {
|
||||
float d = (b - a).Length;
|
||||
float t = (r - a).Length / d;
|
||||
if (t < 0) t = 0;
|
||||
if (t > 1) t = 1;
|
||||
t = t < tMin ? tMin : (t > tMax ? tMax : t);
|
||||
r = a + (b - a) * t;
|
||||
}
|
||||
return r;
|
||||
|
|
|
@ -5,8 +5,9 @@ class Trackballer : dof {
|
|||
// data
|
||||
public Btn btnIn, btnOut;
|
||||
public Quat ori = Quat.Identity;
|
||||
Vec3 oldLocalPad;
|
||||
Quat momentum = Quat.Identity;
|
||||
Quat delta = Quat.Identity;
|
||||
Vec3 oldLocalPad;
|
||||
|
||||
public void Init() {}
|
||||
|
||||
|
@ -18,12 +19,20 @@ class Trackballer : dof {
|
|||
Matrix mAnchor = Matrix.TR(anchor, hand.palm.orientation);
|
||||
Matrix mAnchorInv = mAnchor.Inverse;
|
||||
|
||||
Vec3 pad = anchor.SnapToLine(
|
||||
hand.Get(FingerId.Thumb, JointId.Tip).position,
|
||||
hand.Get(FingerId.Thumb, JointId.KnuckleMinor).position,
|
||||
true
|
||||
Vec3 thumbTip = hand.Get(FingerId.Thumb, JointId.Tip).position;
|
||||
Vec3 thumbKnuckle = hand.Get(FingerId.Thumb, JointId.KnuckleMinor).position;
|
||||
Vec3 pad = anchor.SnapToLine(
|
||||
thumbKnuckle, thumbTip,
|
||||
true,
|
||||
out float t, 0, 0.666f
|
||||
);
|
||||
Vec3 localPad = mAnchorInv.Transform(pad);
|
||||
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);
|
||||
|
||||
Lines.Add(thumbTip, thumbKnuckle, Color.White, 0.002f);
|
||||
|
||||
Color color = Color.White;
|
||||
if (btnIn.held) {
|
||||
|
@ -41,13 +50,15 @@ class Trackballer : dof {
|
|||
color = btnOut.held ? new Color(0, 1, 0) : color;
|
||||
|
||||
if (btnIn.held) {
|
||||
delta = Quat.Identity;
|
||||
delta = momentum = Quat.Identity;
|
||||
} else {
|
||||
if (localPad.Length < layer[1]) {
|
||||
delta = PullRequest.Relative(
|
||||
hand.palm.orientation,
|
||||
PullRequest.Delta(localPad.Normalized, oldLocalPad.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));
|
||||
}
|
||||
|
||||
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) {
|
||||
ori = newOri;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue