diff --git a/add/dither.png b/add/dither.png new file mode 100644 index 0000000..41aa44d Binary files /dev/null and b/add/dither.png differ diff --git a/add/oriel.glb b/add/oriel.glb index 801ce6d..3c2e0e1 100644 Binary files a/add/oriel.glb and b/add/oriel.glb differ diff --git a/add/shaders/frame.hlsl b/add/shaders/frame.hlsl new file mode 100644 index 0000000..4cc5a3f --- /dev/null +++ b/add/shaders/frame.hlsl @@ -0,0 +1,107 @@ +#include "stereokit.hlsli" + +// --name = dofdev/frame +float3 _rGlovePos; +float _time; + +Texture2D dither : register(t0); +SamplerState dither_s : register(s0); + +struct vsIn { + float4 pos : SV_POSITION; + float3 norm : NORMAL; + float4 col : COLOR; +}; +struct psIn { + float4 pos : SV_POSITION; + float4 world : POSITION0; + float3 norm : NORMAL0; + float4 col : COLOR; + float3 campos : POSITION2; + float3 camdir : NORMAL1; + uint view_id : SV_RenderTargetArrayIndex; + uint id : SV_VertexID; +}; + +psIn vs(vsIn input, uint id : SV_InstanceID) { + psIn o; + o.view_id = id % sk_view_count; + id = id / sk_view_count; + + o.world = mul(input.pos, sk_inst[id].world); + o.pos = mul(o.world, sk_viewproj[o.view_id]); + o.norm = normalize(mul(input.norm, (float3x3)sk_inst[id].world)); + // o.col = sk_inst[id].color; + o.col = input.col; + + o.campos = sk_camera_pos[o.view_id].xyz; + o.camdir = sk_camera_dir[o.view_id].xyz; + + o.id = id; + return o; +} + +float3 hsv2rgb(float3 hsv) { + float4 K = float4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); + float3 p = abs(frac(hsv.xxx + K.xyz) * 6.0 - K.www); + + return hsv.z * lerp(K.xxx, clamp(p - K.xxx, 0.0, 1.0), hsv.y); +} + +float remap_tri(float v) +{ + float orig = v * 2.0 - 1.0; + v = max(-1.0f, orig / sqrt(abs(orig))); + return v - sign(orig) + 0.5f; +} + +float4 ps(psIn input) : SV_TARGET { + + // float4 c = input.col; + // float3 rLocal = (input.world.xyz - _rGlovePos) / 2; + // c.r = 1 - min(abs(rLocal.x), 1.0); + // c.g = 1 - min(abs(rLocal.y), 1.0); + // c.b = 1 - min(abs(rLocal.z), 1.0); + + // float m = min(c.r, min(c.g, c.b)); + // c.rgb *= m; + + float3 flatnorm = (input.col.rgb - float3(0.5, 0.5, 0.5)) * 2; + + flatnorm = normalize(mul(flatnorm, (float3x3)sk_inst[input.id].world)); + + // float3 cross = input.camDir * input.norm; + float dist = length(input.world.xyz - input.campos); + float3 raydir = normalize(input.world.xyz - input.campos); + + float facing = 1 - dot(raydir, input.camdir); + // facing = (1 + facing) / 2; + // facing = facing; + + + + // float dot = (dot(input.norm, raydir) + dot(flatnorm, raydir)) / 2; + + + + + float h = (1 + dot(input.norm, raydir)) / 2; + + float d = dither.Sample(dither_s, input.pos.xy / 64.0).r; // time scroll through dither textures + + // d = remap_tri(d); + + return float4(hsv2rgb(float3(h, 1, 1)), facing * facing * d * 24); + + // float4 col = float4(1, 1, 1, 0); + // float n = saturate(dot(raydir, input.norm)); + // float shade = n / 0.333; + // if (n < 0.333) + // { + // col.g *= 0.92 - 0.2; + // // col.r *= 0.96 - 0.2; + // col.r *= 1 - ((1 - shade) / 3); + // } + // col.a = shade; + // return col; +} diff --git a/add/shaders/wireframe.hlsl b/add/shaders/wireframe.hlsl deleted file mode 100644 index 252c387..0000000 --- a/add/shaders/wireframe.hlsl +++ /dev/null @@ -1,57 +0,0 @@ -#include "stereokit.hlsli" - -// --name = dofdev/wireframe -float3 _rGlovePos; - -struct vsIn { - float4 pos : SV_POSITION; - float3 norm : NORMAL; -}; -struct psIn { - float4 pos : SV_POSITION; - float4 col : COLOR; - float4 camDir : POSITION0; - float4 world : WORLD; - uint view_id : SV_RenderTargetArrayIndex; -}; - -psIn vs(vsIn input, uint id : SV_InstanceID) { - psIn o; - o.view_id = id % sk_view_count; - id = id / sk_view_count; - - float3 norm = normalize(input.norm); - - // input.pos.xyz += norm * 0.01; - // wirefame - // o.pos = mul(sk_view[o.view_id], input.pos); - - // float4 viewPosition = mul(input.pos, sk_view[o.view_id]); - // o.pos = mul(viewPosition, sk_proj[o.view_id]); - o.camDir = sk_camera_dir[0]; - - - o.world = mul(input.pos, sk_inst[id].world); - o.pos = mul(o.world, sk_viewproj[o.view_id]); - o.col = sk_inst[id].color; - - return o; -} - -float4 ps(psIn input) : SV_TARGET { - float4 c = input.col; - // float3 rLocal = (input.world.xyz - _rGlovePos) / 2; - // c.r = 1 - min(abs(rLocal.x), 1.0); - // c.g = 1 - min(abs(rLocal.y), 1.0); - // c.b = 1 - min(abs(rLocal.z), 1.0); - - // float m = min(c.r, min(c.g, c.b)); - // c.rgb *= m; - - c.r = input.camDir.x; - c.g = input.camDir.y; - c.b = input.camDir.z; - c.a = 0.3; - - return c; -} diff --git a/app/Blocks.cs b/app/Blocks.cs index 35aae9e..0c563b4 100644 --- a/app/Blocks.cs +++ b/app/Blocks.cs @@ -1,5 +1,4 @@ -using System; -using StereoKit; +namespace Oriels; public class Block { public bool active; diff --git a/app/ColorCube.cs b/app/ColorCube.cs index 29816b2..b393963 100644 --- a/app/ColorCube.cs +++ b/app/ColorCube.cs @@ -1,5 +1,4 @@ -using System; -using StereoKit; +namespace Oriels; public class ColorCube { static Mesh cube = Default.MeshCube; @@ -13,9 +12,9 @@ public class ColorCube { public Color color = Color.White * 0.5f; - public ColorCube() { + public ColorCube() { // SetColor(Vec3.Zero); - } + } public void Step() { mat.SetVector("_pos", center); @@ -25,7 +24,7 @@ public class ColorCube { for (int i = 0; i < 4; i++) { Quat q = Quat.FromAngles(i * 90, 0, 0); cube.Draw(mat, Matrix.TS(center + q * new Vec3(0, offset, offset), new Vec3(size, thicc, thicc))); - for (int j = -1; j <= 1; j+=2) { + for (int j = -1; j <= 1; j += 2) { Vec3 scale = q * new Vec3(thicc, size, thicc); scale = new Vec3(Math.Abs(scale.x), Math.Abs(scale.y), Math.Abs(scale.z)); cube.Draw(mat, Matrix.TS(center + q * new Vec3(offset * j, 0, offset), scale)); diff --git a/app/Cubics.cs b/app/Cubics.cs index 8e06f90..cd9043e 100644 --- a/app/Cubics.cs +++ b/app/Cubics.cs @@ -1,5 +1,4 @@ -using System; -using StereoKit; +namespace Oriels; public class Cubic { public bool active; @@ -13,7 +12,7 @@ public class Cubic { } public class CubicCon { - public CubicCon() {} + public CubicCon() { } public void Step() { Cubic[] cubics = Mono.inst.cubics; @@ -22,7 +21,7 @@ public class CubicCon { Con lCon = rig.lCon; Vec3 rPos = Mono.inst.rGlove.virtualGlove.position; Vec3 lPos = Mono.inst.lGlove.virtualGlove.position; - + bool place = rCon.device.IsStickJustClicked || lCon.device.IsStickJustClicked; if (place) { for (int i = 0; i < cubics.Length; i++) { @@ -37,7 +36,7 @@ public class CubicCon { } } Cubic cubic = cubics[PullRequest.RandomRange(0, cubics.Length)]; - cubic.p0 = rPos; + cubic.p0 = rPos; cubic.p1 = rig.rCon.pos; cubic.p2 = rig.lCon.pos; cubic.p3 = lPos; diff --git a/app/Glove.cs b/app/Glove.cs index ef08461..c26a778 100644 --- a/app/Glove.cs +++ b/app/Glove.cs @@ -1,5 +1,4 @@ -using System; -using StereoKit; +namespace Oriels; public enum Pull { Stretch, Backhanded @@ -37,7 +36,7 @@ public class Glove { Con con = rig.Con(chirality), otherCon = rig.Con(!chirality); bool pull = otherCon.gripBtn.frameDown; - if (firstFace == 0) { + if (firstFace == 0) { if (con.device.IsX1JustPressed) { firstFace = 1; } if (con.device.IsX2JustPressed) { firstFace = 2; } } @@ -93,10 +92,10 @@ public class Glove { pulling = null; } - if (!twisting) { + if (!twisting) { stretch = Math.Max(Vec3.Distance(pullPoint, con.pos) - stretchDeadzone, 0); twist = 0; - + twistOffset = Quat.Identity; } @@ -116,7 +115,7 @@ public class Glove { } virtualGlove.orientation = con.ori; - } + } oldOri = con.ori; virtualGlove.position = con.pos + direction * (stretch + Math.Abs(twist)) * 3; diff --git a/app/Mono.cs b/app/Mono.cs index 52d38e7..b9a3e80 100644 --- a/app/Mono.cs +++ b/app/Mono.cs @@ -1,24 +1,4 @@ -using System; -using StereoKit; - -SKSettings settings = new SKSettings { - appName = "oriels", - assetsFolder = "add", - depthMode = DepthMode.D32, - disableUnfocusedSleep = true, -}; -if (!SK.Initialize(settings)) - Environment.Exit(1); - -Input.HandSolid(Handed.Max, false); -Input.HandVisible(Handed.Max, true); - -Mono mono = Mono.inst; -while (SK.Step(() => { - mono.Step(); -})) ; -SK.Shutdown(); - +namespace Oriels; public class Mono { private static readonly Lazy lazy = new Lazy(() => new Mono()); @@ -39,13 +19,13 @@ public class Mono { public BlockCon rBlock = new BlockCon(true), lBlock = new BlockCon(false); public BlockCon BlockCon(bool chirality) { return chirality ? rBlock : lBlock; } - public Block[] blocks = new Block[] { - new Block(), new Block(), new Block(), new Block(), new Block(), new Block() + public Block[] blocks = new Block[] { + new Block(), new Block(), new Block(), new Block(), new Block(), new Block() }; public CubicCon cubicCon = new CubicCon(); - public Cubic[] cubics = new Cubic[] { - new Cubic(), new Cubic(), new Cubic(), new Cubic(), new Cubic(), new Cubic() + public Cubic[] cubics = new Cubic[] { + new Cubic(), new Cubic(), new Cubic(), new Cubic(), new Cubic(), new Cubic() }; // ------------------------------------------------- @@ -53,9 +33,20 @@ public class Mono { public Mono() { Renderer.SetClip(0.02f, 1000f); + + spaceMono.Init(); } - Vec3 boardDir = Vec3.Forward; + + // ------------------------------------------------- + + Space.Mono spaceMono = new Space.Mono(); + + + PullRequest.PID pid = new PullRequest.PID(8, 0.8f); + + // ------------------------------------------------- + public void Step() { rig.Step(); @@ -75,6 +66,7 @@ public class Mono { // ------------------------------------------------- + spaceMono.Frame(); // ------------------------------------------------- @@ -84,12 +76,12 @@ public class Mono { ShowWindowButton(); } - Pose windowPoseButton = new Pose(0, 0, 0, Quat.Identity); + Pose windowPoseButton = new Pose(0, 0, -1, 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("Draw Oriel Axis")) { oriel.drawAxis = !oriel.drawAxis; } UI.WindowEnd(); } diff --git a/app/MonoNet.cs b/app/MonoNet.cs index f1f54e0..c14dd8c 100644 --- a/app/MonoNet.cs +++ b/app/MonoNet.cs @@ -1,10 +1,9 @@ -using System; using System.Net; using System.Net.Http; using System.Net.Sockets; using System.Threading; -using System.Threading.Tasks; -using StereoKit; + +namespace Oriels; public class MonoNet { public bool send; @@ -27,7 +26,7 @@ public class MonoNet { socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); string ip = "192.168.1.70"; ip = "139.177.201.219"; - + EndPoint serverEndPoint = new IPEndPoint(IPAddress.Parse(ip), 1234); socket.Connect(serverEndPoint); @@ -234,8 +233,8 @@ public class Peer { rCursor = mono.rGlove.virtualGlove; lCursor = mono.lGlove.virtualGlove; - if (blocks == null || blocks.Length != mono.blocks.Length) { - blocks = new NetBlock[mono.blocks.Length]; + if (blocks == null || blocks.Length != mono.blocks.Length) { + blocks = new NetBlock[mono.blocks.Length]; } for (int i = 0; i < blocks.Length; i++) { blocks[i].active = mono.blocks[i].active; diff --git a/app/OrbitalView.cs b/app/OrbitalView.cs index 37ecc69..57f1263 100644 --- a/app/OrbitalView.cs +++ b/app/OrbitalView.cs @@ -1,24 +1,23 @@ -using System; -using StereoKit; +namespace Oriels; class OrbitalView { - public static float strength = 0.5f; - public static float distance = 0.25f; - public static Matrix transform { - get { - Vec3 pos = Input.Head.position + (Input.Head.Forward * distance); + public static float strength = 0.5f; + public static float distance = 0.25f; + public static Matrix transform { + get { + Vec3 pos = Input.Head.position + (Input.Head.Forward * distance); - Vec2 headDirection2D = Input.Head.Forward.XZ.Normalized; - float angle = -Vec2.AngleBetween(prevDir, headDirection2D); - Quat rot = prevRot * Quat.Slerp(Quat.Identity, Quat.FromAngles(Vec3.Up * angle), strength); + Vec2 headDirection2D = Input.Head.Forward.XZ.Normalized; + float angle = -Vec2.AngleBetween(prevDir, headDirection2D); + Quat rot = prevRot * Quat.Slerp(Quat.Identity, Quat.FromAngles(Vec3.Up * angle), strength); - prevDir = headDirection2D; - prevRot = rot; + prevDir = headDirection2D; + prevRot = rot; - return Matrix.TR(pos, rot); - } - } + return Matrix.TR(pos, rot); + } + } - private static Vec2 prevDir = Vec3.Forward.XZ; - private static Quat prevRot = Quat.Identity; + private static Vec2 prevDir = Vec3.Forward.XZ; + private static Quat prevRot = Quat.Identity; } \ No newline at end of file diff --git a/app/Oriel.cs b/app/Oriel.cs index b4debc9..3ad8c1a 100644 --- a/app/Oriel.cs +++ b/app/Oriel.cs @@ -1,20 +1,16 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using StereoKit; +namespace Oriels; public class Oriel { - static Material matFrame = new Material(Shader.FromFile("shaders/wireframe.hlsl")); - static Material matPanes = new Material(Shader.FromFile("shaders/panes.hlsl")); - static Material matOriel = new Material(Shader.FromFile("shaders/oriel.hlsl")); - static Model model = Model.FromFile("colorball.glb"); + 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 Bounds bounds; public Quat ori; public Matrix matrix; public float crown = 0.0666f; - public bool drawAxis = false; bool adjusting = false; Quat qOffset = Quat.Identity; @@ -32,15 +28,13 @@ public class Oriel { ori = Quat.Identity; matrix = Matrix.TR(bounds.center, ori).Inverse; - matFrame.SetMat(102, Cull.None, true); - matFrame.Transparency = Transparency.Add; + matFrame.SetMat(102, Cull.Back, true); + matFrame.Transparency = Transparency.Blend; + matFrame.SetTexture("dither", Tex.FromFile("dither.png")); matPanes.SetMat(100, Cull.Front, false); matOriel.SetMat(101, Cull.None, true); - // meshFrame = model.GetMesh("Wireframe"); - meshCube = Mesh.Cube; - - Gen(); + meshCube = model.GetMesh("oriel"); } Vec3 detect = Vec3.Zero; @@ -139,10 +133,11 @@ public class Oriel { // matFrame.Wireframe = true; matFrame.DepthTest = DepthTest.Always; matFrame.SetVector("_rGlovePos", rGlovePos); - // meshCube.Draw(matFrame, - // Matrix.TRS(bounds.center, ori, bounds.dimensions), - // new Color(0.1f, 0.1f, 0.1f) - // ); + 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 @@ -160,141 +155,5 @@ public class Oriel { matOriel.SetVector("_dimensions", bounds.dimensions); matOriel.SetVector("_light", ori * new Vec3(0.6f, -0.9f, 0.3f)); matOriel["_matrix"] = (Matrix)System.Numerics.Matrix4x4.Transpose(matrix); - - - - // placeholder "app" - Vec3 playerWorldPos = playerPos * 0.5f * bounds.dimensions.y; - Matrix orielSimMatrix = Matrix.TRS( - new Vec3(0, -bounds.dimensions.y / 2.01f, -playerWorldPos.z), - Quat.Identity, - Vec3.One * 0.5f * bounds.dimensions.y - ); - - - if (drawAxis) { - meshAxis.Draw(matOriel, - Matrix.TRS(Vec3.Zero, Quat.Identity, Vec3.One * 1f) * orielSimMatrix * matrix.Inverse, - Color.White - ); - } - - - - - Mesh.Quad.Draw(matOriel, - Matrix.TRS(Vec3.Zero, Quat.FromAngles(90, 0, 0), Vec3.One * 100f) * orielSimMatrix * matrix.Inverse, - new Color(1.0f, 1.0f, 1.0f) * 0.3f - ); - - meshCube.Draw(matOriel, - rGlove.virtualGlove.ToMatrix(new Vec3(0.025f, 0.1f, 0.1f) / 3 * 1.05f), - new Color(0.3f, 0.3f, 0.6f) - ); - - - - - float fwd = Input.Key(Key.W).IsActive() ? 1 : 0; - playerPos += new Vec3(-rig.lCon.device.stick.x, 0, -rig.lCon.device.stick.y + fwd) * Time.Elapsedf; - meshCube.Draw(matOriel, - Matrix.TRS(playerPos, Quat.Identity, new Vec3(0.4f, 1f, 0.2f)) * orielSimMatrix * matrix.Inverse, - new Color(1.0f, 0.0f, 0.05f) - ); - - // destroy enemies that are too close to the playerPos - for (int i = 0; i < enemies.Count; i++) { - if (Vec3.Distance(enemies[i], playerPos) < 0.5f) { - // enemies.RemoveAt(i); - // i--; - enemies[i] = playerPos + Quat.FromAngles(0, Mono.inst.noise.value * 360f, 0) * Vec3.Forward * 8; - } - } - - // FULLSTICK - // Vec3 Fullstick() { - // Controller con = rig.lCon.device; - // Quat rot = Quat.FromAngles(con.stick.y * -90, 0, con.stick.x * 90); - // Vec3 dir = Vec3.Up * (con.IsStickClicked ? -1 : 1); - // return con.aim.orientation * rot * dir; - // } - // Vec3 fullstick = Fullstick(); - // sword.Move(playerPos + simOffset + fullstick, Quat.LookAt(Vec3.Zero, fullstick, Vec3.Up)); - // meshCube.Draw(matOriel, - // Matrix.TRS(sword.GetPose().position + (Vec3.Up * 0.7f) + (sword.GetPose().orientation * Vec3.Forward * -0.5f) - simOffset, sword.GetPose().orientation, new Vec3(0.1f, 0.03f, 1f)) * orielSimMatrix * matrix.Inverse, - // new Color(0.9f, 0.5f, 0.5f) - // ); - - if (enemies.Count < 100 && Time.Totalf > spawnTime) { - enemies.Add(playerPos + Quat.FromAngles(0, Mono.inst.noise.value * 360f, 0) * Vec3.Forward * 8); - spawnTime = Time.Totalf + 0.05f; - } - - for (int i = 0; i < enemies.Count; i++) { - - // move towards player - Vec3 toPlayer = (playerPos - enemies[i]).Normalized; - float variation = Mono.inst.noise.D1(i); - toPlayer *= Quat.FromAngles(0, MathF.Sin(Time.Totalf * variation) * 90 * variation, 0); - Vec3 newPos = enemies[i] + toPlayer * Time.Elapsedf * 0.5f; - - // if far enough away from other enemies than set new pos - bool setNewPos = true; - int iteration = 0; - while (iteration < 6) { - for (int j = 0; j < enemies.Count; j++) { - if (i == j) continue; - // intersection depth - float radius = 0.5f; - // (newPos - enemies[j]).Length - float depth = (newPos - enemies[j]).Length - radius; - if (depth < 0) { - // pull back - Vec3 toEnemy = (enemies[j] - newPos).Normalized; - newPos = enemies[j] - toEnemy * radius * 1.01f; - - // bump - // enemies[j] += toEnemy * Time.Elapsedf * 0.5f; - - // setNewPos = false; - // break; - // break; - } - } - - iteration++; - } - - if (setNewPos) { - enemies[i] = newPos; - } - - - - - meshCube.Draw(matOriel, - Matrix.TRS(enemies[i], - Quat.LookAt(enemies[i], playerPos, Vec3.Up), - new Vec3(0.4f, 1f, 0.2f) - ) * orielSimMatrix * matrix.Inverse, - Color.White * 0.62f - ); - } - - } - - // Custom > Physics - // issue that we are having is we don't have enough access to the physics sim - // and because of that we run into issues where solutions we've learned of in Unity - // will not carry over simply due to what we have current access to. - - // getting over these physics hurdles is worthwhile, but not when we have a viable alternate solution - Vec3 playerPos; - List enemies = new List(); - float spawnTime; - - Mesh meshAxis; - void Gen() { - meshAxis = model.GetMesh("Axis"); } } \ No newline at end of file diff --git a/app/PullRequest.cs b/app/PullRequest.cs index d66ebe5..29aa8fc 100644 --- a/app/PullRequest.cs +++ b/app/PullRequest.cs @@ -1,6 +1,3 @@ -using System; -using StereoKit; - public static class PullRequest { public static void BoundsDraw(Bounds b, float thickness, Color color) { Vec3 c = Vec3.One / 2; @@ -151,6 +148,33 @@ public static class PullRequest { } } + public static float Clamp01(float v) { + return MathF.Max(0, MathF.Min(1, v)); + } + + public static float Clamp(float v, float min, float max) { + return MathF.Max(min, MathF.Min(max, v)); + } + + [Serializable] + public class PID { + public float p, i; + float integral = 0f; + float value = 0f; + + public PID(float p, float i) { + this.p = p; + this.i = i; + } + + public float Update(float target) { + float error = value - target; + integral += error; + float delta = ((p * error) + (i * integral)); + return value -= delta * Time.Elapsedf; + } + } + [Serializable] public class Lerper { public float t = 0; diff --git a/app/Rig/Mic.cs b/app/Rig/Mic.cs index 05b14d0..649776a 100644 --- a/app/Rig/Mic.cs +++ b/app/Rig/Mic.cs @@ -1,5 +1,4 @@ -using System; -using StereoKit; +namespace Oriels; public class Mic { public float[] bufferRaw = new float[0]; diff --git a/app/Rig/Rig.cs b/app/Rig/Rig.cs index 5c356c6..e872be5 100644 --- a/app/Rig/Rig.cs +++ b/app/Rig/Rig.cs @@ -1,5 +1,4 @@ -using System; -using StereoKit; +namespace Oriels; public class Rig { public Mic mic = new Mic(); @@ -42,9 +41,10 @@ public class Rig { public Con rCon = new Con(), lCon = new Con(); public Con Con(bool chirality) { return chirality ? rCon : lCon; } - bool handleChirality = false; - public Con HandleCon { - get { return Con(handleChirality); } + + + public Vec3 LocalPos(Vec3 p) { + return ori.Inverse * (p - pos); } @@ -55,9 +55,6 @@ public class Rig { rCon.Step(true); lCon.Step(false); - if (rCon.gripBtn.frameDown) { handleChirality = true; } - if (lCon.gripBtn.frameDown) { handleChirality = false; } - // Shoulders Vec3 headPos = Input.Head.position + Input.Head.Forward * -0.15f; // Input.Head -> Head() ? Vec3 shoulderDir = ( diff --git a/app/Scene.cs b/app/Scene.cs index 62ca841..98f8a7c 100644 --- a/app/Scene.cs +++ b/app/Scene.cs @@ -1,7 +1,6 @@ -using System; using System.Runtime.InteropServices; -using StereoKit; +namespace Oriels; [StructLayout(LayoutKind.Sequential)] struct BufferData { public Matrix matrix; @@ -15,6 +14,7 @@ public class Scene { Material matFloor = new Material(Shader.Default); Model shed = Model.FromFile("shed/shed.glb", Shader.FromFile("/shaders/room.hlsl")); + Mesh cube = Mesh.Cube; Solid floor; @@ -55,22 +55,22 @@ public class Scene { - + buffer.Set(data); // PullRequest.BlockOut(floor.GetPose().ToMatrix(floorScale), Color.White * 0.333f, matFloor); // foreach (ModelNode node in shed.Visuals) { - // Console.WriteLine(i + " - " + node.Name); + // Console.WriteLine(i + " - " + node.Name); - // node.Material.SetVector("_center", oriel.bounds.center); - // node.Material.SetVector("_dimensions", oriel.bounds.dimensions); - // node.Material["_matrix"] = (Matrix)System.Numerics.Matrix4x4.Transpose(oriel.matrix); + // node.Material.SetVector("_center", oriel.bounds.center); + // node.Material.SetVector("_dimensions", oriel.bounds.dimensions); + // node.Material["_matrix"] = (Matrix)System.Numerics.Matrix4x4.Transpose(oriel.matrix); - // Console.WriteLine("Shader: " + node.Material.Shader.Name); + // Console.WriteLine("Shader: " + node.Material.Shader.Name); - // node.Mesh.Draw(matRoom, Matrix.TRS(new Vec3(0, World.BoundsPose.position.y, -1), Quat.Identity, Vec3.One)); - // Console.WriteLine(matRoom.ParamCount + " test " + node.Material.ParamCount); + // node.Mesh.Draw(matRoom, Matrix.TRS(new Vec3(0, World.BoundsPose.position.y, -1), Quat.Identity, Vec3.One)); + // Console.WriteLine(matRoom.ParamCount + " test " + node.Material.ParamCount); // } // room.RootNode.Material.SetVector("_center", oriel.bounds.center); // room.RootNode.Material.SetVector("_dimensions", oriel.bounds.dimensions); @@ -78,7 +78,20 @@ public class Scene { // Shader. // World.BoundsPose.position.y + + shed.Draw(Matrix.TRS(new Vec3(0, -1.6f, 0), Quat.Identity, Vec3.One)); - // skatepark.Draw(Matrix.TRS(new Vec3(0, -5.6f, 0), Quat.Identity, Vec3.One)); + + + // draw a grid of cube pillars spaced out evenly along the XZ plane + // for (int i = 0; i < 20; i++) { + // for (int j = 0; j < 20; j++) { + // float x = i * 4 - 20; + // float z = j * 4 - 20; + // float y = 0; + // Matrix m = Matrix.TRS(new Vec3(x, y, z), Quat.Identity, new Vec3(0.25f, 6f, 0.25f)); + // cube.Draw(matFloor, m); + // } + // } } } \ No newline at end of file diff --git a/app/Space/Mono.cs b/app/Space/Mono.cs new file mode 100644 index 0000000..c383d76 --- /dev/null +++ b/app/Space/Mono.cs @@ -0,0 +1,186 @@ +using System.Collections.Generic; + +namespace Space; +public class Mono { + + Vec3 playerPos; + List enemies = new List(); + float spawnTime; + + Mesh meshCube; + + public Mono() { + + } + + public void Init() { + meshCube = Mesh.Cube; + } + + public void Frame() { + + Rig rig = Oriels.Mono.inst.rig; + Oriel oriel = Oriels.Mono.inst.oriel; + + // stretch cursor move + // trackballer spin + // orbital view + // dummy enemies + // points (point of reference *all around) + // roll dodge move + + + + + + + // placeholder "app" + // Vec3 playerWorldPos = playerPos * 0.5f * oriel.bounds.dimensions.y; + Matrix orielSimMatrix = Matrix.TRS( + new Vec3(0, 0, 0), //-oriel.bounds.dimensions.y / 2.01f, -playerWorldPos.z), + Quat.Identity, + Vec3.One * 0.5f * oriel.bounds.dimensions.y + ); + + + // meshCube.Draw(oriel.matOriel, + // rGlove.virtualGlove.ToMatrix(new Vec3(0.025f, 0.1f, 0.1f) / 3 * 1.05f), + // new Color(0.3f, 0.3f, 0.6f) + // ); + + + + + // go hacky for now, just to show that you are doing something + + // but communicate that: + // there are a whole host of things that are taken for granted rn + // that need to be implemented for the real thing + // they aren't that hard, i just can't panic rush through them + + // because they are mundane and somewhat time consuming + // we can show dedication and communicate/ensure importance by streaming and making videos again! + + // stretch cursor pattern: + // stretch = dist(offHand, mainHand) + // max(stretch - deadzone, 0) + // dir = mainHand.fwd + // cursor = mainHand.pos + dir * stretch * 3 + + // stretch cursor code: + float deadzone = 0.1f; + 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; + meshCube.Draw(oriel.matOriel, + Matrix.TRS(cursor, Quat.Identity, Vec3.One * 0.02f), + new Color(1f, 1f, 1f) + ); + + Vec3 localCursor = orielSimMatrix.Inverse.Transform(oriel.matrix.Transform(cursor)); + meshCube.Draw(oriel.matOriel, + Matrix.TRS(localCursor, Quat.Identity, Vec3.One * 0.02f) * orielSimMatrix * oriel.matrix.Inverse, + new Color(0f, 0f, 0f) + ); + + + + // fly player towards cursor: + playerPos += (localCursor - playerPos).Normalized * 1f * Time.Elapsedf; + // use the gorilla tag equation to stop the stutter at when the player is close to the cursor + meshCube.Draw(oriel.matOriel, + Matrix.TRS( + playerPos, + Quat.LookDir((localCursor - playerPos).Normalized), + new Vec3(0.4f, 0.2f, 0.4f) + ) * orielSimMatrix * oriel.matrix.Inverse, + new Color(1.0f, 0.0f, 0.05f) + ); + + + + + + + // destroy enemies that are too close to the playerPos + for (int i = 0; i < enemies.Count; i++) { + if (Vec3.Distance(enemies[i], playerPos) < 0.5f) { + // enemies.RemoveAt(i); + // i--; + enemies[i] = playerPos + Quat.FromAngles(0, Oriels.Mono.inst.noise.value * 360f, 0) * Vec3.Forward * 8; + } + } + + // FULLSTICK + // Vec3 Fullstick() { + // Controller con = rig.lCon.device; + // Quat rot = Quat.FromAngles(con.stick.y * -90, 0, con.stick.x * 90); + // Vec3 dir = Vec3.Up * (con.IsStickClicked ? -1 : 1); + // return con.aim.orientation * rot * dir; + // } + // Vec3 fullstick = Fullstick(); + // sword.Move(playerPos + simOffset + fullstick, Quat.LookAt(Vec3.Zero, fullstick, Vec3.Up)); + // meshCube.Draw(oriel.matOriel, + // Matrix.TRS(sword.GetPose().position + (Vec3.Up * 0.7f) + (sword.GetPose().orientation * Vec3.Forward * -0.5f) - simOffset, sword.GetPose().orientation, new Vec3(0.1f, 0.03f, 1f)) * orielSimMatrix * matrix.Inverse, + // new Color(0.9f, 0.5f, 0.5f) + // ); + + if (enemies.Count < 100 && Time.Totalf > spawnTime) { + // enemies.Add(playerPos + Quat.FromAngles(0, Oriels.Mono.inst.noise.value * 360f, 0) * Vec3.Forward * 8); + spawnTime = Time.Totalf + 0.05f; + } + + for (int i = 0; i < enemies.Count; i++) { + + // move towards player + Vec3 toPlayer = (playerPos - enemies[i]).Normalized; + float variation = Oriels.Mono.inst.noise.D1(i); + toPlayer *= Quat.FromAngles(0, MathF.Sin(Time.Totalf * variation) * 90 * variation, 0); + Vec3 newPos = enemies[i] + toPlayer * Time.Elapsedf * 0.5f; + + // if far enough away from other enemies than set new pos + bool setNewPos = true; + int iteration = 0; + while (iteration < 6) { + for (int j = 0; j < enemies.Count; j++) { + if (i == j) continue; + // intersection depth + float radius = 0.5f; + // (newPos - enemies[j]).Length + float depth = (newPos - enemies[j]).Length - radius; + if (depth < 0) { + // pull back + Vec3 toEnemy = (enemies[j] - newPos).Normalized; + newPos = enemies[j] - toEnemy * radius * 1.01f; + + // bump + // enemies[j] += toEnemy * Time.Elapsedf * 0.5f; + + // setNewPos = false; + // break; + // break; + } + } + + iteration++; + } + + if (setNewPos) { + enemies[i] = newPos; + } + + + + + meshCube.Draw(oriel.matOriel, + Matrix.TRS(enemies[i], + Quat.LookAt(enemies[i], playerPos, Vec3.Up), + new Vec3(0.4f, 1f, 0.2f) + ) * orielSimMatrix * oriel.matrix.Inverse, + Color.White * 0.62f + ); + } + + } +} diff --git a/app/_Init.cs b/app/_Init.cs new file mode 100644 index 0000000..5f9c173 --- /dev/null +++ b/app/_Init.cs @@ -0,0 +1,21 @@ +global using System; +global using StereoKit; +global using Oriels; + +SKSettings settings = new SKSettings { + appName = "oriels", + assetsFolder = "add", + depthMode = DepthMode.D32, + disableUnfocusedSleep = true, +}; +if (!SK.Initialize(settings)) + Environment.Exit(1); + +Input.HandSolid(Handed.Max, false); +Input.HandVisible(Handed.Max, true); + +Mono mono = Mono.inst; +while (SK.Step(() => { + mono.Step(); +})) ; +SK.Shutdown(); \ No newline at end of file diff --git a/oriels.csproj b/oriels.csproj index 1fbe91a..07f2f1a 100644 --- a/oriels.csproj +++ b/oriels.csproj @@ -22,7 +22,7 @@ - + @@ -30,7 +30,7 @@ - + diff --git a/res/oriel.blend b/res/oriel.blend index 3e4c007..ba7bbfe 100644 Binary files a/res/oriel.blend and b/res/oriel.blend differ