From f5088a8304acd110c6640810881843a88d07f27c Mon Sep 17 00:00:00 2001 From: spatialfree Date: Thu, 20 Jan 2022 22:48:50 -0500 Subject: [PATCH] net is back --- app/Blocks.cs | 24 ++--- app/ColorCube.cs | 2 +- app/Cubics.cs | 25 +++-- app/Glove.cs | 25 +---- app/MonoNet.cs | 118 ++++++++++----------- app/Monolith.cs | 261 +++++++++++++++++++---------------------------- app/Scene.cs | 33 ++++++ 7 files changed, 224 insertions(+), 264 deletions(-) create mode 100644 app/Scene.cs diff --git a/app/Blocks.cs b/app/Blocks.cs index 5928257..4b7ee8a 100644 --- a/app/Blocks.cs +++ b/app/Blocks.cs @@ -2,23 +2,21 @@ using System; using StereoKit; public class Block { - public static Mesh mesh = Default.MeshCube; - public static Material mat = Default.Material; - - public bool active = false; + public bool active; + public Color color; + public Vec3 scale; public Solid solid; - public float size = 0.5f; - // if you grab someone else's it becomes your own // how to communicate to the other peer that you have grabbed it? // public int request; // request ownership // public int owner; // then if owner continue as usual // public bool busy; // marked as held so no fighting - public Block(SolidType type) { + public Block(SolidType type = SolidType.Normal) { + color = Color.White; + this.scale = new Vec3(0.2f, 0.2f, 0.34f); this.solid = new Solid(Vec3.Zero, Quat.Identity, type); - this.size = 0.5f; - this.solid.AddBox(Vec3.One * size, 3); + this.solid.AddBox(scale, 3); Disable(); } @@ -32,12 +30,6 @@ public class Block { public void Disable() { solid.Enabled = active = false; } - - public void Draw() { - if (active) { - mesh.Draw(mat, solid.GetPose().ToMatrix(Vec3.One * size)); - } - } } public class BlockCon { @@ -108,7 +100,7 @@ public class BlockCon { for (int i = 0; i < blocks.Length; i++) { Pose blockPose = blocks[i].solid.GetPose(); - Bounds bounds = new Bounds(Vec3.Zero, Vec3.One * blocks[i].size); + Bounds bounds = new Bounds(Vec3.Zero, blocks[i].scale); if (blocks[i].active && bounds.Contains(blockPose.orientation.Inverse * (cursor - blockPose.position))) { index = i; if (otherBlockCon.index == i) { diff --git a/app/ColorCube.cs b/app/ColorCube.cs index 84c5095..80a5e31 100644 --- a/app/ColorCube.cs +++ b/app/ColorCube.cs @@ -1,7 +1,7 @@ using System; using StereoKit; -class ColorCube { +public class ColorCube { static Mesh cube = Default.MeshCube; static Material mat = new Material(Shader.FromFile("colorcube.hlsl")); static Material unlit = Default.MaterialUnlit; diff --git a/app/Cubics.cs b/app/Cubics.cs index e7737b9..42c9f6d 100644 --- a/app/Cubics.cs +++ b/app/Cubics.cs @@ -10,12 +10,6 @@ public class Cubic { color = Color.White; active = false; } - - public void Draw() { - if (active) { - Bezier.Draw(p0, p1, p2, p3, color); - } - } } public class CubicCon { @@ -28,15 +22,26 @@ public class CubicCon { Con rCon = mono.rCon; Con lCon = mono.lCon; Peer peer = mono.net.me; + bool place = rCon.device.IsStickJustClicked || lCon.device.IsStickJustClicked; if (place) { - for (int i = 0; i < cubics.Length; i++) { - if (!cubics[i].active) { - cubics[i].Enable(peer.cursor0, peer.cursor1, peer.cursor2, peer.cursor3, peer.color); + for (int i = 0; i < mono.cubics.Length; i++) { + if (!mono.cubics[i].active) { + mono.cubics[i].active = true; + mono.cubics[i].p0 = mono.rGlove.virtualGlove.position; + mono.cubics[i].p1 = mono.rCon.pos; + mono.cubics[i].p2 = mono.lCon.pos; + mono.cubics[i].p3 = mono.lGlove.virtualGlove.position; + mono.cubics[i].color = Color.White; break; } } - cubics[PullRequest.RandomRange(0, cubics.Length)].Enable(peer.cursor0, peer.cursor1, peer.cursor2, peer.cursor3, peer.color); + Cubic cubic = mono.cubics[PullRequest.RandomRange(0, mono.cubics.Length)]; + cubic.p0 = mono.rGlove.virtualGlove.position; + cubic.p1 = mono.rCon.pos; + cubic.p2 = mono.lCon.pos; + cubic.p3 = mono.lGlove.virtualGlove.position; + cubic.color = Color.White; } } } diff --git a/app/Glove.cs b/app/Glove.cs index 2c47e97..5b21db4 100644 --- a/app/Glove.cs +++ b/app/Glove.cs @@ -157,28 +157,11 @@ public class Glove { mesh.Draw(mat, glove.ToMatrix(new Vec3(0.025f, 0.025f, 0.025f) / 3)); mesh.Draw(mat, virtualGlove.ToMatrix(new Vec3(0.025f, 0.1f, 0.1f) / 3)); - // Lines.AddAxis(glove); - // Handed handed = chirality ? Handed.Right : Handed.Left; - // Hand hand = Input.Hand(handed); - // HandJoint[] joints = hand.fingers; - // for (int i = 0; i < joints.Length; i++) { - // joints[i].position = (joints[i].position - glove.position) + virtualGlove.position; - // } - // Input.HandOverride(chirality ? Handed.Right : Handed.Left, joints); - // Input.HandClearOverride(handed); - - - ModelNode top = model.FindNode("Top"); - top.LocalTransform = Matrix.R(Quat.FromAngles(Vec3.Right * 45)); - Console.WriteLine(top.Name); - - model.Draw(glove.ToMatrix(Vec3.One / 10)); - - // get "Top" node - // Console.WriteLine(nodes[].Name); - // ? for stereo kit nick "can i directly update bone transforms on a skinned mesh" - + // ModelNode top = model.FindNode("Top"); + // top.LocalTransform = Matrix.R(Quat.FromAngles(Vec3.Right * 45)); + // Console.WriteLine(top.Name); + // model.Draw(glove.ToMatrix(Vec3.One / 10)); } } diff --git a/app/MonoNet.cs b/app/MonoNet.cs index 65e9ec6..50df711 100644 --- a/app/MonoNet.cs +++ b/app/MonoNet.cs @@ -13,7 +13,7 @@ public class MonoNet { this.mono = mono; this.send = false; Random rnd = new Random(); - me = new Peer(rnd.Next(1, 1024 * 8)); // let the server determine the id + me = new Peer(this, rnd.Next(1, 1024 * 8)); // let the server determine the id // me.block = new Block(new Vec3((float)rnd.NextDouble() * 0.5f, 10, -4), Quat.Identity, SolidType.Normal, Color.White); } public Socket socket; @@ -67,7 +67,7 @@ public class MonoNet { break; } } else { - peers[i] = new Peer(id); + peers[i] = new Peer(this, id); index = i; break; } @@ -96,12 +96,11 @@ public class MonoNet { bool running = true; while (running) { Thread.Sleep(60); - if (send) - continue; - - wHead = 0; - me.Write(); - socket.Send(wData); + if (send) { + wHead = 0; + me.Write(); + socket.Send(wData); + } } } @@ -215,10 +214,9 @@ public class Peer { MonoNet net; public int id; // on connect: wait on server sending your peer id public Color color; - public Vec3 cursor0, cursor1, cursor2, cursor3; public Pose headset; - public Pose offHand; - public Pose mainHand; + public Pose rHand, lHand; + public Pose rCursor, lCursor; NetBlock[] blocks; NetCubic[] cubics; // public Sound voice; @@ -231,27 +229,25 @@ public class Peer { // voiceInst = voice.Play(Vec3.Zero, 0.5f); } - public Vec3 vGlovePos; - - public void Step(Monolith mono) { // CLIENT SIDE - - // too much in this networking class - // only contain a copy of network related data - // and not be a weird pitstop for game logic + color = mono.colorCube.color; + headset = Input.Head; + rHand = mono.rCon.Pose(); + lHand = mono.lCon.Pose(); + rCursor = mono.rGlove.virtualGlove; + lCursor = mono.lGlove.virtualGlove; - // game logic driven for write, flexible for read (SolidType.Immovable) - - vGlovePos = mono.rGlove.virtualGlove.position; - - - if (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; + blocks[i].color = mono.blocks[i].color; blocks[i].pose = mono.blocks[i].solid.GetPose(); + blocks[i].scale = mono.blocks[i].scale; } - if (cubics.Length != mono.cubics.Length) { cubics = new NetCubic[mono.cubics.Length]; } + if (cubics == null || cubics.Length != mono.cubics.Length) { cubics = new NetCubic[mono.cubics.Length]; } for (int i = 0; i < cubics.Length; i++) { cubics[i].active = mono.cubics[i].active; cubics[i].color = mono.cubics[i].color; @@ -274,38 +270,40 @@ public class Peer { // } // } - Draw(false); + for (int i = 0; i < net.peers.Length; i++) { + Peer peer = net.peers[i]; + if (peer != null) { peer.Draw(mono, true); } + } + Draw(mono, false); } public void Write() { net.WriteInt(id); net.WriteColor(color); - net.WriteVec3(cursor0); - net.WriteVec3(cursor1); - net.WriteVec3(cursor2); - net.WriteVec3(cursor3); net.WritePose(headset); - net.WritePose(offHand); - net.WritePose(mainHand); + net.WritePose(rHand); + net.WritePose(lHand); + net.WritePose(rCursor); + net.WritePose(lCursor); WriteBlock(); WriteCubic(); } public void Read() { color = net.ReadColor(); - cursor0 = net.ReadVec3(); - cursor1 = net.ReadVec3(); - cursor2 = net.ReadVec3(); - cursor3 = net.ReadVec3(); headset = net.ReadPose(); - offHand = net.ReadPose(); - mainHand = net.ReadPose(); + rHand = net.ReadPose(); + lHand = net.ReadPose(); + rCursor = net.ReadPose(); + lCursor = net.ReadPose(); ReadBlock(); ReadCubic(); } struct NetBlock { public bool active; + public Color color; public Pose pose; + public Vec3 scale; } void ReadBlock() { int length = net.ReadInt(); @@ -313,7 +311,9 @@ public class Peer { for (int i = 0; i < length; i++) { NetBlock netBlock = blocks[i]; netBlock.active = net.ReadBool(); + netBlock.color = net.ReadColor(); netBlock.pose = net.ReadPose(); + netBlock.scale = net.ReadVec3(); } } void WriteBlock() { @@ -321,7 +321,9 @@ public class Peer { for (int i = 0; i < blocks.Length; i++) { NetBlock netBlock = blocks[i]; net.WriteBool(netBlock.active); + net.WriteColor(netBlock.color); net.WritePose(netBlock.pose); + net.WriteVec3(netBlock.scale); } } @@ -355,39 +357,31 @@ public class Peer { } } - - - - - public void Draw(bool body) { + public void Draw(Monolith mono, bool body) { if (body) { - Cube(Matrix.TRS(headset.position + Input.Head.Forward * -0.15f, headset.orientation, Vec3.One * 0.3f), color); + PullRequest.BlockOut(Matrix.TRS(headset.position + Input.Head.Forward * -0.15f, headset.orientation, Vec3.One * 0.3f), color); } - Bezier.Draw(cursor0, cur Color.White); // overlap - // Cube(offHand.ToMatrix(new Vec3(0.1f, 0.025f, 0.1f)), color); - // Cube(mainHand.ToMatrix(new Vec3(0.1f, 0.025f, 0.1f)), color); - - Cube(Matrix.TRS(cursor0, mainHand.orientation, new Vec3(0.025f, 0.1f, 0.1f)), color); - Cube(Matrix.TRS(cursor3, offHand.orientation, new Vec3(0.025f, 0.1f, 0.1f)), color); + Bezier.Draw( + mono.rGlove.virtualGlove.position, + mono.rCon.pos, + mono.lCon.pos, + mono.lGlove.virtualGlove.position, + Color.White + ); for (int i = 0; i < blocks.Length; i++) { - if (blocks[i].solid.GetPose().position.y < -10) { - blocks[i].Disable(); - } else { - blocks[i].Draw(); + NetBlock block = blocks[i]; + if (block.active) { + PullRequest.BlockOut(block.pose.ToMatrix(block.scale), block.color); } } for (int i = 0; i < cubics.Length; i++) { - cubics[i].Draw(); + NetCubic cubic = cubics[i]; + if (cubic.active) { + Bezier.Draw(cubic.p0, cubic.p1, cubic.p2, cubic.p3, color); + } } } - - static Mesh meshCube = Default.MeshCube; - static Material matCube = Default.Material; - public void Cube(Matrix m, Color color) { - matCube.FaceCull = Cull.None; - meshCube.Draw(matCube, m, color); - } } \ No newline at end of file diff --git a/app/Monolith.cs b/app/Monolith.cs index fff1370..7b11a23 100644 --- a/app/Monolith.cs +++ b/app/Monolith.cs @@ -49,6 +49,7 @@ public struct Btn { public class Monolith { public MonoNet net; + public Scene scene; public Mic mic; public Con rCon = new Con(), lCon = new Con(); @@ -67,6 +68,7 @@ public class Monolith { public Glove Glove(bool chirality) { return chirality ? rGlove : lGlove; } + public ColorCube colorCube = new ColorCube(); public Block[] blocks; public BlockCon rBlock, lBlock; public BlockCon BlockCon(bool chirality) { @@ -85,14 +87,15 @@ public class Monolith { public void Run() { Renderer.SetClip(0.02f, 1000f); + scene = new Scene(this); net = new MonoNet(this); net.Start(); // mic = new Mic(); rGlove = new Glove(this, true); lGlove = new Glove(this, false); blocks = new Block[] { - new Block(SolidType.Normal), new Block(type), new Block(type), - new Block(type), new Block(type), new Block(type) + new Block(), new Block(), new Block(), + new Block(), new Block(), new Block() }; rBlock = new BlockCon(this, true); lBlock = new BlockCon(this, false); @@ -106,41 +109,13 @@ public class Monolith { Vec3 pos = new Vec3(0, 0, 0); Vec3 vel = new Vec3(0, 0, 0); - Solid floor = new Solid(Vec3.Up * -1.5f, Quat.Identity, SolidType.Immovable); - float scale = 64f; - Vec3 floorScale = new Vec3(scale, 0.1f, scale); - floor.AddBox(floorScale); - // box on each side - floor.AddBox(new Vec3(scale, scale / 2, 0.1f), 1, new Vec3(0, scale / 4, -scale / 2)); - floor.AddBox(new Vec3(scale, scale / 2, 0.1f), 1, new Vec3(0, scale / 4, scale / 2)); - floor.AddBox(new Vec3(0.1f, scale / 2, scale), 1, new Vec3(-scale / 2, scale / 4, 0)); - floor.AddBox(new Vec3(0.1f, scale / 2, scale), 1, new Vec3(scale / 2, scale / 4, 0)); - // and ceiling - floor.AddBox(new Vec3(scale, 0.1f, scale), 1, new Vec3(0, scale / 2, 0)); - Material matFloor = new Material(Shader.Default); - matFloor.SetTexture("diffuse", Tex.FromFile("floor.png")); - matFloor.SetFloat("tex_scale", 32); - - Oriel oriel = new Oriel(); oriel.Start(3); // Oriel otherOriel = new Oriel(); // otherOriel.Start(4); - ColorCube colorCube = new ColorCube(); Vec3 oldLPos = Vec3.Zero; - SpatialCursor cubicFlow = new CubicFlow(this); - - Vec3 gripPos = Vec3.Zero; - - - float grindDir = 1f; - bool grinding = false; - bool grinded = false; - Vec3 grindVel = Vec3.Forward; - Vec3[] grindRail = new Vec3[4]; - while (SK.Step(() => { Renderer.CameraRoot = Matrix.T(pos); @@ -171,25 +146,13 @@ public class Monolith { lBlock.Step(); // Cubic - cubicCon.Step(rCon, lCon, this); - - - // cubicFlow.Step(new Pose[] { new Pose(rightReachCursor.p0, rCon.ori), new Pose(leftReachCursor.p0, lCon.ori) }, 1); - // if (rCon.stick.y > 0.1f || lCon.stick.y > 0.1f) { - // Bezier.Draw(cubicFlow.p0, cubicFlow.p1, cubicFlow.p2, cubicFlow.p3, Color.White); - // net.me.cursor0 = cubicFlow.p0; net.me.cursor1 = cubicFlow.p1; net.me.cursor2 = cubicFlow.p2; net.me.cursor3 = cubicFlow.p3; - // } else { - // net.me.cursor0 = rightReachCursor.p0; net.me.cursor1 = rightReachCursor.p0; net.me.cursor2 = leftReachCursor.p0; net.me.cursor3 = leftReachCursor.p0; - // } - - + cubicCon.Step(); + // boolean over network to determine if a peers cubic flow should be drawn // throw yourself (delta -> vel -> momentum) // bring rails back - // boolean over network to determine if a peers cubic flow should be drawn - // FULLSTICK // Quat rot = Quat.FromAngles(subCon.stick.y * -90, 0, subCon.stick.x * 90); @@ -201,8 +164,8 @@ public class Monolith { // DRAG DRIFT - Vec3 rPos = net.me.cursor0; - Vec3 lPos = net.me.cursor3; + // Vec3 rPos = net.me.cursor0; + // Vec3 lPos = net.me.cursor3; // use grip grab reach cursor origin it then becoming a backhanded stretch cursor // if (rCon.grip > 0.5f) { @@ -239,96 +202,95 @@ public class Monolith { // CUBIC BEZIER RAIL - // Vec3[] rail = new Vec3[] { - // new Vec3(0, 0, -1), - // new Vec3(0, 0, -2), - // new Vec3(1, 2, -3), - // new Vec3(0, 1, -4), - // }; - // Bezier.Draw(rail); - if (rCon.device.grip > 0.5f) { - if (!grinded) { - if (!grinding) { - int closest = 0; - float closestDist = float.MaxValue; - Vec3 closestPoint = Vec3.Zero; - int closestRail = 0; - for (int i = 0; i < net.me.cubics.Length; i++) { - if (net.me.cubics[i].active) { - Vec3[] rail = new Vec3[] { - net.me.cubics[i].p0, - net.me.cubics[i].p1, - net.me.cubics[i].p2, - net.me.cubics[i].p3, - }; - for (int j = 0; j < rail.Length; j++) { - Vec3 point = Bezier.Sample(rail, (float)j / (rail.Length - 1f)); - float dist = Vec3.Distance(point, rCon.pos + vel.Normalized * 0.25f); - if (dist < closestDist && dist < 0.5f) { - closest = j; - closestRail = i; - closestDist = dist; - closestPoint = point; - railT = (float)j / (rail.Length - 1f); - grinding = true; - } - } - } - } - if (grinding) { - grindRail = new Vec3[] { - net.me.cubics[closestRail].p0, - net.me.cubics[closestRail].p1, - net.me.cubics[closestRail].p2, - net.me.cubics[closestRail].p3, - }; - // pos = closestPoint - (subCon.pose.position - pos); - grindVel = vel; - Vec3 fromPos = Bezier.Sample(grindRail[0], grindRail[1], grindRail[2], grindRail[3], railT); - Vec3 toPos = Bezier.Sample(grindRail[0], grindRail[1], grindRail[2], grindRail[3], railT + 0.1f); - grindDir = Vec3.Dot((fromPos - toPos).Normalized, grindVel) < 0f ? 1 : -1; - } - } + // float grindDir = 1f; + // bool grinding = false; + // bool grinded = false; + // Vec3 grindVel = Vec3.Forward; + // Vec3[] grindRail = new Vec3[4]; - if (grinding) { - Vec3 grindPos = Bezier.Sample(grindRail[0], grindRail[1], grindRail[2], grindRail[3], railT); - Vec3 nextPos = Bezier.Sample(grindRail[0], grindRail[1], grindRail[2], grindRail[3], railT + 0.1f * grindDir); + // if (rCon.device.grip > 0.5f) { + // if (!grinded) { + // if (!grinding) { + // int closest = 0; + // float closestDist = float.MaxValue; + // Vec3 closestPoint = Vec3.Zero; + // int closestRail = 0; + // for (int i = 0; i < net.me.cubics.Length; i++) { + // if (net.me.cubics[i].active) { + // Vec3[] rail = new Vec3[] { + // net.me.cubics[i].p0, + // net.me.cubics[i].p1, + // net.me.cubics[i].p2, + // net.me.cubics[i].p3, + // }; + // for (int j = 0; j < rail.Length; j++) { + // Vec3 point = Bezier.Sample(rail, (float)j / (rail.Length - 1f)); + // float dist = Vec3.Distance(point, rCon.pos + vel.Normalized * 0.25f); + // if (dist < closestDist && dist < 0.5f) { + // closest = j; + // closestRail = i; + // closestDist = dist; + // closestPoint = point; + // railT = (float)j / (rail.Length - 1f); + // grinding = true; + // } + // } + // } + // } + // if (grinding) { + // grindRail = new Vec3[] { + // net.me.cubics[closestRail].p0, + // net.me.cubics[closestRail].p1, + // net.me.cubics[closestRail].p2, + // net.me.cubics[closestRail].p3, + // }; + // // pos = closestPoint - (subCon.pose.position - pos); + // grindVel = vel; + // Vec3 fromPos = Bezier.Sample(grindRail[0], grindRail[1], grindRail[2], grindRail[3], railT); + // Vec3 toPos = Bezier.Sample(grindRail[0], grindRail[1], grindRail[2], grindRail[3], railT + 0.1f); + // grindDir = Vec3.Dot((fromPos - toPos).Normalized, grindVel) < 0f ? 1 : -1; + // } + // } - // vel += (toPos - fromPos); + // if (grinding) { + // Vec3 grindPos = Bezier.Sample(grindRail[0], grindRail[1], grindRail[2], grindRail[3], railT); + // Vec3 nextPos = Bezier.Sample(grindRail[0], grindRail[1], grindRail[2], grindRail[3], railT + 0.1f * grindDir); - pos = -(rCon.pos - Input.Head.position) + grindPos - (Input.Head.position - pos); - vel = Vec3.Zero; + // // vel += (toPos - fromPos); - railT += Time.Elapsedf * grindVel.Magnitude * grindDir; // scale based on length of rail * calculate and cache on place - // bool clamped = false; - // float railTpreClamp = railT; - // if - railT = Math.Clamp(railT, 0, 1); + // pos = -(rCon.pos - Input.Head.position) + grindPos - (Input.Head.position - pos); + // vel = Vec3.Zero; - grindVel = (nextPos - grindPos).Normalized * grindVel.Magnitude; + // railT += Time.Elapsedf * grindVel.Magnitude * grindDir; // scale based on length of rail * calculate and cache on place + // // bool clamped = false; + // // float railTpreClamp = railT; + // // if + // railT = Math.Clamp(railT, 0, 1); - if (railT == 1 || railT == 0) { - vel = grindVel; - grinding = false; - grinded = true; - railT = 0f; - } + // grindVel = (nextPos - grindPos).Normalized * grindVel.Magnitude; + + // if (railT == 1 || railT == 0) { + // vel = grindVel; + // grinding = false; + // grinded = true; + // railT = 0f; + // } - cube.Draw(mat, Matrix.TS(grindPos, new Vec3(0.1f, 0.1f, 0.1f))); - // cube.Draw(mat, Matrix.TS(toPos, new Vec3(0.1f, 0.1f, 0.1f) * 0.333f)); - // pos = Vec3.Lerp(pos, Bezier.Sample(net.me.cubics[0].p0, net.me.cubics[0].p1, net.me.cubics[0].p2, net.me.cubics[0].p3, railT) - (subCon.aim.position - pos), Time.Elapsedf * 6f); - // how to reliably determine and control which direction to go? (velocity) - } - } - } else { - grinded = false; - if (grinding) { - vel = grindVel; - grinding = false; - } - } + // cube.Draw(mat, Matrix.TS(grindPos, new Vec3(0.1f, 0.1f, 0.1f))); + // // cube.Draw(mat, Matrix.TS(toPos, new Vec3(0.1f, 0.1f, 0.1f) * 0.333f)); + // // pos = Vec3.Lerp(pos, Bezier.Sample(net.me.cubics[0].p0, net.me.cubics[0].p1, net.me.cubics[0].p2, net.me.cubics[0].p3, railT) - (subCon.aim.position - pos), Time.Elapsedf * 6f); + // // how to reliably determine and control which direction to go? (velocity) + // } + // } + // } else { + // grinded = false; + // if (grinding) { + // vel = grindVel; + // grinding = false; + // } + // } // Console.WriteLine(World.RefreshInterval.ToString()); @@ -342,30 +304,18 @@ public class Monolith { // not cursor dependent // pos.x = (float)Math.Sin(Time.Total * 0.1f) * 0.5f; - if (!grinding) { - pos += vel * Time.Elapsedf; - } + + pos += vel * Time.Elapsedf; - float preX = pos.x; pos.x = Math.Clamp(pos.x, -scale / 2, scale / 2); if (pos.x != preX) { vel.x = 0; } - float preY = pos.y; pos.y = Math.Clamp(pos.y, 0f, scale / 2); if (pos.y != preY) { vel.y = 0; } - float preZ = pos.z; pos.z = Math.Clamp(pos.z, -scale / 2, scale / 2); if (pos.z != preZ) { vel.z = 0; } + float preX = pos.x; pos.x = Math.Clamp(pos.x, -scene.scale / 2, scene.scale / 2); if (pos.x != preX) { vel.x = 0; } + float preY = pos.y; pos.y = Math.Clamp(pos.y, 0f, scene.scale / 2); if (pos.y != preY) { vel.y = 0; } + float preZ = pos.z; pos.z = Math.Clamp(pos.z, -scene.scale / 2, scene.scale / 2); if (pos.z != preZ) { vel.z = 0; } vel *= 1 - Time.Elapsedf * 0.2f; - - - - // Scene - cube.Draw(matFloor, floor.GetPose().ToMatrix(floorScale), Color.White * 0.666f); - - - - - - // COLOR CUBE // reveal when palm up float reveal = lCon.device.pose.Right.y * 1.666f; @@ -388,21 +338,13 @@ public class Monolith { oldLPos = lCon.device.pose.position; - oriel.Step(net.me.cursor0, net.me.cursor3); + oriel.Step(rGlove.virtualGlove.position, lGlove.virtualGlove.position); // Matrix orbitMatrix = OrbitalView.transform; // cube.Step(Matrix.S(Vec3.One * 0.2f) * orbitMatrix); // Default.MaterialHand["color"] = cube.color; + scene.Step(); - - net.me.color = colorCube.color; - net.me.headset = Input.Head; - net.me.mainHand = rCon.Pose(); - net.me.offHand = lCon.Pose(); - for (int i = 0; i < net.peers.Length; i++) { - Peer peer = net.peers[i]; - if (peer != null) { peer.Draw(true); } - } net.me.Step(this); net.send = true; @@ -487,4 +429,15 @@ public static class PullRequest { public static Vec3 Direction(Vec3 to, Vec3 from) { return (to - from).Normalized; } + + + static Mesh meshCube = Default.MeshCube; + static Material matCube = Default.Material; + public static void BlockOut(Matrix m, Color color, Material mat = null) { + if (mat == null) { + mat = matCube; + mat.FaceCull = Cull.None; + } + meshCube.Draw(mat, m, color); + } } diff --git a/app/Scene.cs b/app/Scene.cs new file mode 100644 index 0000000..17dc272 --- /dev/null +++ b/app/Scene.cs @@ -0,0 +1,33 @@ +using System; +using StereoKit; + +public class Scene { + Monolith mono; + Material matFloor = new Material(Shader.Default); + Solid floor; + public Scene(Monolith mono) { + this.mono = mono; + + floor = new Solid(Vec3.Up * -1.5f, Quat.Identity, SolidType.Immovable); + scale = 64f; + floorScale = new Vec3(scale, 0.1f, scale); + floor.AddBox(floorScale); + // box on each side + floor.AddBox(new Vec3(scale, scale / 2, 0.1f), 1, new Vec3(0, scale / 4, -scale / 2)); + floor.AddBox(new Vec3(scale, scale / 2, 0.1f), 1, new Vec3(0, scale / 4, scale / 2)); + floor.AddBox(new Vec3(0.1f, scale / 2, scale), 1, new Vec3(-scale / 2, scale / 4, 0)); + floor.AddBox(new Vec3(0.1f, scale / 2, scale), 1, new Vec3(scale / 2, scale / 4, 0)); + // and ceiling + floor.AddBox(new Vec3(scale, 0.1f, scale), 1, new Vec3(0, scale / 2, 0)); + matFloor.SetTexture("diffuse", Tex.FromFile("floor.png")); + matFloor.SetFloat("tex_scale", 32); + } + + public float scale; + public Vec3 floorScale; + + + public void Step() { + PullRequest.BlockOut(floor.GetPose().ToMatrix(floorScale), Color.White * 0.666f, matFloor); + } +} \ No newline at end of file