mostly fixed but grinding broken

This commit is contained in:
spatialfree 2021-12-05 19:46:56 -05:00
parent 28afb4da83
commit eee1c2c951
3 changed files with 152 additions and 105 deletions

View file

@ -324,8 +324,8 @@ public class MonoNet {
CubicCon cubicCon = new CubicCon(); CubicCon cubicCon = new CubicCon();
public void Step(Controller domCon, Controller subCon) { public void Step(Controller domCon, Controller subCon) {
dBlock.Step(domCon, cursor0, ref sBlock, ref blocks); dBlock.Step(domCon, subCon, cursor0, ref sBlock, ref blocks);
sBlock.Step(subCon, cursor3, ref dBlock, ref blocks); sBlock.Step(subCon, domCon, cursor3, ref dBlock, ref blocks);
cubicCon.Step(domCon, subCon, this, ref cubics); cubicCon.Step(domCon, subCon, this, ref cubics);
@ -339,16 +339,36 @@ public class MonoNet {
public Quat oldConRot = Quat.Identity, oldHeldRot = Quat.Identity; public Quat oldConRot = Quat.Identity, oldHeldRot = Quat.Identity;
public Vec3 delta = Vec3.Zero, momentum = Vec3.Zero, angularMomentum = Vec3.Zero; public Vec3 delta = Vec3.Zero, momentum = Vec3.Zero, angularMomentum = Vec3.Zero;
public void Step(Controller con, Vec3 cursor, ref BlockCon otherBlockCon, ref Block[] blocks) { float lastPressed = 0;
if (con.stickClick.IsJustActive()) { bool pressed = false;
public void Step(Controller con, Controller otherCon, Vec3 cursor, ref BlockCon otherBlockCon, ref Block[] blocks) {
bool doublePressed = false;
if (con.trigger > 0.5f) {
if (!pressed) {
if (lastPressed > Time.Totalf - 0.5f) {
doublePressed = true;
}
lastPressed = Time.Totalf;
pressed = true;
}
} else {
pressed = false;
}
if (doublePressed) {
if (index < 0) { if (index < 0) {
bool bFound = false;
for (int i = 0; i < blocks.Length; i++) { for (int i = 0; i < blocks.Length; i++) {
if (!blocks[i].active) { if (!blocks[i].active) {
blocks[i].Enable(cursor, Quat.Identity); blocks[i].Enable(cursor, Quat.Identity);
bFound = true;
break; break;
} }
} }
blocks[PullRequest.RandomRange(0, blocks.Length)].Enable(cursor, Quat.Identity); if (!bFound) {
blocks[PullRequest.RandomRange(0, blocks.Length)].Enable(cursor, Quat.Identity);
}
} else { } else {
blocks[index].Disable(); blocks[index].Disable();
index = -1; index = -1;
@ -357,7 +377,7 @@ public class MonoNet {
Quat conRotDelta = (con.aim.orientation * oldConRot.Inverse).Normalized; Quat conRotDelta = (con.aim.orientation * oldConRot.Inverse).Normalized;
if (con.grip > 0.5f) { if (con.trigger > 0.1f) {
if (index < 0) { if (index < 0) {
// BLOCK EXCHANGE // BLOCK EXCHANGE
// loop over peer blocks as well // loop over peer blocks as well
@ -367,7 +387,7 @@ public class MonoNet {
for (int i = 0; i < blocks.Length; i++) { for (int i = 0; i < blocks.Length; i++) {
Pose blockPose = blocks[i].solid.GetPose(); Pose blockPose = blocks[i].solid.GetPose();
Bounds bounds = new Bounds(Vec3.Zero, Vec3.One); Bounds bounds = new Bounds(Vec3.Zero, Vec3.One * blocks[i].size);
if (blocks[i].active && bounds.Contains(blockPose.orientation.Inverse * (cursor - blockPose.position))) { if (blocks[i].active && bounds.Contains(blockPose.orientation.Inverse * (cursor - blockPose.position))) {
index = i; index = i;
if (otherBlockCon.index == i) { if (otherBlockCon.index == i) {
@ -391,14 +411,14 @@ public class MonoNet {
if (index >= 0) { if (index >= 0) {
Quat newRot = (con.aim.orientation * heldRot * spinRot).Normalized; Quat newRot = (con.aim.orientation * heldRot * spinRot).Normalized;
// trackballer // trackballer
if (con.IsX2Pressed) { if (con.trigger > 0.99f) {
spinDelta = Quat.Slerp( spinDelta = Quat.Slerp(
spinDelta.Normalized, spinDelta.Normalized,
(newRot.Inverse * conRotDelta * newRot).Normalized, (newRot.Inverse * conRotDelta * newRot).Normalized,
Time.Elapsedf / 0.1f Time.Elapsedf / 0.1f
); );
} }
spinRot *= spinDelta; spinRot *= spinDelta * spinDelta;
Quat toRot = (con.aim.orientation * heldRot * spinRot).Normalized; Quat toRot = (con.aim.orientation * heldRot * spinRot).Normalized;
Vec3 toPos = cursor + (con.aim.orientation * heldRot * spinRot).Normalized * offset; Vec3 toPos = cursor + (con.aim.orientation * heldRot * spinRot).Normalized * offset;
// cursor - offset; // cursor - offset;
@ -425,7 +445,7 @@ public class MonoNet {
class CubicCon { class CubicCon {
public void Step(Controller domCon, Controller subCon, Peer peer, ref Cubic[] cubics) { public void Step(Controller domCon, Controller subCon, Peer peer, ref Cubic[] cubics) {
bool place = domCon.IsX2JustPressed; bool place = domCon.IsStickJustClicked || subCon.IsStickJustClicked;
if (place) { if (place) {
for (int i = 0; i < cubics.Length; i++) { for (int i = 0; i < cubics.Length; i++) {
if (!cubics[i].active) { if (!cubics[i].active) {
@ -447,7 +467,6 @@ public class MonoNet {
Bezier.Draw(cursor0, cursor1, cursor2, cursor3, Color.White); Bezier.Draw(cursor0, cursor1, cursor2, cursor3, Color.White);
} }
// cubicFlow.Draw(peer.cursorA, peer.cursorB, peer.cursorC, peer.cursorD);
for (int i = 0; i < blocks.Length; i++) { for (int i = 0; i < blocks.Length; i++) {
if (blocks[i].solid.GetPose().position.y < -10) { if (blocks[i].solid.GetPose().position.y < -10) {
@ -478,6 +497,7 @@ public class Block {
public Solid solid; public Solid solid;
public Color color; public Color color;
public float size = 0.5f;
// if you grab someone else's it becomes your own // if you grab someone else's it becomes your own
// how to communicate to the other peer that you have grabbed it? // how to communicate to the other peer that you have grabbed it?
@ -486,7 +506,8 @@ public class Block {
// public bool busy; // marked as held so no fighting // public bool busy; // marked as held so no fighting
public Block(SolidType type, Color color) { public Block(SolidType type, Color color) {
this.solid = new Solid(Vec3.Zero, Quat.Identity, type); this.solid = new Solid(Vec3.Zero, Quat.Identity, type);
this.solid.AddBox(Vec3.One, 3); this.size = 0.5f;
this.solid.AddBox(Vec3.One * size, 3);
this.color = color; this.color = color;
Disable(); Disable();
} }
@ -510,7 +531,7 @@ public class Block {
public void Draw() { public void Draw() {
if (active) { if (active) {
mesh.Draw(mat, solid.GetPose().ToMatrix(), color); mesh.Draw(mat, solid.GetPose().ToMatrix(Vec3.One * size), color);
} }
} }
} }

View file

@ -75,6 +75,7 @@ public class Mono {
float grindDir = 1f; float grindDir = 1f;
bool grinding = false; bool grinding = false;
bool grinded = false;
Vec3 grindVel = Vec3.Forward; Vec3 grindVel = Vec3.Forward;
Vec3[] grindRail = new Vec3[4]; Vec3[] grindRail = new Vec3[4];
@ -119,18 +120,32 @@ public class Mono {
cursor.Step(new Pose[] { domCon.aim, new Pose(rShoulder, Quat.LookDir(middl)) }, ((Input.Controller(Handed.Right).stick.y + 1) / 2)); cursor.Step(new Pose[] { domCon.aim, new Pose(rShoulder, Quat.LookDir(middl)) }, ((Input.Controller(Handed.Right).stick.y + 1) / 2));
if (domCon.trigger > 0.5f) { // if (domCon.trigger > 0.5f) {
cursor.Calibrate(); // cursor.Calibrate();
} // }
subCursor.Step(new Pose[] { subCon.aim, new Pose(lShoulder, Quat.LookDir(middl)) }, ((Input.Controller(Handed.Left).stick.y + 1) / 2)); subCursor.Step(new Pose[] { subCon.aim, new Pose(lShoulder, Quat.LookDir(middl)) }, ((Input.Controller(Handed.Left).stick.y + 1) / 2));
if (subCon.trigger > 0.5f) { // if (subCon.trigger > 0.5f) {
subCursor.Calibrate(); // subCursor.Calibrate();
} cursor.p1 = subCursor.p0; // override *later change all one handed cursors to be dual wielded by default* // } cursor.p1 = subCursor.p0; // override *later change all one handed cursors to be dual wielded by default*
cubicFlow.Step(new Pose[] { domCon.aim, subCon.aim }, 1);
if (domCon.stick.MagnitudeSq != 0 || subCon.stick.MagnitudeSq != 0) {
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 {
cube.Draw(mat, Matrix.TS(cursor.p0, 0.1f));
cube.Draw(mat, Matrix.TS(subCursor.p0, 0.1f));
net.me.cursor0 = cursor.p0; net.me.cursor1 = cursor.p0; net.me.cursor2 = subCursor.p0; net.me.cursor3 = subCursor.p0;
}
for (int i = 0; i < net.me.blocks.Length; i++) { for (int i = 0; i < net.me.blocks.Length; i++) {
Pose blockPose = net.me.blocks[i].solid.GetPose(); Pose blockPose = net.me.blocks[i].solid.GetPose();
Bounds bounds = new Bounds(Vec3.Zero, Vec3.One); Bounds bounds = new Bounds(Vec3.Zero, Vec3.One * net.me.blocks[i].size);
if (net.me.blocks[i].active && (bounds.Contains(blockPose.orientation.Inverse * (cursor.p0 - blockPose.position)) || bounds.Contains(blockPose.orientation.Inverse * (cursor.p1 - blockPose.position)))) { if (net.me.blocks[i].active && (
bounds.Contains(blockPose.orientation.Inverse * (net.me.cursor0 - blockPose.position)) ||
bounds.Contains(blockPose.orientation.Inverse * (net.me.cursor3 - blockPose.position))
)) {
net.me.blocks[i].color = new Color(0.8f, 1, 1); net.me.blocks[i].color = new Color(0.8f, 1, 1);
} else { } else {
net.me.blocks[i].color = new Color(1, 1, 1); net.me.blocks[i].color = new Color(1, 1, 1);
@ -144,6 +159,25 @@ public class Mono {
// Vec3 fullstick = subCon.aim.orientation * rot * dir; // Vec3 fullstick = subCon.aim.orientation * rot * dir;
// pos += fullstick * subCon.trigger * Time.Elapsedf; // pos += fullstick * subCon.trigger * Time.Elapsedf;
// DRAG DRIFT
Vec3 domPos = domCon.aim.position;
// if (domCon.grip) {
// // movePress = Time.Totalf;
// domDragStart = domPos;
// }
vel += -(domPos - domDragStart) * 24 * domCon.grip;
domDragStart = domPos;
Vec3 subPos = subCon.aim.position;
// if (subCon.grip) {
// // movePress = Time.Totalf;
// subDragStart = subPos;
// }
// if (subCon.IsX1Pressed) {
// }
vel += -(subPos - subDragStart) * 24 * subCon.grip;
subDragStart = subPos;
// CUBIC BEZIER RAIL // CUBIC BEZIER RAIL
// Vec3[] rail = new Vec3[] { // Vec3[] rail = new Vec3[] {
// new Vec3(0, 0, -1), // new Vec3(0, 0, -1),
@ -154,72 +188,82 @@ public class Mono {
// Bezier.Draw(rail); // Bezier.Draw(rail);
if (domCon.grip > 0.5f) { if (domCon.grip > 0.5f) {
if (!grinding) { if (!grinded) {
int closest = 0; if (!grinding) {
float closestDist = float.MaxValue; int closest = 0;
Vec3 closestPoint = Vec3.Zero; float closestDist = float.MaxValue;
int closestRail = 0; Vec3 closestPoint = Vec3.Zero;
for (int i = 0; i < net.me.cubics.Length; i++) { int closestRail = 0;
if (net.me.cubics[i].active) { for (int i = 0; i < net.me.cubics.Length; i++) {
Vec3[] rail = new Vec3[] { if (net.me.cubics[i].active) {
net.me.cubics[i].p0, Vec3[] rail = new Vec3[] {
net.me.cubics[i].p1, net.me.cubics[i].p0,
net.me.cubics[i].p2, net.me.cubics[i].p1,
net.me.cubics[i].p3, 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)); for (int j = 0; j < rail.Length; j++) {
float dist = Vec3.Distance(point, domCon.aim.position + domCon.aim.Forward * 0.2f); Vec3 point = Bezier.Sample(rail, (float)j / (rail.Length - 1f));
if (dist < closestDist) { float dist = Vec3.Distance(point, domCon.aim.position + vel.Normalized * 0.25f);
closest = j; if (dist < closestDist && dist < 0.5f) {
closestRail = i; closest = j;
closestDist = dist; closestRail = i;
closestPoint = point; closestDist = dist;
railT = (float)j / (rail.Length - 1f); closestPoint = point;
grinding = true; 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.aim.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;
}
} }
if (grinding) { if (grinding) {
grindRail = new Vec3[] { Vec3 grindPos = Bezier.Sample(grindRail[0], grindRail[1], grindRail[2], grindRail[3], railT);
net.me.cubics[closestRail].p0, Vec3 nextPos = Bezier.Sample(grindRail[0], grindRail[1], grindRail[2], grindRail[3], railT + 0.1f * grindDir);
net.me.cubics[closestRail].p1,
net.me.cubics[closestRail].p2, // vel += (toPos - fromPos);
net.me.cubics[closestRail].p3,
}; pos = -(domCon.aim.position - Input.Head.position) + grindPos - (Input.Head.position - pos);
// pos = closestPoint - (subCon.aim.position - pos); vel = Vec3.Zero;
grindVel = vel;
Vec3 fromPos = Bezier.Sample(grindRail[0], grindRail[1], grindRail[2], grindRail[3], railT); railT += Time.Elapsedf * grindVel.Magnitude * grindDir; // scale based on length of rail * calculate and cache on place
Vec3 toPos = Bezier.Sample(grindRail[0], grindRail[1], grindRail[2], grindRail[3], railT + 0.1f); // bool clamped = false;
grindDir = Vec3.Dot((fromPos - toPos).Normalized, grindVel) < 0f ? 1 : -1; // float railTpreClamp = railT;
// if
railT = Math.Clamp(railT, 0, 1);
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)
} }
} }
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);
// vel += (toPos - fromPos);
pos = -(domCon.aim.position - Input.Head.position) + grindPos - (Input.Head.position - pos);
vel = Vec3.Zero;
railT += Time.Elapsedf * grindVel.Magnitude * grindDir;
// bool clamped = false;
// float railTpreClamp = railT;
// if
railT = Math.Clamp(railT, 0f, 1f);
grindVel = (nextPos - grindPos).Normalized * grindVel.Magnitude;
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 { } else {
grinded = false;
if (grinding) { if (grinding) {
vel = grindVel; vel = grindVel;
grinding = false; grinding = false;
@ -228,26 +272,7 @@ public class Mono {
// Console.WriteLine(World.RefreshInterval.ToString()); // Console.WriteLine(World.RefreshInterval.ToString());
// DRAG DRIFT
Vec3 domPos = domCon.aim.position;
if (domCon.IsX1JustPressed) {
// movePress = Time.Totalf;
domDragStart = domPos;
}
if (domCon.IsX1Pressed) {
vel += -(domPos - domDragStart) * 24;
domDragStart = domPos;
}
Vec3 subPos = subCon.aim.position;
if (subCon.IsX1JustPressed) {
// movePress = Time.Totalf;
subDragStart = subPos;
}
if (subCon.IsX1Pressed) {
vel += -(subPos - subDragStart) * 24;
subDragStart = subPos;
}
// if (domCon.IsX1JustUnPressed && Time.Totalf - movePress < 0.2f) { // if (domCon.IsX1JustUnPressed && Time.Totalf - movePress < 0.2f) {
// pos = p00 - (Input.Head.position - pos); // pos = p00 - (Input.Head.position - pos);
@ -257,8 +282,10 @@ public class Mono {
// not cursor dependent // not cursor dependent
// pos.x = (float)Math.Sin(Time.Total * 0.1f) * 0.5f; // 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 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 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 preZ = pos.z; pos.z = Math.Clamp(pos.z, -scale / 2, scale / 2); if (pos.z != preZ) { vel.z = 0; }
@ -285,11 +312,11 @@ public class Mono {
oldSubPos = subCon.pose.position; oldSubPos = subCon.pose.position;
cubicFlow.Step(new Pose[] {domCon.aim, subCon.aim}, 1);
// net.me.cursorA = Vec3.Up * (float)Math.Sin(Time.Total); // net.me.cursorA = Vec3.Up * (float)Math.Sin(Time.Total);
net.me.color = colorCube.color; net.me.color = colorCube.color;
net.me.cursor0 = cubicFlow.p0; net.me.cursor1 = cubicFlow.p1; // net.me.cursor0 = cubicFlow.p0; net.me.cursor1 = cubicFlow.p1;
net.me.cursor2 = cubicFlow.p2; net.me.cursor3 = cubicFlow.p3; // net.me.cursor2 = cubicFlow.p2; net.me.cursor3 = cubicFlow.p3;
net.me.headset = Input.Head; net.me.headset = Input.Head;
net.me.mainHand = domCon.aim; net.me.offHand = subCon.aim; net.me.mainHand = domCon.aim; net.me.offHand = subCon.aim;
for (int i = 0; i < net.peers.Length; i++) { for (int i = 0; i < net.peers.Length; i++) {

View file

@ -145,7 +145,6 @@ public class CubicFlow : SpatialCursor {
p3 = np3; p3 = np3;
// if toggle // if toggle
Bezier.Draw(this.p0, this.p1, this.p2, this.p3, Color.White);
} }
public override void Calibrate() {} public override void Calibrate() {}