mostly fixed
This commit is contained in:
parent
5faf748913
commit
26a58941a8
3 changed files with 85 additions and 32 deletions
54
MonoNet.cs
54
MonoNet.cs
|
@ -308,7 +308,8 @@ public class MonoNet {
|
|||
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;
|
||||
public Quat oldConRot = Quat.Identity, oldHeldRot = Quat.Identity;
|
||||
public Vec3 delta = Vec3.Zero, momentum = Vec3.Zero, angularMomentum = Vec3.Zero;
|
||||
}
|
||||
void Blocks(Controller con, Vec3 cursor, ref BlockCon blockCon, ref BlockCon otherBlockCon) {
|
||||
if (con.IsX2JustPressed) {
|
||||
|
@ -332,15 +333,20 @@ 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);
|
||||
// Quat.Difference() !! this is useful **delta**
|
||||
if (blocks[i].active && bounds.Contains(blockPose.orientation.Inverse * (cursor - blockPose.position))) {
|
||||
blockCon.offset = cursor - blockPose.position;
|
||||
// block.color = colorCube.color;
|
||||
blockCon.index = i;
|
||||
if (otherBlockCon.index == i) {
|
||||
otherBlockCon.index = -1;
|
||||
}
|
||||
// block.color = colorCube.color;
|
||||
// clear
|
||||
blockCon.spinRot = blockCon.spinDelta = Quat.Identity;
|
||||
// set
|
||||
blockCon.heldRot = Quat.Difference(con.aim.orientation, blockPose.orientation);
|
||||
blockCon.offset = blockPose.orientation.Inverse * (blockPose.position - cursor);
|
||||
|
||||
blockCon.heldRot = blockCon.spinRot = blockCon.spinDelta = Quat.Identity;
|
||||
//
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -349,7 +355,7 @@ public class MonoNet {
|
|||
if (blockCon.index >= 0) {
|
||||
Quat newRot = con.aim.orientation * blockCon.heldRot * blockCon.spinRot;
|
||||
// trackballer
|
||||
if (con.trigger > 0.5f) {
|
||||
if (con.trigger > 0.75f) {
|
||||
blockCon.spinDelta = Quat.Slerp(
|
||||
blockCon.spinDelta,
|
||||
((newRot.Inverse * conRotDelta) * newRot).Normalized,
|
||||
|
@ -358,16 +364,52 @@ public class MonoNet {
|
|||
}
|
||||
blockCon.spinRot *= blockCon.spinDelta;
|
||||
Quat toRot = con.aim.orientation * blockCon.heldRot * blockCon.spinRot;
|
||||
Vec3 toPos = cursor + con.aim.orientation * blockCon.heldRot * blockCon.spinRot * blockCon.offset;
|
||||
// cursor - blockCon.offset;
|
||||
blocks[blockCon.index].solid.Move(toPos, toRot);
|
||||
|
||||
blocks[blockCon.index].solid.Move(cursor - blockCon.offset, toRot);
|
||||
Quat newHeldRot = blocks[blockCon.index].solid.GetPose().orientation;
|
||||
blockCon.angularMomentum = Vec3.Lerp(blockCon.angularMomentum, AngularDisplacement(Quat.Difference(blockCon.oldHeldRot, newHeldRot)), Time.Elapsedf / 0.1f);
|
||||
blockCon.oldHeldRot = newHeldRot;
|
||||
|
||||
blockCon.delta = (cursor + con.aim.orientation * blockCon.heldRot * blockCon.spinRot * blockCon.offset) - blocks[blockCon.index].solid.GetPose().position;
|
||||
blockCon.momentum = Vec3.Lerp(blockCon.momentum, blockCon.delta, Time.Elapsedf / 0.1f);
|
||||
}
|
||||
} else {
|
||||
if (blockCon.index > 0) {
|
||||
blocks[blockCon.index].solid.SetAngularVelocity(blockCon.angularMomentum / Time.Elapsedf);
|
||||
blocks[blockCon.index].solid.SetVelocity(blockCon.momentum / Time.Elapsedf);
|
||||
}
|
||||
blockCon.index = -1;
|
||||
}
|
||||
|
||||
blockCon.oldConRot = con.aim.orientation;
|
||||
}
|
||||
|
||||
Vec3 AngularDisplacement(Quat rotDelta) {
|
||||
float angleInDegrees;
|
||||
Vec3 rotationAxis;
|
||||
ToAngleAxis(rotDelta, out angleInDegrees, out rotationAxis);
|
||||
return rotationAxis * angleInDegrees * (float)(Math.PI / 180);
|
||||
}
|
||||
|
||||
public void ToAngleAxis(Quat q1, out float angle, out Vec3 axis) {
|
||||
if (q1.w > 1) q1.Normalize(); // if w>1 acos and sqrt will produce errors, this cant happen if quaternion is normalised
|
||||
angle = 2 * (float)Math.Acos(q1.w);
|
||||
float s = (float)Math.Sqrt(1 - q1.w * q1.w); // assuming quaternion normalised then w is less than 1, so term always positive.
|
||||
axis = Vec3.Zero;
|
||||
if (s < 0.001) { // test to avoid divide by zero, s is always positive due to sqrt
|
||||
// if s close to zero then direction of axis not important
|
||||
axis.x = q1.x; // if it is important that axis is normalised then replace with x=1; y=z=0;
|
||||
axis.y = q1.y;
|
||||
axis.z = q1.z;
|
||||
} else {
|
||||
axis.x = q1.x / s; // normalise axis
|
||||
axis.y = q1.y / s;
|
||||
axis.z = q1.z / s;
|
||||
}
|
||||
}
|
||||
|
||||
public void Draw(bool body) {
|
||||
if (body){
|
||||
Cube(Matrix.TRS(cursorA, Quat.Identity, Vec3.One * 0.05f));
|
||||
|
|
59
Program.cs
59
Program.cs
|
@ -30,10 +30,19 @@ public class Mono {
|
|||
public void Run() {
|
||||
// mic = new Mic();
|
||||
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);
|
||||
Vec3 floorScale = new Vec3(10, 0.1f, 10);
|
||||
Vec3 floorScale = new Vec3(32f, 0.1f, 32f);
|
||||
floor.AddBox(floorScale);
|
||||
// box on each side
|
||||
floor.AddBox(new Vec3(32f, 16f, 0.1f), 1, new Vec3(0, 8f, -16f));
|
||||
floor.AddBox(new Vec3(32f, 16f, 0.1f), 1, new Vec3(0, 8f, 16f));
|
||||
floor.AddBox(new Vec3(0.1f, 16f, 32f), 1, new Vec3(-16f, 8f, 0));
|
||||
floor.AddBox(new Vec3(0.1f, 16f, 32f), 1, new Vec3(16f, 8f, 0));
|
||||
// and ceiling
|
||||
floor.AddBox(new Vec3(32f, 0.1f, 32f), 1, new Vec3(0, 16f, 0));
|
||||
|
||||
|
||||
Cursors cursors = new Cursors(this);
|
||||
|
||||
|
@ -49,10 +58,6 @@ public class Mono {
|
|||
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); }
|
||||
|
@ -61,14 +66,12 @@ public class Mono {
|
|||
|
||||
// ball.Draw(ballMat, Matrix.TS(pos, 0.1f));
|
||||
|
||||
Renderer.CameraRoot = Matrix.T(pos);
|
||||
|
||||
// SpatialCursor cursor = cursors.Step(domCon.aim, subCon.aim);
|
||||
cursor.Step(new Pose[] { domCon.aim });
|
||||
cursor.Step(new Pose[] { domCon.aim, Input.Head });
|
||||
if (domCon.IsStickJustClicked) {
|
||||
cursor.Calibrate();
|
||||
}
|
||||
subCursor.Step(new Pose[] { subCon.aim });
|
||||
subCursor.Step(new Pose[] { subCon.aim, Input.Head });
|
||||
if (subCon.IsStickJustClicked) {
|
||||
subCursor.Calibrate();
|
||||
} cursor.p1 = subCursor.p0; // override *later change all one handed cursors to be dual wielded by default*
|
||||
|
@ -85,7 +88,7 @@ public class Mono {
|
|||
new Vec3(1, 2, -3),
|
||||
new Vec3(0, 1, -4),
|
||||
};
|
||||
Bezier.Draw(rail);
|
||||
// Bezier.Draw(rail);
|
||||
if (subCon.IsX1JustPressed) {
|
||||
int closest = 0;
|
||||
float closestDist = float.MaxValue;
|
||||
|
@ -110,19 +113,34 @@ public class Mono {
|
|||
|
||||
// Console.WriteLine(World.RefreshInterval.ToString());
|
||||
|
||||
Vec3 p00 = domCon.aim.position;
|
||||
if (domCon.IsX1JustPressed) {
|
||||
movePress = Time.Totalf;
|
||||
dragStart = cursor.p0;
|
||||
// movePress = Time.Totalf;
|
||||
dragStart = p00;
|
||||
}
|
||||
if (domCon.IsX1Pressed) {
|
||||
pos -= cursor.p0 - dragStart;
|
||||
dragStart = cursor.p0;
|
||||
}
|
||||
if (domCon.IsX1JustUnPressed && Time.Totalf - movePress < 0.2f) {
|
||||
pos = cursor.p0 - (Input.Head.position - pos);
|
||||
vel = -((p00 - dragStart) / Time.Elapsedf);
|
||||
dragStart = p00;
|
||||
}
|
||||
// if (domCon.IsX1JustUnPressed && Time.Totalf - movePress < 0.2f) {
|
||||
// pos = p00 - (Input.Head.position - pos);
|
||||
// }
|
||||
|
||||
// just push off of the air lol better than teleporting
|
||||
// not cursor dependent
|
||||
|
||||
// pos.x = (float)Math.Sin(Time.Total * 0.1f) * 0.5f;
|
||||
|
||||
pos += vel * Time.Elapsedf;
|
||||
float preX = pos.x; pos.x = Math.Clamp(pos.x, -16f, 16f); if (pos.x != preX) { vel.x = 0; }
|
||||
float preY = pos.y; pos.y = Math.Clamp(pos.y, 0f, 16f); if (pos.y != preY) { vel.y = 0; }
|
||||
float preZ = pos.z; pos.z = Math.Clamp(pos.z, -16f, 16f); if (pos.z != preZ) { vel.z = 0; }
|
||||
Renderer.CameraRoot = Matrix.T(pos);
|
||||
|
||||
float friction = 1 - Math.Clamp(vel.Magnitude / Time.Elapsedf / 45f, 0f, 1f);
|
||||
friction = friction * friction * friction;
|
||||
vel = Vec3.Lerp(Vec3.Zero, vel, 1 - (friction * Time.Elapsedf));
|
||||
|
||||
// reveal when palm up
|
||||
float reveal = subCon.pose.Right.y * 2;
|
||||
colorCube.size = colorCube.ogSize * Math.Clamp(reveal, 0, 1);
|
||||
|
@ -146,13 +164,6 @@ 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);
|
||||
// }
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="StereoKit" Version="0.3.5-preview.2" />
|
||||
<PackageReference Include="StereoKit" Version="0.3.5-preview.3" />
|
||||
<PackageReference Include="System.Speech" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue