diff --git a/Program.cs b/Program.cs index 92de6fd..7d28e26 100644 --- a/Program.cs +++ b/Program.cs @@ -15,12 +15,16 @@ class Program { OrbitalView.distance = 0.4f; cube.thickness = 0.01f; - while(SK.Step(() => { - Matrix orbitMatrix = OrbitalView.transform; - cube.Step(Matrix.S(Vec3.One * 0.2f) * orbitMatrix); - Default.MaterialHand["color"] = cube.color; + ReachCursor reachCursor = new ReachCursor(); - cursor.Draw(Matrix.S(0.1f)); + while(SK.Step(() => { + // Matrix orbitMatrix = OrbitalView.transform; + // cube.Step(Matrix.S(Vec3.One * 0.2f) * orbitMatrix); + // Default.MaterialHand["color"] = cube.color; + + reachCursor.Step(); + + // cursor.Draw(Matrix.S(0.1f)); })); SK.Shutdown(); } diff --git a/ReachCursor.cs b/ReachCursor.cs new file mode 100644 index 0000000..ee74128 --- /dev/null +++ b/ReachCursor.cs @@ -0,0 +1,36 @@ +using System; +using StereoKit; + +public class ReachCursor { + static Material unlitMat = Default.MaterialUnlit.Copy(); + + static Model modelCursor = Model.FromFile("cursor.glb", Shader.Default); + static Model modelSphere = new Model(Default.MeshSphere, unlitMat); + + static Vec3[] pullPoints = new Vec3[2]; + + public void Step() { + Matrix matrix = new Matrix(); + matrix.Translation = new Vec3(0, 0, -1); + + for (int h = 0; h < (int)Handed.Max; h++) + { + // Get the pose for the index fingertip + Hand hand = Input.Hand((Handed)h); + Vec3 indexTip = hand[FingerId.Index, JointId.Tip].Pose.position; + Vec3 thumbTip = hand[FingerId.Thumb, JointId.Tip].Pose.position; + Vec3 pinchPos = Vec3.Lerp(indexTip, thumbTip, 0.5f); + if (hand.IsPinched) + { + pullPoints[h] = pinchPos; + } + + float stretch = (pullPoints[h] - pinchPos).Length; + Vec3 dir = (pinchPos - pullPoints[h]).Normalized; + Vec3 pos = pinchPos + dir * stretch * 3; + modelCursor.Draw(Matrix.TS(pos, 0.06f)); + Lines.Add(pullPoints[h], pos, Color.White, 0.01f); + modelSphere.Draw(Matrix.TS(pullPoints[h], 0.04f)); + } + } +} \ No newline at end of file