°board v1 complete

This commit is contained in:
spatialfree 2022-05-02 21:10:44 -04:00
parent 9d797ab6d0
commit d5407f478e
4 changed files with 88 additions and 41 deletions

View file

@ -23,7 +23,7 @@ public class Glove {
float stretchDeadzone = 0; float stretchDeadzone = 0;
Vec3 pullPoint; Vec3 pullPoint;
float twist; public float twist;
bool twistOut; bool twistOut;
Quat twistOffset; Quat twistOffset;
Quat oldOri; Quat oldOri;

View file

@ -56,12 +56,8 @@ public class Mono {
Renderer.SetClip(0.02f, 1000f); Renderer.SetClip(0.02f, 1000f);
} }
Vec3 pos = new Vec3(0f, 0f, 0f); Vec3 boardDir = Vec3.Forward;
Quat ori = Quat.Identity;
float yy = 0f;
public void Step() { public void Step() {
Renderer.CameraRoot = Matrix.TR(pos, ori);
rig.Step(); rig.Step();
scene.Step(); scene.Step();
@ -81,44 +77,59 @@ public class Mono {
//// ////
// °board // °board
// trigger & stick.x will be remapped to tracked motions next // handling = 200±
// str = 100±
// speed = 10± // speed = 10±
// con.grip.frameDown: handleCon = con // board.dir = Vec3.fwd
// turn = handleCon.stick.x // con.grip.frameDown:
// rig.rot *= Quat(0f, turn * strength * delta, 0f); // handle = con
// accel = handleCon.trigger // board.pos = FloorCenter
// rig.pos += boardDir * accel * speed * delta // newDir = handle.pos.X0Z - board.pos.X0Z
// board.dir = newDir.MagSq > 0.001f ? newDir.normalized : board.dir
// board.ori = Quat.LookDir(board.dir)
// board.pos = rig.floorCenter + rig.pos // twist = handle.grip * -(Quat.LookDir(board.dir).Inverse * handle.backhandDir).x
// board.dir = (handleCon.pos.X0Z - board.pos.X0Z).normalized // rig.ori *= Quat(0, twist * handling * delta, 0)
// board.rot = Quat(board.dir, Vec3.up)
// accel = handle.trigger
// rig.pos += board.dir * accel * speed * delta
Con handleCon = rig.HandleCon();
Vec3 boardDir = (handleCon.pos.X0Z - pos.X0Z).Normalized;
Quat boardRot = Quat.LookDir(boardDir);
pos += boardDir * handleCon.device.trigger * Time.Elapsedf; // °board
yy += handleCon.device.stick.x * 90 * Time.Elapsedf; float handling = 200;
ori = Quat.FromAngles(0f, yy, 0f); // stick.x -> twist z float speed = 10;
Vec3 boardPos = rig.FloorCenter;
Vec3 newDir = rig.HandleCon.pos.X0Z - boardPos.X0Z;
boardDir = newDir.MagnitudeSq > 0.001f ? newDir.Normalized : boardDir;
Quat boardOri = Quat.LookDir(boardDir);
float twist = rig.HandleCon.device.grip * -(Quat.LookDir(boardDir).Inverse * rig.HandleCon.backhandDir).x;
rig.ori *= Quat.FromAngles(0f, twist * handling * Time.Elapsedf, 0f);
float accel = rig.HandleCon.device.trigger;
rig.pos += boardDir * accel * speed * Time.Elapsedf;
// Lines.Add(rig.HandleCon.pos, rig.HandleCon.pos + rig.HandleCon.backhandDir, Color.White, 0.01f);
Mesh.Cube.Draw(Material.Default, Matrix.TRS(boardPos, boardOri, new Vec3(0.18f, 0.06f, 0.6f)));
// DEPRECATED
// PullRequest.Slerp(boardDir.Normalized, handleDelta.Normalized, handleDelta.Magnitude * handling * Time.Elapsedf) : boardDir;
// Quat from = Quat.LookAt(rig.Head.position, rig.HandleCon.pos);
// Lines.Add(rig.HandleCon.pos, rig.HandleCon.pos + from * Vec3.Up, Color.Black, 0.01f);
Vec3 boardPos = pos.X0Z + Vec3.Up * -1.35f; // rig.Head().position.X0Z // does the FloorCenter move with the CameraRoot?
Mesh.Cube.Draw(Material.Default, Matrix.TRS(boardPos, boardRot, new Vec3(0.18f, 0.06f, 0.6f)));
// having a board underneath my feet and a virtual handlebar in my hand // having a board underneath my feet and a virtual handlebar in my hand
// did a lot to improve the quality of the experience (+immersion -sickness) // did a lot to improve the quality of the experience (+immersion -sickness)
// the ability and quality at which this can be propagated is higher than I first imagined
// don't do more just yet! // next?
// these are all important, but lets start small and scrappy + it's 9AM
// twist turning
// handleCon
// tighter boardDir
// lean turning (head moving in relation to hand, doesn't that happen a little already?) // lean turning (head moving in relation to hand, doesn't that happen a little already?)
// ------------------------------------------------- // -------------------------------------------------

View file

@ -88,6 +88,17 @@ public static class PullRequest {
return a + (b - a) * t; return a + (b - a) * t;
} }
public static Vec3 Slerp(Vec3 a, Vec3 b, float t) {
// spherical linear interpolation
float dot = Vec3.Dot(a, b);
if (dot > 0.9995f) {
return Vec3.Lerp(a, b, t);
}
float theta = (float)Math.Acos(dot);
float sinTheta = (float)Math.Sin(theta);
return Vec3.Lerp(a * (float)Math.Sin(theta - theta * t) / sinTheta, b * (float)Math.Sin(theta * t) / sinTheta, t);
}
static Pose _pose = new Pose(); static Pose _pose = new Pose();
public static Pose WorldPose(this Pose pose, float scale = 1) { public static Pose WorldPose(this Pose pose, float scale = 1) {
return pose; return pose;

View file

@ -2,23 +2,36 @@ using System;
using StereoKit; using StereoKit;
public class Rig { public class Rig {
public Mic mic; public Mic mic = new Mic();
public Vec3 pos = new Vec3(0, 0, 0);
public Quat ori = Quat.Identity;
public Rig() { public Rig() {
mic = new Mic(); if (World.HasBounds) {
// pos.XZ = World.BoundsPose.position.XZ;
// pos.y = World.BoundsPose.position.y;
// ori = World.BoundsPose.orientation;
}
} }
public Con rCon = new Con(), lCon = new Con(); // public Vec3 center;
public Con Con(bool chirality) { return chirality ? rCon : lCon; } // public void Recenter() {
bool handleChirality = false; // center = World.BoundsPose.position.X0Z - Head.position.X0Z;
public Con HandleCon() { // }
return Con(handleChirality);
public Vec3 FloorCenter {
get {
if (World.HasBounds) { return World.BoundsPose.position; }
return new Vec3(0, 0, 0);
}
} }
public Pose Head() { public Pose Head {
Pose pose = Input.Head; get {
pose.position += pose.orientation * Vec3.Forward * -0.1f; Pose pose = Input.Head; // between eyes pose
return pose; pose.position += pose.orientation * Vec3.Forward * -0.1f;
return pose;
}
} }
public Pose rShoulder, lShoulder; public Pose rShoulder, lShoulder;
@ -27,7 +40,17 @@ public class Rig {
public Pose rWrist, lWrist; public Pose rWrist, lWrist;
public Pose Wrist(bool chirality) { return chirality ? rWrist : lWrist; } public Pose Wrist(bool chirality) { return chirality ? rWrist : lWrist; }
public Con rCon = new Con(), lCon = new Con();
public Con Con(bool chirality) { return chirality ? rCon : lCon; }
bool handleChirality = false;
public Con HandleCon {
get { return Con(handleChirality); }
}
public void Step() { public void Step() {
Renderer.CameraRoot = Matrix.TR(pos, ori);
// Controllers // Controllers
rCon.Step(true); rCon.Step(true);
lCon.Step(false); lCon.Step(false);
@ -63,6 +86,7 @@ public class Con {
public Controller device; public Controller device;
public Vec3 pos; public Vec3 pos;
public Quat ori; public Quat ori;
public Vec3 backhandDir;
public Btn gripBtn; public Btn gripBtn;
public Btn triggerBtn; public Btn triggerBtn;
@ -70,6 +94,7 @@ public class Con {
device = Input.Controller(chirality ? Handed.Right : Handed.Left); device = Input.Controller(chirality ? Handed.Right : Handed.Left);
pos = device.pose.position; pos = device.pose.position;
ori = device.aim.orientation; ori = device.aim.orientation;
backhandDir = ori * (chirality ? Vec3.Right : -Vec3.Right);
gripBtn.Step(device.grip > 0.5f); gripBtn.Step(device.grip > 0.5f);
triggerBtn.Step(device.trigger > 0.5f); triggerBtn.Step(device.trigger > 0.5f);
} }