backrooms, oriel refactor, bad scaling
This commit is contained in:
parent
d69e6fc55d
commit
39a587a3c1
15 changed files with 424 additions and 136 deletions
BIN
add/backrooms/Carpet.png
Normal file
BIN
add/backrooms/Carpet.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 MiB |
BIN
add/backrooms/Ceiling.png
Normal file
BIN
add/backrooms/Ceiling.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 294 KiB |
BIN
add/backrooms/Lights.png
Normal file
BIN
add/backrooms/Lights.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 770 B |
BIN
add/backrooms/Vents.png
Normal file
BIN
add/backrooms/Vents.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 180 KiB |
BIN
add/backrooms/Walls.png
Normal file
BIN
add/backrooms/Walls.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.1 MiB |
BIN
add/backrooms/backrooms.blend
Normal file
BIN
add/backrooms/backrooms.blend
Normal file
Binary file not shown.
BIN
add/backrooms/backrooms.glb
Normal file
BIN
add/backrooms/backrooms.glb
Normal file
Binary file not shown.
|
@ -83,6 +83,7 @@ float4 ps(psIn input) : SV_TARGET {
|
||||||
float3 ro = input.campos;
|
float3 ro = input.campos;
|
||||||
float3 rd = normalize(input.world - ro);
|
float3 rd = normalize(input.world - ro);
|
||||||
float ol = raymarch(ro, rd);
|
float ol = raymarch(ro, rd);
|
||||||
|
|
||||||
clip(-(100 - (ol + 1)));
|
clip(-(100 - (ol + 1)));
|
||||||
// if ((100 - (ol + 1)) > 0) {
|
// if ((100 - (ol + 1)) > 0) {
|
||||||
// col *= 0.1;
|
// col *= 0.1;
|
||||||
|
|
|
@ -2,50 +2,118 @@ using Oriels;
|
||||||
|
|
||||||
namespace Greenyard;
|
namespace Greenyard;
|
||||||
public class Mono {
|
public class Mono {
|
||||||
Model greenyardModel = Model.FromFile("greenyard.glb");
|
// Model greenyardModel = Model.FromFile("greenyard.glb");
|
||||||
Mesh[] greenyard;
|
// Mesh[] greenyard;
|
||||||
Material greenyardMat = new Material(Shader.FromFile("/shaders/oriel.hlsl"));
|
// Material greenyardMat = new Material(Shader.FromFile("/shaders/oriel.hlsl"));
|
||||||
|
|
||||||
Vec3 offset = new Vec3(0, 0, 0);
|
Vec3 offset = new Vec3(2, 0, -2);
|
||||||
|
|
||||||
|
Thing[] thing;
|
||||||
|
Model model = Model.FromFile("/backrooms/backrooms.glb");
|
||||||
|
|
||||||
public Mono() {
|
public Mono() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Init() {
|
public void Init() {
|
||||||
greenyard = new Mesh[12];
|
// greenyard = new Mesh[12];
|
||||||
for (int i = 0; i < greenyard.Length; i++) {
|
// for (int i = 0; i < greenyard.Length; i++) {
|
||||||
greenyard[i] = greenyardModel.GetMesh("Object_" + (i + 2));
|
// greenyard[i] = greenyardModel.GetMesh("Object_" + (i + 2));
|
||||||
}
|
// }
|
||||||
greenyardMat.SetMat(101, Cull.None, true);
|
// greenyardMat.SetMat(101, Cull.None, true);
|
||||||
greenyardMat.SetTexture("diffuse", Tex.FromFile("greenyard.jpeg"));
|
// greenyardMat.SetTexture("diffuse", Tex.FromFile("greenyard.jpeg"));
|
||||||
|
|
||||||
|
thing = new Thing[] {
|
||||||
|
new Thing(
|
||||||
|
model.GetMesh("Carpet"),
|
||||||
|
new Material(Shader.FromFile("/shaders/oriel.hlsl")),
|
||||||
|
"backrooms/Carpet.png"
|
||||||
|
),
|
||||||
|
new Thing(
|
||||||
|
model.GetMesh("Walls"),
|
||||||
|
new Material(Shader.FromFile("/shaders/oriel.hlsl")),
|
||||||
|
"backrooms/Walls.png"
|
||||||
|
),
|
||||||
|
new Thing(
|
||||||
|
model.GetMesh("Ceiling"),
|
||||||
|
new Material(Shader.FromFile("/shaders/oriel.hlsl")),
|
||||||
|
"backrooms/Ceiling.png"
|
||||||
|
),
|
||||||
|
new Thing(
|
||||||
|
model.GetMesh("Vents"),
|
||||||
|
new Material(Shader.FromFile("/shaders/oriel.hlsl")),
|
||||||
|
"backrooms/Vents.png"
|
||||||
|
),
|
||||||
|
new Thing(
|
||||||
|
model.GetMesh("Lights"),
|
||||||
|
new Material(Shader.FromFile("/shaders/oriel.hlsl")),
|
||||||
|
"backrooms/Lights.png"
|
||||||
|
),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Frame() {
|
public void Frame() {
|
||||||
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;
|
||||||
|
|
||||||
|
// Oriel
|
||||||
|
float scale = oriel.scale * oriel.multiplier;
|
||||||
|
if (oriel.scaleHeight) {
|
||||||
|
scale *= oriel.bounds.dimensions.y;
|
||||||
|
}
|
||||||
|
|
||||||
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.Identity,
|
||||||
Vec3.One * 0.1f * oriel.bounds.dimensions.y
|
Vec3.One * scale
|
||||||
);
|
);
|
||||||
|
|
||||||
// Render
|
// Render
|
||||||
greenyardMat.SetVector("_center", oriel.bounds.center);
|
// greenyardMat.SetVector("_center", oriel.bounds.center);
|
||||||
greenyardMat.SetVector("_dimensions", oriel.bounds.dimensions);
|
// greenyardMat.SetVector("_dimensions", oriel.bounds.dimensions);
|
||||||
greenyardMat.SetVector("_light", oriel.ori * new Vec3(0.6f, -0.9f, 0.3f));
|
// greenyardMat.SetVector("_light", oriel.ori * new Vec3(0.6f, -0.9f, 0.3f));
|
||||||
greenyardMat.SetFloat("_lit", 0);
|
// greenyardMat.SetFloat("_lit", 0);
|
||||||
greenyardMat["_matrix"] = (Matrix)System.Numerics.Matrix4x4.Transpose(oriel.matrix);
|
// greenyardMat["_matrix"] = (Matrix)System.Numerics.Matrix4x4.Transpose(oriel.matrixInv);
|
||||||
for (int i = 0; i < greenyard.Length; i++) {
|
// for (int i = 0; i < greenyard.Length; i++) {
|
||||||
greenyard[i].Draw(greenyardMat,
|
// greenyard[i].Draw(greenyardMat,
|
||||||
|
// Matrix.TRS(
|
||||||
|
// offset,
|
||||||
|
// Quat.Identity,
|
||||||
|
// new Vec3(1f, 1f, 1f)
|
||||||
|
// ) * simMatrix * oriel.matrix,
|
||||||
|
// Color.White
|
||||||
|
// );
|
||||||
|
// }
|
||||||
|
|
||||||
|
for (int i = 0; i < thing.Length; i++) {
|
||||||
|
Thing t = thing[i];
|
||||||
|
t.mat.SetVector("_center", oriel.bounds.center);
|
||||||
|
t.mat.SetVector("_dimensions", oriel.bounds.dimensions);
|
||||||
|
t.mat.SetVector("_light", oriel.ori * new Vec3(0.6f, -0.9f, 0.3f));
|
||||||
|
t.mat.SetFloat("_lit", 0);
|
||||||
|
t.mat["_matrix"] = (Matrix)System.Numerics.Matrix4x4.Transpose(oriel.matrixInv);
|
||||||
|
t.mesh.Draw(t.mat,
|
||||||
Matrix.TRS(
|
Matrix.TRS(
|
||||||
offset,
|
offset,
|
||||||
Quat.Identity,
|
Quat.Identity,
|
||||||
new Vec3(1f, 1f, 1f)
|
new Vec3(1f, 1f, 1f)
|
||||||
) * simMatrix * oriel.matrix.Inverse,
|
) * simMatrix * oriel.matrix,
|
||||||
Color.White
|
Color.White
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
public class Thing {
|
||||||
|
public Mesh mesh;
|
||||||
|
public Material mat;
|
||||||
|
|
||||||
|
public Thing(Mesh mesh, Material mat, string tex) {
|
||||||
|
this.mesh = mesh;
|
||||||
|
this.mat = mat;
|
||||||
|
|
||||||
|
mat.SetMat(101, Cull.None, true);
|
||||||
|
mat.SetTexture("diffuse", Tex.FromFile(tex));
|
||||||
|
}
|
||||||
|
}
|
132
app/Mono.cs
132
app/Mono.cs
|
@ -46,6 +46,7 @@ public class Mono {
|
||||||
|
|
||||||
// Space.Mono spaceMono = new Space.Mono();
|
// Space.Mono spaceMono = new Space.Mono();
|
||||||
Greenyard.Mono greenyard = new Greenyard.Mono();
|
Greenyard.Mono greenyard = new Greenyard.Mono();
|
||||||
|
Board board = new Board();
|
||||||
|
|
||||||
|
|
||||||
PullRequest.PID pid = new PullRequest.PID(8, 0.8f);
|
PullRequest.PID pid = new PullRequest.PID(8, 0.8f);
|
||||||
|
@ -55,7 +56,6 @@ public class Mono {
|
||||||
public void Step() {
|
public void Step() {
|
||||||
|
|
||||||
rig.Step();
|
rig.Step();
|
||||||
scene.Step();
|
|
||||||
|
|
||||||
// -------------------------------------------------
|
// -------------------------------------------------
|
||||||
|
|
||||||
|
@ -67,28 +67,154 @@ public class Mono {
|
||||||
|
|
||||||
// colorCube.Palm(lCon.device);
|
// colorCube.Palm(lCon.device);
|
||||||
|
|
||||||
oriel.Step();
|
oriel.Frame();
|
||||||
|
|
||||||
|
scene.Step(); // after! (render scene after oriel)
|
||||||
|
|
||||||
// -------------------------------------------------
|
// -------------------------------------------------
|
||||||
|
|
||||||
// spaceMono.Frame();
|
// spaceMono.Frame();
|
||||||
greenyard.Frame();
|
greenyard.Frame();
|
||||||
|
// board.Frame();
|
||||||
|
|
||||||
// -------------------------------------------------
|
// -------------------------------------------------
|
||||||
|
|
||||||
|
oriel.Render();
|
||||||
|
|
||||||
net.me.Step();
|
net.me.Step();
|
||||||
net.send = true;
|
net.send = true;
|
||||||
|
|
||||||
ShowWindowButton();
|
ShowWindowButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
Pose windowPoseButton = new Pose(0, 0, -1, Quat.Identity);
|
Pose windowPoseButton = new Pose(0, 0, -0.5f, Quat.Identity);
|
||||||
void ShowWindowButton() {
|
void ShowWindowButton() {
|
||||||
UI.WindowBegin("Window Button", ref windowPoseButton);
|
UI.WindowBegin("Window Button", ref windowPoseButton);
|
||||||
|
|
||||||
if (UI.Button("Reset Oriel Quat")) { oriel.ori = Quat.Identity; }
|
if (UI.Button("Reset Oriel Quat")) { oriel.ori = Quat.Identity; }
|
||||||
// if (UI.Button("Draw Oriel Axis")) { oriel.drawAxis = !oriel.drawAxis; }
|
// if (UI.Button("Draw Oriel Axis")) { oriel.drawAxis = !oriel.drawAxis; }
|
||||||
|
if (UI.Button("Scale w/Height")) { oriel.scaleHeight = !oriel.scaleHeight; }
|
||||||
|
UI.HSlider("Scale", ref oriel.scale, 0.1f, 1f, 0.1f);
|
||||||
|
UI.HSlider("Multiplier", ref oriel.multiplier, 0.1f, 1f, 0.1f);
|
||||||
|
|
||||||
|
|
||||||
UI.WindowEnd();
|
UI.WindowEnd();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
public class Board {
|
||||||
|
// velocity button controls
|
||||||
|
// "center off mass" thrust vector steering
|
||||||
|
|
||||||
|
Mesh meshCube = Mesh.Cube;
|
||||||
|
|
||||||
|
public bool goofy = false;
|
||||||
|
|
||||||
|
public Vec3 front, back, pos, dir, vector;
|
||||||
|
public float vel;
|
||||||
|
|
||||||
|
float length = 1.5f;
|
||||||
|
public Board() {
|
||||||
|
front = new Vec3(0, 0, -1) * length / 2;
|
||||||
|
back = new Vec3(0, 0, 1) * length / 2;
|
||||||
|
dir = new Vec3(0, 0, -1);
|
||||||
|
vel = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Frame() {
|
||||||
|
// tilt steer ("back wheel" turns *rudder)
|
||||||
|
// button velocity controls
|
||||||
|
Con con = goofy ? Mono.inst.rig.rCon : Mono.inst.rig.lCon;
|
||||||
|
float accel = con.device.trigger;
|
||||||
|
float deccel = con.device.grip;
|
||||||
|
float lean = Mono.inst.rig.LocalPos(Mono.inst.rig.Head.position).x;
|
||||||
|
|
||||||
|
// float length = 1.5f;
|
||||||
|
float drag = 0.1f;
|
||||||
|
float speed = 4f;
|
||||||
|
float brake = 12f;
|
||||||
|
float tight = 60f;
|
||||||
|
|
||||||
|
|
||||||
|
// velocity
|
||||||
|
vel *= 1f - (drag * Time.Elapsedf);
|
||||||
|
vel += accel * speed * Time.Elapsedf;
|
||||||
|
vel = MathF.Max(vel - deccel * brake * Time.Elapsedf, 0);
|
||||||
|
|
||||||
|
// steering
|
||||||
|
vector = Quat.LookDir(dir) * Quat.FromAngles(0, lean * tight, 0) * Vec3.Forward;
|
||||||
|
back += vector * vel * Time.Elapsedf;
|
||||||
|
dir = (front - back).Normalized;
|
||||||
|
|
||||||
|
front = back + dir * length;
|
||||||
|
pos = Vec3.Lerp(front, back, 0.5f);
|
||||||
|
|
||||||
|
|
||||||
|
Mono.inst.rig.pos = pos;
|
||||||
|
Mono.inst.rig.ori = Quat.LookDir(dir);
|
||||||
|
|
||||||
|
// hover
|
||||||
|
// if (rig.lCon.gripBtn.held) {
|
||||||
|
// rig.pos.y = pid.Update(rig.LocalPos(rig.Head.position).y);
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
meshCube.Draw(Material.Default,
|
||||||
|
Matrix.TRS(
|
||||||
|
Mono.inst.rig.FloorCenter,
|
||||||
|
Quat.LookDir(dir),
|
||||||
|
new Vec3(0.05f, 0.2f, 0.2f)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
// mini board in hand for debugging
|
||||||
|
// meshCube.Draw(Material.Default,
|
||||||
|
// Matrix.TRS(
|
||||||
|
// rig.rCon.pos,
|
||||||
|
// board.ori,
|
||||||
|
// new Vec3(0.4f, 0.1f, reach * 2) * 0.1f
|
||||||
|
// )
|
||||||
|
// );
|
||||||
|
// // front wheel
|
||||||
|
// meshCube.Draw(Material.Default,
|
||||||
|
// Matrix.TRS(
|
||||||
|
// rig.rCon.pos + board.dir * reach * 0.1f,
|
||||||
|
// Quat.LookDir(frontDir),
|
||||||
|
// new Vec3(0.05f, 0.2f, 0.2f) * 0.1f
|
||||||
|
// )
|
||||||
|
// );
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// pillars to hover through
|
||||||
|
// spawn in front every 1m away from last
|
||||||
|
if (Vec3.Distance(pos, lastSpawnPos) > 1f) {
|
||||||
|
// odd or even
|
||||||
|
float chirality = pillarIndex % 2 == 0 ? 1f : -1f;
|
||||||
|
pillars[pillarIndex] = pos + Quat.LookDir(dir) * new Vec3(chirality * 8 * Mono.inst.noise.uvalue, 0, -24);
|
||||||
|
|
||||||
|
lastSpawnPos = pos;
|
||||||
|
|
||||||
|
pillarIndex++;
|
||||||
|
if (pillarIndex >= pillars.Length) { pillarIndex = 0; }
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < pillars.Length; i++) {
|
||||||
|
meshCube.Draw(Material.Default,
|
||||||
|
Matrix.TRS(
|
||||||
|
pillars[i],
|
||||||
|
Quat.Identity,
|
||||||
|
new Vec3(0.1f, 20f, 0.1f)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Vec3[] pillars = new Vec3[64];
|
||||||
|
int pillarIndex = 0;
|
||||||
|
Vec3 lastSpawnPos = Vec3.Zero;
|
||||||
|
}
|
303
app/Oriel.cs
303
app/Oriel.cs
|
@ -1,32 +1,29 @@
|
||||||
namespace Oriels;
|
namespace Oriels;
|
||||||
|
|
||||||
public class Oriel {
|
public class Oriel {
|
||||||
|
Model model = Model.FromFile("oriel.glb");
|
||||||
|
Mesh meshCube, meshSphere;
|
||||||
|
|
||||||
|
Material matClear = new Material(Shader.Default);
|
||||||
|
|
||||||
|
public Material matOriel = new Material(Shader.FromFile("shaders/oriel.hlsl"));
|
||||||
Material matFrame = new Material(Shader.FromFile("shaders/frame.hlsl"));
|
Material matFrame = new Material(Shader.FromFile("shaders/frame.hlsl"));
|
||||||
Material matPanes = new Material(Shader.FromFile("shaders/panes.hlsl"));
|
Material matPanes = new Material(Shader.FromFile("shaders/panes.hlsl"));
|
||||||
public Material matOriel = new Material(Shader.FromFile("shaders/oriel.hlsl"));
|
|
||||||
Model model = Model.FromFile("oriel.glb");
|
|
||||||
Mesh meshCube;
|
|
||||||
|
|
||||||
|
public Matrix matrix, matrixInv;
|
||||||
public Bounds bounds;
|
public Bounds bounds;
|
||||||
public Quat ori;
|
public Quat ori = Quat.Identity;
|
||||||
public Matrix matrix;
|
|
||||||
public float crown = 0.0666f;
|
|
||||||
|
|
||||||
bool adjusting = false;
|
// inner matrix
|
||||||
Quat qOffset = Quat.Identity;
|
public bool scaleHeight = true;
|
||||||
Vec3 vOffset = Vec3.Zero;
|
public float scale = 0.1f;
|
||||||
Vec3 lOffset = Vec3.Zero;
|
public float multiplier = 1f;
|
||||||
Vec3 anchor = Vec3.Zero;
|
|
||||||
Matrix mOffset = Matrix.Identity;
|
|
||||||
|
|
||||||
public Oriel() {
|
public Oriel() {
|
||||||
bounds = new Bounds(
|
// meshCube = model.GetMesh("oriel");
|
||||||
new Vec3(-1.0f, -0.5f, 0.0f),
|
meshCube = Mesh.Cube;
|
||||||
new Vec3(0.8f, 0.5f, 0.5f)
|
meshSphere = Mesh.Sphere;
|
||||||
);
|
matClear.Transparency = Transparency.Add;
|
||||||
|
|
||||||
ori = Quat.Identity;
|
|
||||||
matrix = Matrix.TR(bounds.center, ori).Inverse;
|
|
||||||
|
|
||||||
matFrame.SetMat(102, Cull.Back, true);
|
matFrame.SetMat(102, Cull.Back, true);
|
||||||
matFrame.Transparency = Transparency.Blend;
|
matFrame.Transparency = Transparency.Blend;
|
||||||
|
@ -34,128 +31,214 @@ public class Oriel {
|
||||||
matPanes.SetMat(100, Cull.Front, false);
|
matPanes.SetMat(100, Cull.Front, false);
|
||||||
matOriel.SetMat(101, Cull.None, true);
|
matOriel.SetMat(101, Cull.None, true);
|
||||||
|
|
||||||
meshCube = Mesh.Cube;
|
bounds = new Bounds(
|
||||||
// meshCube = model.GetMesh("oriel");
|
new Vec3(-1.0f, -0.5f, 0.5f),
|
||||||
|
new Vec3(0.8f, 0.5f, 0.5f)
|
||||||
|
);
|
||||||
|
matrix = Matrix.TR(bounds.center, ori);
|
||||||
|
matrixInv = matrix.Inverse;
|
||||||
|
|
||||||
|
|
||||||
|
cursor = bounds.center;
|
||||||
|
cornerRadius = cursorRadius / 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Vec3 cursor = Vec3.Zero;
|
||||||
|
public float cursorRadius = 0.1f;
|
||||||
|
public float cornerRadius;
|
||||||
|
|
||||||
Vec3 detect = Vec3.Zero;
|
Vec3 detect = Vec3.Zero;
|
||||||
int detectCount = 0;
|
int detectCount = 0;
|
||||||
public void Step() {
|
public Vec3 LocalAnchor { get { return detect * bounds.dimensions / 2; } }
|
||||||
matrix = Matrix.TR(bounds.center, ori).Inverse;
|
public Vec3 Anchor { get { return matrix.Transform(LocalAnchor); } }
|
||||||
|
|
||||||
|
Quat qOffset = Quat.Identity;
|
||||||
|
Vec3 vOffset = Vec3.Zero;
|
||||||
|
Vec3 lOffset = Vec3.Zero;
|
||||||
|
Matrix mOffset = Matrix.Identity;
|
||||||
|
public void Frame() {
|
||||||
|
// input
|
||||||
Rig rig = Mono.inst.rig;
|
Rig rig = Mono.inst.rig;
|
||||||
Glove rGlove = Mono.inst.rGlove;
|
Glove rGlove = Mono.inst.rGlove;
|
||||||
Vec3 rGlovePos = rGlove.virtualGlove.position;
|
// cursor = rGlove.virtualGlove.position;
|
||||||
Quat rGloveRot = rGlove.virtualGlove.orientation;
|
Quat rGloveRot = rGlove.virtualGlove.orientation;
|
||||||
// Vec3 lGlovePos = rig.lGlove.virtualGlove.position;
|
// Vec3 lGlovePos = rig.lGlove.virtualGlove.position;
|
||||||
|
bool grab = !Input.Key(Key.Space).IsActive(); // !rig.rCon.triggerBtn.held
|
||||||
|
|
||||||
// face detection = (1 axis)
|
if (!Input.Key(Key.Shift).IsActive()) {
|
||||||
// edge detection = (2 axis)
|
Vec3 input = new Vec3(
|
||||||
// corner detection = (3 axis)
|
(Input.Key(Key.S).IsActive() ? 1 : 0) - (Input.Key(Key.A).IsActive() ? 1 : 0),
|
||||||
// Pose pose = new Pose();
|
(Input.Key(Key.F).IsActive() ? 1 : 0) - (Input.Key(Key.Q).IsActive() ? 1 : 0),
|
||||||
|
(Input.Key(Key.R).IsActive() ? 1 : 0) - (Input.Key(Key.W).IsActive() ? 1 : 0)
|
||||||
|
|
||||||
Vec3 localPos = ori.Inverse * (rGlovePos - bounds.center);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if (!rig.rCon.triggerBtn.held) {
|
|
||||||
float margin = PullRequest.Lerp(0.03f, 0.5f, bounds.dimensions.y / 2);
|
|
||||||
Vec3 newDetect = Vec3.Zero;
|
|
||||||
if ((bounds.dimensions.x / 2) - MathF.Abs(localPos.x) < 0) newDetect.x = 1 * MathF.Sign(localPos.x);
|
|
||||||
if ((bounds.dimensions.y / 2) - MathF.Abs(localPos.y) < 0) newDetect.y = 1 * MathF.Sign(localPos.y);
|
|
||||||
if ((bounds.dimensions.z / 2) - MathF.Abs(localPos.z) < 0) newDetect.z = 1 * MathF.Sign(localPos.z);
|
|
||||||
|
|
||||||
if (newDetect.x != detect.x || newDetect.y != detect.y || newDetect.z != detect.z) {
|
|
||||||
detect = newDetect;
|
|
||||||
detectCount = (int)(MathF.Abs(detect.x) + MathF.Abs(detect.y) + MathF.Abs(detect.z));
|
|
||||||
// Console.WriteLine(detectCount + ": " + detect);
|
|
||||||
}
|
|
||||||
|
|
||||||
Vec3 dim = new Vec3(
|
|
||||||
bounds.dimensions.x + 0.1f,
|
|
||||||
bounds.dimensions.y + 0.1f,
|
|
||||||
bounds.dimensions.z + 0.1f
|
|
||||||
);
|
);
|
||||||
Bounds arounds = new Bounds(Vec3.Zero, dim);
|
if (input.Length > 0) {
|
||||||
if (!arounds.Contains(localPos) || bounds.Contains(bounds.center + localPos)) {
|
cursor += input.Normalized * Time.Elapsedf * 0.4f;
|
||||||
detect = Vec3.Zero;
|
}
|
||||||
detectCount = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vOffset = rGlovePos - bounds.center;
|
Vec3 localCursor = matrixInv.Transform(cursor);
|
||||||
|
|
||||||
|
// ori = Quat.FromAngles(0, MathF.Sin(Time.Totalf) * 90f, 0);
|
||||||
|
|
||||||
|
|
||||||
|
if (grab) {
|
||||||
|
// generate all the potential anchors
|
||||||
|
// pick the closest one
|
||||||
|
Vec3 v = Vec3.Zero;
|
||||||
|
float minDist = float.MaxValue;
|
||||||
|
for (int i = 0; i < anchors.Length; i++) {
|
||||||
|
Vec3 a = matrix.Transform(anchors[i] * bounds.dimensions / 2);
|
||||||
|
float dist = (a - cursor).Length;
|
||||||
|
if (dist < minDist) {
|
||||||
|
minDist = dist;
|
||||||
|
v = anchors[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
detect = v; // rename this
|
||||||
|
detectCount = (int)(MathF.Abs(v.x) + MathF.Abs(v.y) + MathF.Abs(v.z));
|
||||||
|
|
||||||
|
vOffset = cursor - bounds.center;
|
||||||
lOffset = ori.Inverse * vOffset;
|
lOffset = ori.Inverse * vOffset;
|
||||||
qOffset = (ori.Inverse * rGloveRot).Normalized;
|
qOffset = (ori.Inverse * rGloveRot).Normalized;
|
||||||
mOffset = matrix;
|
mOffset = matrix;
|
||||||
anchor = bounds.center + ori * -(detect * bounds.dimensions / 2);
|
}
|
||||||
|
else {
|
||||||
adjusting = false;
|
if (detectCount == 1) { // Move (face -> crown *face)
|
||||||
} else {
|
|
||||||
if (detectCount == 1) { // Move
|
|
||||||
ori = (rGloveRot * qOffset.Inverse).Normalized;
|
ori = (rGloveRot * qOffset.Inverse).Normalized;
|
||||||
bounds.center = rGlovePos - ori * lOffset;
|
bounds.center = cursor - ori * lOffset;
|
||||||
} else if (detectCount == 2) { // Rotate
|
}
|
||||||
localPos = mOffset.Transform(rGlovePos);
|
else if (detectCount == 2) { // Rotate (edge -> edge)
|
||||||
Vec3 dir = new Vec3(
|
// localPos = mOffset.Inverse.Transform(cursor);
|
||||||
detect.x == 0 ? 0 : localPos.x,
|
// Vec3 dir = new Vec3(
|
||||||
detect.y == 0 ? 0 : localPos.y,
|
// detect.x == 0 ? 0 : localPos.x,
|
||||||
detect.z == 0 ? 0 : localPos.z
|
// detect.y == 0 ? 0 : localPos.y,
|
||||||
);
|
// detect.z == 0 ? 0 : localPos.z
|
||||||
|
// );
|
||||||
Vec3 up = new Vec3(
|
// Vec3 up = new Vec3(
|
||||||
detect.x == 0 ? 1 : 0,
|
// detect.x == 0 ? 1 : 0,
|
||||||
detect.y == 0 ? 1 : 0,
|
// detect.y == 0 ? 1 : 0,
|
||||||
detect.z == 0 ? 1 : 0
|
// detect.z == 0 ? 1 : 0
|
||||||
);
|
// );
|
||||||
|
|
||||||
Quat q = Quat.LookAt(Vec3.Zero, dir, up);
|
// Quat q = Quat.LookAt(Vec3.Zero, dir, up);
|
||||||
|
|
||||||
if (!adjusting) {
|
// if (!adjusting) {
|
||||||
qOffset = (q.Inverse * ori).Normalized;
|
// qOffset = (q.Inverse * ori).Normalized;
|
||||||
adjusting = true;
|
// adjusting = true;
|
||||||
} else {
|
// } else {
|
||||||
ori = (q * qOffset).Normalized;
|
// ori = (q * qOffset).Normalized;
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
else if (detectCount == 3) { // Scale (corner -> corner)
|
||||||
|
Vec3 zAnchor = Anchor - ori * detect.JustZ() * cornerRadius;
|
||||||
|
float stab = MathF.Max(cursorRadius - Vec3.Distance(zAnchor, cursor), 0);
|
||||||
|
|
||||||
|
if (stab > 0) {
|
||||||
|
float distZ = Math.Abs(-LocalAnchor.z - localCursor.z);
|
||||||
|
bounds.center.z = PullRequest.Lerp(matrix.Transform(-LocalAnchor).z, cursor.z, 0.5f);
|
||||||
|
bounds.dimensions.z = distZ;
|
||||||
}
|
}
|
||||||
} else if (detectCount == 3) { // Scale
|
|
||||||
Vec3 localAnchor = matrix.Transform(anchor);
|
|
||||||
float distX = Math.Abs(localAnchor.x - localPos.x);
|
|
||||||
float distY = Math.Abs(localAnchor.y - localPos.y);
|
|
||||||
float distZ = Math.Abs(localAnchor.z - localPos.z);
|
|
||||||
bounds.dimensions = new Vec3(distX, distY, distZ);
|
|
||||||
bounds.center = Vec3.Lerp(anchor, rGlovePos, 0.5f);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
matrix = Matrix.TR(bounds.center, ori);
|
||||||
matrix = Matrix.TR(bounds.center, ori).Inverse;
|
matrixInv = matrix.Inverse;
|
||||||
|
|
||||||
|
|
||||||
// matFrame.Wireframe = true;
|
|
||||||
matFrame.DepthTest = DepthTest.Always;
|
|
||||||
matFrame.SetVector("_rGlovePos", rGlovePos);
|
|
||||||
matFrame.SetFloat("_time", Time.Totalf);
|
|
||||||
meshCube.Draw(matFrame,
|
|
||||||
Matrix.TRS(bounds.center, ori, bounds.dimensions),
|
|
||||||
new Color(0.1f, 0.1f, 0.1f)
|
|
||||||
);
|
|
||||||
if (detectCount > 0) {
|
|
||||||
meshCube.Draw(Material.Default,
|
|
||||||
Matrix.TS(detect * (bounds.dimensions / 2), Vec3.One * 0.01f) * matrix.Inverse
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// design vars
|
||||||
|
public float crown = 0.16f;
|
||||||
|
|
||||||
|
public void Render() {
|
||||||
|
// // matFrame.Wireframe = true;
|
||||||
|
// matFrame.DepthTest = DepthTest.Always;
|
||||||
|
// matFrame.SetVector("_cursor", cursor);
|
||||||
|
// matFrame.SetFloat("_time", Time.Totalf);
|
||||||
|
// meshCube.Draw(matFrame,
|
||||||
|
// Matrix.TRS(bounds.center, ori, bounds.dimensions),
|
||||||
|
// new Color(0.1f, 0.1f, 0.1f)
|
||||||
|
// );
|
||||||
|
|
||||||
// matPanes.DepthTest = DepthTest.Greater;
|
// matPanes.DepthTest = DepthTest.Greater;
|
||||||
matPanes["_matrix"] = (Matrix)System.Numerics.Matrix4x4.Transpose(matrix);
|
matPanes["_matrix"] = (Matrix)System.Numerics.Matrix4x4.Transpose(matrixInv);
|
||||||
meshCube.Draw(matPanes,
|
meshCube.Draw(matPanes,
|
||||||
Matrix.TRS(bounds.center, ori, bounds.dimensions),
|
Matrix.TRS(bounds.center, ori, bounds.dimensions),
|
||||||
new Color(0.0f, 0.0f, 0.5f)
|
new Color(0f, 0f, 0f)
|
||||||
|
// new Color(78 / 256f, 142 / 256f, 191 / 256f)
|
||||||
);
|
);
|
||||||
|
|
||||||
matOriel.SetVector("_center", bounds.center);
|
matOriel.SetVector("_center", bounds.center);
|
||||||
matOriel.SetVector("_dimensions", bounds.dimensions);
|
matOriel.SetVector("_dimensions", bounds.dimensions);
|
||||||
matOriel.SetVector("_light", ori * new Vec3(0.6f, -0.9f, 0.3f));
|
matOriel.SetVector("_light", ori * new Vec3(0.6f, -0.9f, 0.3f));
|
||||||
matOriel.SetFloat("_lit", 1);
|
matOriel.SetFloat("_lit", 1);
|
||||||
matOriel["_matrix"] = (Matrix)System.Numerics.Matrix4x4.Transpose(matrix);
|
matOriel["_matrix"] = (Matrix)System.Numerics.Matrix4x4.Transpose(matrixInv);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// cursor
|
||||||
|
if (detectCount > 0) {
|
||||||
|
meshCube.Draw(Material.Default,
|
||||||
|
Matrix.TS(LocalAnchor, Vec3.One * 0.01f) * matrix
|
||||||
|
);
|
||||||
|
|
||||||
|
// draw the corner with 0.1f length lines
|
||||||
|
if (detectCount == 3) {
|
||||||
|
Color col = new Color(1f, 1f, 1f);
|
||||||
|
float thk = 0.005f;
|
||||||
|
Lines.Add(Anchor, Anchor - ori * detect.JustX() * cornerRadius, col, thk);
|
||||||
|
Lines.Add(Anchor, Anchor - ori * detect.JustY() * cornerRadius, col, thk);
|
||||||
|
Lines.Add(Anchor, Anchor - ori * detect.JustZ() * cornerRadius, col, thk);
|
||||||
|
|
||||||
|
// draw cube(s) on intersecting corner ends
|
||||||
|
|
||||||
|
// Lines.Add(
|
||||||
|
// zAnchor, zAnchor + ori * detect.JustZ() * stab * 1.5f,
|
||||||
|
// new Color(0, 0, 1), 0.01f
|
||||||
|
// );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
meshCube.Draw(Material.Default,
|
||||||
|
Matrix.TRS(cursor, Quat.Identity, new Vec3(0.01f, 0.01f, 0.01f)),
|
||||||
|
new Color(1f, 1f, 1f)
|
||||||
|
);
|
||||||
|
|
||||||
|
meshSphere.Draw(matClear,
|
||||||
|
Matrix.TRS(cursor, Quat.Identity, new Vec3(1f, 1f, 1f) * cursorRadius * 2),
|
||||||
|
new Color(0.5f, 0.5f, 0.5f)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// faces, edges, corners
|
||||||
|
Vec3[] anchors = new Vec3[] {
|
||||||
|
// faces
|
||||||
|
new Vec3(1, 0, 0),
|
||||||
|
new Vec3(-1, 0, 0),
|
||||||
|
new Vec3(0, 1, 0),
|
||||||
|
new Vec3(0, -1, 0),
|
||||||
|
new Vec3(0, 0, 1),
|
||||||
|
new Vec3(0, 0, -1),
|
||||||
|
// edges
|
||||||
|
new Vec3(1, 1, 0),
|
||||||
|
new Vec3(-1, 1, 0),
|
||||||
|
new Vec3(1, -1, 0),
|
||||||
|
new Vec3(-1, -1, 0),
|
||||||
|
new Vec3(1, 0, 1),
|
||||||
|
new Vec3(-1, 0, 1),
|
||||||
|
new Vec3(1, 0, -1),
|
||||||
|
new Vec3(-1, 0, -1),
|
||||||
|
new Vec3(0, 1, 1),
|
||||||
|
new Vec3(0, -1, 1),
|
||||||
|
new Vec3(0, 1, -1),
|
||||||
|
new Vec3(0, -1, -1),
|
||||||
|
// corners
|
||||||
|
new Vec3(1, 1, 1),
|
||||||
|
new Vec3(-1, 1, 1),
|
||||||
|
new Vec3(1, -1, 1),
|
||||||
|
new Vec3(-1, -1, 1),
|
||||||
|
new Vec3(1, 1, -1),
|
||||||
|
new Vec3(-1, 1, -1),
|
||||||
|
new Vec3(1, -1, -1),
|
||||||
|
new Vec3(-1, -1, -1)
|
||||||
|
};
|
||||||
}
|
}
|
|
@ -46,6 +46,16 @@ public static class PullRequest {
|
||||||
return (to - from).Normalized;
|
return (to - from).Normalized;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// swizzle
|
||||||
|
public static Vec3 JustX(this Vec3 v) {
|
||||||
|
return new Vec3(v.x, 0, 0);
|
||||||
|
}
|
||||||
|
public static Vec3 JustY(this Vec3 v) {
|
||||||
|
return new Vec3(0, v.y, 0);
|
||||||
|
}
|
||||||
|
public static Vec3 JustZ(this Vec3 v) {
|
||||||
|
return new Vec3(0, 0, v.z);
|
||||||
|
}
|
||||||
|
|
||||||
static Mesh meshCube = Default.MeshCube;
|
static Mesh meshCube = Default.MeshCube;
|
||||||
static Material matCube = Default.Material;
|
static Material matCube = Default.Material;
|
||||||
|
|
|
@ -43,7 +43,7 @@ public class Scene {
|
||||||
|
|
||||||
public void Step() {
|
public void Step() {
|
||||||
Oriel oriel = Mono.inst.oriel;
|
Oriel oriel = Mono.inst.oriel;
|
||||||
data.matrix = (Matrix)System.Numerics.Matrix4x4.Transpose(oriel.matrix);
|
data.matrix = (Matrix)System.Numerics.Matrix4x4.Transpose(oriel.matrixInv);
|
||||||
data.dimensions = oriel.bounds.dimensions;
|
data.dimensions = oriel.bounds.dimensions;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -73,7 +73,7 @@ public class Mono {
|
||||||
float stretch = Vec3.Distance(rig.lCon.pos, rig.rCon.pos);
|
float stretch = Vec3.Distance(rig.lCon.pos, rig.rCon.pos);
|
||||||
stretch = Math.Max(stretch - deadzone, 0);
|
stretch = Math.Max(stretch - deadzone, 0);
|
||||||
Vec3 cursor = rig.rCon.pos + rig.rCon.ori * Vec3.Forward * stretch * 3;
|
Vec3 cursor = rig.rCon.pos + rig.rCon.ori * Vec3.Forward * stretch * 3;
|
||||||
Vec3 localCursor = simMatrix.Inverse.Transform(oriel.matrix.Transform(cursor));
|
Vec3 localCursor = simMatrix.Inverse.Transform(oriel.matrixInv.Transform(cursor));
|
||||||
|
|
||||||
localCursor = new Vec3(
|
localCursor = new Vec3(
|
||||||
MathF.Sin(Time.Totalf * 2f) * 3f,
|
MathF.Sin(Time.Totalf * 2f) * 3f,
|
||||||
|
@ -97,7 +97,7 @@ public class Mono {
|
||||||
// RENDER
|
// RENDER
|
||||||
for (int i = 0; i < nodes.Length; i++) {
|
for (int i = 0; i < nodes.Length; i++) {
|
||||||
meshCube.Draw(oriel.matOriel,
|
meshCube.Draw(oriel.matOriel,
|
||||||
Matrix.TRS(nodes[i].pos, Quat.Identity, Vec3.One * 1f) * simMatrix * oriel.matrix.Inverse,
|
Matrix.TRS(nodes[i].pos, Quat.Identity, Vec3.One * 1f) * simMatrix * oriel.matrix,
|
||||||
Color.HSV(nodes[i].hue, 1f, 1f)
|
Color.HSV(nodes[i].hue, 1f, 1f)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -107,7 +107,7 @@ public class Mono {
|
||||||
new Color(1f, 1f, 1f)
|
new Color(1f, 1f, 1f)
|
||||||
);
|
);
|
||||||
meshCube.Draw(oriel.matOriel,
|
meshCube.Draw(oriel.matOriel,
|
||||||
Matrix.TRS(localCursor, Quat.Identity, Vec3.One * 0.02f) * simMatrix * oriel.matrix.Inverse,
|
Matrix.TRS(localCursor, Quat.Identity, Vec3.One * 0.02f) * simMatrix * oriel.matrix,
|
||||||
new Color(0f, 0f, 0f)
|
new Color(0f, 0f, 0f)
|
||||||
);
|
);
|
||||||
meshCube.Draw(oriel.matOriel,
|
meshCube.Draw(oriel.matOriel,
|
||||||
|
@ -115,7 +115,7 @@ public class Mono {
|
||||||
playerPos,
|
playerPos,
|
||||||
Quat.LookDir((localCursor - playerPos).Normalized),
|
Quat.LookDir((localCursor - playerPos).Normalized),
|
||||||
new Vec3(0.4f, 0.2f, 0.4f)
|
new Vec3(0.4f, 0.2f, 0.4f)
|
||||||
) * simMatrix * oriel.matrix.Inverse,
|
) * simMatrix * oriel.matrix,
|
||||||
new Color(1.0f, 0.0f, 0.05f)
|
new Color(1.0f, 0.0f, 0.05f)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -130,7 +130,7 @@ public class Mono {
|
||||||
// playerPos,
|
// playerPos,
|
||||||
// Quat.Identity,
|
// Quat.Identity,
|
||||||
// new Vec3(10f, 10f, 10f)
|
// new Vec3(10f, 10f, 10f)
|
||||||
// ) * simMatrix * oriel.matrix.Inverse,
|
// ) * simMatrix * oriel.matrix,
|
||||||
// Color.White
|
// Color.White
|
||||||
// );
|
// );
|
||||||
|
|
||||||
|
@ -195,7 +195,7 @@ public class Mono {
|
||||||
Matrix.TRS(enemies[i],
|
Matrix.TRS(enemies[i],
|
||||||
Quat.LookAt(enemies[i], playerPos, Vec3.Up),
|
Quat.LookAt(enemies[i], playerPos, Vec3.Up),
|
||||||
new Vec3(0.4f, 1f, 0.2f)
|
new Vec3(0.4f, 1f, 0.2f)
|
||||||
) * simMatrix * oriel.matrix.Inverse,
|
) * simMatrix * oriel.matrix,
|
||||||
Color.White * 0.62f
|
Color.White * 0.62f
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ SKSettings settings = new SKSettings {
|
||||||
assetsFolder = "add",
|
assetsFolder = "add",
|
||||||
depthMode = DepthMode.D32,
|
depthMode = DepthMode.D32,
|
||||||
disableUnfocusedSleep = true,
|
disableUnfocusedSleep = true,
|
||||||
// displayPreference = DisplayMode.Flatscreen,
|
displayPreference = DisplayMode.Flatscreen,
|
||||||
};
|
};
|
||||||
if (!SK.Initialize(settings))
|
if (!SK.Initialize(settings))
|
||||||
Environment.Exit(1);
|
Environment.Exit(1);
|
||||||
|
|
Loading…
Add table
Reference in a new issue