From fd15fe1e336adaf4155a35616f8d8eec46a0b429 Mon Sep 17 00:00:00 2001 From: spatialfree Date: Wed, 3 Aug 2022 22:06:43 -0400 Subject: [PATCH] fixed singleton initialization --- app/Mono.cs | 7 +++++-- app/PullRequest.cs | 16 +++++++++++----- app/Space/Mono.cs | 35 +++++++++++++++++++++++++++++++---- app/SpatialCursor.cs | 9 ++++----- app/_Init.cs | 7 ++++--- 5 files changed, 55 insertions(+), 19 deletions(-) diff --git a/app/Mono.cs b/app/Mono.cs index b9a3e80..3e1b6ba 100644 --- a/app/Mono.cs +++ b/app/Mono.cs @@ -1,8 +1,8 @@ namespace Oriels; public class Mono { - private static readonly Lazy lazy = new Lazy(() => new Mono()); - public static Mono inst { get { return lazy.Value; } } + private static readonly Lazy lazy = new Lazy(() => new Oriels.Mono()); + public static Oriels.Mono inst { get { return lazy.Value; } } public PullRequest.Noise noise = new PullRequest.Noise(939949595); @@ -34,6 +34,9 @@ public class Mono { public Mono() { Renderer.SetClip(0.02f, 1000f); + } + + public void Init() { spaceMono.Init(); } diff --git a/app/PullRequest.cs b/app/PullRequest.cs index 104d82a..f522814 100644 --- a/app/PullRequest.cs +++ b/app/PullRequest.cs @@ -111,7 +111,7 @@ public static class PullRequest { } int position; - public float value { + public float uvalue { get { float v = RNG(position, seed) / (float)CAP; position++; @@ -119,8 +119,14 @@ public static class PullRequest { } } - public float D1(int position) { - return RNG(position, seed) / (float)CAP; + public float value { // not ideal *loss of precision* + get { + return uvalue * 2 - 1; + } + } + + public float D1(int pos) { + return RNG(pos, seed) / (float)CAP; } public float D2(int x, int y) { @@ -136,8 +142,8 @@ public static class PullRequest { return RNG(x + (PRIME1 * y) + (PRIME2 * z), seed) / (float)CAP; } - public uint RNG(int position, uint seed) { - uint mangled = (uint)position; + public uint RNG(int pos, uint seed) { + uint mangled = (uint)pos; mangled *= BIT_NOISE1; mangled += seed; mangled ^= mangled >> 8; diff --git a/app/Space/Mono.cs b/app/Space/Mono.cs index 8050b04..df0799c 100644 --- a/app/Space/Mono.cs +++ b/app/Space/Mono.cs @@ -10,7 +10,7 @@ using System.Collections.Generic; namespace Space; public class Mono { - + Node[] nodes = new Node[18]; Vec3 playerPos; List enemies = new List(); float spawnTime; @@ -26,12 +26,25 @@ public class Mono { } public void Init() { + Oriels.PullRequest.Noise noise = Oriels.Mono.inst.noise; + + // place nodes around a 10x4x10 cube + for (int i = 0; i < nodes.Length; i++) { + nodes[i] = new Node( + new Vec3( + noise.value * 5f, + noise.value * 2f, + noise.value * 5f + ) + ); + } + meshCube = Mesh.Cube; } public void Frame() { - Rig rig = Oriels.Mono.inst.rig; - Oriel oriel = Oriels.Mono.inst.oriel; + Oriels.Rig rig = Oriels.Mono.inst.rig; + Oriels.Oriel oriel = Oriels.Mono.inst.oriel; Matrix simMatrix = Matrix.TRS( new Vec3(0, 0, 0), //-oriel.bounds.dimensions.y / 2.01f, -playerWorldPos.z), @@ -65,8 +78,14 @@ 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, + Color.White + ); + } + meshCube.Draw(oriel.matOriel, Matrix.TRS(cursor, Quat.Identity, Vec3.One * 0.02f), new Color(1f, 1f, 1f) @@ -153,3 +172,11 @@ public class Mono { float moveP = 8f; float moveI = 0.2f; } + +public class Node { + public Vec3 pos; + + public Node(Vec3 pos) { + this.pos = pos; + } +} \ No newline at end of file diff --git a/app/SpatialCursor.cs b/app/SpatialCursor.cs index af4de3b..92571e2 100644 --- a/app/SpatialCursor.cs +++ b/app/SpatialCursor.cs @@ -1,5 +1,4 @@ -using System; -using StereoKit; +namespace Oriels; public abstract class SpatialCursor { public Vec3 p0, p1, p2, p3; @@ -26,7 +25,7 @@ public class StretchCursor : SpatialCursor { model.Draw(Matrix.TS(p0, 0.06f)); } - public override void Calibrate() {} + public override void Calibrate() { } } public class ReachCursor : SpatialCursor { @@ -80,7 +79,7 @@ public class TwistCursor : SpatialCursor { Quat from = Quat.LookAt(Vec3.Zero, quat * Vec3.Forward, twistFrom); float twist = (float)(Math.Acos(Vec3.Dot(from * Vec3.Up, quat * Vec3.Up)) / Math.PI); outty = Vec3.Dot(from * Vec3.Up, quat * Vec3.Right * (chirality ? 1 : -1)) > 0; - + p0 = pos + quat * Vec3.Forward * twist * str; // Render @@ -174,7 +173,7 @@ public class CubicFlow : SpatialCursor { // if toggle } - public override void Calibrate() {} + public override void Calibrate() { } } // a more symmetrical one would be cool diff --git a/app/_Init.cs b/app/_Init.cs index 5f9c173..f3e36b2 100644 --- a/app/_Init.cs +++ b/app/_Init.cs @@ -1,6 +1,6 @@ global using System; global using StereoKit; -global using Oriels; +// global using Oriels; SKSettings settings = new SKSettings { appName = "oriels", @@ -14,8 +14,9 @@ if (!SK.Initialize(settings)) Input.HandSolid(Handed.Max, false); Input.HandVisible(Handed.Max, true); -Mono mono = Mono.inst; +Oriels.Mono mono = Oriels.Mono.inst; +mono.Init(); while (SK.Step(() => { mono.Step(); -})) ; +})); SK.Shutdown(); \ No newline at end of file