Design Momentum
This commit is contained in:
parent
519d3b7813
commit
63dfbcf5f6
4 changed files with 77 additions and 50 deletions
72
app/Mono.cs
72
app/Mono.cs
|
@ -136,35 +136,34 @@ public class Mono {
|
||||||
UI.SetThemeColor(UIColor.Primary, new Color(0.5f, 0.5f, 0.5f));
|
UI.SetThemeColor(UIColor.Primary, new Color(0.5f, 0.5f, 0.5f));
|
||||||
UI.PushTextStyle(style);
|
UI.PushTextStyle(style);
|
||||||
|
|
||||||
|
|
||||||
// if (UI.Button("Draw Oriel Axis")) { oriel.drawAxis = !oriel.drawAxis; }
|
// if (UI.Button("Draw Oriel Axis")) { oriel.drawAxis = !oriel.drawAxis; }
|
||||||
|
|
||||||
// if (UI.Button("Reset Oriel Quat")) { oriel.ori = Quat.Identity; }
|
// if (UI.Button("Reset Oriel Quat")) { oriel.ori = Quat.Identity; }
|
||||||
// if (UI.Button("Scale w/Height")) { oriel.scaleWithHeight = !oriel.scaleWithHeight; }
|
// if (UI.Button("Scale w/Height")) { oriel.scaleWithHeight = !oriel.scaleWithHeight; }
|
||||||
// UI.HSlider("Scale", ref oriel.scale, 0.1f, 1f, 0.1f);
|
// UI.HSlider("Scale", ref oriel.scale, 0.1f, 1f, 0.1f);
|
||||||
// UI.HSlider("Multiplier", ref oriel.multiplier, 0.1f, 1f, 0.1f);
|
// UI.HSlider("Multiplier", ref oriel.multiplier, 0.1f, 1f, 0.1f);
|
||||||
// // UI.Label("Player.y");
|
// // UI.Label("Player.y");
|
||||||
// UI.HSlider("Player.y", ref greenyard.height, 1f, 6f, 0.2f);
|
// UI.HSlider("Player.y", ref greenyard.height, 1f, 6f, 0.2f);
|
||||||
|
|
||||||
// UI.Label("pos.y");
|
// UI.Label("pos.y");
|
||||||
// UI.HSlider("pos.y", ref playerY, -1f, 1f, 0.1f);
|
// UI.HSlider("pos.y", ref playerY, -1f, 1f, 0.1f);
|
||||||
|
|
||||||
UI.Label("wavecursor.");
|
UI.Label("°wavecursor");
|
||||||
UI.Input("wavecursor.reach", ref wcReach, fieldSize, TextContext.Number);
|
UI.Input("wavecursor.reach", ref wcReach.str, fieldSize, TextContext.Number);
|
||||||
UI.SameLine(); UI.Label("reach");
|
UI.SameLine(); UI.Label("reach");
|
||||||
UI.Input("wavecursor.length", ref wcLength, fieldSize, TextContext.Number);
|
UI.Input("wavecursor.length", ref wcLength.str, fieldSize, TextContext.Number);
|
||||||
UI.SameLine(); UI.Label("length");
|
UI.SameLine(); UI.Label("length");
|
||||||
UI.Input("wavecursor.scale", ref wcScale, fieldSize, TextContext.Number);
|
UI.Input("wavecursor.scale", ref wcScale.str, fieldSize, TextContext.Number);
|
||||||
UI.SameLine(); UI.Label("scale");
|
UI.SameLine(); UI.Label("scale");
|
||||||
|
UI.Input("wavecursor.radius", ref wcRadius.str, fieldSize, TextContext.Number);
|
||||||
|
UI.SameLine(); UI.Label("radius");
|
||||||
|
|
||||||
UI.Label("trackballer.");
|
UI.Label("°trackballer");
|
||||||
UI.Input("trackballer.compliance", ref tbCompliance, fieldSize, TextContext.Number);
|
UI.Input("trackballer.compliance", ref tbCompliance.str, fieldSize, TextContext.Number);
|
||||||
UI.SameLine(); UI.Label("compliance");
|
UI.SameLine(); UI.Label("compliance");
|
||||||
UI.Input("trackballer.x", ref tbX, fieldSize, TextContext.Number);
|
UI.Input("trackballer.x", ref tbX.str, fieldSize, TextContext.Number);
|
||||||
UI.SameLine(); UI.Label("x");
|
UI.SameLine(); UI.Label("x");
|
||||||
UI.Input("trackballer.y", ref tbY, fieldSize, TextContext.Number);
|
UI.Input("trackballer.y", ref tbY.str, fieldSize, TextContext.Number);
|
||||||
UI.SameLine(); UI.Label("y");
|
UI.SameLine(); UI.Label("y");
|
||||||
UI.Input("trackballer.z", ref tbZ, fieldSize, TextContext.Number);
|
UI.Input("trackballer.z", ref tbZ.str, fieldSize, TextContext.Number);
|
||||||
UI.SameLine(); UI.Label("z");
|
UI.SameLine(); UI.Label("z");
|
||||||
|
|
||||||
// flipIndex
|
// flipIndex
|
||||||
|
@ -173,25 +172,50 @@ public class Mono {
|
||||||
UI.WindowEnd();
|
UI.WindowEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
public string wcReach = "1.0";
|
public Design wcReach = new Design("1.0", 0);
|
||||||
public string wcLength = "0.666";
|
public Design wcLength = new Design("0.666", 0f, 1f);
|
||||||
public string wcScale = "0.333";
|
public Design wcScale = new Design("0.333", 0.001f);
|
||||||
|
public Design wcRadius = new Design("4", 0);
|
||||||
public string tbCompliance = "0.0";
|
|
||||||
public string tbX = "1.0";
|
|
||||||
public string tbY = "2.0";
|
|
||||||
public string tbZ = "-4.0";
|
|
||||||
|
|
||||||
|
public Design tbCompliance = new Design("0.0", 0f, 1f);
|
||||||
|
public Design tbX = new Design("1.0", -10f, 10f);
|
||||||
|
public Design tbY = new Design("2.0", -10f, 10f);
|
||||||
|
public Design tbZ = new Design("-4.0", -10f, 10f);
|
||||||
|
|
||||||
// public float playerY = 0;
|
// public float playerY = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert into a class
|
// convert into a class
|
||||||
class Design {
|
// which also simplifies injection and persistence
|
||||||
public string txt;
|
public class Design {
|
||||||
public int integer;
|
public string str;
|
||||||
public float floating;
|
|
||||||
|
float min, max;
|
||||||
|
public Design(string str,
|
||||||
|
float min = float.NegativeInfinity,
|
||||||
|
float max = float.PositiveInfinity
|
||||||
|
) {
|
||||||
|
this.str = str;
|
||||||
|
this.min = min;
|
||||||
|
this.max = max;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float value {
|
||||||
|
get {
|
||||||
|
try {
|
||||||
|
float value = PullRequest.Clamp(float.Parse(str), min, max);
|
||||||
|
// if clamped, update string
|
||||||
|
if (value != float.Parse(str)) {
|
||||||
|
str = value.ToString();
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
} catch {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// public int integer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -289,22 +289,22 @@ public static class PullRequest {
|
||||||
return MathF.Max(min, MathF.Min(max, v));
|
return MathF.Max(min, MathF.Min(max, v));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float ToFloat(
|
// public static float ToFloat(
|
||||||
ref string s,
|
// ref string s,
|
||||||
float min = float.NegativeInfinity,
|
// float min = float.NegativeInfinity,
|
||||||
float max = float.PositiveInfinity
|
// float max = float.PositiveInfinity
|
||||||
) {
|
// ) {
|
||||||
try {
|
// try {
|
||||||
float value = Clamp(float.Parse(s), min, max);
|
// float value = Clamp(float.Parse(s), min, max);
|
||||||
// if clamped, update string
|
// // if clamped, update string
|
||||||
if (value != float.Parse(s)) {
|
// if (value != float.Parse(s)) {
|
||||||
s = value.ToString();
|
// s = value.ToString();
|
||||||
}
|
// }
|
||||||
return value;
|
// return value;
|
||||||
} catch {
|
// } catch {
|
||||||
return 0;
|
// return 0;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
public class PID {
|
public class PID {
|
||||||
public float p, i;
|
public float p, i;
|
||||||
|
|
|
@ -46,7 +46,7 @@ class WaveCursor : dof {
|
||||||
|
|
||||||
public float deadzone = 0.3f;
|
public float deadzone = 0.3f;
|
||||||
public float strength {
|
public float strength {
|
||||||
get { return PullRequest.ToFloat(ref Mono.inst.wcReach, 0); } // 3f
|
get { return Mono.inst.wcReach.value; } // 1f
|
||||||
}
|
}
|
||||||
public Handed handed = Handed.Left;
|
public Handed handed = Handed.Left;
|
||||||
|
|
||||||
|
@ -76,7 +76,10 @@ class WaveCursor : dof {
|
||||||
Vec3[] zL = new Vec3[81];
|
Vec3[] zL = new Vec3[81];
|
||||||
Vec3[] zR = new Vec3[81];
|
Vec3[] zR = new Vec3[81];
|
||||||
public void Demo(Quat ori) {
|
public void Demo(Quat ori) {
|
||||||
Trail(mm, cursor.smooth + ori * new Vec3(0, 0, 0.08f));
|
Trail(
|
||||||
|
mm,
|
||||||
|
cursor.smooth + ori * new Vec3(0, 0, Mono.inst.wcRadius.value * U.cm)
|
||||||
|
);
|
||||||
|
|
||||||
// Trail(xL, smoothPos + cursor.orientation * new Vec3(-1, 0, 0) * 0.1f);
|
// Trail(xL, smoothPos + cursor.orientation * new Vec3(-1, 0, 0) * 0.1f);
|
||||||
// Trail(xR, smoothPos + cursor.orientation * new Vec3( 1, 0, 0) * 0.1f);
|
// Trail(xR, smoothPos + cursor.orientation * new Vec3( 1, 0, 0) * 0.1f);
|
||||||
|
@ -87,7 +90,7 @@ class WaveCursor : dof {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Trail(Vec3[] points, Vec3 nextPos) {
|
void Trail(Vec3[] points, Vec3 nextPos) {
|
||||||
float scale = PullRequest.ToFloat(ref Mono.inst.wcScale, 0.001f);
|
float scale = Mono.inst.wcScale.value;
|
||||||
while (Vec3.Distance(points[0], nextPos) > 0.03f * scale) {
|
while (Vec3.Distance(points[0], nextPos) > 0.03f * scale) {
|
||||||
for (int i = points.Length - 1; i > 0; i--) {
|
for (int i = points.Length - 1; i > 0; i--) {
|
||||||
points[i] = points[i - 1];
|
points[i] = points[i - 1];
|
||||||
|
@ -97,7 +100,7 @@ class WaveCursor : dof {
|
||||||
|
|
||||||
|
|
||||||
// points[0] = nextPos;
|
// points[0] = nextPos;
|
||||||
int len = (int)(points.Length * PullRequest.ToFloat(ref Mono.inst.wcLength, 0f, 1f));
|
int len = (int)(points.Length * Mono.inst.wcLength.value);
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
// if (i > 0) {
|
// if (i > 0) {
|
||||||
// Vec3 dir = Vec3.Forward;
|
// Vec3 dir = Vec3.Forward;
|
||||||
|
|
|
@ -52,9 +52,9 @@ class Trackballer : dof {
|
||||||
// Ball anchor
|
// Ball anchor
|
||||||
HandJoint ballJoint = hand.Get(FingerId.Index, JointId.KnuckleMajor);
|
HandJoint ballJoint = hand.Get(FingerId.Index, JointId.KnuckleMajor);
|
||||||
Vec3 anchorPos = ballJoint.position + hand.palm.orientation * new Vec3(
|
Vec3 anchorPos = ballJoint.position + hand.palm.orientation * new Vec3(
|
||||||
PullRequest.ToFloat(ref Mono.inst.tbX, -10f, 10f) * U.cm * (handed == Handed.Left ? -1 : 1),
|
Mono.inst.tbX.value * U.cm * (handed == Handed.Left ? -1 : 1),
|
||||||
PullRequest.ToFloat(ref Mono.inst.tbY, -10f, 10f) * U.cm,
|
Mono.inst.tbY.value * U.cm,
|
||||||
PullRequest.ToFloat(ref Mono.inst.tbZ, -10f, 10f) * U.cm
|
Mono.inst.tbZ.value * U.cm
|
||||||
);
|
);
|
||||||
anchorPos += compliance.Update(
|
anchorPos += compliance.Update(
|
||||||
Vec3.Zero,
|
Vec3.Zero,
|
||||||
|
@ -130,7 +130,7 @@ class Trackballer : dof {
|
||||||
// offset.z = 0;
|
// offset.z = 0;
|
||||||
|
|
||||||
offset = hand.palm.orientation * offset;
|
offset = hand.palm.orientation * offset;
|
||||||
compliance.value += offset * PullRequest.ToFloat(ref Mono.inst.tbCompliance, 0f, 1f);
|
compliance.value += offset * Mono.inst.tbCompliance.value;
|
||||||
compliance.integral = Vec3.Zero;
|
compliance.integral = Vec3.Zero;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -168,12 +168,12 @@ class Trackballer : dof {
|
||||||
|
|
||||||
|
|
||||||
cursorPos.x = PullRequest.Clamp(
|
cursorPos.x = PullRequest.Clamp(
|
||||||
cursorPos.x + (delta * Vec3.Right).z * 0.1f,
|
cursorPos.x + (momentum * Vec3.Right).z * 0.1f,
|
||||||
width / -2f,
|
width / -2f,
|
||||||
width / 2f
|
width / 2f
|
||||||
);
|
);
|
||||||
cursorPos.y = PullRequest.Clamp(
|
cursorPos.y = PullRequest.Clamp(
|
||||||
cursorPos.y + (delta * Vec3.Right).y * -0.1f,
|
cursorPos.y + (momentum * Vec3.Right).y * -0.1f,
|
||||||
height / -2f,
|
height / -2f,
|
||||||
height / 2f
|
height / 2f
|
||||||
);
|
);
|
||||||
|
|
Loading…
Add table
Reference in a new issue