mostly fixed but grinding broken
This commit is contained in:
parent
28afb4da83
commit
eee1c2c951
3 changed files with 152 additions and 105 deletions
49
MonoNet.cs
49
MonoNet.cs
|
@ -324,8 +324,8 @@ public class MonoNet {
|
|||
CubicCon cubicCon = new CubicCon();
|
||||
|
||||
public void Step(Controller domCon, Controller subCon) {
|
||||
dBlock.Step(domCon, cursor0, ref sBlock, ref blocks);
|
||||
sBlock.Step(subCon, cursor3, ref dBlock, ref blocks);
|
||||
dBlock.Step(domCon, subCon, cursor0, ref sBlock, ref blocks);
|
||||
sBlock.Step(subCon, domCon, cursor3, ref dBlock, ref blocks);
|
||||
|
||||
cubicCon.Step(domCon, subCon, this, ref cubics);
|
||||
|
||||
|
@ -339,25 +339,45 @@ public class MonoNet {
|
|||
public Quat oldConRot = Quat.Identity, oldHeldRot = Quat.Identity;
|
||||
public Vec3 delta = Vec3.Zero, momentum = Vec3.Zero, angularMomentum = Vec3.Zero;
|
||||
|
||||
public void Step(Controller con, Vec3 cursor, ref BlockCon otherBlockCon, ref Block[] blocks) {
|
||||
if (con.stickClick.IsJustActive()) {
|
||||
float lastPressed = 0;
|
||||
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) {
|
||||
bool bFound = false;
|
||||
for (int i = 0; i < blocks.Length; i++) {
|
||||
if (!blocks[i].active) {
|
||||
blocks[i].Enable(cursor, Quat.Identity);
|
||||
bFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
blocks[PullRequest.RandomRange(0, blocks.Length)].Enable(cursor, Quat.Identity);
|
||||
if (!bFound) {
|
||||
blocks[PullRequest.RandomRange(0, blocks.Length)].Enable(cursor, Quat.Identity);
|
||||
}
|
||||
} else {
|
||||
blocks[index].Disable();
|
||||
index = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Quat conRotDelta = (con.aim.orientation * oldConRot.Inverse).Normalized;
|
||||
|
||||
if (con.grip > 0.5f) {
|
||||
if (con.trigger > 0.1f) {
|
||||
if (index < 0) {
|
||||
// BLOCK EXCHANGE
|
||||
// loop over peer blocks as well
|
||||
|
@ -367,7 +387,7 @@ public class MonoNet {
|
|||
|
||||
for (int i = 0; i < blocks.Length; i++) {
|
||||
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))) {
|
||||
index = i;
|
||||
if (otherBlockCon.index == i) {
|
||||
|
@ -391,14 +411,14 @@ public class MonoNet {
|
|||
if (index >= 0) {
|
||||
Quat newRot = (con.aim.orientation * heldRot * spinRot).Normalized;
|
||||
// trackballer
|
||||
if (con.IsX2Pressed) {
|
||||
if (con.trigger > 0.99f) {
|
||||
spinDelta = Quat.Slerp(
|
||||
spinDelta.Normalized,
|
||||
(newRot.Inverse * conRotDelta * newRot).Normalized,
|
||||
Time.Elapsedf / 0.1f
|
||||
);
|
||||
}
|
||||
spinRot *= spinDelta;
|
||||
spinRot *= spinDelta * spinDelta;
|
||||
Quat toRot = (con.aim.orientation * heldRot * spinRot).Normalized;
|
||||
Vec3 toPos = cursor + (con.aim.orientation * heldRot * spinRot).Normalized * offset;
|
||||
// cursor - offset;
|
||||
|
@ -425,7 +445,7 @@ public class MonoNet {
|
|||
|
||||
class CubicCon {
|
||||
public void Step(Controller domCon, Controller subCon, Peer peer, ref Cubic[] cubics) {
|
||||
bool place = domCon.IsX2JustPressed;
|
||||
bool place = domCon.IsStickJustClicked || subCon.IsStickJustClicked;
|
||||
if (place) {
|
||||
for (int i = 0; i < cubics.Length; i++) {
|
||||
if (!cubics[i].active) {
|
||||
|
@ -447,7 +467,6 @@ public class MonoNet {
|
|||
|
||||
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++) {
|
||||
if (blocks[i].solid.GetPose().position.y < -10) {
|
||||
|
@ -478,6 +497,7 @@ public class Block {
|
|||
public Solid solid;
|
||||
|
||||
public Color color;
|
||||
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?
|
||||
|
@ -486,7 +506,8 @@ public class Block {
|
|||
// public bool busy; // marked as held so no fighting
|
||||
public Block(SolidType type, Color color) {
|
||||
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;
|
||||
Disable();
|
||||
}
|
||||
|
@ -510,7 +531,7 @@ public class Block {
|
|||
|
||||
public void Draw() {
|
||||
if (active) {
|
||||
mesh.Draw(mat, solid.GetPose().ToMatrix(), color);
|
||||
mesh.Draw(mat, solid.GetPose().ToMatrix(Vec3.One * size), color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
207
Program.cs
207
Program.cs
|
@ -75,6 +75,7 @@ public class Mono {
|
|||
|
||||
float grindDir = 1f;
|
||||
bool grinding = false;
|
||||
bool grinded = false;
|
||||
Vec3 grindVel = Vec3.Forward;
|
||||
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));
|
||||
if (domCon.trigger > 0.5f) {
|
||||
cursor.Calibrate();
|
||||
}
|
||||
// if (domCon.trigger > 0.5f) {
|
||||
// cursor.Calibrate();
|
||||
// }
|
||||
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) {
|
||||
subCursor.Calibrate();
|
||||
} cursor.p1 = subCursor.p0; // override *later change all one handed cursors to be dual wielded by default*
|
||||
// if (subCon.trigger > 0.5f) {
|
||||
// subCursor.Calibrate();
|
||||
// } 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++) {
|
||||
Pose blockPose = net.me.blocks[i].solid.GetPose();
|
||||
Bounds bounds = new Bounds(Vec3.Zero, Vec3.One);
|
||||
if (net.me.blocks[i].active && (bounds.Contains(blockPose.orientation.Inverse * (cursor.p0 - blockPose.position)) || bounds.Contains(blockPose.orientation.Inverse * (cursor.p1 - blockPose.position)))) {
|
||||
Bounds bounds = new Bounds(Vec3.Zero, Vec3.One * net.me.blocks[i].size);
|
||||
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);
|
||||
} else {
|
||||
net.me.blocks[i].color = new Color(1, 1, 1);
|
||||
|
@ -144,6 +159,25 @@ public class Mono {
|
|||
// Vec3 fullstick = subCon.aim.orientation * rot * dir;
|
||||
// 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
|
||||
// Vec3[] rail = new Vec3[] {
|
||||
// new Vec3(0, 0, -1),
|
||||
|
@ -154,72 +188,82 @@ public class Mono {
|
|||
// Bezier.Draw(rail);
|
||||
|
||||
if (domCon.grip > 0.5f) {
|
||||
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, domCon.aim.position + domCon.aim.Forward * 0.2f);
|
||||
if (dist < closestDist) {
|
||||
closest = j;
|
||||
closestRail = i;
|
||||
closestDist = dist;
|
||||
closestPoint = point;
|
||||
railT = (float)j / (rail.Length - 1f);
|
||||
grinding = true;
|
||||
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, domCon.aim.position + 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.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) {
|
||||
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;
|
||||
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; // scale based on length of rail * calculate and cache on place
|
||||
// bool clamped = false;
|
||||
// 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 {
|
||||
grinded = false;
|
||||
if (grinding) {
|
||||
vel = grindVel;
|
||||
grinding = false;
|
||||
|
@ -228,26 +272,7 @@ public class Mono {
|
|||
|
||||
// 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) {
|
||||
// pos = p00 - (Input.Head.position - pos);
|
||||
|
@ -257,8 +282,10 @@ public class Mono {
|
|||
// 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; }
|
||||
|
@ -285,11 +312,11 @@ public class Mono {
|
|||
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.color = colorCube.color;
|
||||
net.me.cursor0 = cubicFlow.p0; net.me.cursor1 = cubicFlow.p1;
|
||||
net.me.cursor2 = cubicFlow.p2; net.me.cursor3 = cubicFlow.p3;
|
||||
// net.me.cursor0 = cubicFlow.p0; net.me.cursor1 = cubicFlow.p1;
|
||||
// net.me.cursor2 = cubicFlow.p2; net.me.cursor3 = cubicFlow.p3;
|
||||
|
||||
net.me.headset = Input.Head;
|
||||
net.me.mainHand = domCon.aim; net.me.offHand = subCon.aim;
|
||||
for (int i = 0; i < net.peers.Length; i++) {
|
||||
|
|
|
@ -145,7 +145,6 @@ public class CubicFlow : SpatialCursor {
|
|||
p3 = np3;
|
||||
// if toggle
|
||||
|
||||
Bezier.Draw(this.p0, this.p1, this.p2, this.p3, Color.White);
|
||||
}
|
||||
|
||||
public override void Calibrate() {}
|
||||
|
|
Loading…
Add table
Reference in a new issue