Design Momentum

This commit is contained in:
spatialfree 2022-10-25 05:06:16 -04:00
parent 519d3b7813
commit 63dfbcf5f6
4 changed files with 77 additions and 50 deletions

View file

@ -136,35 +136,34 @@ public class Mono {
UI.SetThemeColor(UIColor.Primary, new Color(0.5f, 0.5f, 0.5f));
UI.PushTextStyle(style);
// if (UI.Button("Draw Oriel Axis")) { oriel.drawAxis = !oriel.drawAxis; }
// if (UI.Button("Reset Oriel Quat")) { oriel.ori = Quat.Identity; }
// if (UI.Button("Scale w/Height")) { oriel.scaleWithHeight = !oriel.scaleWithHeight; }
// UI.HSlider("Scale", ref oriel.scale, 0.1f, 1f, 0.1f);
// UI.HSlider("Multiplier", ref oriel.multiplier, 0.1f, 1f, 0.1f);
// // UI.Label("Player.y");
// UI.HSlider("Player.y", ref greenyard.height, 1f, 6f, 0.2f);
// UI.Label("pos.y");
// UI.HSlider("pos.y", ref playerY, -1f, 1f, 0.1f);
UI.Label("wavecursor.");
UI.Input("wavecursor.reach", ref wcReach, fieldSize, TextContext.Number);
UI.Label("°wavecursor");
UI.Input("wavecursor.reach", ref wcReach.str, fieldSize, TextContext.Number);
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.Input("wavecursor.scale", ref wcScale, fieldSize, TextContext.Number);
UI.Input("wavecursor.scale", ref wcScale.str, fieldSize, TextContext.Number);
UI.SameLine(); UI.Label("scale");
UI.Input("wavecursor.radius", ref wcRadius.str, fieldSize, TextContext.Number);
UI.SameLine(); UI.Label("radius");
UI.Label("trackballer.");
UI.Input("trackballer.compliance", ref tbCompliance, fieldSize, TextContext.Number);
UI.Label("°trackballer");
UI.Input("trackballer.compliance", ref tbCompliance.str, fieldSize, TextContext.Number);
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.Input("trackballer.y", ref tbY, fieldSize, TextContext.Number);
UI.Input("trackballer.y", ref tbY.str, fieldSize, TextContext.Number);
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");
// flipIndex
@ -173,25 +172,50 @@ public class Mono {
UI.WindowEnd();
}
public string wcReach = "1.0";
public string wcLength = "0.666";
public string wcScale = "0.333";
public string tbCompliance = "0.0";
public string tbX = "1.0";
public string tbY = "2.0";
public string tbZ = "-4.0";
public Design wcReach = new Design("1.0", 0);
public Design wcLength = new Design("0.666", 0f, 1f);
public Design wcScale = new Design("0.333", 0.001f);
public Design wcRadius = new Design("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;
}
// convert into a class
class Design {
public string txt;
public int integer;
public float floating;
// which also simplifies injection and persistence
public class Design {
public string str;
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;
}

View file

@ -289,22 +289,22 @@ public static class PullRequest {
return MathF.Max(min, MathF.Min(max, v));
}
public static float ToFloat(
ref string s,
float min = float.NegativeInfinity,
float max = float.PositiveInfinity
) {
try {
float value = Clamp(float.Parse(s), min, max);
// if clamped, update string
if (value != float.Parse(s)) {
s = value.ToString();
}
return value;
} catch {
return 0;
}
}
// public static float ToFloat(
// ref string s,
// float min = float.NegativeInfinity,
// float max = float.PositiveInfinity
// ) {
// try {
// float value = Clamp(float.Parse(s), min, max);
// // if clamped, update string
// if (value != float.Parse(s)) {
// s = value.ToString();
// }
// return value;
// } catch {
// return 0;
// }
// }
public class PID {
public float p, i;

View file

@ -46,7 +46,7 @@ class WaveCursor : dof {
public float deadzone = 0.3f;
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;
@ -76,7 +76,10 @@ class WaveCursor : dof {
Vec3[] zL = new Vec3[81];
Vec3[] zR = new Vec3[81];
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(xR, smoothPos + cursor.orientation * new Vec3( 1, 0, 0) * 0.1f);
@ -87,7 +90,7 @@ class WaveCursor : dof {
}
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) {
for (int i = points.Length - 1; i > 0; i--) {
points[i] = points[i - 1];
@ -97,7 +100,7 @@ class WaveCursor : dof {
// 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++) {
// if (i > 0) {
// Vec3 dir = Vec3.Forward;

View file

@ -52,9 +52,9 @@ class Trackballer : dof {
// Ball anchor
HandJoint ballJoint = hand.Get(FingerId.Index, JointId.KnuckleMajor);
Vec3 anchorPos = ballJoint.position + hand.palm.orientation * new Vec3(
PullRequest.ToFloat(ref Mono.inst.tbX, -10f, 10f) * U.cm * (handed == Handed.Left ? -1 : 1),
PullRequest.ToFloat(ref Mono.inst.tbY, -10f, 10f) * U.cm,
PullRequest.ToFloat(ref Mono.inst.tbZ, -10f, 10f) * U.cm
Mono.inst.tbX.value * U.cm * (handed == Handed.Left ? -1 : 1),
Mono.inst.tbY.value * U.cm,
Mono.inst.tbZ.value * U.cm
);
anchorPos += compliance.Update(
Vec3.Zero,
@ -130,7 +130,7 @@ class Trackballer : dof {
// offset.z = 0;
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;
}
}
@ -168,12 +168,12 @@ class Trackballer : dof {
cursorPos.x = PullRequest.Clamp(
cursorPos.x + (delta * Vec3.Right).z * 0.1f,
cursorPos.x + (momentum * Vec3.Right).z * 0.1f,
width / -2f,
width / 2f
);
cursorPos.y = PullRequest.Clamp(
cursorPos.y + (delta * Vec3.Right).y * -0.1f,
cursorPos.y + (momentum * Vec3.Right).y * -0.1f,
height / -2f,
height / 2f
);