diff --git a/MonoNet.cs b/MonoNet.cs index e9401a7..5cc02d5 100644 --- a/MonoNet.cs +++ b/MonoNet.cs @@ -294,47 +294,78 @@ public class MonoNet { // voiceInst = voice.Play(Vec3.Zero, 0.5f); } - int blockIndex = -1; - Vec3 blockOffset = Vec3.Zero; - public void Step(Controller domCon) { - if (domCon.IsX2JustPressed) { - if (blockIndex < 0) { + BlockCon dBlock = new BlockCon(); + BlockCon sBlock = new BlockCon(); + + public void Step(Controller domCon, Controller subCon) { + Blocks(domCon, cursorA, ref dBlock, ref sBlock); + Blocks(subCon, cursorB, ref sBlock, ref dBlock); + + Draw(false); + } + + class BlockCon { + public int index = -1; + public Vec3 offset = Vec3.Zero; + public Quat heldRot = Quat.Identity, spinRot = Quat.Identity, spinDelta = Quat.Identity; + public Quat oldConRot = Quat.Identity; + } + void Blocks(Controller con, Vec3 cursor, ref BlockCon blockCon, ref BlockCon otherBlockCon) { + if (con.IsX2JustPressed) { + if (blockCon.index < 0) { for (int i = 0; i < blocks.Length; i++) { if (!blocks[i].active) { - blockIndex = i; - blocks[i].Enable(cursorA, Quat.Identity); - // blockOffset = blocks[i].solid.GetPose().position; + blocks[i].Enable(cursor, Quat.Identity); break; } } } else { - blocks[blockIndex].Disable(); - blockIndex = -1; + blocks[blockCon.index].Disable(); + blockCon.index = -1; } } - if (domCon.grip > 0.5f) { - if (blockIndex < 0) { + Quat conRotDelta = con.aim.orientation * blockCon.oldConRot.Inverse; + + if (con.grip > 0.5f) { + if (blockCon.index < 0) { for (int i = 0; i < blocks.Length; i++) { Pose blockPose = blocks[i].solid.GetPose(); Bounds bounds = new Bounds(Vec3.Zero, Vec3.One); - if (blocks[i].active && bounds.Contains(blockPose.orientation.Inverse * (cursorA - blockPose.position))) { - blockOffset = cursorA - blockPose.position; + if (blocks[i].active && bounds.Contains(blockPose.orientation.Inverse * (cursor - blockPose.position))) { + blockCon.offset = cursor - blockPose.position; // block.color = colorCube.color; - blockIndex = i; + blockCon.index = i; + if (otherBlockCon.index == i) { + otherBlockCon.index = -1; + } + + blockCon.heldRot = blockCon.spinRot = blockCon.spinDelta = Quat.Identity; break; } } - } - - if (blockIndex >= 0) { + } + + if (blockCon.index >= 0) { + Quat newRot = con.aim.orientation * blockCon.heldRot * blockCon.spinRot; // trackballer - blocks[blockIndex].solid.Move(cursorA - blockOffset, blocks[blockIndex].solid.GetPose().orientation); + if (con.trigger > 0.5f) { + blockCon.spinDelta = Quat.Slerp( + blockCon.spinDelta, + ((newRot.Inverse * conRotDelta) * newRot).Normalized, + Time.Elapsedf / 0.1f + ); + } + blockCon.spinRot *= blockCon.spinDelta; + Quat toRot = con.aim.orientation * blockCon.heldRot * blockCon.spinRot; + + blocks[blockCon.index].solid.Move(cursor - blockCon.offset, toRot); } } else { - blockIndex = -1; + blockCon.index = -1; } - Draw(false); + + blockCon.oldConRot = con.aim.orientation; } public void Draw(bool body) { diff --git a/Program.cs b/Program.cs index cb615fe..d884ebb 100644 --- a/Program.cs +++ b/Program.cs @@ -46,21 +46,38 @@ public class Mono { ColorCube colorCube = new ColorCube(); Vec3 oldSubPos = Vec3.Zero; + SpatialCursor cursor = new ReachCursor(); + SpatialCursor subCursor = new ReachCursor(); + + Solid solidTest = new Solid(Vec3.Forward * 2, Quat.Identity, SolidType.Normal); + solidTest.AddBox(Vec3.One); + Quat quatTest = Quat.Identity; + + while (SK.Step(() => { if (lefty) { domCon = Input.Controller(Handed.Left); subCon = Input.Controller(Handed.Right); } else { domCon = Input.Controller(Handed.Right); subCon = Input.Controller(Handed.Left); } - if (subCon.IsX2JustPressed) { lefty = !lefty; } + // if (subCon.IsX2JustPressed) { lefty = !lefty; } // ball.Draw(ballMat, Matrix.TS(pos, 0.1f)); Renderer.CameraRoot = Matrix.T(pos); - SpatialCursor cursor = cursors.Step(domCon.aim, subCon.aim); + // SpatialCursor cursor = cursors.Step(domCon.aim, subCon.aim); + cursor.Step(new Pose[] { domCon.aim }); + if (domCon.IsStickJustClicked) { + cursor.Calibrate(); + } + subCursor.Step(new Pose[] { subCon.aim }); + if (subCon.IsStickJustClicked) { + subCursor.Calibrate(); + } cursor.p1 = subCursor.p0; // override *later change all one handed cursors to be dual wielded by default* - Quat rot = Quat.FromAngles(subCon.stick.y * -90, 0, subCon.stick.x * 90); - Vec3 dir = Vec3.Up * (subCon.IsStickClicked ? -1 : 1); - Vec3 fullstick = subCon.aim.orientation * rot * dir; - pos += fullstick * subCon.trigger * Time.Elapsedf; + // fullstick + // Quat rot = Quat.FromAngles(subCon.stick.y * -90, 0, subCon.stick.x * 90); + // Vec3 dir = Vec3.Up * (subCon.IsStickClicked ? -1 : 1); + // Vec3 fullstick = subCon.aim.orientation * rot * dir; + // pos += fullstick * subCon.trigger * Time.Elapsedf; Vec3[] rail = new Vec3[] { new Vec3(0, 0, -1), @@ -128,6 +145,14 @@ public class Mono { cube.Draw(mat, floor.GetPose().ToMatrix(floorScale)); + + quatTest *= Quat.FromAngles( + (float)Math.Sin(Time.Total + 0), + (float)Math.Sin(Time.Total + 6), + (float)Math.Sin(Time.Total + 9) + ); + solidTest.Move(Vec3.Forward * 2, quatTest); + cube.Draw(mat, solidTest.GetPose().ToMatrix()); // for (int i = 0; i < net.me.blocks.Length; i++) { // cube.Draw(mat, net.me.blocks[i].solid.GetPose().ToMatrix(), net.me.blocks[i].color); // } @@ -145,8 +170,8 @@ public class Mono { } } - net.me.Step(domCon); - + net.me.Step(domCon, subCon); + // oriel.Step(); // Matrix orbitMatrix = OrbitalView.transform; diff --git a/SpatialCursor.cs b/SpatialCursor.cs index ec321ef..80ac85f 100644 --- a/SpatialCursor.cs +++ b/SpatialCursor.cs @@ -16,7 +16,7 @@ public class Cursors { public Cursors(Mono mono) { this.mono = mono; } - SpatialCursor[] oneHanded = new SpatialCursor[] { new ReachCursor(), new TwistCursor() }; int oneIndex = 1; + SpatialCursor[] oneHanded = new SpatialCursor[] { new ReachCursor(), new TwistCursor() }; int oneIndex = 0; SpatialCursor[] twoHanded = new SpatialCursor[] { new StretchCursor(), new CubicFlow(), new SupineCursor() }; int twoIndex = 0; public SpatialCursor Step(Pose domHand, Pose subHand) { @@ -55,12 +55,12 @@ public class ReachCursor : SpatialCursor { Vec3 origin; public override void Step(Pose[] poses) { pos = poses[0].position; - float stretch = (origin - pos).Length; + float stretch = Vec3.Distance(origin, pos); Vec3 dir = (pos - origin).Normalized; - p0 = pos + dir * stretch * 3; + p0 = pos + dir * stretch * str; - model.Draw(Matrix.TS(pos, 0.06f)); - Lines.Add(origin, pos, Color.White, 0.01f); + model.Draw(Matrix.TS(p0, 0.06f)); + Lines.Add(origin, p0, Color.White, 0.01f); model.Draw(Matrix.TS(origin, 0.04f)); } public override void Calibrate() {