From 90b058786d59797ba4ac2027171938d7a965d4b3 Mon Sep 17 00:00:00 2001 From: spatialfree Date: Wed, 19 Oct 2022 02:42:07 -0400 Subject: [PATCH] multi oriel draft --- add/shaders/oriel.hlsl | 34 ++++++- add/shaders/room.hlsl | 10 +- app/Backrooms/Mono.cs | 126 +++++++++++++++++++++++ app/Compositor.cs | 99 ++++++++++++++++++ app/Glove.cs | 16 +++ app/Greenyard/Mono.cs | 200 +++++++++++++------------------------ app/PullRequest.cs | 76 +++++++++++++- app/Rig/Rig.cs | 4 +- app/{Scene.cs => Space.cs} | 28 +++--- app/Space/Mono.cs | 6 +- app/_Init.cs | 2 + app/dofs/oriel/Oriel.cs | 94 +++++++++-------- 12 files changed, 488 insertions(+), 207 deletions(-) create mode 100644 app/Backrooms/Mono.cs create mode 100644 app/Compositor.cs rename app/{Scene.cs => Space.cs} (88%) diff --git a/add/shaders/oriel.hlsl b/add/shaders/oriel.hlsl index 9f4db5b..447fb62 100644 --- a/add/shaders/oriel.hlsl +++ b/add/shaders/oriel.hlsl @@ -51,7 +51,11 @@ psIn vs(vsIn input, uint id : SV_InstanceID) { } float3 cross(float3 a, float3 b) { - return float3(a.y * b.z - a.z * b.y, a.z * b.x - a.x * b.z, a.x * b.y - a.y * b.x); + return float3( + a.y * b.z - a.z * b.y, + a.z * b.x - a.x * b.z, + a.x * b.y - a.y * b.x + ); } float dot(float3 a, float3 b) { @@ -74,7 +78,21 @@ float raymarch(float3 origin, float3 direction) { for (int i = 0; i < 256; i++) { float3 pos = origin + dist * direction; float step = sdBox(pos, _dimensions / 2.0); - if (step < 0.0001 || dist > 100) break; // 100 == distmax + if (step < 0.0001 || dist > 100) break; // 100 == distmax + dist += step; + } + + return dist; +} + +float raymarchy(float3 origin, float3 direction) { + origin = mul(float4(origin, 1), _matrix).xyz; + direction = mul(float4(direction, 0), _matrix).xyz; + float dist = 0.0; + for (int i = 0; i < 256; i++) { + float3 pos = origin + dist * direction; + float step = sdBox(pos, _dimensions / 4.0); + if (step < 0.0001 || dist > 100) break; // 100 == distmax dist += step; } @@ -93,6 +111,18 @@ psOut ps(psIn input) { origin += ol * direction; + float oll = raymarchy(origin, direction); + if (oll < 99) { + o.color = float4(1, 1, 1, 1); + + float3 origin2 = origin + oll * direction; + float4 og = mul(float4(origin2, 1), sk_viewproj[input.view_id]); + // o.depth = og.z; + o.depth = (og * rcp(og.w)).z; + return o; + } + + clip(distance(input.campos, input.world) - distance(input.campos, origin)); float t = 1 - (1 + dot(input.normal, _light)) / 2; diff --git a/add/shaders/room.hlsl b/add/shaders/room.hlsl index ff94f68..fe4fab4 100644 --- a/add/shaders/room.hlsl +++ b/add/shaders/room.hlsl @@ -61,9 +61,9 @@ float sdSphere(float3 p, float r) { return length(p) - r; } -float raymarch(float3 ro, float3 rd) { - ro = mul(float4(ro, 1), oriel_matrix).xyz; - rd = mul(float4(rd, 0), oriel_matrix).xyz; +float raymarch(float4x4 m, float3 ro, float3 rd) { + ro = mul(float4(ro, 1), m).xyz; + rd = mul(float4(rd, 0), m).xyz; float dist = 0.0; for (int i = 0; i < 256; i++) { float3 pos = ro + dist * rd; @@ -101,7 +101,7 @@ float4 ps(psIn input) : SV_TARGET { float3 ro = input.campos; float3 rd = normalize(input.world - ro); - float ol = raymarch(ro, rd); + float ol = raymarch(oriel_matrix, ro, rd); clip(-(100 - (ol + 1))); // if ((100 - (ol + 1)) > 0) { @@ -122,5 +122,5 @@ float4 ps(psIn input) : SV_TARGET { // float value = (col.r + col.r + col.g + col.g + col.g + col.b) / 6; // return float4(value, value, value, 1); - return col; + return col * 0.333; } \ No newline at end of file diff --git a/app/Backrooms/Mono.cs b/app/Backrooms/Mono.cs new file mode 100644 index 0000000..b82a153 --- /dev/null +++ b/app/Backrooms/Mono.cs @@ -0,0 +1,126 @@ +using Oriels; + +namespace Backrooms; +public class Mono { + public Oriel oriel = new Oriel( + new Vec3(-1.0f,-0.5f, 0.5f), + Quat.FromAngles(0, 90, 0), + new Vec3( 0.8f, 0.5f, 0.5f) + ) { color = new Color(0, 0, 0) }; + + Matrix matrix = Matrix.Identity; + Vec3 offset = new Vec3(2, 1, -2); + public float height = 1f; + Vec3 angle = new Vec3(0, 0, 0); + + Thing[] thing; + Model model = Model.FromFile("/backrooms/backrooms.glb"); + + public void Init() { + 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; + + // angle.x -= rig.rCon.device.stick.y * 90f * Time.Elapsedf; + // angle.x = PullRequest.Clamp(angle.x, -89, 89); + angle.y -= rig.rCon.device.stick.x * 90f * Time.Elapsedf; + + Vec3 input = new Vec3( + rig.lCon.device.stick.x, + 0, + rig.lCon.device.stick.y + ); + if (input.MagnitudeSq > 0.01f) { + 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 + float scale = 1f; // oriel.scale * oriel.multiplier; + // scale w/height? + // scale *= oriel.bounds.dimensions.y; + + matrix = 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 + ); + } + + public void Render() { + 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) + ) * matrix * oriel.matrix, + Color.White + ); + } + } +} + + + +// temp placement +[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.Transparency = Transparency.Add; + // mat.DepthTest = DepthTest.Always; + mat.SetTexture("diffuse", Tex.FromFile(tex)); + } +} \ No newline at end of file diff --git a/app/Compositor.cs b/app/Compositor.cs new file mode 100644 index 0000000..ff0b310 --- /dev/null +++ b/app/Compositor.cs @@ -0,0 +1,99 @@ +namespace Oriels; + +public class Compositor { + + // these are in a weird place, + // as a process would not be hosted by a compositor... + Backrooms.Mono backrooms = new Backrooms.Mono(); + Greenyard.Mono greenyard = new Greenyard.Mono(); + bool other = false; + + public void Init() { + backrooms.Init(); + greenyard.Init(); + } + + public void Frame() { + Mono mono = Mono.inst; + + // backrooms.oriel.Frame(); + // greenyard.oriel.Frame(); + + // // mono.space.Frame(); + // Glove rGlove = Mono.inst.rGlove; + // Vec3 cursor = rGlove.virtualGlove.position; + + // if (other) { + // greenyard.Frame(); + + // Vec3 localCursor = backrooms.oriel.matrixInv.Transform(cursor); + // if (backrooms.oriel.bounds.Contains(localCursor + backrooms.oriel.bounds.center)) { + // Console.WriteLine("in backrooms"); + // other = false; + // } + // } else { + // backrooms.Frame(); + + // Vec3 localCursor = greenyard.oriel.matrixInv.Transform(cursor); + // if (greenyard.oriel.bounds.Contains(localCursor + greenyard.oriel.bounds.center)) { + // Console.WriteLine("in greenyard"); + // other = true; + // } + // } + + // render buffers ? or just use the depth buffer? + + mono.space.Frame(); + // backrooms.oriel.Render(); // -> Frame() by moving Input specific parts to the compositor? + // backrooms.Render(); + // greenyard.oriel.Render(); + // greenyard.Render(); + + // active oriel + // how to show this? + // well popping up a wireframe would get in the way and look bad + // and a glow would be hard to keep consistent across backgrounds + // am I bringing the crown back? + + // matFrame.Wireframe = true; + // matFrame.DepthTest = DepthTest.Always; + // matFrame.SetVector("_cursor", cursor); + // matFrame.SetFloat("_time", Time.Totalf); + // Mesh.Cube.Draw(matFrame, + // Matrix.TRS(bounds.center, ori, bounds.dimensions), + // new Color(0.1f, 0.1f, 0.1f) + // ); + // Model model = Model.FromFile("oriel.glb"); + // ~ Mesh mesh = model.GetMesh("oriel"); + } + + void Place() { + + } +} + + +/* + COMMENTS + + mono (kernel) + compositor + oriel (client) + app + + Frame and Render is not a useful distinction + cycle or loop or step instead of frame? + draw instead of render? + + we keep combining the two, and it's not a good idea + as input can be polled at a higher frequency than rendering can be output? + + Hertz & Frame + + does a process ever not have a GUI? *can be hidden &| locked + we are trying to skip the tty! + + would be nice to have a dedicated thread(s) + for essential GUI + +*/ \ No newline at end of file diff --git a/app/Glove.cs b/app/Glove.cs index e11bf46..25425dc 100644 --- a/app/Glove.cs +++ b/app/Glove.cs @@ -125,6 +125,14 @@ public class Glove { Vec3 thumb = hand.Get(FingerId.Thumb, JointId.Tip).position - con.pos; virtualGlove.position += Vec3.Lerp(index, thumb, 0.5f); + Vec3 delta = virtualGlove.position - con.pos; + HandJoint[] joints = hand.fingers; + for (int i = 0; i < joints.Length; i++) { + joints[i].position += delta - Vec3.Lerp(index, thumb, 0.5f); + } + Input.HandOverride(chirality ? Handed.Right : Handed.Left, joints); + + Render(con.pose, virtualGlove, wrist, stretch, twist, chirality); } @@ -168,3 +176,11 @@ public class Glove { // model.Draw(glove.ToMatrix(Vec3.One / 10)); } } + + +/* + COMMENTS + + con -> hand + +*/ \ No newline at end of file diff --git a/app/Greenyard/Mono.cs b/app/Greenyard/Mono.cs index 5f1a621..e24fdcc 100644 --- a/app/Greenyard/Mono.cs +++ b/app/Greenyard/Mono.cs @@ -2,145 +2,87 @@ using Oriels; namespace Greenyard; public class Mono { - // Model greenyardModel = Model.FromFile("greenyard.glb"); - // Mesh[] greenyard; - // Material greenyardMat = new Material(Shader.FromFile("/shaders/oriel.hlsl")); + public Oriel oriel = new Oriel( + new Vec3(0.0f, -0.5f, 0.5f), + Quat.FromAngles(0, 90, 0), + new Vec3(0.8f, 0.5f, 0.5f) + ) { color = new Color(78 / 256f, 142 / 256f, 191 / 256f) * 0.333f }; - Vec3 offset = new Vec3(2, 1, -2); - public float height = 1f; - Vec3 angle = new Vec3(0, 0, 0); + Model greenyardModel = Model.FromFile("greenyard.glb"); + Mesh[] greenyard; + Material greenyardMat = new Material(Shader.FromFile("/shaders/oriel.hlsl")); - Thing[] thing; - Model model = Model.FromFile("/backrooms/backrooms.glb"); + Matrix matrix = Matrix.Identity; + Vec3 offset = new Vec3(2, 1, -12); + public float height = 6f; + Vec3 angle = new Vec3(0, 180, 0); - 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.Transparency = Transparency.Add; + // greenyardMat.DepthTest = DepthTest.Always; + greenyardMat.SetTexture("diffuse", Tex.FromFile("greenyard.jpeg")); + } - 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")); + public void Frame() { + Oriels.Rig rig = Oriels.Mono.inst.rig; - 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" - ), - }; - } + // angle.x -= rig.rCon.device.stick.y * 90f * Time.Elapsedf; + // angle.x = PullRequest.Clamp(angle.x, -89, 89); + angle.y -= rig.rCon.device.stick.x * 90f * Time.Elapsedf; - public void Frame() { - Oriels.Rig rig = Oriels.Mono.inst.rig; - Oriels.Oriel oriel = Oriels.Mono.inst.oriel; - - // angle.x -= rig.rCon.device.stick.y * 90f * Time.Elapsedf; - // angle.x = PullRequest.Clamp(angle.x, -89, 89); - angle.y -= rig.rCon.device.stick.x * 90f * Time.Elapsedf; - - Vec3 input = new Vec3( - rig.lCon.device.stick.x, - 0, - rig.lCon.device.stick.y - ); - if (input.MagnitudeSq > 0.01f) { - 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; + Vec3 input = new Vec3( + rig.lCon.device.stick.x, + 0, + rig.lCon.device.stick.y + ); + if (input.MagnitudeSq > 0.01f) { + 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 - float scale = oriel.scale * oriel.multiplier; - if (oriel.scaleWithHeight) { - scale *= oriel.bounds.dimensions.y; - } + float scale = 0.1f; // oriel.scale * oriel.multiplier; + // scale w/height? + // scale *= oriel.bounds.dimensions.y; - 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 - ); + matrix = 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 + ); + } - // 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.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, - 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)); - } + public void 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.matrixInv); + for (int i = 0; i < greenyard.Length; i++) { + greenyard[i].Draw(greenyardMat, + Matrix.TRS( + offset, + Quat.Identity, + new Vec3(1f, 1f, 1f) + ) * matrix * oriel.matrix, + Color.White + ); + } + } } \ No newline at end of file diff --git a/app/PullRequest.cs b/app/PullRequest.cs index abb92da..0518a74 100644 --- a/app/PullRequest.cs +++ b/app/PullRequest.cs @@ -219,7 +219,6 @@ public static class PullRequest { // return Vec3.Lerp(a * (float)Math.Sin(theta - theta * t) / sinTheta, b * (float)Math.Sin(theta * t) / sinTheta, t); // } - [Serializable] public class Noise { const uint CAP = 4294967295; const uint BIT_NOISE1 = 0xB5297A4D; @@ -285,7 +284,6 @@ public static class PullRequest { return MathF.Max(min, MathF.Min(max, v)); } - [Serializable] public class PID { public float p, i; float integral = 0f; @@ -305,7 +303,6 @@ public static class PullRequest { } } - [Serializable] public class Lerper { public float t = 0; public float spring = 1; @@ -335,4 +332,77 @@ public static class PullRequest { t = vel = 0; } } + + public class OneEuroFilter { + public OneEuroFilter(double minCutoff, double beta) { + firstTime = true; + this.minCutoff = minCutoff; + this.beta = beta; + + xFilt = new LowpassFilter(); + dxFilt = new LowpassFilter(); + dcutoff = 1; + } + + protected bool firstTime; + protected double minCutoff; + protected double beta; + protected LowpassFilter xFilt; + protected LowpassFilter dxFilt; + protected double dcutoff; + + public double MinCutoff { + get { return minCutoff; } + set { minCutoff = value; } + } + + public double Beta { + get { return beta; } + set { beta = value; } + } + + public double Filter(double x, double rate) { + double dx = firstTime ? 0 : (x - xFilt.Last()) * rate; + if (firstTime) { + firstTime = false; + } + + var edx = dxFilt.Filter(dx, Alpha(rate, dcutoff)); + var cutoff = minCutoff + beta * Math.Abs(edx); + + return xFilt.Filter(x, Alpha(rate, cutoff)); + } + + protected double Alpha(double rate, double cutoff) { + var tau = 1.0 / (2 * Math.PI * cutoff); + var te = 1.0 / rate; + return 1.0 / (1.0 + tau / te); + } + } + + public class LowpassFilter { + public LowpassFilter() { + firstTime = true; + } + + protected bool firstTime; + protected double hatXPrev; + + public double Last() { + return hatXPrev; + } + + public double Filter(double x, double alpha) { + double hatX = 0; + if (firstTime) { + firstTime = false; + hatX = x; + } else + hatX = alpha * x + (1 - alpha) * hatXPrev; + + hatXPrev = hatX; + + return hatX; + } + } } diff --git a/app/Rig/Rig.cs b/app/Rig/Rig.cs index c9cf099..ba360ef 100644 --- a/app/Rig/Rig.cs +++ b/app/Rig/Rig.cs @@ -82,7 +82,7 @@ public class Rig { public class Con { public Controller device; public Vec3 pos; - public Quat ori; + public Quat ori = Quat.Identity; public Pose pose; public Vec3 backhandDir; public Btn gripBtn; @@ -91,7 +91,7 @@ public class Con { public void Step(bool chirality) { device = Input.Controller(chirality ? Handed.Right : Handed.Left); pose.position = pos = device.pose.position; - pose.orientation = ori = device.aim.orientation; + pose.orientation = ori = Quat.Identity; // device.pose.orientation; backhandDir = ori * (chirality ? Vec3.Right : -Vec3.Right); gripBtn.Step(device.grip > 0.5f); triggerBtn.Step(device.trigger > 0.5f); diff --git a/app/Scene.cs b/app/Space.cs similarity index 88% rename from app/Scene.cs rename to app/Space.cs index 959a452..31ba70a 100644 --- a/app/Scene.cs +++ b/app/Space.cs @@ -8,7 +8,7 @@ struct BufferData { public float time; } -public class Scene { +public class Space { MaterialBuffer buffer; BufferData data = new BufferData(); @@ -18,7 +18,7 @@ public class Scene { Solid floor; - public Scene() { + public Space() { buffer = new MaterialBuffer(3); // index @@ -41,23 +41,19 @@ public class Scene { public Vec3 floorScale; - public void Step() { - Oriel oriel = Mono.inst.oriel; - data.matrix = (Matrix)System.Numerics.Matrix4x4.Transpose(oriel.matrixInv); - data.dimensions = oriel.bounds.dimensions; - - - - - - // data.dimensions = Vec3.Zero; - - - - + public void Frame() { + // Oriel oriel = Mono.inst.oriel; + // data.matrix = (Matrix)System.Numerics.Matrix4x4.Transpose(oriel.matrixInv); + // data.dimensions = oriel.bounds.dimensions; + data.matrix = (Matrix)System.Numerics.Matrix4x4.Transpose(Matrix.T(Vec3.Up)); + data.dimensions = new Vec3(0.1f, 0.1f, 0.1f); buffer.Set(data); + + + + // PullRequest.BlockOut(floor.GetPose().ToMatrix(floorScale), Color.White * 0.333f, matFloor); // foreach (ModelNode node in shed.Visuals) { diff --git a/app/Space/Mono.cs b/app/Space/Mono.cs index 93e76ff..e8605fb 100644 --- a/app/Space/Mono.cs +++ b/app/Space/Mono.cs @@ -11,6 +11,11 @@ using Oriels; namespace Space; public class Mono { + public Oriel oriel = new Oriel( + new Vec3(1.0f, -0.5f, 0.5f), + Quat.Identity, + new Vec3(0.8f, 0.5f, 0.5f) + ); Node[] nodes = new Node[18]; Vec3 playerPos; List enemies = new List(); @@ -53,7 +58,6 @@ public class Mono { public void Frame() { Oriels.Rig rig = Oriels.Mono.inst.rig; - Oriels.Oriel oriel = Oriels.Mono.inst.oriel; Matrix simMatrix = Matrix.TRS( -playerPos * 0.5f * oriel.bounds.dimensions.y, //-oriel.bounds.dimensions.y / 2.01f, -playerWorldPos.z), diff --git a/app/_Init.cs b/app/_Init.cs index 9214642..3662d3b 100644 --- a/app/_Init.cs +++ b/app/_Init.cs @@ -15,6 +15,8 @@ if (!SK.Initialize(settings)) Input.HandSolid(Handed.Max, false); Input.HandVisible(Handed.Max, true); +Renderer.EnableSky = false; +Renderer.ClearColor = new Color(0f, 0f, 0f); Oriels.Mono mono = Oriels.Mono.inst; mono.Init(); diff --git a/app/dofs/oriel/Oriel.cs b/app/dofs/oriel/Oriel.cs index 1a4c7e1..3357dc7 100644 --- a/app/dofs/oriel/Oriel.cs +++ b/app/dofs/oriel/Oriel.cs @@ -1,9 +1,6 @@ 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")); @@ -13,31 +10,26 @@ public class Oriel { public Matrix matrix, matrixInv; public Bounds bounds; public Quat ori = Quat.Identity; + public Color color = new Color(0.5f, 0.5f, 0.5f); - // inner matrix - public bool scaleWithHeight = false; - public float scale = 0.5f; - public float multiplier = 1f; - - public Oriel() { - // meshCube = model.GetMesh("oriel"); - meshCube = Mesh.Cube; - meshSphere = Mesh.Sphere; + public Oriel(Vec3 pos, Quat ori, Vec3 dimensions) { matClear.Transparency = Transparency.Add; matFrame.SetMat(102, Cull.Back, true); - matFrame.Transparency = Transparency.Blend; + // matFrame.Transparency = Transparency.Add; matFrame.SetTexture("dither", Tex.FromFile("dither.png")); - matPanes.SetMat(100, Cull.Front, false); - matOriel.SetMat(101, Cull.None, true); + + matPanes.SetMat(100, Cull.Front, false); // true? + // matPanes.Transparency = Transparency.Add; + // matPanes.DepthTest = DepthTest.Always; - 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); + matOriel.SetMat(101, Cull.None, true); + // matOriel.Transparency = Transparency.Add; + // matOriel.DepthTest = DepthTest.Always; + + bounds = new Bounds(pos, dimensions); + this.ori = ori; + matrix = Matrix.TR(bounds.center, this.ori); matrixInv = matrix.Inverse; @@ -95,22 +87,26 @@ public class Oriel { Glove rGlove = Mono.inst.rGlove; // Vec3 lGlovePos = rig.lGlove.virtualGlove.position; + // glove - // bool frameDown = rig.rCon.triggerBtn.frameDown; - // bool held = rig.rCon.triggerBtn.held; - // bool frameUp = rig.rCon.triggerBtn.frameUp; - // cursor = rGlove.virtualGlove.position; - // cursorOri = rGlove.virtualGlove.orientation; + Hand rHand = Input.Hand(Handed.Right); + // why do I have to do this? + // rHand.IsJustPinched || + bool frameDown = Input.Key(Key.MouseLeft).IsJustActive() || rig.rCon.triggerBtn.frameDown; + bool held = Input.Key(Key.MouseLeft).IsActive() || rig.rCon.triggerBtn.held; + bool frameUp = Input.Key(Key.MouseLeft).IsJustInactive() || rig.rCon.triggerBtn.frameUp; + cursor = rGlove.virtualGlove.position; + cursorOri = rGlove.virtualGlove.orientation; // hand - Trackballer tb = (Trackballer)Mono.inst.dofs[3]; - bool frameDown = tb.btnOut.frameDown; - bool held = tb.btnOut.held; - bool frameUp = tb.btnOut.frameUp; + // Trackballer tb = (Trackballer)Mono.inst.dofs[3]; + // bool frameDown = tb.btnOut.frameDown; + // bool held = tb.btnOut.held; + // bool frameUp = tb.btnOut.frameUp; - WaveCursor wc = (WaveCursor)Mono.inst.dofs[1]; - cursor = wc.cursor.position; - cursorOri = Quat.Identity; // wc.cursor.orientation; + // WaveCursor wc = (WaveCursor)Mono.inst.dofs[1]; + // cursor = wc.cursor.position; + // cursorOri = Quat.Identity; // wc.cursor.orientation; // debug @@ -159,7 +155,7 @@ public class Oriel { qOffset = (ori.Inverse * cursorOri).Normalized; mOffset = matrix; - interacting = frameDown; + interacting = frameDown && minDist < cursorRadius; scaling = false; cornerDetect = Vec3.Zero; } @@ -232,17 +228,16 @@ public class Oriel { // matFrame.DepthTest = DepthTest.Always; // matFrame.SetVector("_cursor", cursor); // matFrame.SetFloat("_time", Time.Totalf); - // meshCube.Draw(matFrame, + // Mesh.Cube.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(matrixInv); - meshCube.Draw(matPanes, + Mesh.Cube.Draw(matPanes, Matrix.TRS(bounds.center, ori, bounds.dimensions), - new Color(0f, 0f, 0f) - // new Color(78 / 256f, 142 / 256f, 191 / 256f) + color ); matOriel.SetVector("_center", bounds.center); @@ -261,7 +256,7 @@ public class Oriel { ) / cursorRadius; if (detectCount == 1 || detectCount == 2) { Vec3 edge = Vec3.One - detect.Abs(); - meshCube.Draw(matClear, + Mesh.Cube.Draw(matClear, Matrix.TS( LocalAnchor, (Vec3.One * thk) + (edge * bounds.dimensions / 3f * prx) @@ -269,19 +264,19 @@ public class Oriel { ); } if (detectCount == 3) { - meshCube.Draw(matClear, + Mesh.Cube.Draw(matClear, Matrix.TS( Vec3.Lerp(XAnchor, LocalAnchor, 0.5f), new Vec3(MathF.Abs(XAnchor.x - LocalAnchor.x), thk, thk) ) * matrix, col ); - meshCube.Draw(matClear, + Mesh.Cube.Draw(matClear, Matrix.TS( Vec3.Lerp(YAnchor, LocalAnchor, 0.5f), new Vec3(thk, MathF.Abs(YAnchor.y - LocalAnchor.y), thk) ) * matrix, col ); - meshCube.Draw(matClear, + Mesh.Cube.Draw(matClear, Matrix.TS( Vec3.Lerp(ZAnchor, LocalAnchor, 0.5f), new Vec3(thk, thk, MathF.Abs(ZAnchor.z - LocalAnchor.z)) @@ -290,31 +285,31 @@ public class Oriel { // draw cube(s) on intersecting corner ends if (cornerDetect.x > 0) { - meshCube.Draw(matClear, + Mesh.Cube.Draw(matClear, Matrix.TS(XAnchor, Vec3.One * thk * 2) * matrix, new Color(1, 0, 0) ); } if (cornerDetect.y > 0) { - meshCube.Draw(matClear, + Mesh.Cube.Draw(matClear, Matrix.TS(YAnchor, Vec3.One * thk * 2) * matrix, new Color(0, 1, 0) ); } if (cornerDetect.z > 0) { - meshCube.Draw(matClear, + Mesh.Cube.Draw(matClear, Matrix.TS(ZAnchor, Vec3.One * thk * 2) * matrix, new Color(0, 0, 1) ); } } - meshCube.Draw(Mono.inst.matHolo, - Matrix.TRS(cursor, cursorOri, new Vec3(0.02f, 0.005f, 0.02f)), + Mesh.Sphere.Draw(Mono.inst.matHolo, + Matrix.TRS(cursor, cursorOri, new Vec3(0.02f, 0.02f, 0.02f)), cursorColor ); - meshSphere.Draw(Mono.inst.matHolo, + Mesh.Sphere.Draw(Mono.inst.matHolo, Matrix.TS(cursor, new Vec3(1f, 1f, 1f) * cursorRadius * 2), new Color(0.1f, 0.1f, 0.1f) ); @@ -350,4 +345,5 @@ public class Oriel { compositor multi-oriel requires a compositor approach even if you just start with input management + */ \ No newline at end of file