naive roll
This commit is contained in:
parent
097377a89e
commit
0384bc6494
5 changed files with 183 additions and 106 deletions
60
app/Mono.cs
60
app/Mono.cs
|
@ -44,18 +44,18 @@ public class Mono {
|
||||||
Renderer.SetClip(0.02f, 1000f);
|
Renderer.SetClip(0.02f, 1000f);
|
||||||
|
|
||||||
dofs = new dof[] {
|
dofs = new dof[] {
|
||||||
new Chiral() {
|
new Chiral(new dof[] {
|
||||||
dofs = new dof[] {
|
new RollsCursor() { handed = Handed.Left },
|
||||||
|
new RollsCursor() { handed = Handed.Right }
|
||||||
|
}),
|
||||||
|
new Chiral(new dof[] {
|
||||||
new WaveCursor() { handed = Handed.Left },
|
new WaveCursor() { handed = Handed.Left },
|
||||||
new WaveCursor() { handed = Handed.Right }
|
new WaveCursor() { handed = Handed.Right }
|
||||||
}
|
}),
|
||||||
},
|
new Chiral(new dof[] {
|
||||||
new Chiral() {
|
|
||||||
dofs = new dof[] {
|
|
||||||
new Trackballer() { handed = Handed.Left },
|
new Trackballer() { handed = Handed.Left },
|
||||||
new Trackballer() { handed = Handed.Right }
|
new Trackballer() { handed = Handed.Right }
|
||||||
}
|
}),
|
||||||
},
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,30 +122,31 @@ public class Mono {
|
||||||
}
|
}
|
||||||
|
|
||||||
// <Heresy>
|
// <Heresy>
|
||||||
WaveCursor lwc = (WaveCursor)((Chiral)dofs[0]).dofs[0];
|
// WaveCursor lwc = (WaveCursor)((Chiral)dofs[0]).dofs[0];
|
||||||
WaveCursor rwc = (WaveCursor)((Chiral)dofs[0]).dofs[1];
|
// WaveCursor rwc = (WaveCursor)((Chiral)dofs[0]).dofs[1];
|
||||||
Trackballer ltb = (Trackballer)((Chiral)dofs[1]).dofs[0];
|
// Trackballer ltb = (Trackballer)((Chiral)dofs[1]).dofs[0];
|
||||||
Trackballer rtb = (Trackballer)((Chiral)dofs[1]).dofs[1];
|
// Trackballer rtb = (Trackballer)((Chiral)dofs[1]).dofs[1];
|
||||||
|
|
||||||
if (lwc.Active) {
|
// if (lwc.Active) {
|
||||||
lwc.Demo(ltb.ori);
|
// lwc.Demo(ltb.ori);
|
||||||
}
|
// }
|
||||||
if (rwc.Active) {
|
// if (rwc.Active) {
|
||||||
rwc.Demo(rtb.ori);
|
// rwc.Demo(rtb.ori);
|
||||||
}
|
// }
|
||||||
|
|
||||||
if (rtb.Active) {
|
// if (rtb.Active) {
|
||||||
rtb.Demo();
|
// rtb.Demo();
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
// if (!shapeHeld) {
|
||||||
|
// shapeHeld = rtb.btnPush.frameDown;
|
||||||
|
// }
|
||||||
|
// if (shapeHeld) {
|
||||||
|
// shape.position = rwc.cursor.smooth;
|
||||||
|
// shape.orientation = rtb.ori;
|
||||||
|
// shapeHeld = !rtb.btnPull.frameDown;
|
||||||
|
// }
|
||||||
|
|
||||||
if (!shapeHeld) {
|
|
||||||
shapeHeld = rtb.btnPush.frameDown;
|
|
||||||
}
|
|
||||||
if (shapeHeld) {
|
|
||||||
shape.position = rwc.cursor.smooth;
|
|
||||||
shape.orientation = rtb.ori;
|
|
||||||
shapeHeld = !rtb.btnPull.frameDown;
|
|
||||||
}
|
|
||||||
// I'd rather have it be pose.pos & pose.ori
|
// I'd rather have it be pose.pos & pose.ori
|
||||||
// as it's a bit of space hog
|
// as it's a bit of space hog
|
||||||
|
|
||||||
|
@ -261,6 +262,7 @@ public class Mono {
|
||||||
|
|
||||||
// Chiral : handedness implies symmetry
|
// Chiral : handedness implies symmetry
|
||||||
public class Chiral : dof {
|
public class Chiral : dof {
|
||||||
|
public Chiral(dof[] dofs) => this.dofs = dofs;
|
||||||
private bool active;
|
private bool active;
|
||||||
public bool Active {
|
public bool Active {
|
||||||
get { return this.active; }
|
get { return this.active; }
|
||||||
|
|
|
@ -83,6 +83,21 @@ public class Rig {
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public float Flexion(Hand hand, FingerId finger, float deadzone = 0.3f) {
|
||||||
|
float flexion = (Vec3.Dot(
|
||||||
|
PullRequest.Direction(
|
||||||
|
hand.Get(finger, JointId.Tip).position,
|
||||||
|
hand.Get(finger, JointId.KnuckleMinor).position
|
||||||
|
),
|
||||||
|
PullRequest.Direction(
|
||||||
|
hand.Get(finger, JointId.KnuckleMid).position,
|
||||||
|
hand.Get(finger, JointId.KnuckleMajor).position
|
||||||
|
)
|
||||||
|
) + 1f) / 2;
|
||||||
|
|
||||||
|
return Math.Max(flexion - deadzone, 0f) / (1 - deadzone);
|
||||||
|
}
|
||||||
|
|
||||||
public Vec3 Fullstick(bool chirality) {
|
public Vec3 Fullstick(bool chirality) {
|
||||||
Controller con = Con(chirality).device;
|
Controller con = Con(chirality).device;
|
||||||
Quat rot = Quat.FromAngles(con.stick.y * -90, 0, con.stick.x * 90);
|
Quat rot = Quat.FromAngles(con.stick.y * -90, 0, con.stick.x * 90);
|
||||||
|
|
17
app/Space.cs
17
app/Space.cs
|
@ -183,14 +183,20 @@ public class Space {
|
||||||
float r; // damage
|
float r; // damage
|
||||||
float g; // resources
|
float g; // resources
|
||||||
float b; // peak
|
float b; // peak
|
||||||
|
Vec3 pos;
|
||||||
|
float angle;
|
||||||
// color(r, max(g, b), b)
|
// color(r, max(g, b), b)
|
||||||
// height = b
|
// height = b
|
||||||
|
|
||||||
public void Frame() {
|
public void Frame() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
|
/*
|
||||||
|
COMMENTS
|
||||||
|
|
||||||
sapling
|
sapling
|
||||||
e
|
e
|
||||||
|
@ -214,7 +220,7 @@ public class Space {
|
||||||
g -= e
|
g -= e
|
||||||
|
|
||||||
if g > 1 - r
|
if g > 1 - r
|
||||||
seed(g)
|
seed(g, pos + Quat.FromAngles(0, noise.value * 360f, 0) * b)
|
||||||
g = 0
|
g = 0
|
||||||
|
|
||||||
tilt towards best spot
|
tilt towards best spot
|
||||||
|
@ -226,9 +232,4 @@ public class Space {
|
||||||
if b > 1
|
if b > 1
|
||||||
poof
|
poof
|
||||||
|
|
||||||
seed
|
*/
|
||||||
g = what was passed down
|
|
||||||
pos = parent.pos + Quat.FromAngles(0, noise.value * 360f, 0) * parent.r // lol
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
}
|
|
73
app/dofs/rolls-cursor/RollsCursor.cs
Normal file
73
app/dofs/rolls-cursor/RollsCursor.cs
Normal file
|
@ -0,0 +1,73 @@
|
||||||
|
namespace Oriels;
|
||||||
|
|
||||||
|
class RollsCursor : dof {
|
||||||
|
public bool Active { get; set; }
|
||||||
|
|
||||||
|
// input
|
||||||
|
public Handed handed = Handed.Left;
|
||||||
|
|
||||||
|
// data
|
||||||
|
public Cursor cursor = new Cursor();
|
||||||
|
|
||||||
|
public void Init() { }
|
||||||
|
|
||||||
|
public void Frame() {
|
||||||
|
Rig rig = Mono.inst.rig;
|
||||||
|
Hand hand = Input.Hand(handed);
|
||||||
|
if (hand.tracked.IsActive() && !hand.tracked.IsJustActive()) {
|
||||||
|
float fI = rig.Flexion(hand, FingerId.Index);
|
||||||
|
float fM = rig.Flexion(hand, FingerId.Middle);
|
||||||
|
float fR = rig.Flexion(hand, FingerId.Ring);
|
||||||
|
float fL = rig.Flexion(hand, FingerId.Little);
|
||||||
|
|
||||||
|
// Biased by finger length
|
||||||
|
float stretch = (fI + fI + fM + fM + fM + fR + fR + fL) / 8f;
|
||||||
|
|
||||||
|
Vec3 to = Roll(hand, JointId.Tip, fI, fM, fR, fL);
|
||||||
|
Vec3 from = Roll(hand, JointId.KnuckleMajor, fI, fM, fR, fL);
|
||||||
|
|
||||||
|
Vec3 dir = PullRequest.Direction(to, from);
|
||||||
|
|
||||||
|
cursor.raw = to + dir * stretch * reach.value;
|
||||||
|
|
||||||
|
Mesh.Sphere.Draw(Mono.inst.matHoloframe, Matrix.TRS(cursor.raw, Quat.Identity, 0.01f), new Color(1, 0, 0));
|
||||||
|
Mesh.Sphere.Draw(Mono.inst.matHoloframe, Matrix.TRS(cursor.pos, Quat.Identity, 0.01f), new Color(0, 1, 0));
|
||||||
|
Mesh.Sphere.Draw(Mono.inst.matHoloframe, Matrix.TRS(cursor.smooth, Quat.Identity, 0.01f), new Color(0, 0, 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// design
|
||||||
|
public Design reach = new Design { str = "1.0", term = "0+m", min = 0 };
|
||||||
|
|
||||||
|
// Roll
|
||||||
|
// based on flexion
|
||||||
|
// with a "recursive" lerp
|
||||||
|
// i - m - r - l
|
||||||
|
// im - mr - rl
|
||||||
|
// imr - mrl
|
||||||
|
// imrl
|
||||||
|
public Vec3 Roll(Hand hand, JointId jointId, float fI, float fM, float fR, float fL) {
|
||||||
|
Vec3 i = hand.Get(FingerId.Index, jointId).position;
|
||||||
|
Vec3 m = hand.Get(FingerId.Middle, jointId).position;
|
||||||
|
Vec3 r = hand.Get(FingerId.Ring, jointId).position;
|
||||||
|
Vec3 l = hand.Get(FingerId.Little, jointId).position;
|
||||||
|
|
||||||
|
Vec3 im = Vec3.Lerp(i , m , fM / (fM + fI));
|
||||||
|
Vec3 mr = Vec3.Lerp( m , r , fR / (fR + fM));
|
||||||
|
Vec3 rl = Vec3.Lerp( r, l, fL / (fL + fR));
|
||||||
|
|
||||||
|
Vec3 imr = Vec3.Lerp(im , mr , fR / (fR + fM + fI));
|
||||||
|
Vec3 mrl = Vec3.Lerp( mr, rl, fL / (fL + fR + fM));
|
||||||
|
|
||||||
|
Vec3 imrl = Vec3.Lerp(imr, mrl, fL / (fL + fR + fM + fI));
|
||||||
|
|
||||||
|
return imrl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
COMMENTS
|
||||||
|
|
||||||
|
*/
|
|
@ -12,22 +12,23 @@ class WaveCursor : dof {
|
||||||
public void Init() {}
|
public void Init() {}
|
||||||
|
|
||||||
public void Frame() {
|
public void Frame() {
|
||||||
|
Rig rig = Mono.inst.rig;
|
||||||
Hand hand = Input.Hand(handed);
|
Hand hand = Input.Hand(handed);
|
||||||
if (hand.tracked.IsActive() && !hand.tracked.IsJustActive()) {
|
if (hand.tracked.IsActive() && !hand.tracked.IsJustActive()) {
|
||||||
float fI = Flexion(hand, FingerId.Index);
|
float fI = rig.Flexion(hand, FingerId.Index);
|
||||||
float fM = Flexion(hand, FingerId.Middle);
|
float fM = rig.Flexion(hand, FingerId.Middle);
|
||||||
float fR = Flexion(hand, FingerId.Ring);
|
float fR = rig.Flexion(hand, FingerId.Ring);
|
||||||
float fL = Flexion(hand, FingerId.Little);
|
float fL = rig.Flexion(hand, FingerId.Little);
|
||||||
|
|
||||||
// Biased by finger length
|
// Biased by finger length
|
||||||
float stretch = (fI + fI + fM + fM + fM + fR + fR + fL) / 8f;
|
float stretch = (fI + fI + fM + fM + fM + fR + fR + fL) / 8f;
|
||||||
|
|
||||||
Vec3 dir = PullRequest.Direction(
|
Vec3 to = hand.Get(FingerId.Index, JointId.Tip).position;
|
||||||
hand.Get(FingerId.Index, JointId.Tip).position,
|
Vec3 from = hand.Get(FingerId.Index, JointId.KnuckleMajor).position;
|
||||||
hand.Get(FingerId.Index, JointId.KnuckleMajor).position
|
|
||||||
);
|
|
||||||
|
|
||||||
cursor.raw = hand.Get(FingerId.Index, JointId.Tip).position + dir * stretch * reach.value;
|
Vec3 dir = PullRequest.Direction(to, from);
|
||||||
|
|
||||||
|
cursor.raw = to + dir * stretch * reach.value;
|
||||||
|
|
||||||
Mesh.Sphere.Draw(Mono.inst.matHoloframe, Matrix.TRS(cursor.raw, Quat.Identity, 0.01f), new Color(1, 0, 0));
|
Mesh.Sphere.Draw(Mono.inst.matHoloframe, Matrix.TRS(cursor.raw, Quat.Identity, 0.01f), new Color(1, 0, 0));
|
||||||
Mesh.Sphere.Draw(Mono.inst.matHoloframe, Matrix.TRS(cursor.pos, Quat.Identity, 0.01f), new Color(0, 1, 0));
|
Mesh.Sphere.Draw(Mono.inst.matHoloframe, Matrix.TRS(cursor.pos, Quat.Identity, 0.01f), new Color(0, 1, 0));
|
||||||
|
@ -36,23 +37,8 @@ class WaveCursor : dof {
|
||||||
}
|
}
|
||||||
|
|
||||||
// design
|
// design
|
||||||
public Design deadzone = new Design { str="0.3", term="0+1t", min=0, max=1 };
|
|
||||||
public Design reach = new Design { str="1.0", term="0+m", min=0 };
|
public Design reach = new Design { str="1.0", term="0+m", min=0 };
|
||||||
|
|
||||||
float Flexion(Hand hand, FingerId finger) {
|
|
||||||
float flexion = (Vec3.Dot(
|
|
||||||
PullRequest.Direction(
|
|
||||||
hand.Get(finger, JointId.Tip).position,
|
|
||||||
hand.Get(finger, JointId.KnuckleMinor).position
|
|
||||||
),
|
|
||||||
PullRequest.Direction(
|
|
||||||
hand.Get(finger, JointId.KnuckleMid).position,
|
|
||||||
hand.Get(finger, JointId.KnuckleMajor).position
|
|
||||||
)
|
|
||||||
) + 1f) / 2;
|
|
||||||
|
|
||||||
return Math.Max(flexion - deadzone.value, 0f) / (1 - deadzone.value);
|
|
||||||
}
|
|
||||||
|
|
||||||
// demo
|
// demo
|
||||||
public Design snakeLength = new Design { str="0.5", term="0+1t", min=0, max=1 };
|
public Design snakeLength = new Design { str="0.5", term="0+1t", min=0, max=1 };
|
||||||
|
|
Loading…
Add table
Reference in a new issue