trackballer pad mesh

This commit is contained in:
spatialfree 2022-10-19 19:56:22 -04:00
parent 94917f5b3d
commit ffd8fbb3d8
4 changed files with 36 additions and 29 deletions

Binary file not shown.

View file

@ -68,6 +68,7 @@ public class Mono {
matHolo.Transparency = Transparency.Add; matHolo.Transparency = Transparency.Add;
matHolo.DepthWrite = false; matHolo.DepthWrite = false;
matHolo.DepthTest = DepthTest.Always; matHolo.DepthTest = DepthTest.Always;
matHolo.FaceCull = Cull.None;
matHolo.SetTexture("diffuse", Tex.DevTex); matHolo.SetTexture("diffuse", Tex.DevTex);
} }

View file

@ -7,7 +7,7 @@ class Trackballer : dof {
public Quat ori = Quat.Identity; public Quat ori = Quat.Identity;
Quat momentum = Quat.Identity; Quat momentum = Quat.Identity;
Quat delta = Quat.Identity; Quat delta = Quat.Identity;
Vec3 oldTip; Matrix oldMeshMatrix = Matrix.Identity;
PullRequest.OneEuroFilter xF = new PullRequest.OneEuroFilter(0.0001f, 0.1f); PullRequest.OneEuroFilter xF = new PullRequest.OneEuroFilter(0.0001f, 0.1f);
PullRequest.OneEuroFilter yF = new PullRequest.OneEuroFilter(0.0001f, 0.1f); PullRequest.OneEuroFilter yF = new PullRequest.OneEuroFilter(0.0001f, 0.1f);
@ -29,8 +29,8 @@ class Trackballer : dof {
Matrix mAnchorInv = mAnchor.Inverse; Matrix mAnchorInv = mAnchor.Inverse;
Vec3 thumbTip = hand.Get(FingerId.Thumb, JointId.Tip).position; Vec3 thumbTip = hand.Get(FingerId.Thumb, JointId.Tip).position;
Vec3 tipDelta = mAnchorInv.Transform(thumbTip) - mAnchorInv.Transform(oldTip); // Vec3 tipDelta = mAnchorInv.Transform(thumbTip) - mAnchorInv.Transform(oldTip);
oldTip = thumbTip; // oldTip = thumbTip;
Vec3 thumbKnuckle = hand.Get(FingerId.Thumb, JointId.KnuckleMinor).position; Vec3 thumbKnuckle = hand.Get(FingerId.Thumb, JointId.KnuckleMinor).position;
Quat thumbRot = hand.Get(FingerId.Thumb, JointId.Tip).orientation; Quat thumbRot = hand.Get(FingerId.Thumb, JointId.Tip).orientation;
@ -39,41 +39,47 @@ class Trackballer : dof {
thumbRot, thumbRot,
new Vec3(handed == Handed.Left ? -1f : 1f, 1f, 1f) * 0.1666f new Vec3(handed == Handed.Left ? -1f : 1f, 1f, 1f) * 0.1666f
); );
// mesh.Draw(Mono.inst.matHolo, mMesh, new Color(0, 0, 1)); mesh.Draw(Mono.inst.matHolo, mMesh, new Color(0, 0, 1));
// closest to anchor // closest to anchor
float closest = 1000f; float closest = 100000f;
int closestIndex = -1; int closestIndex = -1;
Vertex[] verts = mesh.GetVerts(); Vertex[] verts = mesh.GetVerts();
for (int i = 0; i < verts.Length; i++) { for (int i = 0; i < verts.Length; i++) {
Vec3 v = mMesh * verts[i].pos; Vec3 v = mMesh.Transform(verts[i].pos);
float d = (v - anchor).Length; float d = (v - anchor).LengthSq;
if (d < closest) { if (d < closest) {
closest = d; closest = d;
closestIndex = i; closestIndex = i;
} }
} }
// Mesh.Sphere.Draw(Mono.inst.matHolo, Matrix.TRS(mMesh * verts[closestIndex].pos, Quat.Identity, 0.01f), new Color(1, 0, 0));
Vec3 localPad = mAnchorInv.Transform(mMesh.Transform(verts[closestIndex].pos));
Vec3 oldPad = mAnchorInv.Transform(oldMeshMatrix.Transform(verts[closestIndex].pos));
oldMeshMatrix = mMesh;
// //
Vec3 pad = anchor.SnapToLine( // Vec3 pad = anchor.SnapToLine(
thumbKnuckle, thumbTip, // thumbKnuckle, thumbTip,
true, // true,
out float t, 0f, 1f // out float t, 0f, 1f
); // );
// // t = 1 - t;
// // scale to 0.666f - 1f
// // t = (t - 0.666f) / 0.334f;
// t = t * t;
// t = 1 - t; // t = 1 - t;
// scale to 0.666f - 1f // pad += hand.Get(FingerId.Thumb, JointId.Tip).orientation * -Vec3.Up * 0.00666f * t;
// t = (t - 0.666f) / 0.334f;
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);
Vec3 localPad = mAnchorInv.Transform(thumbTip); // Vec3 localPad = mAnchorInv.Transform(thumbTip);
localPad.x = (float)xF.Filter(localPad.x, (double)Time.Elapsedf);
localPad.y = (float)yF.Filter(localPad.y, (double)Time.Elapsedf); // ?
localPad.z = (float)zF.Filter(localPad.z, (double)Time.Elapsedf); // localPad.x = (float)xF.Filter(localPad.x, (double)Time.Elapsedf);
// localPad.y = (float)yF.Filter(localPad.y, (double)Time.Elapsedf);
// localPad.z = (float)zF.Filter(localPad.z, (double)Time.Elapsedf);
@ -81,11 +87,11 @@ class Trackballer : dof {
Mesh.Sphere.Draw(Mono.inst.matHolo, Matrix.TRS(mAnchor.Transform(localPad), hand.palm.orientation, 0.004f), new Color(0, 1, 0)); Mesh.Sphere.Draw(Mono.inst.matHolo, Matrix.TRS(mAnchor.Transform(localPad), hand.palm.orientation, 0.004f), new Color(0, 1, 0));
if (btnIn.held) { // if (btnIn.held) {
btnIn.Step(localPad.Length < layer[1]); // btnIn.Step(localPad.Length < layer[1]);
} else { // } else {
btnIn.Step(localPad.Length < layer[0]); // btnIn.Step(localPad.Length < layer[0]);
} // }
float inT = btnIn.held ? 1 : 0.333f; float inT = btnIn.held ? 1 : 0.333f;
if (btnOut.held) { if (btnOut.held) {
@ -102,8 +108,8 @@ class Trackballer : dof {
delta = PullRequest.Relative( delta = PullRequest.Relative(
hand.palm.orientation, hand.palm.orientation,
Quat.Delta( Quat.Delta(
localPad.Normalized, oldPad.Normalized,
(localPad + tipDelta).Normalized localPad.Normalized
) )
).Normalized; ).Normalized;

Binary file not shown.