reach cursor deadzone

This commit is contained in:
spatialfree 2022-01-05 08:49:48 -05:00
parent 10029f21d3
commit 63acd14576
2 changed files with 40 additions and 4 deletions

View file

@ -40,7 +40,7 @@ public class Monolith {
Mesh cube = Default.MeshCube;
public void Run() {
Renderer.SetClip(0.0f, 1000f);
Renderer.SetClip(0.02f, 1000f);
// Renderer.
// mic = new Mic();
Vec3 pos = new Vec3(0, 0, 0);
@ -90,6 +90,8 @@ public class Monolith {
bool rightGripping = false, leftGripping = false;
bool gripLeft = false;
bool rightGripDown = false, leftGripDown = false;
float grindDir = 1f;
bool grinding = false;
@ -197,13 +199,43 @@ public class Monolith {
}
if (rCon.grip > 0.5f) {
leftReachCursor.origin = lShoulder.orientation.Inverse * (rCon.pose.position - lShoulder.position);
Vec3 toPos = lShoulder.orientation.Inverse * (rCon.pose.position - lShoulder.position);
if (!rightGripDown) {
float deadzone = Vec3.Distance(leftReachCursor.origin, toPos);
if (deadzone < 0.1f) {
leftReachCursor.deadzone = deadzone;
rightGripDown = true;
}
}
if (rightGripDown) {
leftReachCursor.origin = toPos;
}
} else {
leftReachCursor.deadzone = 0;
rightGripDown = false;
}
if (lCon.grip > 0.5f) {
rightReachCursor.origin = rShoulder.orientation.Inverse * (lCon.pose.position - rShoulder.position);
Vec3 toPos = rShoulder.orientation.Inverse * (lCon.pose.position - rShoulder.position);
if (!leftGripDown) {
float deadzone = Vec3.Distance(rightReachCursor.origin, toPos);
if (deadzone < 0.1f) {
rightReachCursor.deadzone = deadzone;
leftGripDown = true;
}
}
if (leftGripDown) {
rightReachCursor.origin = toPos;
}
} else {
rightReachCursor.deadzone = 0;
leftGripDown = false;
}
rightReachCursor.Step(new Pose[] { rCon.pose }, 0.2f);
leftReachCursor.Step(new Pose[] { lCon.pose }, 0.2f);

View file

@ -39,9 +39,11 @@ public class ReachCursor : SpatialCursor {
this.min = 1f;
this.str = 3f;
this.max = 10f;
this.deadzone = 0;
}
Vec3 pos;
public Vec3 origin;
public float deadzone;
public override void Step(Pose[] poses, float scalar) {
pos = poses[0].position;
Vec3 wrist = mono.Wrist(chirality).position;
@ -52,6 +54,8 @@ public class ReachCursor : SpatialCursor {
str = min + (scalar * max);
float stretch = Vec3.Distance(from, wrist);
stretch = Math.Max(stretch - deadzone, 0);
Vec3 dir = (pos - from).Normalized;
p0 = pos + dir * stretch * str;