no lift, new twist
This commit is contained in:
parent
fd530efdcc
commit
0de5825654
3 changed files with 49 additions and 5 deletions
10
README.md
10
README.md
|
@ -47,6 +47,16 @@ exec(vlai)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# bookmark(next page)
|
||||||
|
lift for all
|
||||||
|
|
||||||
|
glove visuals
|
||||||
|
*pull points
|
||||||
|
*mesh
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# m--
|
# m--
|
||||||
unity
|
unity
|
||||||
|
|
||||||
|
|
40
app/Glove.cs
40
app/Glove.cs
|
@ -20,14 +20,20 @@ public class Glove {
|
||||||
float stretch;
|
float stretch;
|
||||||
float stretchDeadzone = 0;
|
float stretchDeadzone = 0;
|
||||||
Vec3 pullPoint;
|
Vec3 pullPoint;
|
||||||
|
Vec3 twistPoint;
|
||||||
|
bool twistOut;
|
||||||
|
|
||||||
public void Step() {
|
public void Step() {
|
||||||
Pose shoulder = mono.Shoulder(chirality);
|
Pose shoulder = mono.Shoulder(chirality);
|
||||||
|
Pose wrist = mono.Wrist(chirality);
|
||||||
Con con = mono.Con(chirality), otherCon = mono.Con(!chirality);
|
Con con = mono.Con(chirality), otherCon = mono.Con(!chirality);
|
||||||
bool reach = con.device.IsX2Pressed;
|
bool reach = con.device.IsX2Pressed;
|
||||||
bool pull = otherCon.gripBtn.frameDown;
|
bool pull = otherCon.gripBtn.frameDown;
|
||||||
bool lift = con.device.IsX1Pressed;
|
bool lift = con.device.IsX1Pressed;
|
||||||
|
lift = false;
|
||||||
|
bool twist = con.device.IsX1Pressed;
|
||||||
|
|
||||||
|
// exclusive states?
|
||||||
|
|
||||||
if (reach) {
|
if (reach) {
|
||||||
// shoulder stuff
|
// shoulder stuff
|
||||||
|
@ -71,9 +77,20 @@ public class Glove {
|
||||||
}
|
}
|
||||||
|
|
||||||
stretch = Math.Max(Vec3.Distance(pullPoint, con.pos) - stretchDeadzone, 0);
|
stretch = Math.Max(Vec3.Distance(pullPoint, con.pos) - stretchDeadzone, 0);
|
||||||
|
|
||||||
|
if (!twist) { twistPoint = con.ori * Vec3.Up; }
|
||||||
|
Quat twistFrom = Quat.LookAt(Vec3.Zero, con.ori * Vec3.Forward, twistPoint);
|
||||||
|
if (twist) {
|
||||||
|
stretch = (float)(Math.Acos(Vec3.Dot(twistFrom * Vec3.Up, con.ori * Vec3.Up)) / Math.PI);
|
||||||
|
twistOut = Vec3.Dot(twistFrom * Vec3.Up, con.ori * Vec3.Right * (chirality ? 1 : -1)) > 0;
|
||||||
|
|
||||||
|
direction = con.ori * Vec3.Forward;
|
||||||
|
virtualGlove.orientation = twistFrom;
|
||||||
|
}
|
||||||
|
|
||||||
virtualGlove.position = con.pos + direction * stretch * 3;
|
virtualGlove.position = con.pos + direction * stretch * 3;
|
||||||
|
|
||||||
Render(con.Pose(), virtualGlove);
|
Render(con.Pose(), virtualGlove, wrist, twist, stretch, twistOut, twistFrom);
|
||||||
}
|
}
|
||||||
|
|
||||||
// decouple the rendering
|
// decouple the rendering
|
||||||
|
@ -81,10 +98,27 @@ public class Glove {
|
||||||
// that way we can render the same way for all peers
|
// that way we can render the same way for all peers
|
||||||
static Mesh mesh = Default.MeshCube;
|
static Mesh mesh = Default.MeshCube;
|
||||||
static Material mat = Default.Material;
|
static Material mat = Default.Material;
|
||||||
public void Render(Pose glove, Pose virtualGlove) {
|
public void Render(Pose glove, Pose virtualGlove, Pose wrist, bool twist, float stretch, bool twistOut, Quat twistFrom) {
|
||||||
Lines.Add(pullPoint, glove.position, new Color(1, 0, 1), 0.005f);
|
Lines.Add(pullPoint, glove.position, new Color(1, 0, 1), 0.005f);
|
||||||
Lines.Add(glove.position, virtualGlove.position, new Color(0, 1, 1), 0.005f);
|
Lines.Add(glove.position, virtualGlove.position, new Color(0, 1, 1), 0.005f);
|
||||||
|
|
||||||
|
// Twist
|
||||||
|
float twistValue = twist ? stretch : 0;
|
||||||
|
Lines.Add(
|
||||||
|
wrist.position + glove.orientation * Vec3.Up * 0.04f,
|
||||||
|
wrist.position + glove.orientation * Vec3.Up * 0.05f,
|
||||||
|
new Color(1, 1, 0), 0.005f
|
||||||
|
);
|
||||||
|
Vec3 lastPos = wrist.position;
|
||||||
|
for (int i = 0; i < 32; i++) {
|
||||||
|
float tw = twistValue * (i / 31f);
|
||||||
|
tw *= twistOut ? -1 : 1;
|
||||||
|
Vec3 nextPos = wrist.position + twistFrom * new Vec3(SKMath.Sin(tw * SKMath.Pi), SKMath.Cos(tw * SKMath.Pi), 0) * 0.05f;
|
||||||
|
|
||||||
|
Lines.Add(lastPos, nextPos, new Color(1, 1, 0), 0.005f); // convert to LinePoints ?
|
||||||
|
lastPos = nextPos;
|
||||||
|
}
|
||||||
|
|
||||||
mesh.Draw(mat, glove.ToMatrix(new Vec3(0.025f, 0.1f, 0.1f) / 3));
|
mesh.Draw(mat, glove.ToMatrix(new Vec3(0.025f, 0.1f, 0.1f) / 3));
|
||||||
mesh.Draw(mat, virtualGlove.ToMatrix(new Vec3(0.025f, 0.1f, 0.1f)));
|
mesh.Draw(mat, virtualGlove.ToMatrix(new Vec3(0.025f, 0.1f, 0.1f)));
|
||||||
}
|
}
|
||||||
|
|
|
@ -87,9 +87,9 @@ public class TwistCursor : SpatialCursor {
|
||||||
outty = Vec3.Dot(from * Vec3.Up, quat * Vec3.Right * (chirality ? 1 : -1)) > 0;
|
outty = Vec3.Dot(from * Vec3.Up, quat * Vec3.Right * (chirality ? 1 : -1)) > 0;
|
||||||
|
|
||||||
p0 = pos + quat * Vec3.Forward * twist * str;
|
p0 = pos + quat * Vec3.Forward * twist * str;
|
||||||
// model.Draw(Matrix.TS(p0, 0.02f));
|
|
||||||
|
|
||||||
// Lines.Add(pos, pos + from * Vec3.Up * 0.1f, new Color(1, 0, 1), 0.005f);
|
// Render
|
||||||
|
// model.Draw(Matrix.TS(p0, 0.02f));
|
||||||
Lines.Add(pos, pos + quat * Vec3.Up * 0.1f, new Color(1, 0, 1), 0.005f);
|
Lines.Add(pos, pos + quat * Vec3.Up * 0.1f, new Color(1, 0, 1), 0.005f);
|
||||||
Lines.Add(pos, p0, new Color(0, 1, 1), 0.005f);
|
Lines.Add(pos, p0, new Color(0, 1, 1), 0.005f);
|
||||||
// draw the twist (angle)
|
// draw the twist (angle)
|
||||||
|
|
Loading…
Add table
Reference in a new issue