horizon snapping
This commit is contained in:
parent
ba17e09029
commit
4022a93ad1
3 changed files with 23 additions and 10 deletions
|
@ -87,7 +87,7 @@ public class Mono {
|
||||||
ShowWindowButton();
|
ShowWindowButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
Pose windowPoseButton = new Pose(0, 0, 0.25f, Quat.Identity);
|
Pose windowPoseButton = new Pose(0, 0, 0.75f, Quat.Identity);
|
||||||
void ShowWindowButton() {
|
void ShowWindowButton() {
|
||||||
UI.WindowBegin("Window Button", ref windowPoseButton);
|
UI.WindowBegin("Window Button", ref windowPoseButton);
|
||||||
|
|
||||||
|
|
27
app/Oriel.cs
27
app/Oriel.cs
|
@ -49,6 +49,8 @@ public class Oriel {
|
||||||
public bool scaling;
|
public bool scaling;
|
||||||
|
|
||||||
public Vec3 cursor = Vec3.Zero;
|
public Vec3 cursor = Vec3.Zero;
|
||||||
|
public Quat cursorOri = Quat.Identity;
|
||||||
|
public Color cursorColor = Color.White;
|
||||||
public float cursorRadius = 0.1f;
|
public float cursorRadius = 0.1f;
|
||||||
public float cornerRadius;
|
public float cornerRadius;
|
||||||
|
|
||||||
|
@ -71,13 +73,13 @@ public class Oriel {
|
||||||
// input
|
// input
|
||||||
Rig rig = Mono.inst.rig;
|
Rig rig = Mono.inst.rig;
|
||||||
Glove rGlove = Mono.inst.rGlove;
|
Glove rGlove = Mono.inst.rGlove;
|
||||||
Quat rGloveRot = rGlove.virtualGlove.orientation;
|
|
||||||
// Vec3 lGlovePos = rig.lGlove.virtualGlove.position;
|
// Vec3 lGlovePos = rig.lGlove.virtualGlove.position;
|
||||||
|
|
||||||
bool onpress = rig.rCon.triggerBtn.frameDown;
|
bool onpress = rig.rCon.triggerBtn.frameDown;
|
||||||
bool held = rig.rCon.triggerBtn.held;
|
bool held = rig.rCon.triggerBtn.held;
|
||||||
bool onlift = rig.rCon.triggerBtn.frameUp;
|
bool onlift = rig.rCon.triggerBtn.frameUp;
|
||||||
cursor = rGlove.virtualGlove.position;
|
cursor = rGlove.virtualGlove.position;
|
||||||
|
cursorOri = rGlove.virtualGlove.orientation;
|
||||||
|
|
||||||
// bool onpress = Input.Key(Key.Space).IsJustActive();
|
// bool onpress = Input.Key(Key.Space).IsJustActive();
|
||||||
// bool held = Input.Key(Key.Space).IsActive();
|
// bool held = Input.Key(Key.Space).IsActive();
|
||||||
|
@ -92,12 +94,12 @@ public class Oriel {
|
||||||
// cursor += input.Normalized * Time.Elapsedf * 0.4f;
|
// cursor += input.Normalized * Time.Elapsedf * 0.4f;
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
// cursorOri = Quat.FromAngles(MathF.Sin(Time.Totalf) * 15, 0, 0);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Vec3 localCursor = matrixInv.Transform(cursor);
|
Vec3 localCursor = matrixInv.Transform(cursor);
|
||||||
|
|
||||||
// ori = Quat.FromAngles(0, MathF.Sin(Time.Totalf) * 90f, 0);
|
|
||||||
|
|
||||||
|
|
||||||
if (!interacting) {
|
if (!interacting) {
|
||||||
// generate all the potential anchors
|
// generate all the potential anchors
|
||||||
// pick the closest one
|
// pick the closest one
|
||||||
|
@ -106,6 +108,7 @@ public class Oriel {
|
||||||
for (int i = 0; i < anchors.Length; i++) {
|
for (int i = 0; i < anchors.Length; i++) {
|
||||||
Vec3 a = matrix.Transform(anchors[i] * bounds.dimensions / 2);
|
Vec3 a = matrix.Transform(anchors[i] * bounds.dimensions / 2);
|
||||||
float dist = (a - cursor).Length;
|
float dist = (a - cursor).Length;
|
||||||
|
// Vec3.Dot((bounds.center - rig.Head.position).Normalized, (matrix.Transform(anchors[i]) - bounds.center).Normalized) > 0 &&
|
||||||
if (dist < minDist) {
|
if (dist < minDist) {
|
||||||
minDist = dist;
|
minDist = dist;
|
||||||
v = anchors[i];
|
v = anchors[i];
|
||||||
|
@ -117,7 +120,7 @@ public class Oriel {
|
||||||
|
|
||||||
vOffset = cursor - bounds.center;
|
vOffset = cursor - bounds.center;
|
||||||
lOffset = ori.Inverse * vOffset;
|
lOffset = ori.Inverse * vOffset;
|
||||||
qOffset = (ori.Inverse * rGloveRot).Normalized;
|
qOffset = (ori.Inverse * cursorOri).Normalized;
|
||||||
mOffset = matrix;
|
mOffset = matrix;
|
||||||
|
|
||||||
interacting = onpress;
|
interacting = onpress;
|
||||||
|
@ -127,7 +130,13 @@ public class Oriel {
|
||||||
|
|
||||||
if (interacting) {
|
if (interacting) {
|
||||||
if (detectCount == 1) { // Move (face -> crown *face)
|
if (detectCount == 1) { // Move (face -> crown *face)
|
||||||
ori = (rGloveRot * qOffset.Inverse).Normalized;
|
ori = (cursorOri * qOffset.Inverse).Normalized;
|
||||||
|
// gravity snapping (within 6 degrees) *horizontal
|
||||||
|
// always? *here **tilt = nosnap
|
||||||
|
if (Vec3.Dot(-Vec3.Up, ori * -Vec3.Up) > 0.9998f) {
|
||||||
|
Vec3 fwd = ori * Vec3.Forward;
|
||||||
|
ori = Quat.LookDir(fwd.X0Z.Normalized);
|
||||||
|
}
|
||||||
bounds.center = cursor - ori * lOffset;
|
bounds.center = cursor - ori * lOffset;
|
||||||
|
|
||||||
interacting = held;
|
interacting = held;
|
||||||
|
@ -215,7 +224,7 @@ public class Oriel {
|
||||||
|
|
||||||
|
|
||||||
// cursor
|
// cursor
|
||||||
Color col = new Color(0.333f, 0.333f, 0.333f);
|
Color col = new Color(0.15f, 0.15f, 0.15f);
|
||||||
float thk = 0.005f;
|
float thk = 0.005f;
|
||||||
if (detectCount == 1 || detectCount == 2) {
|
if (detectCount == 1 || detectCount == 2) {
|
||||||
Vec3 edge = Vec3.One - detect.Abs();
|
Vec3 edge = Vec3.One - detect.Abs();
|
||||||
|
@ -281,8 +290,8 @@ public class Oriel {
|
||||||
}
|
}
|
||||||
|
|
||||||
meshCube.Draw(Material.Default,
|
meshCube.Draw(Material.Default,
|
||||||
Matrix.TS(cursor, new Vec3(0.01f, 0.01f, 0.01f)),
|
Matrix.TRS(cursor, cursorOri, new Vec3(0.04f, 0.01f, 0.04f)),
|
||||||
new Color(1f, 1f, 1f)
|
cursorColor
|
||||||
);
|
);
|
||||||
|
|
||||||
meshSphere.Draw(matClear,
|
meshSphere.Draw(matClear,
|
||||||
|
|
|
@ -57,6 +57,10 @@ public static class PullRequest {
|
||||||
return new Vec3(0, 0, v.z);
|
return new Vec3(0, 0, v.z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// public static Vec3 Down {
|
||||||
|
// get { return new Vec3(0, -1, 0); }
|
||||||
|
// }
|
||||||
|
|
||||||
public static Vec3 Abs(this Vec3 v) {
|
public static Vec3 Abs(this Vec3 v) {
|
||||||
return new Vec3(
|
return new Vec3(
|
||||||
MathF.Abs(v.x),
|
MathF.Abs(v.x),
|
||||||
|
|
Loading…
Add table
Reference in a new issue