unbroken
This commit is contained in:
parent
52946f0573
commit
ba17e09029
4 changed files with 62 additions and 40 deletions
|
@ -104,9 +104,9 @@ psOut ps(psIn input) {
|
||||||
// clip(-1);
|
// clip(-1);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// if (dot(direction, input.normal) > 0) {
|
if (dot(direction, input.normal) > 0) {
|
||||||
// o.color = float4(0.5, 0.5, 0.5, 1);
|
o.color = float4(0, 0, 0, 1);
|
||||||
// }
|
}
|
||||||
|
|
||||||
return o;
|
return o;
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ public class Mono {
|
||||||
// Material greenyardMat = new Material(Shader.FromFile("/shaders/oriel.hlsl"));
|
// Material greenyardMat = new Material(Shader.FromFile("/shaders/oriel.hlsl"));
|
||||||
|
|
||||||
Vec3 offset = new Vec3(2, 0, -2);
|
Vec3 offset = new Vec3(2, 0, -2);
|
||||||
|
Vec3 angle = new Vec3(0, 0, 0);
|
||||||
|
|
||||||
Thing[] thing;
|
Thing[] thing;
|
||||||
Model model = Model.FromFile("/backrooms/backrooms.glb");
|
Model model = Model.FromFile("/backrooms/backrooms.glb");
|
||||||
|
@ -56,6 +57,21 @@ public class Mono {
|
||||||
Oriels.Rig rig = Oriels.Mono.inst.rig;
|
Oriels.Rig rig = Oriels.Mono.inst.rig;
|
||||||
Oriels.Oriel oriel = Oriels.Mono.inst.oriel;
|
Oriels.Oriel oriel = Oriels.Mono.inst.oriel;
|
||||||
|
|
||||||
|
// angle.x += rig.rCon.device.stick.y * Time.Elapsedf;
|
||||||
|
angle.y += rig.rCon.device.stick.x * -60f * Time.Elapsedf;
|
||||||
|
|
||||||
|
Vec3 input = new Vec3(
|
||||||
|
rig.lCon.device.stick.x,
|
||||||
|
0,
|
||||||
|
rig.lCon.device.stick.y
|
||||||
|
);
|
||||||
|
if (input.MagnitudeSq > 0.01f) {
|
||||||
|
offset += Quat.FromAngles(0, angle.y, 0).Inverse * input * Time.Elapsedf;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Oriel
|
// Oriel
|
||||||
float scale = oriel.scale * oriel.multiplier;
|
float scale = oriel.scale * oriel.multiplier;
|
||||||
if (oriel.scaleHeight) {
|
if (oriel.scaleHeight) {
|
||||||
|
@ -64,7 +80,7 @@ public class Mono {
|
||||||
|
|
||||||
Matrix simMatrix = Matrix.TRS(
|
Matrix simMatrix = Matrix.TRS(
|
||||||
new Vec3(0, -oriel.bounds.dimensions.y / 2.01f, 0),
|
new Vec3(0, -oriel.bounds.dimensions.y / 2.01f, 0),
|
||||||
Quat.Identity,
|
Quat.FromAngles(0, angle.y, 0),
|
||||||
Vec3.One * scale
|
Vec3.One * scale
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
59
app/Oriel.cs
59
app/Oriel.cs
|
@ -33,8 +33,10 @@ public class Oriel {
|
||||||
|
|
||||||
bounds = new Bounds(
|
bounds = new Bounds(
|
||||||
new Vec3(-1.0f, -0.5f, 0.5f),
|
new Vec3(-1.0f, -0.5f, 0.5f),
|
||||||
|
// Vec3.Zero,
|
||||||
new Vec3(0.8f, 0.5f, 0.5f)
|
new Vec3(0.8f, 0.5f, 0.5f)
|
||||||
);
|
);
|
||||||
|
ori = Quat.FromAngles(0, 90, 0);
|
||||||
matrix = Matrix.TR(bounds.center, ori);
|
matrix = Matrix.TR(bounds.center, ori);
|
||||||
matrixInv = matrix.Inverse;
|
matrixInv = matrix.Inverse;
|
||||||
|
|
||||||
|
@ -54,15 +56,17 @@ public class Oriel {
|
||||||
int detectCount = 0;
|
int detectCount = 0;
|
||||||
public Vec3 LocalAnchor { get { return detect * bounds.dimensions / 2; } }
|
public Vec3 LocalAnchor { get { return detect * bounds.dimensions / 2; } }
|
||||||
public Vec3 Anchor { get { return matrix.Transform(LocalAnchor); } }
|
public Vec3 Anchor { get { return matrix.Transform(LocalAnchor); } }
|
||||||
|
|
||||||
Vec3 cornerDetect = Vec3.Zero;
|
|
||||||
|
|
||||||
Vec3 anchorOffset = Vec3.Zero;
|
|
||||||
Vec3 localAnchorOffset = Vec3.Zero;
|
|
||||||
Quat qOffset = Quat.Identity;
|
Quat qOffset = Quat.Identity;
|
||||||
Vec3 vOffset = Vec3.Zero;
|
Vec3 vOffset = Vec3.Zero;
|
||||||
Vec3 lOffset = Vec3.Zero;
|
Vec3 lOffset = Vec3.Zero;
|
||||||
Matrix mOffset = Matrix.Identity;
|
Matrix mOffset = Matrix.Identity;
|
||||||
|
|
||||||
|
Vec3 cornerDetect = Vec3.Zero;
|
||||||
|
public Vec3 XAnchor { get { return LocalAnchor - detect.JustX() * cornerRadius; } }
|
||||||
|
public Vec3 YAnchor { get { return LocalAnchor - detect.JustY() * cornerRadius; } }
|
||||||
|
public Vec3 ZAnchor { get { return LocalAnchor - detect.JustZ() * cornerRadius; } }
|
||||||
|
Vec3 anchorOffset = Vec3.Zero;
|
||||||
|
|
||||||
public void Frame() {
|
public void Frame() {
|
||||||
// input
|
// input
|
||||||
Rig rig = Mono.inst.rig;
|
Rig rig = Mono.inst.rig;
|
||||||
|
@ -70,11 +74,10 @@ public class Oriel {
|
||||||
Quat rGloveRot = rGlove.virtualGlove.orientation;
|
Quat rGloveRot = rGlove.virtualGlove.orientation;
|
||||||
// Vec3 lGlovePos = rig.lGlove.virtualGlove.position;
|
// Vec3 lGlovePos = rig.lGlove.virtualGlove.position;
|
||||||
|
|
||||||
cursor = rGlove.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;
|
||||||
|
|
||||||
// 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();
|
||||||
|
@ -150,40 +153,27 @@ public class Oriel {
|
||||||
// } else {
|
// } else {
|
||||||
// ori = (q * qOffset).Normalized;
|
// ori = (q * qOffset).Normalized;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
interacting = held;
|
||||||
}
|
}
|
||||||
else if (detectCount == 3) { // Scale (corner -> corner)
|
else if (detectCount == 3) { // Scale (corner -> corner)
|
||||||
if (!scaling) {
|
if (!scaling) {
|
||||||
Vec3 xAnchor = Anchor - ori * detect.JustX() * cornerRadius;
|
|
||||||
Vec3 yAnchor = Anchor - ori * detect.JustY() * cornerRadius;
|
|
||||||
Vec3 zAnchor = Anchor - ori * detect.JustZ() * cornerRadius;
|
|
||||||
cornerDetect = new Vec3(
|
cornerDetect = new Vec3(
|
||||||
MathF.Max(cursorRadius - Vec3.Distance(xAnchor, cursor), 0),
|
MathF.Max(cursorRadius - Vec3.Distance(XAnchor, localCursor), 0),
|
||||||
MathF.Max(cursorRadius - Vec3.Distance(yAnchor, cursor), 0),
|
MathF.Max(cursorRadius - Vec3.Distance(YAnchor, localCursor), 0),
|
||||||
MathF.Max(cursorRadius - Vec3.Distance(zAnchor, cursor), 0)
|
MathF.Max(cursorRadius - Vec3.Distance(ZAnchor, localCursor), 0)
|
||||||
);
|
);
|
||||||
|
|
||||||
anchorOffset = cursor - Anchor;
|
anchorOffset = localCursor - LocalAnchor;
|
||||||
localAnchorOffset = localCursor - LocalAnchor;
|
|
||||||
|
|
||||||
scaling = onlift;
|
scaling = onlift;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scaling) {
|
if (scaling) {
|
||||||
if (cornerDetect.x > 0) {
|
Vec3 oldAnchor = Anchor;
|
||||||
float distX = Math.Abs(-LocalAnchor.x - localCursor.x + localAnchorOffset.x);
|
Vec3 delta = ((localCursor - anchorOffset) + LocalAnchor).Abs();
|
||||||
bounds.center.x = PullRequest.Lerp(matrix.Transform(-LocalAnchor).x, cursor.x - anchorOffset.x, 0.5f);
|
bounds.dimensions = bounds.dimensions.Splice(delta, cornerDetect, true);
|
||||||
bounds.dimensions.x = distX;
|
bounds.center += Anchor - oldAnchor;
|
||||||
}
|
|
||||||
if (cornerDetect.y > 0) {
|
|
||||||
float distY = Math.Abs(-LocalAnchor.y - localCursor.y + localAnchorOffset.y);
|
|
||||||
bounds.center.y = PullRequest.Lerp(matrix.Transform(-LocalAnchor).y, cursor.y - anchorOffset.y, 0.5f);
|
|
||||||
bounds.dimensions.y = distY;
|
|
||||||
}
|
|
||||||
if (cornerDetect.z > 0) {
|
|
||||||
float distZ = Math.Abs(-LocalAnchor.z - localCursor.z + localAnchorOffset.z);
|
|
||||||
bounds.center.z = PullRequest.Lerp(matrix.Transform(-LocalAnchor).z, cursor.z - anchorOffset.z, 0.5f);
|
|
||||||
bounds.dimensions.z = distZ;
|
|
||||||
}
|
|
||||||
|
|
||||||
scaling = !held;
|
scaling = !held;
|
||||||
interacting = !held;
|
interacting = !held;
|
||||||
|
@ -265,24 +255,21 @@ public class Oriel {
|
||||||
// draw cube(s) on intersecting corner ends
|
// draw cube(s) on intersecting corner ends
|
||||||
|
|
||||||
|
|
||||||
Vec3 xAnchor = Anchor - ori * detect.JustX() * cornerRadius;
|
|
||||||
if (cornerDetect.x > 0) {
|
if (cornerDetect.x > 0) {
|
||||||
meshCube.Draw(matClear,
|
meshCube.Draw(matClear,
|
||||||
Matrix.TS(xAnchor, Vec3.One * thk * 2),
|
Matrix.TS(XAnchor, Vec3.One * thk * 2) * matrix,
|
||||||
new Color(1, 0, 0)
|
new Color(1, 0, 0)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Vec3 yAnchor = Anchor - ori * detect.JustY() * cornerRadius;
|
|
||||||
if (cornerDetect.y > 0) {
|
if (cornerDetect.y > 0) {
|
||||||
meshCube.Draw(matClear,
|
meshCube.Draw(matClear,
|
||||||
Matrix.TS(yAnchor, Vec3.One * thk * 2),
|
Matrix.TS(YAnchor, Vec3.One * thk * 2) * matrix,
|
||||||
new Color(0, 1, 0)
|
new Color(0, 1, 0)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Vec3 zAnchor = Anchor - ori * detect.JustZ() * cornerRadius;
|
|
||||||
if (cornerDetect.z > 0) {
|
if (cornerDetect.z > 0) {
|
||||||
meshCube.Draw(matClear,
|
meshCube.Draw(matClear,
|
||||||
Matrix.TS(zAnchor, Vec3.One * thk * 2),
|
Matrix.TS(ZAnchor, Vec3.One * thk * 2) * matrix,
|
||||||
new Color(0, 0, 1)
|
new Color(0, 0, 1)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,6 +65,25 @@ public static class PullRequest {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Vec3 Sign(this Vec3 v) {
|
||||||
|
return new Vec3(
|
||||||
|
MathF.Sign(v.x),
|
||||||
|
MathF.Sign(v.y),
|
||||||
|
MathF.Sign(v.z)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// a(1,1,1) b(2,2,2) t(0,1,0.5) return(1,2,1.5)
|
||||||
|
/// </summary>
|
||||||
|
public static Vec3 Splice(this Vec3 a, Vec3 b, Vec3 t, bool nor = false) {
|
||||||
|
return new Vec3(
|
||||||
|
Lerp(a.x, b.x, nor ? MathF.Sign(t.x) : t.x),
|
||||||
|
Lerp(a.y, b.y, nor ? MathF.Sign(t.y) : t.y),
|
||||||
|
Lerp(a.z, b.z, nor ? MathF.Sign(t.z) : t.z)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
static Mesh meshCube = Default.MeshCube;
|
static Mesh meshCube = Default.MeshCube;
|
||||||
static Material matCube = Default.Material;
|
static Material matCube = Default.Material;
|
||||||
public static void BlockOut(Matrix m, Color color, Material mat = null) {
|
public static void BlockOut(Matrix m, Color color, Material mat = null) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue