stretch value
This commit is contained in:
parent
0c219a748d
commit
6378acae90
2 changed files with 64 additions and 39 deletions
46
app/Glove.cs
46
app/Glove.cs
|
@ -1,23 +1,22 @@
|
||||||
using System;
|
using System;
|
||||||
using StereoKit;
|
using StereoKit;
|
||||||
|
|
||||||
public enum Grab {
|
public enum Pull {
|
||||||
Stretch, Backhanded
|
Stretch, Backhanded
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Glove {
|
public class Glove {
|
||||||
Monolith mono;
|
Monolith mono;
|
||||||
bool chirality;
|
bool chirality;
|
||||||
public ReachCursor reachCursor;
|
|
||||||
public Glove(Monolith mono, bool chirality) {
|
public Glove(Monolith mono, bool chirality) {
|
||||||
this.mono = mono;
|
this.mono = mono;
|
||||||
this.chirality = chirality;
|
this.chirality = chirality;
|
||||||
this.reachCursor = new ReachCursor(mono, chirality);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vec3 cursor;
|
public Pose cursor;
|
||||||
|
Vec3 cursorDir;
|
||||||
|
|
||||||
public Grab? grabbed = null;
|
public Pull? pulling = null;
|
||||||
float stretchDeadzone = 0;
|
float stretchDeadzone = 0;
|
||||||
Vec3 pullPoint;
|
Vec3 pullPoint;
|
||||||
|
|
||||||
|
@ -25,39 +24,43 @@ public class Glove {
|
||||||
|
|
||||||
public void Step() {
|
public void Step() {
|
||||||
Pose shoulder = mono.Shoulder(chirality);
|
Pose shoulder = mono.Shoulder(chirality);
|
||||||
Con con = mono.Con(chirality); // !chirality
|
Con con = mono.Con(chirality), otherCon = mono.Con(!chirality);
|
||||||
|
|
||||||
pullPoint = con.pos;
|
pullPoint = con.pos;
|
||||||
|
// cursorDir = (con.pos - pullPoint).Normalized; // WRONG PLACE?
|
||||||
|
|
||||||
switch (grabbed) {
|
switch (pulling) {
|
||||||
case Grab.Stretch:
|
case Pull.Stretch:
|
||||||
|
pullPoint = otherCon.pos;
|
||||||
|
cursorDir = con.ori * Vec3.Forward;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Grab.Backhanded:
|
case Pull.Backhanded:
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (con.gripBtn.frameDown) {
|
if (otherCon.gripBtn.frameDown) {
|
||||||
// comparison evaluation
|
// comparison evaluation
|
||||||
grabbed = Grab.Stretch;
|
pulling = Pull.Stretch;
|
||||||
|
stretchDeadzone = Vec3.Distance(con.pos, otherCon.pos);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!con.gripBtn.held) {
|
if (!otherCon.gripBtn.held) {
|
||||||
// null
|
// null
|
||||||
grabbed = null;
|
pulling = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vec3 from = (shoulder.orientation * origin) + shoulder.position;
|
// Vec3 from = (shoulder.orientation * origin) + shoulder.position;
|
||||||
float stretch = Vec3.Distance(pullPoint, con.pos);
|
float stretch = Vec3.Distance(pullPoint, con.pos);
|
||||||
stretch = Math.Max(stretch - stretchDeadzone, 0);
|
stretch = Math.Max(stretch - stretchDeadzone, 0);
|
||||||
|
|
||||||
cursor = con.pos + (con.pos - pullPoint).Normalized * stretch * 3;
|
cursor.position = con.pos + cursorDir * stretch * 3;
|
||||||
|
|
||||||
Lines.Add(pullPoint, con.pos, new Color(1, 0, 1), 0.005f);
|
Lines.Add(pullPoint, con.pos, new Color(1, 0, 1), 0.005f);
|
||||||
Lines.Add(con.pos, cursor, new Color(0, 1, 1), 0.005f);
|
Lines.Add(con.pos, cursor.position, new Color(0, 1, 1), 0.005f);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -92,5 +95,16 @@ public class Glove {
|
||||||
// rightGripDown = false;
|
// rightGripDown = false;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
Render(con.Pose(), cursor);
|
||||||
|
}
|
||||||
|
|
||||||
|
// decouple the rendering
|
||||||
|
// render-relevent DATA that gets streamed over the network
|
||||||
|
// that way we can render the same way for all peers
|
||||||
|
static Mesh mesh = Default.MeshCube;
|
||||||
|
static Material mat = Default.Material;
|
||||||
|
public void Render(Pose pose, Pose cursor) {
|
||||||
|
mesh.Draw(mat, pose.ToMatrix(new Vec3(0.025f, 0.1f, 0.1f)));
|
||||||
|
mesh.Draw(mat, cursor.ToMatrix(Vec3.One * 0.035f));
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -25,15 +25,19 @@ public class Con {
|
||||||
public Btn triggerBtn;
|
public Btn triggerBtn;
|
||||||
|
|
||||||
public void Step(bool chirality) {
|
public void Step(bool chirality) {
|
||||||
device = Input.Controller(Handed.Right);
|
device = Input.Controller(chirality ? Handed.Right : Handed.Left);
|
||||||
pos = device.pose.position;
|
pos = device.pose.position;
|
||||||
ori = device.aim.orientation;
|
ori = device.aim.orientation;
|
||||||
gripBtn.Step(device.grip > 0.5f);
|
gripBtn.Step(device.grip > 0.5f);
|
||||||
triggerBtn.Step(device.trigger > 0.5f);
|
triggerBtn.Step(device.trigger > 0.5f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Pose Pose() {
|
||||||
|
return new Pose(pos, ori);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Btn {
|
public struct Btn {
|
||||||
public bool frameDown, held, frameUp;
|
public bool frameDown, held, frameUp;
|
||||||
|
|
||||||
public void Step(bool down) {
|
public void Step(bool down) {
|
||||||
|
@ -46,6 +50,10 @@ public class Btn {
|
||||||
public class Monolith {
|
public class Monolith {
|
||||||
public Mic mic;
|
public Mic mic;
|
||||||
|
|
||||||
|
public Con rCon = new Con(), lCon = new Con();
|
||||||
|
public Con Con(bool chirality) {
|
||||||
|
return chirality ? rCon : lCon;
|
||||||
|
}
|
||||||
public Pose rShoulder, lShoulder;
|
public Pose rShoulder, lShoulder;
|
||||||
public Pose Shoulder(bool chirality) {
|
public Pose Shoulder(bool chirality) {
|
||||||
return chirality ? rShoulder : lShoulder;
|
return chirality ? rShoulder : lShoulder;
|
||||||
|
@ -58,10 +66,6 @@ public class Monolith {
|
||||||
public Glove Glove(bool chirality) {
|
public Glove Glove(bool chirality) {
|
||||||
return chirality ? rGlove : lGlove;
|
return chirality ? rGlove : lGlove;
|
||||||
}
|
}
|
||||||
public Con rCon, lCon;
|
|
||||||
public Con Con(bool chirality) {
|
|
||||||
return chirality ? rCon : lCon;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Vec3 rDragStart, lDragStart;
|
public Vec3 rDragStart, lDragStart;
|
||||||
public float railT;
|
public float railT;
|
||||||
|
@ -72,8 +76,11 @@ public class Monolith {
|
||||||
|
|
||||||
public void Run() {
|
public void Run() {
|
||||||
Renderer.SetClip(0.02f, 1000f);
|
Renderer.SetClip(0.02f, 1000f);
|
||||||
// Renderer.
|
|
||||||
// mic = new Mic();
|
// mic = new Mic();
|
||||||
|
rGlove = new Glove(this, true);
|
||||||
|
lGlove = new Glove(this, false);
|
||||||
|
|
||||||
|
|
||||||
Vec3 pos = new Vec3(0, 0, 0);
|
Vec3 pos = new Vec3(0, 0, 0);
|
||||||
Vec3 vel = new Vec3(0, 0, 0);
|
Vec3 vel = new Vec3(0, 0, 0);
|
||||||
|
|
||||||
|
@ -106,12 +113,6 @@ public class Monolith {
|
||||||
|
|
||||||
SpatialCursor cubicFlow = new CubicFlow(this);
|
SpatialCursor cubicFlow = new CubicFlow(this);
|
||||||
|
|
||||||
Tex camTex = new Tex(TexType.Rendertarget);
|
|
||||||
camTex.SetSize(600, 400);
|
|
||||||
Material camMat = new Material(Shader.Unlit);
|
|
||||||
camMat.SetTexture("diffuse", camTex);
|
|
||||||
Mesh quad = Default.MeshQuad;
|
|
||||||
|
|
||||||
Vec3 gripPos = Vec3.Zero;
|
Vec3 gripPos = Vec3.Zero;
|
||||||
|
|
||||||
|
|
||||||
|
@ -123,10 +124,10 @@ public class Monolith {
|
||||||
|
|
||||||
while (SK.Step(() => {
|
while (SK.Step(() => {
|
||||||
Renderer.CameraRoot = Matrix.T(pos);
|
Renderer.CameraRoot = Matrix.T(pos);
|
||||||
|
|
||||||
rCon.Step(true);
|
rCon.Step(true);
|
||||||
lCon.Step(false);
|
lCon.Step(false);
|
||||||
|
|
||||||
|
|
||||||
// Shoulders
|
// Shoulders
|
||||||
Vec3 headPos = Input.Head.position + Input.Head.Forward * -0.15f;
|
Vec3 headPos = Input.Head.position + Input.Head.Forward * -0.15f;
|
||||||
Vec3 shoulderDir = (
|
Vec3 shoulderDir = (
|
||||||
|
@ -137,19 +138,29 @@ public class Monolith {
|
||||||
if (Vec3.Dot(shoulderDir, Input.Head.Forward) < 0) { shoulderDir = -shoulderDir; }
|
if (Vec3.Dot(shoulderDir, Input.Head.Forward) < 0) { shoulderDir = -shoulderDir; }
|
||||||
rShoulder = new Pose(headPos + Quat.LookDir(shoulderDir) * new Vec3(0.2f, -0.2f, 0), Quat.LookDir(shoulderDir));
|
rShoulder = new Pose(headPos + Quat.LookDir(shoulderDir) * new Vec3(0.2f, -0.2f, 0), Quat.LookDir(shoulderDir));
|
||||||
lShoulder = new Pose(headPos + Quat.LookDir(shoulderDir) * new Vec3(-0.2f, -0.2f, 0), Quat.LookDir(shoulderDir));
|
lShoulder = new Pose(headPos + Quat.LookDir(shoulderDir) * new Vec3(-0.2f, -0.2f, 0), Quat.LookDir(shoulderDir));
|
||||||
|
|
||||||
|
// Wrists
|
||||||
rWrist = new Pose(rCon.pos + rCon.ori * new Vec3(0, 0, 0.052f), rCon.ori);
|
rWrist = new Pose(rCon.pos + rCon.ori * new Vec3(0, 0, 0.052f), rCon.ori);
|
||||||
lWrist = new Pose(lCon.pos + lCon.ori * new Vec3(0, 0, 0.052f), lCon.ori);
|
lWrist = new Pose(lCon.pos + lCon.ori * new Vec3(0, 0, 0.052f), lCon.ori);
|
||||||
|
|
||||||
|
// Gloves
|
||||||
|
rGlove.Step();
|
||||||
|
lGlove.Step();
|
||||||
|
|
||||||
|
|
||||||
// past this point more questions arise
|
// past this point more questions arise
|
||||||
|
|
||||||
cubicFlow.Step(new Pose[] { new Pose(rightReachCursor.p0, rCon.ori), new Pose(leftReachCursor.p0, lCon.ori) }, 1);
|
// cubicFlow.Step(new Pose[] { new Pose(rightReachCursor.p0, rCon.ori), new Pose(leftReachCursor.p0, lCon.ori) }, 1);
|
||||||
if (rCon.stick.y > 0.1f || lCon.stick.y > 0.1f) {
|
// if (rCon.stick.y > 0.1f || lCon.stick.y > 0.1f) {
|
||||||
Bezier.Draw(cubicFlow.p0, cubicFlow.p1, cubicFlow.p2, cubicFlow.p3, Color.White);
|
// 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;
|
// net.me.cursor0 = cubicFlow.p0; net.me.cursor1 = cubicFlow.p1; net.me.cursor2 = cubicFlow.p2; net.me.cursor3 = cubicFlow.p3;
|
||||||
} else {
|
// } else {
|
||||||
net.me.cursor0 = rightReachCursor.p0; net.me.cursor1 = rightReachCursor.p0; net.me.cursor2 = leftReachCursor.p0; net.me.cursor3 = leftReachCursor.p0;
|
// net.me.cursor0 = rightReachCursor.p0; net.me.cursor1 = rightReachCursor.p0; net.me.cursor2 = leftReachCursor.p0; net.me.cursor3 = leftReachCursor.p0;
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// throw yourself (delta -> vel -> momentum)
|
// throw yourself (delta -> vel -> momentum)
|
||||||
// bring rails back
|
// bring rails back
|
||||||
|
|
Loading…
Add table
Reference in a new issue