diff --git a/add/backrooms/Carpet.png b/add/backrooms/Carpet.png new file mode 100644 index 0000000..357d2f0 Binary files /dev/null and b/add/backrooms/Carpet.png differ diff --git a/add/backrooms/Ceiling.png b/add/backrooms/Ceiling.png new file mode 100644 index 0000000..405fa23 Binary files /dev/null and b/add/backrooms/Ceiling.png differ diff --git a/add/backrooms/Lights.png b/add/backrooms/Lights.png new file mode 100644 index 0000000..ba33cb2 Binary files /dev/null and b/add/backrooms/Lights.png differ diff --git a/add/backrooms/Vents.png b/add/backrooms/Vents.png new file mode 100644 index 0000000..6451281 Binary files /dev/null and b/add/backrooms/Vents.png differ diff --git a/add/backrooms/Walls.png b/add/backrooms/Walls.png new file mode 100644 index 0000000..1e510af Binary files /dev/null and b/add/backrooms/Walls.png differ diff --git a/add/backrooms/backrooms.blend b/add/backrooms/backrooms.blend new file mode 100644 index 0000000..b11690d Binary files /dev/null and b/add/backrooms/backrooms.blend differ diff --git a/add/backrooms/backrooms.glb b/add/backrooms/backrooms.glb new file mode 100644 index 0000000..eb04a59 Binary files /dev/null and b/add/backrooms/backrooms.glb differ diff --git a/add/shaders/room.hlsl b/add/shaders/room.hlsl index 3da36bf..f45c453 100644 --- a/add/shaders/room.hlsl +++ b/add/shaders/room.hlsl @@ -83,6 +83,7 @@ float4 ps(psIn input) : SV_TARGET { float3 ro = input.campos; float3 rd = normalize(input.world - ro); float ol = raymarch(ro, rd); + clip(-(100 - (ol + 1))); // if ((100 - (ol + 1)) > 0) { // col *= 0.1; diff --git a/app/Greenyard/Mono.cs b/app/Greenyard/Mono.cs index 2b29c59..56c0ffe 100644 --- a/app/Greenyard/Mono.cs +++ b/app/Greenyard/Mono.cs @@ -2,50 +2,118 @@ using Oriels; namespace Greenyard; public class Mono { - Model greenyardModel = Model.FromFile("greenyard.glb"); - Mesh[] greenyard; - Material greenyardMat = new Material(Shader.FromFile("/shaders/oriel.hlsl")); + // Model greenyardModel = Model.FromFile("greenyard.glb"); + // Mesh[] greenyard; + // Material greenyardMat = new Material(Shader.FromFile("/shaders/oriel.hlsl")); - Vec3 offset = new Vec3(0, 0, 0); + Vec3 offset = new Vec3(2, 0, -2); + + Thing[] thing; + Model model = Model.FromFile("/backrooms/backrooms.glb"); public Mono() { } public void Init() { - greenyard = new Mesh[12]; - for (int i = 0; i < greenyard.Length; i++) { - greenyard[i] = greenyardModel.GetMesh("Object_" + (i + 2)); - } - greenyardMat.SetMat(101, Cull.None, true); - greenyardMat.SetTexture("diffuse", Tex.FromFile("greenyard.jpeg")); + // greenyard = new Mesh[12]; + // for (int i = 0; i < greenyard.Length; i++) { + // greenyard[i] = greenyardModel.GetMesh("Object_" + (i + 2)); + // } + // greenyardMat.SetMat(101, Cull.None, true); + // greenyardMat.SetTexture("diffuse", Tex.FromFile("greenyard.jpeg")); + + thing = new Thing[] { + new Thing( + model.GetMesh("Carpet"), + new Material(Shader.FromFile("/shaders/oriel.hlsl")), + "backrooms/Carpet.png" + ), + new Thing( + model.GetMesh("Walls"), + new Material(Shader.FromFile("/shaders/oriel.hlsl")), + "backrooms/Walls.png" + ), + new Thing( + model.GetMesh("Ceiling"), + new Material(Shader.FromFile("/shaders/oriel.hlsl")), + "backrooms/Ceiling.png" + ), + new Thing( + model.GetMesh("Vents"), + new Material(Shader.FromFile("/shaders/oriel.hlsl")), + "backrooms/Vents.png" + ), + new Thing( + model.GetMesh("Lights"), + new Material(Shader.FromFile("/shaders/oriel.hlsl")), + "backrooms/Lights.png" + ), + }; } public void Frame() { Oriels.Rig rig = Oriels.Mono.inst.rig; Oriels.Oriel oriel = Oriels.Mono.inst.oriel; + // Oriel + float scale = oriel.scale * oriel.multiplier; + if (oriel.scaleHeight) { + scale *= oriel.bounds.dimensions.y; + } + Matrix simMatrix = Matrix.TRS( new Vec3(0, -oriel.bounds.dimensions.y / 2.01f, 0), Quat.Identity, - Vec3.One * 0.1f * oriel.bounds.dimensions.y + Vec3.One * scale ); // Render - greenyardMat.SetVector("_center", oriel.bounds.center); - greenyardMat.SetVector("_dimensions", oriel.bounds.dimensions); - greenyardMat.SetVector("_light", oriel.ori * new Vec3(0.6f, -0.9f, 0.3f)); - greenyardMat.SetFloat("_lit", 0); - greenyardMat["_matrix"] = (Matrix)System.Numerics.Matrix4x4.Transpose(oriel.matrix); - for (int i = 0; i < greenyard.Length; i++) { - greenyard[i].Draw(greenyardMat, + // greenyardMat.SetVector("_center", oriel.bounds.center); + // greenyardMat.SetVector("_dimensions", oriel.bounds.dimensions); + // greenyardMat.SetVector("_light", oriel.ori * new Vec3(0.6f, -0.9f, 0.3f)); + // greenyardMat.SetFloat("_lit", 0); + // greenyardMat["_matrix"] = (Matrix)System.Numerics.Matrix4x4.Transpose(oriel.matrixInv); + // for (int i = 0; i < greenyard.Length; i++) { + // greenyard[i].Draw(greenyardMat, + // Matrix.TRS( + // offset, + // Quat.Identity, + // new Vec3(1f, 1f, 1f) + // ) * simMatrix * oriel.matrix, + // Color.White + // ); + // } + + for (int i = 0; i < thing.Length; i++) { + Thing t = thing[i]; + t.mat.SetVector("_center", oriel.bounds.center); + t.mat.SetVector("_dimensions", oriel.bounds.dimensions); + t.mat.SetVector("_light", oriel.ori * new Vec3(0.6f, -0.9f, 0.3f)); + t.mat.SetFloat("_lit", 0); + t.mat["_matrix"] = (Matrix)System.Numerics.Matrix4x4.Transpose(oriel.matrixInv); + t.mesh.Draw(t.mat, Matrix.TRS( offset, Quat.Identity, new Vec3(1f, 1f, 1f) - ) * simMatrix * oriel.matrix.Inverse, + ) * simMatrix * oriel.matrix, Color.White ); } } +} + +[Serializable] +public class Thing { + public Mesh mesh; + public Material mat; + + public Thing(Mesh mesh, Material mat, string tex) { + this.mesh = mesh; + this.mat = mat; + + mat.SetMat(101, Cull.None, true); + mat.SetTexture("diffuse", Tex.FromFile(tex)); + } } \ No newline at end of file diff --git a/app/Mono.cs b/app/Mono.cs index 48ae80d..2a646bf 100644 --- a/app/Mono.cs +++ b/app/Mono.cs @@ -46,6 +46,7 @@ public class Mono { // Space.Mono spaceMono = new Space.Mono(); Greenyard.Mono greenyard = new Greenyard.Mono(); + Board board = new Board(); PullRequest.PID pid = new PullRequest.PID(8, 0.8f); @@ -55,7 +56,6 @@ public class Mono { public void Step() { rig.Step(); - scene.Step(); // ------------------------------------------------- @@ -67,28 +67,154 @@ public class Mono { // colorCube.Palm(lCon.device); - oriel.Step(); + oriel.Frame(); + + scene.Step(); // after! (render scene after oriel) // ------------------------------------------------- // spaceMono.Frame(); greenyard.Frame(); + // board.Frame(); // ------------------------------------------------- + oriel.Render(); + net.me.Step(); net.send = true; ShowWindowButton(); } - Pose windowPoseButton = new Pose(0, 0, -1, Quat.Identity); + Pose windowPoseButton = new Pose(0, 0, -0.5f, Quat.Identity); void ShowWindowButton() { UI.WindowBegin("Window Button", ref windowPoseButton); if (UI.Button("Reset Oriel Quat")) { oriel.ori = Quat.Identity; } // if (UI.Button("Draw Oriel Axis")) { oriel.drawAxis = !oriel.drawAxis; } + if (UI.Button("Scale w/Height")) { oriel.scaleHeight = !oriel.scaleHeight; } + UI.HSlider("Scale", ref oriel.scale, 0.1f, 1f, 0.1f); + UI.HSlider("Multiplier", ref oriel.multiplier, 0.1f, 1f, 0.1f); + UI.WindowEnd(); } } + + + +[Serializable] +public class Board { + // velocity button controls + // "center off mass" thrust vector steering + + Mesh meshCube = Mesh.Cube; + + public bool goofy = false; + + public Vec3 front, back, pos, dir, vector; + public float vel; + + float length = 1.5f; + public Board() { + front = new Vec3(0, 0, -1) * length / 2; + back = new Vec3(0, 0, 1) * length / 2; + dir = new Vec3(0, 0, -1); + vel = 0; + } + + public void Frame() { + // tilt steer ("back wheel" turns *rudder) + // button velocity controls + Con con = goofy ? Mono.inst.rig.rCon : Mono.inst.rig.lCon; + float accel = con.device.trigger; + float deccel = con.device.grip; + float lean = Mono.inst.rig.LocalPos(Mono.inst.rig.Head.position).x; + + // float length = 1.5f; + float drag = 0.1f; + float speed = 4f; + float brake = 12f; + float tight = 60f; + + + // velocity + vel *= 1f - (drag * Time.Elapsedf); + vel += accel * speed * Time.Elapsedf; + vel = MathF.Max(vel - deccel * brake * Time.Elapsedf, 0); + + // steering + vector = Quat.LookDir(dir) * Quat.FromAngles(0, lean * tight, 0) * Vec3.Forward; + back += vector * vel * Time.Elapsedf; + dir = (front - back).Normalized; + + front = back + dir * length; + pos = Vec3.Lerp(front, back, 0.5f); + + + Mono.inst.rig.pos = pos; + Mono.inst.rig.ori = Quat.LookDir(dir); + + // hover + // if (rig.lCon.gripBtn.held) { + // rig.pos.y = pid.Update(rig.LocalPos(rig.Head.position).y); + // } + + + meshCube.Draw(Material.Default, + Matrix.TRS( + Mono.inst.rig.FloorCenter, + Quat.LookDir(dir), + new Vec3(0.05f, 0.2f, 0.2f) + ) + ); + + // mini board in hand for debugging + // meshCube.Draw(Material.Default, + // Matrix.TRS( + // rig.rCon.pos, + // board.ori, + // new Vec3(0.4f, 0.1f, reach * 2) * 0.1f + // ) + // ); + // // front wheel + // meshCube.Draw(Material.Default, + // Matrix.TRS( + // rig.rCon.pos + board.dir * reach * 0.1f, + // Quat.LookDir(frontDir), + // new Vec3(0.05f, 0.2f, 0.2f) * 0.1f + // ) + // ); + + + + + + // pillars to hover through + // spawn in front every 1m away from last + if (Vec3.Distance(pos, lastSpawnPos) > 1f) { + // odd or even + float chirality = pillarIndex % 2 == 0 ? 1f : -1f; + pillars[pillarIndex] = pos + Quat.LookDir(dir) * new Vec3(chirality * 8 * Mono.inst.noise.uvalue, 0, -24); + + lastSpawnPos = pos; + + pillarIndex++; + if (pillarIndex >= pillars.Length) { pillarIndex = 0; } + } + + for (int i = 0; i < pillars.Length; i++) { + meshCube.Draw(Material.Default, + Matrix.TRS( + pillars[i], + Quat.Identity, + new Vec3(0.1f, 20f, 0.1f) + ) + ); + } + } + Vec3[] pillars = new Vec3[64]; + int pillarIndex = 0; + Vec3 lastSpawnPos = Vec3.Zero; +} \ No newline at end of file diff --git a/app/Oriel.cs b/app/Oriel.cs index 75a4523..8a7acff 100644 --- a/app/Oriel.cs +++ b/app/Oriel.cs @@ -1,32 +1,29 @@ namespace Oriels; public class Oriel { + Model model = Model.FromFile("oriel.glb"); + Mesh meshCube, meshSphere; + + Material matClear = new Material(Shader.Default); + + public Material matOriel = new Material(Shader.FromFile("shaders/oriel.hlsl")); Material matFrame = new Material(Shader.FromFile("shaders/frame.hlsl")); Material matPanes = new Material(Shader.FromFile("shaders/panes.hlsl")); - public Material matOriel = new Material(Shader.FromFile("shaders/oriel.hlsl")); - Model model = Model.FromFile("oriel.glb"); - Mesh meshCube; + public Matrix matrix, matrixInv; public Bounds bounds; - public Quat ori; - public Matrix matrix; - public float crown = 0.0666f; + public Quat ori = Quat.Identity; - bool adjusting = false; - Quat qOffset = Quat.Identity; - Vec3 vOffset = Vec3.Zero; - Vec3 lOffset = Vec3.Zero; - Vec3 anchor = Vec3.Zero; - Matrix mOffset = Matrix.Identity; + // inner matrix + public bool scaleHeight = true; + public float scale = 0.1f; + public float multiplier = 1f; public Oriel() { - bounds = new Bounds( - new Vec3(-1.0f, -0.5f, 0.0f), - new Vec3(0.8f, 0.5f, 0.5f) - ); - - ori = Quat.Identity; - matrix = Matrix.TR(bounds.center, ori).Inverse; + // meshCube = model.GetMesh("oriel"); + meshCube = Mesh.Cube; + meshSphere = Mesh.Sphere; + matClear.Transparency = Transparency.Add; matFrame.SetMat(102, Cull.Back, true); matFrame.Transparency = Transparency.Blend; @@ -34,128 +31,214 @@ public class Oriel { matPanes.SetMat(100, Cull.Front, false); matOriel.SetMat(101, Cull.None, true); - meshCube = Mesh.Cube; - // meshCube = model.GetMesh("oriel"); + bounds = new Bounds( + new Vec3(-1.0f, -0.5f, 0.5f), + new Vec3(0.8f, 0.5f, 0.5f) + ); + matrix = Matrix.TR(bounds.center, ori); + matrixInv = matrix.Inverse; + + + cursor = bounds.center; + cornerRadius = cursorRadius / 2; } + public Vec3 cursor = Vec3.Zero; + public float cursorRadius = 0.1f; + public float cornerRadius; + Vec3 detect = Vec3.Zero; int detectCount = 0; - public void Step() { - matrix = Matrix.TR(bounds.center, ori).Inverse; + public Vec3 LocalAnchor { get { return detect * bounds.dimensions / 2; } } + public Vec3 Anchor { get { return matrix.Transform(LocalAnchor); } } + Quat qOffset = Quat.Identity; + Vec3 vOffset = Vec3.Zero; + Vec3 lOffset = Vec3.Zero; + Matrix mOffset = Matrix.Identity; + public void Frame() { + // input Rig rig = Mono.inst.rig; Glove rGlove = Mono.inst.rGlove; - Vec3 rGlovePos = rGlove.virtualGlove.position; + // cursor = rGlove.virtualGlove.position; Quat rGloveRot = rGlove.virtualGlove.orientation; // Vec3 lGlovePos = rig.lGlove.virtualGlove.position; + bool grab = !Input.Key(Key.Space).IsActive(); // !rig.rCon.triggerBtn.held - // face detection = (1 axis) - // edge detection = (2 axis) - // corner detection = (3 axis) - // Pose pose = new Pose(); - - - Vec3 localPos = ori.Inverse * (rGlovePos - bounds.center); - - - - - if (!rig.rCon.triggerBtn.held) { - float margin = PullRequest.Lerp(0.03f, 0.5f, bounds.dimensions.y / 2); - Vec3 newDetect = Vec3.Zero; - if ((bounds.dimensions.x / 2) - MathF.Abs(localPos.x) < 0) newDetect.x = 1 * MathF.Sign(localPos.x); - if ((bounds.dimensions.y / 2) - MathF.Abs(localPos.y) < 0) newDetect.y = 1 * MathF.Sign(localPos.y); - if ((bounds.dimensions.z / 2) - MathF.Abs(localPos.z) < 0) newDetect.z = 1 * MathF.Sign(localPos.z); - - if (newDetect.x != detect.x || newDetect.y != detect.y || newDetect.z != detect.z) { - detect = newDetect; - detectCount = (int)(MathF.Abs(detect.x) + MathF.Abs(detect.y) + MathF.Abs(detect.z)); - // Console.WriteLine(detectCount + ": " + detect); - } - - Vec3 dim = new Vec3( - bounds.dimensions.x + 0.1f, - bounds.dimensions.y + 0.1f, - bounds.dimensions.z + 0.1f + if (!Input.Key(Key.Shift).IsActive()) { + Vec3 input = new Vec3( + (Input.Key(Key.S).IsActive() ? 1 : 0) - (Input.Key(Key.A).IsActive() ? 1 : 0), + (Input.Key(Key.F).IsActive() ? 1 : 0) - (Input.Key(Key.Q).IsActive() ? 1 : 0), + (Input.Key(Key.R).IsActive() ? 1 : 0) - (Input.Key(Key.W).IsActive() ? 1 : 0) ); - Bounds arounds = new Bounds(Vec3.Zero, dim); - if (!arounds.Contains(localPos) || bounds.Contains(bounds.center + localPos)) { - detect = Vec3.Zero; - detectCount = 0; + if (input.Length > 0) { + cursor += input.Normalized * Time.Elapsedf * 0.4f; + } + } + + Vec3 localCursor = matrixInv.Transform(cursor); + + // ori = Quat.FromAngles(0, MathF.Sin(Time.Totalf) * 90f, 0); + + + if (grab) { + // generate all the potential anchors + // pick the closest one + Vec3 v = Vec3.Zero; + float minDist = float.MaxValue; + for (int i = 0; i < anchors.Length; i++) { + Vec3 a = matrix.Transform(anchors[i] * bounds.dimensions / 2); + float dist = (a - cursor).Length; + if (dist < minDist) { + minDist = dist; + v = anchors[i]; + } } - vOffset = rGlovePos - bounds.center; + detect = v; // rename this + detectCount = (int)(MathF.Abs(v.x) + MathF.Abs(v.y) + MathF.Abs(v.z)); + + vOffset = cursor - bounds.center; lOffset = ori.Inverse * vOffset; qOffset = (ori.Inverse * rGloveRot).Normalized; mOffset = matrix; - anchor = bounds.center + ori * -(detect * bounds.dimensions / 2); - - adjusting = false; - } else { - if (detectCount == 1) { // Move + } + else { + if (detectCount == 1) { // Move (face -> crown *face) ori = (rGloveRot * qOffset.Inverse).Normalized; - bounds.center = rGlovePos - ori * lOffset; - } else if (detectCount == 2) { // Rotate - localPos = mOffset.Transform(rGlovePos); - Vec3 dir = new Vec3( - detect.x == 0 ? 0 : localPos.x, - detect.y == 0 ? 0 : localPos.y, - detect.z == 0 ? 0 : localPos.z - ); + bounds.center = cursor - ori * lOffset; + } + else if (detectCount == 2) { // Rotate (edge -> edge) + // localPos = mOffset.Inverse.Transform(cursor); + // Vec3 dir = new Vec3( + // detect.x == 0 ? 0 : localPos.x, + // detect.y == 0 ? 0 : localPos.y, + // detect.z == 0 ? 0 : localPos.z + // ); + // Vec3 up = new Vec3( + // detect.x == 0 ? 1 : 0, + // detect.y == 0 ? 1 : 0, + // detect.z == 0 ? 1 : 0 + // ); - Vec3 up = new Vec3( - detect.x == 0 ? 1 : 0, - detect.y == 0 ? 1 : 0, - detect.z == 0 ? 1 : 0 - ); + // Quat q = Quat.LookAt(Vec3.Zero, dir, up); - Quat q = Quat.LookAt(Vec3.Zero, dir, up); + // if (!adjusting) { + // qOffset = (q.Inverse * ori).Normalized; + // adjusting = true; + // } else { + // ori = (q * qOffset).Normalized; + // } + } + else if (detectCount == 3) { // Scale (corner -> corner) + Vec3 zAnchor = Anchor - ori * detect.JustZ() * cornerRadius; + float stab = MathF.Max(cursorRadius - Vec3.Distance(zAnchor, cursor), 0); - if (!adjusting) { - qOffset = (q.Inverse * ori).Normalized; - adjusting = true; - } else { - ori = (q * qOffset).Normalized; + if (stab > 0) { + float distZ = Math.Abs(-LocalAnchor.z - localCursor.z); + bounds.center.z = PullRequest.Lerp(matrix.Transform(-LocalAnchor).z, cursor.z, 0.5f); + bounds.dimensions.z = distZ; } - } else if (detectCount == 3) { // Scale - Vec3 localAnchor = matrix.Transform(anchor); - float distX = Math.Abs(localAnchor.x - localPos.x); - float distY = Math.Abs(localAnchor.y - localPos.y); - float distZ = Math.Abs(localAnchor.z - localPos.z); - bounds.dimensions = new Vec3(distX, distY, distZ); - bounds.center = Vec3.Lerp(anchor, rGlovePos, 0.5f); } } + matrix = Matrix.TR(bounds.center, ori); + matrixInv = matrix.Inverse; + } - matrix = Matrix.TR(bounds.center, ori).Inverse; + // design vars + public float crown = 0.16f; - - // matFrame.Wireframe = true; - matFrame.DepthTest = DepthTest.Always; - matFrame.SetVector("_rGlovePos", rGlovePos); - matFrame.SetFloat("_time", Time.Totalf); - meshCube.Draw(matFrame, - Matrix.TRS(bounds.center, ori, bounds.dimensions), - new Color(0.1f, 0.1f, 0.1f) - ); - if (detectCount > 0) { - meshCube.Draw(Material.Default, - Matrix.TS(detect * (bounds.dimensions / 2), Vec3.One * 0.01f) * matrix.Inverse - ); - } + public void Render() { + // // matFrame.Wireframe = true; + // matFrame.DepthTest = DepthTest.Always; + // matFrame.SetVector("_cursor", cursor); + // matFrame.SetFloat("_time", Time.Totalf); + // meshCube.Draw(matFrame, + // Matrix.TRS(bounds.center, ori, bounds.dimensions), + // new Color(0.1f, 0.1f, 0.1f) + // ); // matPanes.DepthTest = DepthTest.Greater; - matPanes["_matrix"] = (Matrix)System.Numerics.Matrix4x4.Transpose(matrix); + matPanes["_matrix"] = (Matrix)System.Numerics.Matrix4x4.Transpose(matrixInv); meshCube.Draw(matPanes, Matrix.TRS(bounds.center, ori, bounds.dimensions), - new Color(0.0f, 0.0f, 0.5f) + new Color(0f, 0f, 0f) + // new Color(78 / 256f, 142 / 256f, 191 / 256f) ); matOriel.SetVector("_center", bounds.center); matOriel.SetVector("_dimensions", bounds.dimensions); matOriel.SetVector("_light", ori * new Vec3(0.6f, -0.9f, 0.3f)); matOriel.SetFloat("_lit", 1); - matOriel["_matrix"] = (Matrix)System.Numerics.Matrix4x4.Transpose(matrix); + matOriel["_matrix"] = (Matrix)System.Numerics.Matrix4x4.Transpose(matrixInv); + + + + // cursor + if (detectCount > 0) { + meshCube.Draw(Material.Default, + Matrix.TS(LocalAnchor, Vec3.One * 0.01f) * matrix + ); + + // draw the corner with 0.1f length lines + if (detectCount == 3) { + Color col = new Color(1f, 1f, 1f); + float thk = 0.005f; + 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); + + // draw cube(s) on intersecting corner ends + + // Lines.Add( + // zAnchor, zAnchor + ori * detect.JustZ() * stab * 1.5f, + // new Color(0, 0, 1), 0.01f + // ); + } + } + + meshCube.Draw(Material.Default, + Matrix.TRS(cursor, Quat.Identity, new Vec3(0.01f, 0.01f, 0.01f)), + new Color(1f, 1f, 1f) + ); + + meshSphere.Draw(matClear, + Matrix.TRS(cursor, Quat.Identity, new Vec3(1f, 1f, 1f) * cursorRadius * 2), + new Color(0.5f, 0.5f, 0.5f) + ); } + + // 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), + // 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), + // 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) + }; } \ No newline at end of file diff --git a/app/PullRequest.cs b/app/PullRequest.cs index f522814..b5669a6 100644 --- a/app/PullRequest.cs +++ b/app/PullRequest.cs @@ -46,6 +46,16 @@ public static class PullRequest { return (to - from).Normalized; } + // swizzle + public static Vec3 JustX(this Vec3 v) { + return new Vec3(v.x, 0, 0); + } + public static Vec3 JustY(this Vec3 v) { + return new Vec3(0, v.y, 0); + } + public static Vec3 JustZ(this Vec3 v) { + return new Vec3(0, 0, v.z); + } static Mesh meshCube = Default.MeshCube; static Material matCube = Default.Material; diff --git a/app/Scene.cs b/app/Scene.cs index 98f8a7c..959a452 100644 --- a/app/Scene.cs +++ b/app/Scene.cs @@ -43,7 +43,7 @@ public class Scene { public void Step() { Oriel oriel = Mono.inst.oriel; - data.matrix = (Matrix)System.Numerics.Matrix4x4.Transpose(oriel.matrix); + data.matrix = (Matrix)System.Numerics.Matrix4x4.Transpose(oriel.matrixInv); data.dimensions = oriel.bounds.dimensions; diff --git a/app/Space/Mono.cs b/app/Space/Mono.cs index 06395df..93e76ff 100644 --- a/app/Space/Mono.cs +++ b/app/Space/Mono.cs @@ -73,7 +73,7 @@ public class Mono { float stretch = Vec3.Distance(rig.lCon.pos, rig.rCon.pos); stretch = Math.Max(stretch - deadzone, 0); Vec3 cursor = rig.rCon.pos + rig.rCon.ori * Vec3.Forward * stretch * 3; - Vec3 localCursor = simMatrix.Inverse.Transform(oriel.matrix.Transform(cursor)); + Vec3 localCursor = simMatrix.Inverse.Transform(oriel.matrixInv.Transform(cursor)); localCursor = new Vec3( MathF.Sin(Time.Totalf * 2f) * 3f, @@ -97,7 +97,7 @@ public class Mono { // RENDER for (int i = 0; i < nodes.Length; i++) { meshCube.Draw(oriel.matOriel, - Matrix.TRS(nodes[i].pos, Quat.Identity, Vec3.One * 1f) * simMatrix * oriel.matrix.Inverse, + Matrix.TRS(nodes[i].pos, Quat.Identity, Vec3.One * 1f) * simMatrix * oriel.matrix, Color.HSV(nodes[i].hue, 1f, 1f) ); } @@ -107,7 +107,7 @@ public class Mono { new Color(1f, 1f, 1f) ); meshCube.Draw(oriel.matOriel, - Matrix.TRS(localCursor, Quat.Identity, Vec3.One * 0.02f) * simMatrix * oriel.matrix.Inverse, + Matrix.TRS(localCursor, Quat.Identity, Vec3.One * 0.02f) * simMatrix * oriel.matrix, new Color(0f, 0f, 0f) ); meshCube.Draw(oriel.matOriel, @@ -115,7 +115,7 @@ public class Mono { playerPos, Quat.LookDir((localCursor - playerPos).Normalized), new Vec3(0.4f, 0.2f, 0.4f) - ) * simMatrix * oriel.matrix.Inverse, + ) * simMatrix * oriel.matrix, new Color(1.0f, 0.0f, 0.05f) ); @@ -130,7 +130,7 @@ public class Mono { // playerPos, // Quat.Identity, // new Vec3(10f, 10f, 10f) - // ) * simMatrix * oriel.matrix.Inverse, + // ) * simMatrix * oriel.matrix, // Color.White // ); @@ -195,7 +195,7 @@ public class Mono { Matrix.TRS(enemies[i], Quat.LookAt(enemies[i], playerPos, Vec3.Up), new Vec3(0.4f, 1f, 0.2f) - ) * simMatrix * oriel.matrix.Inverse, + ) * simMatrix * oriel.matrix, Color.White * 0.62f ); } diff --git a/app/_Init.cs b/app/_Init.cs index 3eb1b28..c60f344 100644 --- a/app/_Init.cs +++ b/app/_Init.cs @@ -7,7 +7,7 @@ SKSettings settings = new SKSettings { assetsFolder = "add", depthMode = DepthMode.D32, disableUnfocusedSleep = true, - // displayPreference = DisplayMode.Flatscreen, + displayPreference = DisplayMode.Flatscreen, }; if (!SK.Initialize(settings)) Environment.Exit(1);