relative & responsive

This commit is contained in:
spatialfree 2022-08-29 22:02:07 -04:00
parent 0879701456
commit 84ec2ffdd1
4 changed files with 86 additions and 63 deletions

View file

@ -119,6 +119,11 @@ public class Glove {
oldOri = con.ori;
virtualGlove.position = con.pos + direction * (stretch + Math.Abs(twist)) * 3;
// relative to index finger
Hand hand = Input.Hand(chirality ? Handed.Right : Handed.Left);
Vec3 index = hand.Get(FingerId.Index, JointId.Tip).position - con.pos;
Vec3 thumb = hand.Get(FingerId.Thumb, JointId.Tip).position - con.pos;
virtualGlove.position += Vec3.Lerp(index, thumb, 0.5f);
Render(con.Pose(), virtualGlove, wrist, stretch, twist, chirality);
}
@ -154,7 +159,7 @@ public class Glove {
Lines.Add(linePoints);
// mesh.Draw(mat, glove.ToMatrix(new Vec3(0.02f, 0.08f, 0.08f) / 1));
mesh.Draw(mat, virtualGlove.ToMatrix(new Vec3(0.025f, 0.1f, 0.1f) / 3));
// mesh.Draw(mat, virtualGlove.ToMatrix(new Vec3(0.025f, 0.1f, 0.1f) / 3));
// ModelNode top = model.FindNode("Top");

View file

@ -6,7 +6,8 @@ public class Mono {
// Mesh[] greenyard;
// Material greenyardMat = new Material(Shader.FromFile("/shaders/oriel.hlsl"));
Vec3 offset = new Vec3(2, 0, -2);
Vec3 offset = new Vec3(2, 1, -2);
public float height = 1f;
Vec3 angle = new Vec3(0, 0, 0);
Thing[] thing;
@ -57,7 +58,8 @@ public class Mono {
Oriels.Rig rig = Oriels.Mono.inst.rig;
Oriels.Oriel oriel = Oriels.Mono.inst.oriel;
// angle.x += rig.rCon.device.stick.y * Time.Elapsedf;
angle.x += rig.rCon.device.stick.y * -60f * Time.Elapsedf;
angle.x = PullRequest.Clamp(angle.x, -89, 89);
angle.y += rig.rCon.device.stick.x * -60f * Time.Elapsedf;
Vec3 input = new Vec3(
@ -66,10 +68,18 @@ public class Mono {
rig.lCon.device.stick.y
);
if (input.MagnitudeSq > 0.01f) {
offset += (Quat.FromAngles(0, angle.y, 0).Inverse * rig.lCon.ori).Normalized * input * Time.Elapsedf;
input = (
Quat.FromAngles(angle.x, 0, 0).Inverse *
Quat.FromAngles(0, angle.y, 0).Inverse *
rig.lCon.ori *
oriel.ori.Inverse
).Normalized * input;
input.y = 0;
offset += input * Time.Elapsedf;
}
offset.y = -height;
// Oriel
@ -80,6 +90,7 @@ public class Mono {
Matrix simMatrix = Matrix.TRS(
Vec3.Zero, // -oriel.bounds.dimensions.y / 2.01f
Quat.FromAngles(angle.x, 0, 0) *
Quat.FromAngles(0, angle.y, 0),
Vec3.One * scale
);

View file

@ -96,6 +96,8 @@ public class Mono {
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, 0.1f, 1.5f, 0.1f);
UI.WindowEnd();

View file

@ -49,9 +49,10 @@ public class Oriel {
public bool scaling;
public Vec3 cursor = Vec3.Zero;
public Vec3 localCursor = Vec3.Zero;
public Quat cursorOri = Quat.Identity;
public Color cursorColor = Color.White;
public float cursorRadius = 0.1f;
public Color cursorColor = new Color(0.2f, 0.2f, 0.2f);
public float cursorRadius = 0.04f;
public float cornerRadius;
Vec3 detect = Vec3.Zero;
@ -64,9 +65,27 @@ public class Oriel {
Matrix mOffset = Matrix.Identity;
Vec3 cornerDetect = Vec3.Zero;
public Vec3 XAnchor { get { return LocalAnchor - detect.JustX() * cornerRadius; } }
public Vec3 YAnchor { get { return LocalAnchor - detect.JustY() * cornerRadius; } }
public Vec3 ZAnchor { get { return LocalAnchor - detect.JustZ() * cornerRadius; } }
public Vec3 XAnchor { get {
float x = PullRequest.Clamp(localCursor.x,
LocalAnchor.x - cornerRadius,
LocalAnchor.x + cornerRadius
);
return new Vec3(x, LocalAnchor.y, LocalAnchor.z);
} }
public Vec3 YAnchor { get {
float y = PullRequest.Clamp(localCursor.y,
LocalAnchor.y - cornerRadius,
LocalAnchor.y + cornerRadius
);
return new Vec3(LocalAnchor.x, y, LocalAnchor.z);
} }
public Vec3 ZAnchor { get {
float z = PullRequest.Clamp(localCursor.z,
LocalAnchor.z - cornerRadius,
LocalAnchor.z + cornerRadius
);
return new Vec3(LocalAnchor.x, LocalAnchor.y, z);
} }
Vec3 anchorOffset = Vec3.Zero;
public void Frame() {
@ -81,6 +100,7 @@ public class Oriel {
cursor = rGlove.virtualGlove.position;
cursorOri = rGlove.virtualGlove.orientation;
// debug
// bool onpress = Input.Key(Key.Space).IsJustActive();
// bool held = Input.Key(Key.Space).IsActive();
// bool onlift = Input.Key(Key.Space).IsJustInactive();
@ -98,7 +118,7 @@ public class Oriel {
Vec3 localCursor = matrixInv.Transform(cursor);
localCursor = matrixInv.Transform(cursor);
if (!interacting) {
// generate all the potential anchors
@ -180,12 +200,20 @@ public class Oriel {
if (scaling) {
Vec3 oldAnchor = Anchor;
Vec3 delta = ((localCursor - anchorOffset) + LocalAnchor).Abs();
Vec3 delta = ((localCursor - anchorOffset) + LocalAnchor);
delta = delta * LocalAnchor.Sign(); // instead of delta.Abs();
bounds.dimensions = bounds.dimensions.Splice(delta, cornerDetect, true);
bounds.dimensions = new Vec3(
MathF.Max(bounds.dimensions.x, 0.02f),
MathF.Max(bounds.dimensions.y, 0.02f),
MathF.Max(bounds.dimensions.z, 0.02f)
);
bounds.center += Anchor - oldAnchor;
scaling = !held;
interacting = !held;
scaling = interacting = !held;
if (cornerDetect.MagnitudeSq == 0) {
scaling = interacting = false;
}
}
}
}
@ -225,45 +253,40 @@ public class Oriel {
// cursor
Color col = new Color(0.15f, 0.15f, 0.15f);
float thk = 0.005f;
float thk = 0.002f;
float prx = PullRequest.Clamp(
cursorRadius - (localCursor - LocalAnchor).Magnitude / 3, 0, cursorRadius
) / cursorRadius;
if (detectCount == 1 || detectCount == 2) {
Vec3 edge = Vec3.One - detect.Abs();
meshCube.Draw(matClear,
Matrix.TS(
LocalAnchor,
(Vec3.One * thk) + (edge * bounds.dimensions / 3f)
(Vec3.One * thk) + (edge * bounds.dimensions / 3f * prx)
) * matrix, col
);
}
if (detectCount == 3) {
// Lines.Add(Anchor, Anchor - ori * detect.JustX() * cornerRadius, col, thk);
// Lines.Add(Anchor, Anchor - ori * detect.JustY() * cornerRadius, col, thk);
// Lines.Add(Anchor, Anchor - ori * detect.JustZ() * cornerRadius, col, thk);
Vec3 x = detect.JustX() * cornerRadius;
meshCube.Draw(matClear,
Matrix.TS(
LocalAnchor - (x / 2f),
(Vec3.One * thk) + x
Vec3.Lerp(XAnchor, LocalAnchor, 0.5f),
new Vec3(MathF.Abs(XAnchor.x - LocalAnchor.x), thk, thk)
) * matrix, col
);
Vec3 y = detect.JustY() * cornerRadius;
meshCube.Draw(matClear,
Matrix.TS(
LocalAnchor - (y / 2f),
(Vec3.One * thk) + y
Vec3.Lerp(YAnchor, LocalAnchor, 0.5f),
new Vec3(thk, MathF.Abs(YAnchor.y - LocalAnchor.y), thk)
) * matrix, col
);
Vec3 z = detect.JustZ() * cornerRadius;
meshCube.Draw(matClear,
Matrix.TS(
LocalAnchor - (z / 2f),
(Vec3.One * thk) + z
Vec3.Lerp(ZAnchor, LocalAnchor, 0.5f),
new Vec3(thk, thk, MathF.Abs(ZAnchor.z - LocalAnchor.z))
) * matrix, col
);
// draw cube(s) on intersecting corner ends
if (cornerDetect.x > 0) {
meshCube.Draw(matClear,
Matrix.TS(XAnchor, Vec3.One * thk * 2) * matrix,
@ -282,15 +305,10 @@ public class Oriel {
new Color(0, 0, 1)
);
}
// Lines.Add(
// zAnchor, zAnchor + ori * detect.JustZ() * stab * 1.5f,
// new Color(0, 0, 1), 0.01f
// );
}
meshCube.Draw(Material.Default,
Matrix.TRS(cursor, cursorOri, new Vec3(0.04f, 0.01f, 0.04f)),
meshCube.Draw(matClear,
Matrix.TRS(cursor, cursorOri, new Vec3(0.02f, 0.005f, 0.02f)),
cursorColor
);
@ -303,33 +321,20 @@ public class Oriel {
// faces, edges, corners
Vec3[] anchors = new Vec3[] {
// faces
new Vec3(1, 0, 0),
new Vec3(-1, 0, 0),
new Vec3(0, 1, 0),
new Vec3(0, -1, 0),
new Vec3(0, 0, 1),
new Vec3(0, 0, -1),
new Vec3(1, 0, 0), new Vec3(-1, 0, 0),
new Vec3(0, 1, 0), new Vec3( 0, -1, 0),
new Vec3(0, 0, 1), new Vec3( 0, 0, -1),
// edges
new Vec3(1, 1, 0),
new Vec3(-1, 1, 0),
new Vec3(1, -1, 0),
new Vec3(-1, -1, 0),
new Vec3(1, 0, 1),
new Vec3(-1, 0, 1),
new Vec3(1, 0, -1),
new Vec3(-1, 0, -1),
new Vec3(0, 1, 1),
new Vec3(0, -1, 1),
new Vec3(0, 1, -1),
new Vec3(0, -1, -1),
new Vec3(1, 1, 0), new Vec3(-1, 1, 0),
new Vec3(1, -1, 0), new Vec3(-1, -1, 0),
new Vec3(1, 0, 1), new Vec3(-1, 0, 1),
new Vec3(1, 0, -1), new Vec3(-1, 0, -1),
new Vec3(0, 1, 1), new Vec3( 0, -1, 1),
new Vec3(0, 1, -1), new Vec3( 0, -1, -1),
// corners
new Vec3(1, 1, 1),
new Vec3(-1, 1, 1),
new Vec3(1, -1, 1),
new Vec3(-1, -1, 1),
new Vec3(1, 1, -1),
new Vec3(-1, 1, -1),
new Vec3(1, -1, -1),
new Vec3(-1, -1, -1)
new Vec3(1, 1, 1), new Vec3(-1, 1, 1),
new Vec3(1, -1, 1), new Vec3(-1, -1, 1),
new Vec3(1, 1, -1), new Vec3(-1, 1, -1),
new Vec3(1, -1, -1), new Vec3(-1, -1, -1)
};
}