diff --git a/app/Glove.cs b/app/Glove.cs index 986dd7b..4a3d522 100644 --- a/app/Glove.cs +++ b/app/Glove.cs @@ -1,23 +1,22 @@ using System; using StereoKit; -public enum Grab { +public enum Pull { Stretch, Backhanded } public class Glove { Monolith mono; bool chirality; - public ReachCursor reachCursor; public Glove(Monolith mono, bool chirality) { this.mono = mono; this.chirality = chirality; - this.reachCursor = new ReachCursor(mono, chirality); } - public Vec3 cursor; + public Pose cursor; + Vec3 cursorDir; - public Grab? grabbed = null; + public Pull? pulling = null; float stretchDeadzone = 0; Vec3 pullPoint; @@ -25,39 +24,43 @@ public class Glove { public void Step() { Pose shoulder = mono.Shoulder(chirality); - Con con = mono.Con(chirality); // !chirality + Con con = mono.Con(chirality), otherCon = mono.Con(!chirality); pullPoint = con.pos; + // cursorDir = (con.pos - pullPoint).Normalized; // WRONG PLACE? - switch (grabbed) { - case Grab.Stretch: + switch (pulling) { + case Pull.Stretch: + pullPoint = otherCon.pos; + cursorDir = con.ori * Vec3.Forward; break; - case Grab.Backhanded: + case Pull.Backhanded: + break; default: - if (con.gripBtn.frameDown) { - // comparison evaluation - grabbed = Grab.Stretch; + if (otherCon.gripBtn.frameDown) { + // comparison evaluation + pulling = Pull.Stretch; + stretchDeadzone = Vec3.Distance(con.pos, otherCon.pos); } break; } - if (!con.gripBtn.held) { + if (!otherCon.gripBtn.held) { // null - grabbed = null; + pulling = null; } // Vec3 from = (shoulder.orientation * origin) + shoulder.position; float stretch = Vec3.Distance(pullPoint, con.pos); stretch = Math.Max(stretch - stretchDeadzone, 0); - cursor = con.pos + (con.pos - pullPoint).Normalized * stretch * 3; + cursor.position = con.pos + cursorDir * stretch * 3; Lines.Add(pullPoint, con.pos, new Color(1, 0, 1), 0.005f); - Lines.Add(con.pos, cursor, new Color(0, 1, 1), 0.005f); - + Lines.Add(con.pos, cursor.position, new Color(0, 1, 1), 0.005f); @@ -92,5 +95,16 @@ public class Glove { // rightGripDown = false; // } + Render(con.Pose(), cursor); } -} \ No newline at end of file + + // decouple the rendering + // render-relevent DATA that gets streamed over the network + // that way we can render the same way for all peers + static Mesh mesh = Default.MeshCube; + static Material mat = Default.Material; + public void Render(Pose pose, Pose cursor) { + mesh.Draw(mat, pose.ToMatrix(new Vec3(0.025f, 0.1f, 0.1f))); + mesh.Draw(mat, cursor.ToMatrix(Vec3.One * 0.035f)); + } +} diff --git a/app/Monolith.cs b/app/Monolith.cs index 803498d..7641d7e 100644 --- a/app/Monolith.cs +++ b/app/Monolith.cs @@ -25,15 +25,19 @@ public class Con { public Btn triggerBtn; public void Step(bool chirality) { - device = Input.Controller(Handed.Right); + device = Input.Controller(chirality ? Handed.Right : Handed.Left); pos = device.pose.position; ori = device.aim.orientation; gripBtn.Step(device.grip > 0.5f); triggerBtn.Step(device.trigger > 0.5f); } + + public Pose Pose() { + return new Pose(pos, ori); + } } -public class Btn { +public struct Btn { public bool frameDown, held, frameUp; public void Step(bool down) { @@ -46,6 +50,10 @@ public class Btn { public class Monolith { public Mic mic; + public Con rCon = new Con(), lCon = new Con(); + public Con Con(bool chirality) { + return chirality ? rCon : lCon; + } public Pose rShoulder, lShoulder; public Pose Shoulder(bool chirality) { return chirality ? rShoulder : lShoulder; @@ -58,10 +66,6 @@ public class Monolith { public Glove Glove(bool chirality) { return chirality ? rGlove : lGlove; } - public Con rCon, lCon; - public Con Con(bool chirality) { - return chirality ? rCon : lCon; - } public Vec3 rDragStart, lDragStart; public float railT; @@ -72,8 +76,11 @@ public class Monolith { public void Run() { Renderer.SetClip(0.02f, 1000f); - // Renderer. // mic = new Mic(); + rGlove = new Glove(this, true); + lGlove = new Glove(this, false); + + Vec3 pos = new Vec3(0, 0, 0); Vec3 vel = new Vec3(0, 0, 0); @@ -106,12 +113,6 @@ public class Monolith { SpatialCursor cubicFlow = new CubicFlow(this); - Tex camTex = new Tex(TexType.Rendertarget); - camTex.SetSize(600, 400); - Material camMat = new Material(Shader.Unlit); - camMat.SetTexture("diffuse", camTex); - Mesh quad = Default.MeshQuad; - Vec3 gripPos = Vec3.Zero; @@ -123,10 +124,10 @@ public class Monolith { while (SK.Step(() => { Renderer.CameraRoot = Matrix.T(pos); + rCon.Step(true); lCon.Step(false); - // Shoulders Vec3 headPos = Input.Head.position + Input.Head.Forward * -0.15f; Vec3 shoulderDir = ( @@ -137,19 +138,29 @@ public class Monolith { if (Vec3.Dot(shoulderDir, Input.Head.Forward) < 0) { shoulderDir = -shoulderDir; } rShoulder = new Pose(headPos + Quat.LookDir(shoulderDir) * new Vec3(0.2f, -0.2f, 0), Quat.LookDir(shoulderDir)); lShoulder = new Pose(headPos + Quat.LookDir(shoulderDir) * new Vec3(-0.2f, -0.2f, 0), Quat.LookDir(shoulderDir)); + + // Wrists rWrist = new Pose(rCon.pos + rCon.ori * new Vec3(0, 0, 0.052f), rCon.ori); lWrist = new Pose(lCon.pos + lCon.ori * new Vec3(0, 0, 0.052f), lCon.ori); + // Gloves + rGlove.Step(); + lGlove.Step(); + // past this point more questions arise - 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; - } + // 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; + // } + + + + // throw yourself (delta -> vel -> momentum) // bring rails back