diff --git a/add/shaders/oriel.hlsl b/add/shaders/oriel.hlsl index e9e263e..9f4db5b 100644 --- a/add/shaders/oriel.hlsl +++ b/add/shaders/oriel.hlsl @@ -104,9 +104,9 @@ psOut ps(psIn input) { // clip(-1); // } - // if (dot(direction, input.normal) > 0) { - // o.color = float4(0.5, 0.5, 0.5, 1); - // } + if (dot(direction, input.normal) > 0) { + o.color = float4(0, 0, 0, 1); + } return o; } diff --git a/app/Greenyard/Mono.cs b/app/Greenyard/Mono.cs index 56c0ffe..ab01736 100644 --- a/app/Greenyard/Mono.cs +++ b/app/Greenyard/Mono.cs @@ -7,6 +7,7 @@ public class Mono { // Material greenyardMat = new Material(Shader.FromFile("/shaders/oriel.hlsl")); Vec3 offset = new Vec3(2, 0, -2); + Vec3 angle = new Vec3(0, 0, 0); Thing[] thing; Model model = Model.FromFile("/backrooms/backrooms.glb"); @@ -56,6 +57,21 @@ 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.y += rig.rCon.device.stick.x * -60f * Time.Elapsedf; + + Vec3 input = new Vec3( + rig.lCon.device.stick.x, + 0, + rig.lCon.device.stick.y + ); + if (input.MagnitudeSq > 0.01f) { + offset += Quat.FromAngles(0, angle.y, 0).Inverse * input * Time.Elapsedf; + } + + + + // Oriel float scale = oriel.scale * oriel.multiplier; if (oriel.scaleHeight) { @@ -64,7 +80,7 @@ public class Mono { Matrix simMatrix = Matrix.TRS( new Vec3(0, -oriel.bounds.dimensions.y / 2.01f, 0), - Quat.Identity, + Quat.FromAngles(0, angle.y, 0), Vec3.One * scale ); diff --git a/app/Oriel.cs b/app/Oriel.cs index 82a33e4..3912446 100644 --- a/app/Oriel.cs +++ b/app/Oriel.cs @@ -33,8 +33,10 @@ public class Oriel { bounds = new Bounds( new Vec3(-1.0f, -0.5f, 0.5f), + // Vec3.Zero, new Vec3(0.8f, 0.5f, 0.5f) ); + ori = Quat.FromAngles(0, 90, 0); matrix = Matrix.TR(bounds.center, ori); matrixInv = matrix.Inverse; @@ -54,15 +56,17 @@ public class Oriel { int detectCount = 0; public Vec3 LocalAnchor { get { return detect * bounds.dimensions / 2; } } public Vec3 Anchor { get { return matrix.Transform(LocalAnchor); } } - - Vec3 cornerDetect = Vec3.Zero; - - Vec3 anchorOffset = Vec3.Zero; - Vec3 localAnchorOffset = Vec3.Zero; Quat qOffset = Quat.Identity; Vec3 vOffset = Vec3.Zero; Vec3 lOffset = Vec3.Zero; 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; } } + Vec3 anchorOffset = Vec3.Zero; + public void Frame() { // input Rig rig = Mono.inst.rig; @@ -70,11 +74,10 @@ public class Oriel { Quat rGloveRot = rGlove.virtualGlove.orientation; // Vec3 lGlovePos = rig.lGlove.virtualGlove.position; - cursor = rGlove.virtualGlove.position; - bool onpress = rig.rCon.triggerBtn.frameDown; bool held = rig.rCon.triggerBtn.held; bool onlift = rig.rCon.triggerBtn.frameUp; + cursor = rGlove.virtualGlove.position; // bool onpress = Input.Key(Key.Space).IsJustActive(); // bool held = Input.Key(Key.Space).IsActive(); @@ -150,40 +153,27 @@ public class Oriel { // } else { // ori = (q * qOffset).Normalized; // } + + interacting = held; } else if (detectCount == 3) { // Scale (corner -> corner) if (!scaling) { - Vec3 xAnchor = Anchor - ori * detect.JustX() * cornerRadius; - Vec3 yAnchor = Anchor - ori * detect.JustY() * cornerRadius; - Vec3 zAnchor = Anchor - ori * detect.JustZ() * cornerRadius; cornerDetect = new Vec3( - MathF.Max(cursorRadius - Vec3.Distance(xAnchor, cursor), 0), - MathF.Max(cursorRadius - Vec3.Distance(yAnchor, cursor), 0), - MathF.Max(cursorRadius - Vec3.Distance(zAnchor, cursor), 0) + MathF.Max(cursorRadius - Vec3.Distance(XAnchor, localCursor), 0), + MathF.Max(cursorRadius - Vec3.Distance(YAnchor, localCursor), 0), + MathF.Max(cursorRadius - Vec3.Distance(ZAnchor, localCursor), 0) ); - anchorOffset = cursor - Anchor; - localAnchorOffset = localCursor - LocalAnchor; + anchorOffset = localCursor - LocalAnchor; scaling = onlift; } if (scaling) { - if (cornerDetect.x > 0) { - float distX = Math.Abs(-LocalAnchor.x - localCursor.x + localAnchorOffset.x); - bounds.center.x = PullRequest.Lerp(matrix.Transform(-LocalAnchor).x, cursor.x - anchorOffset.x, 0.5f); - bounds.dimensions.x = distX; - } - if (cornerDetect.y > 0) { - float distY = Math.Abs(-LocalAnchor.y - localCursor.y + localAnchorOffset.y); - bounds.center.y = PullRequest.Lerp(matrix.Transform(-LocalAnchor).y, cursor.y - anchorOffset.y, 0.5f); - bounds.dimensions.y = distY; - } - if (cornerDetect.z > 0) { - float distZ = Math.Abs(-LocalAnchor.z - localCursor.z + localAnchorOffset.z); - bounds.center.z = PullRequest.Lerp(matrix.Transform(-LocalAnchor).z, cursor.z - anchorOffset.z, 0.5f); - bounds.dimensions.z = distZ; - } + Vec3 oldAnchor = Anchor; + Vec3 delta = ((localCursor - anchorOffset) + LocalAnchor).Abs(); + bounds.dimensions = bounds.dimensions.Splice(delta, cornerDetect, true); + bounds.center += Anchor - oldAnchor; scaling = !held; interacting = !held; @@ -265,24 +255,21 @@ public class Oriel { // draw cube(s) on intersecting corner ends - Vec3 xAnchor = Anchor - ori * detect.JustX() * cornerRadius; if (cornerDetect.x > 0) { meshCube.Draw(matClear, - Matrix.TS(xAnchor, Vec3.One * thk * 2), + Matrix.TS(XAnchor, Vec3.One * thk * 2) * matrix, new Color(1, 0, 0) ); } - Vec3 yAnchor = Anchor - ori * detect.JustY() * cornerRadius; if (cornerDetect.y > 0) { meshCube.Draw(matClear, - Matrix.TS(yAnchor, Vec3.One * thk * 2), + Matrix.TS(YAnchor, Vec3.One * thk * 2) * matrix, new Color(0, 1, 0) ); } - Vec3 zAnchor = Anchor - ori * detect.JustZ() * cornerRadius; if (cornerDetect.z > 0) { meshCube.Draw(matClear, - Matrix.TS(zAnchor, Vec3.One * thk * 2), + Matrix.TS(ZAnchor, Vec3.One * thk * 2) * matrix, new Color(0, 0, 1) ); } diff --git a/app/PullRequest.cs b/app/PullRequest.cs index 0c473ed..7fc4231 100644 --- a/app/PullRequest.cs +++ b/app/PullRequest.cs @@ -65,6 +65,25 @@ public static class PullRequest { ); } + public static Vec3 Sign(this Vec3 v) { + return new Vec3( + MathF.Sign(v.x), + MathF.Sign(v.y), + MathF.Sign(v.z) + ); + } + + /// + /// a(1,1,1) b(2,2,2) t(0,1,0.5) return(1,2,1.5) + /// + public static Vec3 Splice(this Vec3 a, Vec3 b, Vec3 t, bool nor = false) { + return new Vec3( + Lerp(a.x, b.x, nor ? MathF.Sign(t.x) : t.x), + Lerp(a.y, b.y, nor ? MathF.Sign(t.y) : t.y), + Lerp(a.z, b.z, nor ? MathF.Sign(t.z) : t.z) + ); + } + static Mesh meshCube = Default.MeshCube; static Material matCube = Default.Material; public static void BlockOut(Matrix m, Color color, Material mat = null) {