refactored down to support a discrete app layer
This commit is contained in:
parent
75c529b3b2
commit
7b07a5ac89
16 changed files with 640 additions and 672 deletions
160
.past/DriftGrind.cs
Normal file
160
.past/DriftGrind.cs
Normal file
|
@ -0,0 +1,160 @@
|
|||
public class DriftGrind {
|
||||
|
||||
public Vec3 rDragStart, lDragStart;
|
||||
public float railT;
|
||||
|
||||
Vec3 pos = new Vec3(0, 0, 0);
|
||||
Vec3 vel = new Vec3(0, 0, 0);
|
||||
|
||||
public void Step() {
|
||||
// DRAG DRIFT
|
||||
// Vec3 rPos = net.me.cursor0;
|
||||
// Vec3 lPos = net.me.cursor3;
|
||||
|
||||
// use grip grab reach cursor origin it then becoming a backhanded stretch cursor
|
||||
// if (rCon.grip > 0.5f) {
|
||||
// if (!rightGripping) {
|
||||
// gripPos = rPos;
|
||||
// gripLeft = false;
|
||||
// rightGripping = true;
|
||||
// }
|
||||
// } else {
|
||||
// rightGripping = false;
|
||||
// }
|
||||
|
||||
// if (lCon.grip > 0.5f) {
|
||||
// if (!leftGripping) {
|
||||
// gripPos = lPos;
|
||||
// gripLeft = true;
|
||||
// leftGripping = true;
|
||||
// }
|
||||
// } else {
|
||||
// leftGripping = false;
|
||||
// }
|
||||
|
||||
// if (rightGripping || leftGripping) {
|
||||
// Vec3 gripTo = gripLeft ? lPos : rPos;
|
||||
// pos = -(gripTo - Input.Head.position) + gripPos - (Input.Head.position - pos);
|
||||
// vel = Vec3.Zero;
|
||||
// }
|
||||
// delete: gripPos, gripLeft, rightGripping, leftGripping
|
||||
// gripPos = r/l OldPos
|
||||
// rightGripping/leftGripping -> state machine (world grip, stretch, backhanded, grinding?)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// CUBIC BEZIER RAIL
|
||||
|
||||
// float grindDir = 1f;
|
||||
// bool grinding = false;
|
||||
// bool grinded = false;
|
||||
// Vec3 grindVel = Vec3.Forward;
|
||||
// Vec3[] grindRail = new Vec3[4];
|
||||
|
||||
// if (rCon.device.grip > 0.5f) {
|
||||
// if (!grinded) {
|
||||
// if (!grinding) {
|
||||
// int closest = 0;
|
||||
// float closestDist = float.MaxValue;
|
||||
// Vec3 closestPoint = Vec3.Zero;
|
||||
// int closestRail = 0;
|
||||
// for (int i = 0; i < net.me.cubics.Length; i++) {
|
||||
// if (net.me.cubics[i].active) {
|
||||
// Vec3[] rail = new Vec3[] {
|
||||
// net.me.cubics[i].p0,
|
||||
// net.me.cubics[i].p1,
|
||||
// net.me.cubics[i].p2,
|
||||
// net.me.cubics[i].p3,
|
||||
// };
|
||||
// for (int j = 0; j < rail.Length; j++) {
|
||||
// Vec3 point = Bezier.Sample(rail, (float)j / (rail.Length - 1f));
|
||||
// float dist = Vec3.Distance(point, rCon.pos + vel.Normalized * 0.25f);
|
||||
// if (dist < closestDist && dist < 0.5f) {
|
||||
// closest = j;
|
||||
// closestRail = i;
|
||||
// closestDist = dist;
|
||||
// closestPoint = point;
|
||||
// railT = (float)j / (rail.Length - 1f);
|
||||
// grinding = true;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if (grinding) {
|
||||
// grindRail = new Vec3[] {
|
||||
// net.me.cubics[closestRail].p0,
|
||||
// net.me.cubics[closestRail].p1,
|
||||
// net.me.cubics[closestRail].p2,
|
||||
// net.me.cubics[closestRail].p3,
|
||||
// };
|
||||
// // pos = closestPoint - (subCon.pose.position - pos);
|
||||
// grindVel = vel;
|
||||
// Vec3 fromPos = Bezier.Sample(grindRail[0], grindRail[1], grindRail[2], grindRail[3], railT);
|
||||
// Vec3 toPos = Bezier.Sample(grindRail[0], grindRail[1], grindRail[2], grindRail[3], railT + 0.1f);
|
||||
// grindDir = Vec3.Dot((fromPos - toPos).Normalized, grindVel) < 0f ? 1 : -1;
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (grinding) {
|
||||
// Vec3 grindPos = Bezier.Sample(grindRail[0], grindRail[1], grindRail[2], grindRail[3], railT);
|
||||
// Vec3 nextPos = Bezier.Sample(grindRail[0], grindRail[1], grindRail[2], grindRail[3], railT + 0.1f * grindDir);
|
||||
|
||||
// // vel += (toPos - fromPos);
|
||||
|
||||
// pos = -(rCon.pos - Input.Head.position) + grindPos - (Input.Head.position - pos);
|
||||
// vel = Vec3.Zero;
|
||||
|
||||
// railT += Time.Elapsedf * grindVel.Magnitude * grindDir; // scale based on length of rail * calculate and cache on place
|
||||
// // bool clamped = false;
|
||||
// // float railTpreClamp = railT;
|
||||
// // if
|
||||
// railT = Math.Clamp(railT, 0, 1);
|
||||
|
||||
// grindVel = (nextPos - grindPos).Normalized * grindVel.Magnitude;
|
||||
|
||||
// if (railT == 1 || railT == 0) {
|
||||
// vel = grindVel;
|
||||
// grinding = false;
|
||||
// grinded = true;
|
||||
// railT = 0f;
|
||||
// }
|
||||
|
||||
|
||||
// cube.Draw(mat, Matrix.TS(grindPos, new Vec3(0.1f, 0.1f, 0.1f)));
|
||||
// // cube.Draw(mat, Matrix.TS(toPos, new Vec3(0.1f, 0.1f, 0.1f) * 0.333f));
|
||||
// // pos = Vec3.Lerp(pos, Bezier.Sample(net.me.cubics[0].p0, net.me.cubics[0].p1, net.me.cubics[0].p2, net.me.cubics[0].p3, railT) - (subCon.aim.position - pos), Time.Elapsedf * 6f);
|
||||
// // how to reliably determine and control which direction to go? (velocity)
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// grinded = false;
|
||||
// if (grinding) {
|
||||
// vel = grindVel;
|
||||
// grinding = false;
|
||||
// }
|
||||
// }
|
||||
|
||||
// Console.WriteLine(World.RefreshInterval.ToString());
|
||||
|
||||
|
||||
|
||||
// if (domCon.IsX1JustUnPressed && Time.Totalf - movePress < 0.2f) {
|
||||
// pos = p00 - (Input.Head.position - pos);
|
||||
// }
|
||||
|
||||
// just push off of the air lol better than teleporting
|
||||
// not cursor dependent
|
||||
|
||||
// pos.x = (float)Math.Sin(Time.Total * 0.1f) * 0.5f;
|
||||
|
||||
// pos += vel * Time.Elapsedf;
|
||||
|
||||
// float preX = pos.x; pos.x = Math.Clamp(pos.x, -scene.scale / 2, scene.scale / 2); if (pos.x != preX) { vel.x = 0; }
|
||||
// float preY = pos.y; pos.y = Math.Clamp(pos.y, 0f, scene.scale / 2); if (pos.y != preY) { vel.y = 0; }
|
||||
// float preZ = pos.z; pos.z = Math.Clamp(pos.z, -scene.scale / 2, scene.scale / 2); if (pos.z != preZ) { vel.z = 0; }
|
||||
|
||||
// vel *= 1 - Time.Elapsedf * 0.2f;
|
||||
}
|
||||
}
|
|
@ -59,7 +59,7 @@ float raymarch(float3 origin, float3 direction) {
|
|||
float dist = 0.0;
|
||||
for (int i = 0; i < 256; i++) {
|
||||
float3 pos = origin + dist * direction;
|
||||
float step = sdBox(pos, _dimensions / 2.0);
|
||||
float step = sdBox(pos, _dimensions / 2.0);
|
||||
if (step < 0.0001 || dist > 100) break; // 100 == distmax
|
||||
dist += step;
|
||||
}
|
||||
|
|
|
@ -9,4 +9,8 @@ public class App {
|
|||
public App() {
|
||||
|
||||
}
|
||||
|
||||
public void Step() {
|
||||
|
||||
}
|
||||
}
|
|
@ -33,10 +33,8 @@ public class Block {
|
|||
}
|
||||
|
||||
public class BlockCon {
|
||||
Monolith mono;
|
||||
bool chirality;
|
||||
public BlockCon(Monolith mono, bool chirality) {
|
||||
this.mono = mono;
|
||||
public BlockCon(bool chirality) {
|
||||
this.chirality = chirality;
|
||||
}
|
||||
|
||||
|
@ -50,11 +48,12 @@ public class BlockCon {
|
|||
bool pressed = false;
|
||||
|
||||
public void Step() {
|
||||
Block[] blocks = mono.blocks;
|
||||
Con con = mono.Con(chirality);
|
||||
Con otherCon = mono.Con(!chirality);
|
||||
Vec3 cursor = mono.Glove(chirality).virtualGlove.position;
|
||||
BlockCon otherBlockCon = mono.BlockCon(!chirality);
|
||||
Block[] blocks = Mono.inst.blocks;
|
||||
Rig rig = Mono.inst.rig;
|
||||
Con con = rig.Con(chirality);
|
||||
Con otherCon = rig.Con(!chirality);
|
||||
Vec3 cursor = Mono.inst.Glove(chirality).virtualGlove.position;
|
||||
BlockCon otherBlockCon = Mono.inst.BlockCon(!chirality);
|
||||
|
||||
bool doublePressed = false;
|
||||
if (con.device.trigger > 0.5f) {
|
||||
|
|
|
@ -49,6 +49,31 @@ public class ColorCube {
|
|||
cube.Draw(unlit, Matrix.TS(p0s, Vec3.One * thicc * 2), color);
|
||||
cube.Draw(unlit, Matrix.TS(raw, Vec3.One * thicc), Color.White);
|
||||
}
|
||||
|
||||
public void Palm(Controller con) {
|
||||
// reveal when palm up
|
||||
float reveal = con.pose.Right.y * 1.666f;
|
||||
float look = 1 - Math.Clamp((1 - Math.Clamp(Vec3.Dot((con.pose.position - Input.Head.position).Normalized, Input.Head.Forward), 0f, 1f)) * 5f, 0f, 1f);
|
||||
reveal *= look;
|
||||
size = ogSize * Math.Clamp(reveal, 0, 1);
|
||||
center = con.pose.position + con.pose.Right * 0.0666f;
|
||||
// move with grip
|
||||
if (reveal > thicc) { // !leftPlanted
|
||||
if (reveal > 1f && con.trigger > 0.5f) {
|
||||
cursor -= (con.pose.position - oldConPos) / ogSize * 2;
|
||||
} else {
|
||||
// clamp 0 - 1
|
||||
cursor.x = Math.Clamp(cursor.x, -1, 1);
|
||||
cursor.y = Math.Clamp(cursor.y, -1, 1);
|
||||
cursor.z = Math.Clamp(cursor.z, -1, 1);
|
||||
}
|
||||
|
||||
|
||||
Step();
|
||||
}
|
||||
oldConPos = con.pose.position;
|
||||
}
|
||||
Vec3 oldConPos = Vec3.Zero;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -13,34 +13,34 @@ public class Cubic {
|
|||
}
|
||||
|
||||
public class CubicCon {
|
||||
Monolith mono;
|
||||
public CubicCon(Monolith mono) {
|
||||
this.mono = mono;
|
||||
}
|
||||
public CubicCon() {}
|
||||
|
||||
public void Step() {
|
||||
Con rCon = mono.rCon;
|
||||
Con lCon = mono.lCon;
|
||||
Peer peer = mono.net.me;
|
||||
Cubic[] cubics = Mono.inst.cubics;
|
||||
Rig rig = Mono.inst.rig;
|
||||
Con rCon = rig.rCon;
|
||||
Con lCon = rig.lCon;
|
||||
Vec3 rPos = Mono.inst.rGlove.virtualGlove.position;
|
||||
Vec3 lPos = Mono.inst.lGlove.virtualGlove.position;
|
||||
|
||||
bool place = rCon.device.IsStickJustClicked || lCon.device.IsStickJustClicked;
|
||||
if (place) {
|
||||
for (int i = 0; i < mono.cubics.Length; i++) {
|
||||
if (!mono.cubics[i].active) {
|
||||
mono.cubics[i].active = true;
|
||||
mono.cubics[i].p0 = mono.rGlove.virtualGlove.position;
|
||||
mono.cubics[i].p1 = mono.rCon.pos;
|
||||
mono.cubics[i].p2 = mono.lCon.pos;
|
||||
mono.cubics[i].p3 = mono.lGlove.virtualGlove.position;
|
||||
mono.cubics[i].color = Color.White;
|
||||
for (int i = 0; i < cubics.Length; i++) {
|
||||
if (!cubics[i].active) {
|
||||
cubics[i].active = true;
|
||||
cubics[i].p0 = rPos;
|
||||
cubics[i].p1 = rig.rCon.pos;
|
||||
cubics[i].p2 = rig.lCon.pos;
|
||||
cubics[i].p3 = lPos;
|
||||
cubics[i].color = Color.White;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Cubic cubic = mono.cubics[PullRequest.RandomRange(0, mono.cubics.Length)];
|
||||
cubic.p0 = mono.rGlove.virtualGlove.position;
|
||||
cubic.p1 = mono.rCon.pos;
|
||||
cubic.p2 = mono.lCon.pos;
|
||||
cubic.p3 = mono.lGlove.virtualGlove.position;
|
||||
Cubic cubic = cubics[PullRequest.RandomRange(0, cubics.Length)];
|
||||
cubic.p0 = rPos;
|
||||
cubic.p1 = rig.rCon.pos;
|
||||
cubic.p2 = rig.lCon.pos;
|
||||
cubic.p3 = lPos;
|
||||
cubic.color = Color.White;
|
||||
}
|
||||
}
|
||||
|
|
11
app/Glove.cs
11
app/Glove.cs
|
@ -6,10 +6,8 @@ public enum Pull {
|
|||
}
|
||||
|
||||
public class Glove {
|
||||
Monolith mono;
|
||||
bool chirality;
|
||||
public Glove(Monolith mono, bool chirality) {
|
||||
this.mono = mono;
|
||||
public Glove(bool chirality) {
|
||||
this.chirality = chirality;
|
||||
}
|
||||
|
||||
|
@ -33,9 +31,10 @@ public class Glove {
|
|||
int firstFace;
|
||||
|
||||
public void Step() {
|
||||
Pose shoulder = mono.Shoulder(chirality);
|
||||
Pose wrist = mono.Wrist(chirality);
|
||||
Con con = mono.Con(chirality), otherCon = mono.Con(!chirality);
|
||||
Rig rig = Mono.inst.rig;
|
||||
Pose shoulder = rig.Shoulder(chirality);
|
||||
Pose wrist = rig.Wrist(chirality);
|
||||
Con con = rig.Con(chirality), otherCon = rig.Con(!chirality);
|
||||
bool pull = otherCon.gripBtn.frameDown;
|
||||
|
||||
if (firstFace == 0) {
|
||||
|
|
108
app/Mono.cs
Normal file
108
app/Mono.cs
Normal file
|
@ -0,0 +1,108 @@
|
|||
using System;
|
||||
using StereoKit;
|
||||
|
||||
SKSettings settings = new SKSettings {
|
||||
appName = "oriels",
|
||||
assetsFolder = "add",
|
||||
depthMode = DepthMode.D32,
|
||||
disableUnfocusedSleep = true,
|
||||
};
|
||||
if (!SK.Initialize(settings))
|
||||
Environment.Exit(1);
|
||||
|
||||
Input.HandSolid(Handed.Max, false);
|
||||
Input.HandVisible(Handed.Max, true);
|
||||
// TextStyle style = Text.MakeStyle(Font.FromFile("DMMono-Regular.ttf"), 0.1f, Color.White);
|
||||
|
||||
Mono mono = Mono.inst;
|
||||
while (SK.Step(() => {
|
||||
mono.Step();
|
||||
})) ;
|
||||
SK.Shutdown();
|
||||
|
||||
|
||||
public class Mono {
|
||||
private static readonly Lazy<Mono> lazy = new Lazy<Mono>(() => new Mono());
|
||||
public static Mono inst { get { return lazy.Value; } }
|
||||
|
||||
public PullRequest.Noise noise = new PullRequest.Noise(939949595);
|
||||
|
||||
public Rig rig = new Rig();
|
||||
public Scene scene = new Scene();
|
||||
|
||||
// -------------------------------------------------
|
||||
public Oriel oriel = new Oriel(); // -> array ?
|
||||
|
||||
public ColorCube colorCube = new ColorCube();
|
||||
|
||||
public Glove rGlove = new Glove(true), lGlove = new Glove(false);
|
||||
public Glove Glove(bool chirality) { return chirality ? rGlove : lGlove; }
|
||||
|
||||
public BlockCon rBlock = new BlockCon(true), lBlock = new BlockCon(false);
|
||||
public BlockCon BlockCon(bool chirality) { return chirality ? rBlock : lBlock; }
|
||||
public Block[] blocks = new Block[] {
|
||||
new Block(), new Block(), new Block(), new Block(), new Block(), new Block()
|
||||
};
|
||||
|
||||
public CubicCon cubicCon = new CubicCon();
|
||||
public Cubic[] cubics = new Cubic[] {
|
||||
new Cubic(), new Cubic(), new Cubic(), new Cubic(), new Cubic(), new Cubic()
|
||||
};
|
||||
// -------------------------------------------------
|
||||
|
||||
public MonoNet net = new MonoNet();
|
||||
|
||||
public Mono() {
|
||||
Renderer.SetClip(0.02f, 1000f);
|
||||
|
||||
// Console.WriteLine("noise = " + noise.value);
|
||||
}
|
||||
|
||||
Vec3 pos = new Vec3(0f, 0f, 0f); // see below
|
||||
public void Step() {
|
||||
Renderer.CameraRoot = Matrix.T(pos);
|
||||
|
||||
rig.Step();
|
||||
scene.Step();
|
||||
|
||||
// -------------------------------------------------
|
||||
|
||||
// Gloves
|
||||
rGlove.Step();
|
||||
lGlove.Step();
|
||||
|
||||
// Blocks
|
||||
rBlock.Step();
|
||||
lBlock.Step();
|
||||
|
||||
// Cubic
|
||||
cubicCon.Step();
|
||||
|
||||
// Fullstick
|
||||
Vec3 fullstick = rig.Fullstick(false);
|
||||
|
||||
// COLOR CUBE (RGB)
|
||||
// colorCube.Palm(lCon.device);
|
||||
|
||||
|
||||
|
||||
oriel.Step();
|
||||
|
||||
// -------------------------------------------------
|
||||
|
||||
net.me.Step();
|
||||
net.send = true;
|
||||
|
||||
ShowWindowButton();
|
||||
}
|
||||
|
||||
Pose windowPoseButton = new Pose(0, 0, 0, Quat.Identity);
|
||||
void ShowWindowButton() {
|
||||
UI.WindowBegin("Window Button", ref windowPoseButton);
|
||||
|
||||
if (UI.Button("Reset Oriel Quat")) { oriel.ori = Quat.Identity; }
|
||||
if (UI.Button("Draw Oriel Axis")) { oriel.drawAxis = !oriel.drawAxis; }
|
||||
|
||||
UI.WindowEnd();
|
||||
}
|
||||
}
|
|
@ -7,15 +7,8 @@ using System.Threading.Tasks;
|
|||
using StereoKit;
|
||||
|
||||
public class MonoNet {
|
||||
public Monolith mono;
|
||||
public bool send;
|
||||
public MonoNet(Monolith mono) {
|
||||
this.mono = mono;
|
||||
this.send = false;
|
||||
Random rnd = new Random();
|
||||
me = new Peer(this, rnd.Next(1, 1024 * 8)); // let the server determine the id
|
||||
// me.block = new Block(new Vec3((float)rnd.NextDouble() * 0.5f, 10, -4), Quat.Identity, SolidType.Normal, Color.White);
|
||||
}
|
||||
|
||||
public Socket socket;
|
||||
int bufferSize = 1024;
|
||||
byte[] rData; int rHead;
|
||||
|
@ -24,7 +17,13 @@ public class MonoNet {
|
|||
public Peer me;
|
||||
public Peer[] peers;
|
||||
|
||||
public void Start() {
|
||||
public MonoNet() {
|
||||
this.send = false;
|
||||
Random rnd = new Random();
|
||||
me = new Peer(this, rnd.Next(1, 1024 * 8)); // let the server determine the id
|
||||
// me.block = new Block(new Vec3((float)rnd.NextDouble() * 0.5f, 10, -4), Quat.Identity, SolidType.Normal, Color.White);
|
||||
|
||||
|
||||
socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
|
||||
string ip = "192.168.1.70";
|
||||
ip = "139.177.201.219";
|
||||
|
@ -42,9 +41,6 @@ public class MonoNet {
|
|||
readThread.Start();
|
||||
Thread writeThread = new Thread(Write);
|
||||
writeThread.Start();
|
||||
|
||||
|
||||
// socket.Close();
|
||||
}
|
||||
|
||||
void Read() {
|
||||
|
@ -229,11 +225,12 @@ public class Peer {
|
|||
// voiceInst = voice.Play(Vec3.Zero, 0.5f);
|
||||
}
|
||||
|
||||
public void Step(Monolith mono) { // CLIENT SIDE
|
||||
public void Step() { // CLIENT SIDE
|
||||
Mono mono = Mono.inst;
|
||||
color = mono.colorCube.color;
|
||||
headset = Input.Head;
|
||||
rHand = mono.rCon.Pose();
|
||||
lHand = mono.lCon.Pose();
|
||||
rHand = mono.rig.rCon.Pose();
|
||||
lHand = mono.rig.lCon.Pose();
|
||||
rCursor = mono.rGlove.virtualGlove;
|
||||
lCursor = mono.lGlove.virtualGlove;
|
||||
|
||||
|
@ -272,9 +269,9 @@ public class Peer {
|
|||
|
||||
for (int i = 0; i < net.peers.Length; i++) {
|
||||
Peer peer = net.peers[i];
|
||||
if (peer != null) { peer.Draw(mono, true); }
|
||||
if (peer != null) { peer.Draw(true); }
|
||||
}
|
||||
Draw(mono, false);
|
||||
Draw(false);
|
||||
}
|
||||
|
||||
public void Write() {
|
||||
|
@ -357,15 +354,16 @@ public class Peer {
|
|||
}
|
||||
}
|
||||
|
||||
public void Draw(Monolith mono, bool body) {
|
||||
public void Draw(bool body) {
|
||||
Mono mono = Mono.inst;
|
||||
if (body) {
|
||||
PullRequest.BlockOut(Matrix.TRS(headset.position + Input.Head.Forward * -0.15f, headset.orientation, Vec3.One * 0.3f), color);
|
||||
}
|
||||
|
||||
Bezier.Draw(
|
||||
mono.rGlove.virtualGlove.position,
|
||||
mono.rCon.pos,
|
||||
mono.lCon.pos,
|
||||
mono.rig.rCon.pos,
|
||||
mono.rig.lCon.pos,
|
||||
mono.lGlove.virtualGlove.position,
|
||||
new Color(1, 1, 1, 0.1f)
|
||||
);
|
||||
|
|
559
app/Monolith.cs
559
app/Monolith.cs
|
@ -1,559 +0,0 @@
|
|||
using System;
|
||||
using StereoKit;
|
||||
|
||||
SKSettings settings = new SKSettings {
|
||||
appName = "oriels",
|
||||
assetsFolder = "add",
|
||||
depthMode = DepthMode.D32,
|
||||
disableUnfocusedSleep = true,
|
||||
};
|
||||
if (!SK.Initialize(settings))
|
||||
Environment.Exit(1);
|
||||
|
||||
Input.HandSolid(Handed.Max, false);
|
||||
Input.HandVisible(Handed.Max, true);
|
||||
// TextStyle style = Text.MakeStyle(Font.FromFile("DMMono-Regular.ttf"), 0.1f, Color.White);
|
||||
|
||||
Monolith mono = new Monolith();
|
||||
mono.Run();
|
||||
|
||||
public class Con {
|
||||
public Controller device;
|
||||
public Vec3 pos;
|
||||
public Quat ori;
|
||||
public Btn gripBtn;
|
||||
public Btn triggerBtn;
|
||||
|
||||
public void Step(bool chirality) {
|
||||
device = Input.Controller(chirality ? Handed.Right : Handed.Left);
|
||||
pos = device.pose.position;
|
||||
ori = device.aim.orientation;
|
||||
gripBtn.Step(device.grip > 0.5f);
|
||||
triggerBtn.Step(device.trigger > 0.5f);
|
||||
}
|
||||
|
||||
public Pose Pose() {
|
||||
return new Pose(pos, ori);
|
||||
}
|
||||
}
|
||||
|
||||
public struct Btn {
|
||||
public bool frameDown, held, frameUp;
|
||||
|
||||
public void Step(bool down) {
|
||||
frameDown = down && !held;
|
||||
frameUp = !down && held;
|
||||
held = down;
|
||||
}
|
||||
}
|
||||
|
||||
public class Monolith {
|
||||
public PullRequest.Noise noise;
|
||||
|
||||
public MonoNet net;
|
||||
public Scene scene;
|
||||
public Mic mic;
|
||||
|
||||
public Con rCon = new Con(), lCon = new Con();
|
||||
public Con Con(bool chirality) {
|
||||
return chirality ? rCon : lCon;
|
||||
}
|
||||
public Pose rShoulder, lShoulder;
|
||||
public Pose Shoulder(bool chirality) {
|
||||
return chirality ? rShoulder : lShoulder;
|
||||
}
|
||||
public Pose rWrist, lWrist;
|
||||
public Pose Wrist(bool chirality) {
|
||||
return chirality ? rWrist : lWrist;
|
||||
}
|
||||
public Glove lGlove, rGlove;
|
||||
public Glove Glove(bool chirality) {
|
||||
return chirality ? rGlove : lGlove;
|
||||
}
|
||||
public Oriel oriel = new Oriel();
|
||||
// Oriel otherOriel = new Oriel(this);
|
||||
|
||||
public ColorCube colorCube = new ColorCube();
|
||||
public Block[] blocks;
|
||||
public BlockCon rBlock, lBlock;
|
||||
public BlockCon BlockCon(bool chirality) {
|
||||
return chirality ? rBlock : lBlock;
|
||||
}
|
||||
public Cubic[] cubics;
|
||||
public CubicCon cubicCon;
|
||||
|
||||
public Vec3 rDragStart, lDragStart;
|
||||
public float railT;
|
||||
|
||||
Mesh ball = Default.MeshSphere;
|
||||
Material mat = Default.Material;
|
||||
Mesh cube = Default.MeshCube;
|
||||
|
||||
public void Run() {
|
||||
Renderer.SetClip(0.02f, 1000f);
|
||||
|
||||
noise = new PullRequest.Noise(978235461);
|
||||
|
||||
Console.WriteLine("noise = " + noise.value);
|
||||
|
||||
scene = new Scene(this);
|
||||
net = new MonoNet(this);
|
||||
net.Start();
|
||||
// mic = new Mic();
|
||||
rGlove = new Glove(this, true);
|
||||
lGlove = new Glove(this, false);
|
||||
blocks = new Block[] {
|
||||
new Block(), new Block(), new Block(),
|
||||
new Block(), new Block(), new Block()
|
||||
};
|
||||
rBlock = new BlockCon(this, true);
|
||||
lBlock = new BlockCon(this, false);
|
||||
cubics = new Cubic[] {
|
||||
new Cubic(), new Cubic(), new Cubic(),
|
||||
new Cubic(), new Cubic(), new Cubic()
|
||||
};
|
||||
cubicCon = new CubicCon(this);
|
||||
|
||||
|
||||
Vec3 pos = new Vec3(0, 0, 0);
|
||||
Vec3 vel = new Vec3(0, 0, 0);
|
||||
|
||||
Vec3 oldLPos = Vec3.Zero;
|
||||
|
||||
while (SK.Step(() => {
|
||||
Renderer.CameraRoot = Matrix.T(pos);
|
||||
|
||||
rCon.Step(true);
|
||||
lCon.Step(false);
|
||||
|
||||
// Shoulders
|
||||
Vec3 headPos = Input.Head.position + Input.Head.Forward * -0.15f;
|
||||
Vec3 shoulderDir = (
|
||||
(lCon.pos.X0Z - headPos.X0Z).Normalized +
|
||||
(rCon.pos.X0Z - headPos.X0Z).Normalized
|
||||
).Normalized;
|
||||
|
||||
if (Vec3.Dot(shoulderDir, Input.Head.Forward) < 0) { shoulderDir = -shoulderDir; }
|
||||
rShoulder = new Pose(headPos + Quat.LookDir(shoulderDir) * new Vec3(0.2f, -0.2f, 0), Quat.LookDir(shoulderDir));
|
||||
lShoulder = new Pose(headPos + Quat.LookDir(shoulderDir) * new Vec3(-0.2f, -0.2f, 0), Quat.LookDir(shoulderDir));
|
||||
|
||||
// Wrists
|
||||
rWrist = new Pose(rCon.pos + rCon.ori * new Vec3(0, 0, 0.052f), rCon.ori);
|
||||
lWrist = new Pose(lCon.pos + lCon.ori * new Vec3(0, 0, 0.052f), lCon.ori);
|
||||
|
||||
// Gloves
|
||||
rGlove.Step();
|
||||
lGlove.Step();
|
||||
|
||||
// Blocks
|
||||
rBlock.Step();
|
||||
lBlock.Step();
|
||||
|
||||
// Cubic
|
||||
cubicCon.Step();
|
||||
|
||||
// boolean over network to determine if a peers cubic flow should be drawn
|
||||
|
||||
|
||||
// throw yourself (delta -> vel -> momentum)
|
||||
// bring rails back
|
||||
|
||||
// FULLSTICK
|
||||
// Quat rot = Quat.FromAngles(subCon.stick.y * -90, 0, subCon.stick.x * 90);
|
||||
// Vec3 dir = Vec3.Up * (subCon.IsStickClicked ? -1 : 1);
|
||||
// Vec3 fullstick = subCon.aim.orientation * rot * dir;
|
||||
// pos += fullstick * subCon.trigger * Time.Elapsedf;
|
||||
|
||||
|
||||
|
||||
|
||||
// DRAG DRIFT
|
||||
// Vec3 rPos = net.me.cursor0;
|
||||
// Vec3 lPos = net.me.cursor3;
|
||||
|
||||
// use grip grab reach cursor origin it then becoming a backhanded stretch cursor
|
||||
// if (rCon.grip > 0.5f) {
|
||||
// if (!rightGripping) {
|
||||
// gripPos = rPos;
|
||||
// gripLeft = false;
|
||||
// rightGripping = true;
|
||||
// }
|
||||
// } else {
|
||||
// rightGripping = false;
|
||||
// }
|
||||
|
||||
// if (lCon.grip > 0.5f) {
|
||||
// if (!leftGripping) {
|
||||
// gripPos = lPos;
|
||||
// gripLeft = true;
|
||||
// leftGripping = true;
|
||||
// }
|
||||
// } else {
|
||||
// leftGripping = false;
|
||||
// }
|
||||
|
||||
// if (rightGripping || leftGripping) {
|
||||
// Vec3 gripTo = gripLeft ? lPos : rPos;
|
||||
// pos = -(gripTo - Input.Head.position) + gripPos - (Input.Head.position - pos);
|
||||
// vel = Vec3.Zero;
|
||||
// }
|
||||
// delete: gripPos, gripLeft, rightGripping, leftGripping
|
||||
// gripPos = r/l OldPos
|
||||
// rightGripping/leftGripping -> state machine (world grip, stretch, backhanded, grinding?)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// CUBIC BEZIER RAIL
|
||||
|
||||
// float grindDir = 1f;
|
||||
// bool grinding = false;
|
||||
// bool grinded = false;
|
||||
// Vec3 grindVel = Vec3.Forward;
|
||||
// Vec3[] grindRail = new Vec3[4];
|
||||
|
||||
// if (rCon.device.grip > 0.5f) {
|
||||
// if (!grinded) {
|
||||
// if (!grinding) {
|
||||
// int closest = 0;
|
||||
// float closestDist = float.MaxValue;
|
||||
// Vec3 closestPoint = Vec3.Zero;
|
||||
// int closestRail = 0;
|
||||
// for (int i = 0; i < net.me.cubics.Length; i++) {
|
||||
// if (net.me.cubics[i].active) {
|
||||
// Vec3[] rail = new Vec3[] {
|
||||
// net.me.cubics[i].p0,
|
||||
// net.me.cubics[i].p1,
|
||||
// net.me.cubics[i].p2,
|
||||
// net.me.cubics[i].p3,
|
||||
// };
|
||||
// for (int j = 0; j < rail.Length; j++) {
|
||||
// Vec3 point = Bezier.Sample(rail, (float)j / (rail.Length - 1f));
|
||||
// float dist = Vec3.Distance(point, rCon.pos + vel.Normalized * 0.25f);
|
||||
// if (dist < closestDist && dist < 0.5f) {
|
||||
// closest = j;
|
||||
// closestRail = i;
|
||||
// closestDist = dist;
|
||||
// closestPoint = point;
|
||||
// railT = (float)j / (rail.Length - 1f);
|
||||
// grinding = true;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if (grinding) {
|
||||
// grindRail = new Vec3[] {
|
||||
// net.me.cubics[closestRail].p0,
|
||||
// net.me.cubics[closestRail].p1,
|
||||
// net.me.cubics[closestRail].p2,
|
||||
// net.me.cubics[closestRail].p3,
|
||||
// };
|
||||
// // pos = closestPoint - (subCon.pose.position - pos);
|
||||
// grindVel = vel;
|
||||
// Vec3 fromPos = Bezier.Sample(grindRail[0], grindRail[1], grindRail[2], grindRail[3], railT);
|
||||
// Vec3 toPos = Bezier.Sample(grindRail[0], grindRail[1], grindRail[2], grindRail[3], railT + 0.1f);
|
||||
// grindDir = Vec3.Dot((fromPos - toPos).Normalized, grindVel) < 0f ? 1 : -1;
|
||||
// }
|
||||
// }
|
||||
|
||||
// if (grinding) {
|
||||
// Vec3 grindPos = Bezier.Sample(grindRail[0], grindRail[1], grindRail[2], grindRail[3], railT);
|
||||
// Vec3 nextPos = Bezier.Sample(grindRail[0], grindRail[1], grindRail[2], grindRail[3], railT + 0.1f * grindDir);
|
||||
|
||||
// // vel += (toPos - fromPos);
|
||||
|
||||
// pos = -(rCon.pos - Input.Head.position) + grindPos - (Input.Head.position - pos);
|
||||
// vel = Vec3.Zero;
|
||||
|
||||
// railT += Time.Elapsedf * grindVel.Magnitude * grindDir; // scale based on length of rail * calculate and cache on place
|
||||
// // bool clamped = false;
|
||||
// // float railTpreClamp = railT;
|
||||
// // if
|
||||
// railT = Math.Clamp(railT, 0, 1);
|
||||
|
||||
// grindVel = (nextPos - grindPos).Normalized * grindVel.Magnitude;
|
||||
|
||||
// if (railT == 1 || railT == 0) {
|
||||
// vel = grindVel;
|
||||
// grinding = false;
|
||||
// grinded = true;
|
||||
// railT = 0f;
|
||||
// }
|
||||
|
||||
|
||||
// cube.Draw(mat, Matrix.TS(grindPos, new Vec3(0.1f, 0.1f, 0.1f)));
|
||||
// // cube.Draw(mat, Matrix.TS(toPos, new Vec3(0.1f, 0.1f, 0.1f) * 0.333f));
|
||||
// // pos = Vec3.Lerp(pos, Bezier.Sample(net.me.cubics[0].p0, net.me.cubics[0].p1, net.me.cubics[0].p2, net.me.cubics[0].p3, railT) - (subCon.aim.position - pos), Time.Elapsedf * 6f);
|
||||
// // how to reliably determine and control which direction to go? (velocity)
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// grinded = false;
|
||||
// if (grinding) {
|
||||
// vel = grindVel;
|
||||
// grinding = false;
|
||||
// }
|
||||
// }
|
||||
|
||||
// Console.WriteLine(World.RefreshInterval.ToString());
|
||||
|
||||
|
||||
|
||||
// if (domCon.IsX1JustUnPressed && Time.Totalf - movePress < 0.2f) {
|
||||
// pos = p00 - (Input.Head.position - pos);
|
||||
// }
|
||||
|
||||
// just push off of the air lol better than teleporting
|
||||
// not cursor dependent
|
||||
|
||||
// pos.x = (float)Math.Sin(Time.Total * 0.1f) * 0.5f;
|
||||
|
||||
pos += vel * Time.Elapsedf;
|
||||
|
||||
float preX = pos.x; pos.x = Math.Clamp(pos.x, -scene.scale / 2, scene.scale / 2); if (pos.x != preX) { vel.x = 0; }
|
||||
float preY = pos.y; pos.y = Math.Clamp(pos.y, 0f, scene.scale / 2); if (pos.y != preY) { vel.y = 0; }
|
||||
float preZ = pos.z; pos.z = Math.Clamp(pos.z, -scene.scale / 2, scene.scale / 2); if (pos.z != preZ) { vel.z = 0; }
|
||||
|
||||
vel *= 1 - Time.Elapsedf * 0.2f;
|
||||
|
||||
|
||||
|
||||
|
||||
// COLOR CUBE (RGB)
|
||||
// reveal when palm up
|
||||
float reveal = lCon.device.pose.Right.y * 1.666f;
|
||||
float look = 1 - Math.Clamp((1 - Math.Clamp(Vec3.Dot((lCon.device.pose.position - Input.Head.position).Normalized, Input.Head.Forward), 0f, 1f)) * 5f, 0f, 1f);
|
||||
reveal *= look;
|
||||
colorCube.size = colorCube.ogSize * Math.Clamp(reveal, 0, 1);
|
||||
colorCube.center = lCon.device.pose.position + lCon.device.pose.Right * 0.0666f;
|
||||
// move with grip
|
||||
if (reveal > colorCube.thicc) { // !leftPlanted
|
||||
if (reveal > 1f && lCon.device.trigger > 0.5f) {
|
||||
colorCube.cursor -= (lCon.device.pose.position - oldLPos) / colorCube.ogSize * 2;
|
||||
} else {
|
||||
// clamp 0 - 1
|
||||
colorCube.cursor.x = Math.Clamp(colorCube.cursor.x, -1, 1);
|
||||
colorCube.cursor.y = Math.Clamp(colorCube.cursor.y, -1, 1);
|
||||
colorCube.cursor.z = Math.Clamp(colorCube.cursor.z, -1, 1);
|
||||
}
|
||||
|
||||
|
||||
// colorCube.Step();
|
||||
|
||||
|
||||
|
||||
}
|
||||
oldLPos = lCon.device.pose.position;
|
||||
|
||||
|
||||
|
||||
oriel.Step(this);
|
||||
|
||||
// Matrix orbitMatrix = OrbitalView.transform;
|
||||
// cube.Step(Matrix.S(Vec3.One * 0.2f) * orbitMatrix);
|
||||
// Default.MaterialHand["color"] = cube.color;
|
||||
|
||||
|
||||
scene.Step();
|
||||
|
||||
net.me.Step(this);
|
||||
net.send = true;
|
||||
|
||||
// if (rCon)
|
||||
ShowWindowButton();
|
||||
|
||||
}));
|
||||
SK.Shutdown();
|
||||
}
|
||||
|
||||
Pose windowPoseButton = new Pose(0, 0, 0, Quat.Identity);
|
||||
void ShowWindowButton() {
|
||||
UI.WindowBegin("Window Button", ref windowPoseButton);
|
||||
|
||||
if (UI.Button("Reset Oriel Quat")) {
|
||||
oriel.ori = Quat.Identity;
|
||||
}
|
||||
|
||||
if (UI.Button("Draw Oriel Axis")) {
|
||||
oriel.drawAxis = !oriel.drawAxis;
|
||||
}
|
||||
|
||||
UI.WindowEnd();
|
||||
}
|
||||
}
|
||||
|
||||
public class Lerper {
|
||||
public float t = 0;
|
||||
public float spring = 1;
|
||||
public float dampen = 1;
|
||||
float vel;
|
||||
|
||||
public void Step(float to = 1, bool bounce = false) {
|
||||
float dir = to - t;
|
||||
vel += dir * spring * Time.Elapsedf;
|
||||
|
||||
if (Math.Sign(vel) != Math.Sign(dir)) {
|
||||
vel *= 1 - (dampen * Time.Elapsedf);
|
||||
} else {
|
||||
vel *= 1 - (dampen * 0.33f * Time.Elapsedf);
|
||||
}
|
||||
|
||||
float newt = t + vel * Time.Elapsedf;
|
||||
if (bounce && (newt < 0 || newt > 1)) {
|
||||
vel *= -0.5f;
|
||||
newt = Math.Clamp(newt, 0, 1);
|
||||
}
|
||||
|
||||
t = newt;
|
||||
}
|
||||
|
||||
public void Reset() {
|
||||
t = vel = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static class PullRequest {
|
||||
public static void BoundsDraw(Bounds b, float thickness, Color color) {
|
||||
Vec3 c = Vec3.One / 2;
|
||||
Vec3 ds = b.dimensions;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
Quat q = Quat.FromAngles(i * 90, 0, 0);
|
||||
Lines.Add(q * (new Vec3(0, 0, 0) - c) * ds, q * (new Vec3(0, 1, 0) - c) * ds, color, color, thickness);
|
||||
Lines.Add(q * (new Vec3(0, 1, 0) - c) * ds, q * (new Vec3(1, 1, 0) - c) * ds, color, color, thickness);
|
||||
Lines.Add(q * (new Vec3(1, 1, 0) - c) * ds, q * (new Vec3(1, 0, 0) - c) * ds, color, color, thickness);
|
||||
|
||||
// convert to linepoints
|
||||
}
|
||||
}
|
||||
|
||||
// amplify quaternions (q * q * lerp(q.i, q, %))
|
||||
|
||||
public static Vec3 AngularDisplacement(Quat q) {
|
||||
float angle; Vec3 axis;
|
||||
ToAngleAxis(q, out angle, out axis);
|
||||
return axis * angle;
|
||||
// * (float)(Math.PI / 180); // radians -> degrees
|
||||
// / Time.Elapsedf; // delta -> velocity
|
||||
}
|
||||
|
||||
public static void ToAngleAxis(Quat q, out float angle, out Vec3 axis) {
|
||||
q = q.Normalized;
|
||||
angle = 2 * (float)Math.Acos(q.w);
|
||||
float s = (float)Math.Sqrt(1 - q.w * q.w);
|
||||
axis = Vec3.Right;
|
||||
// avoid divide by zero
|
||||
// + if s is close to zero then direction of axis not important
|
||||
if (s > 0.001) {
|
||||
axis.x = q.x / s;
|
||||
axis.y = q.y / s;
|
||||
axis.z = q.z / s;
|
||||
}
|
||||
}
|
||||
|
||||
static Random r = new Random();
|
||||
public static int RandomRange(int min, int max) {
|
||||
return r.Next(min, max);
|
||||
}
|
||||
|
||||
public static Vec3 Direction(Vec3 to, Vec3 from) {
|
||||
return (to - from).Normalized;
|
||||
}
|
||||
|
||||
|
||||
static Mesh meshCube = Default.MeshCube;
|
||||
static Material matCube = Default.Material;
|
||||
public static void BlockOut(Matrix m, Color color, Material mat = null) {
|
||||
if (mat == null) {
|
||||
mat = matCube;
|
||||
mat.FaceCull = Cull.None;
|
||||
}
|
||||
meshCube.Draw(mat, m, color);
|
||||
}
|
||||
|
||||
public static Mesh GetMesh(this Model model, string name) {
|
||||
for (int i = 0; i < model.Nodes.Count; i++) {
|
||||
if (model.Nodes[i].Name == name) {
|
||||
return model.Nodes[i].Mesh;
|
||||
}
|
||||
}
|
||||
Console.WriteLine("Mesh not found: " + name);
|
||||
return Mesh.Quad;
|
||||
}
|
||||
|
||||
public static void SetMat(this Material mat, int offset, Cull cull, bool depthWrite) {
|
||||
mat.QueueOffset = offset;
|
||||
mat.FaceCull = cull;
|
||||
mat.DepthWrite = depthWrite;
|
||||
}
|
||||
|
||||
public static Vec3 RandomInCube(Vec3 center, float size) {
|
||||
Random r = new Random();
|
||||
return center + new Vec3(
|
||||
(r.NextSingle() - 0.5f) * size,
|
||||
(r.NextSingle() - 0.5f) * size,
|
||||
(r.NextSingle() - 0.5f) * size
|
||||
);
|
||||
}
|
||||
|
||||
public static float Lerp(float a, float b, float t) {
|
||||
return a + (b - a) * t;
|
||||
}
|
||||
|
||||
static Pose _pose = new Pose();
|
||||
public static Pose WorldPose(this Pose pose, float scale = 1) {
|
||||
return pose;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class Noise {
|
||||
const uint CAP = 4294967295;
|
||||
const uint BIT_NOISE1 = 0xB5297A4D;
|
||||
const uint BIT_NOISE2 = 0x68E31DA4;
|
||||
const uint BIT_NOISE3 = 0x1B56C4E9;
|
||||
|
||||
public uint seed;
|
||||
|
||||
public Noise(uint seed) {
|
||||
this.seed = seed;
|
||||
}
|
||||
|
||||
int position;
|
||||
public float value {
|
||||
get {
|
||||
float v = RNG(position, seed) / (float)CAP;
|
||||
position++;
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
public float D1(int position) {
|
||||
return RNG(position, seed) / (float)CAP;
|
||||
}
|
||||
|
||||
public float D2(int x, int y) {
|
||||
// large prime number with non-boring bits
|
||||
const int PRIME = 198491317;
|
||||
return RNG(x + (PRIME * y), seed) / (float)CAP;
|
||||
}
|
||||
|
||||
public float D3(int x, int y, int z) {
|
||||
// large prime number with non-boring bits
|
||||
const int PRIME1 = 198491317;
|
||||
const int PRIME2 = 6542989;
|
||||
return RNG(x + (PRIME1 * y) + (PRIME2 * z), seed) / (float)CAP;
|
||||
}
|
||||
|
||||
public uint RNG(int position, uint seed) {
|
||||
uint mangled = (uint)position;
|
||||
mangled *= BIT_NOISE1;
|
||||
mangled += seed;
|
||||
mangled ^= mangled >> 8;
|
||||
mangled += BIT_NOISE2;
|
||||
mangled ^= mangled << 8;
|
||||
mangled *= BIT_NOISE3;
|
||||
mangled ^= mangled >> 8;
|
||||
return mangled;
|
||||
}
|
||||
}
|
||||
}
|
34
app/Oriel.cs
34
app/Oriel.cs
|
@ -44,28 +44,16 @@ public class Oriel {
|
|||
Gen();
|
||||
}
|
||||
|
||||
public class Transform {
|
||||
public string name;
|
||||
public Pose pose;
|
||||
public float scale;
|
||||
|
||||
public Transform() {
|
||||
|
||||
}
|
||||
|
||||
public Vec3 LocalPos() {
|
||||
return pose.position;
|
||||
}
|
||||
}
|
||||
|
||||
Vec3 detect = Vec3.Zero;
|
||||
int detectCount = 0;
|
||||
public void Step(Monolith mono) {
|
||||
public void Step() {
|
||||
matrix = Matrix.TR(bounds.center, ori).Inverse;
|
||||
|
||||
Vec3 rGlovePos = mono.rGlove.virtualGlove.position;
|
||||
Quat rGloveRot = mono.rGlove.virtualGlove.orientation;
|
||||
// Vec3 lGlovePos = mono.lGlove.virtualGlove.position;
|
||||
Rig rig = Mono.inst.rig;
|
||||
Glove rGlove = Mono.inst.rGlove;
|
||||
Vec3 rGlovePos = rGlove.virtualGlove.position;
|
||||
Quat rGloveRot = rGlove.virtualGlove.orientation;
|
||||
// Vec3 lGlovePos = rig.lGlove.virtualGlove.position;
|
||||
|
||||
// face detection = (1 axis)
|
||||
// edge detection = (2 axis)
|
||||
|
@ -78,7 +66,7 @@ public class Oriel {
|
|||
|
||||
|
||||
|
||||
if (!mono.rCon.triggerBtn.held) {
|
||||
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);
|
||||
|
@ -218,7 +206,7 @@ public class Oriel {
|
|||
);
|
||||
|
||||
meshCube.Draw(matOriel,
|
||||
mono.rGlove.virtualGlove.ToMatrix(new Vec3(0.025f, 0.1f, 0.1f) / 3 * 1.05f),
|
||||
rGlove.virtualGlove.ToMatrix(new Vec3(0.025f, 0.1f, 0.1f) / 3 * 1.05f),
|
||||
new Color(0.3f, 0.3f, 0.6f)
|
||||
);
|
||||
|
||||
|
@ -226,7 +214,7 @@ public class Oriel {
|
|||
|
||||
|
||||
float fwd = Input.Key(Key.W).IsActive() ? 1 : 0;
|
||||
playerPos += new Vec3(-mono.lCon.device.stick.x, 0, -mono.lCon.device.stick.y + fwd) * Time.Elapsedf;
|
||||
playerPos += new Vec3(-rig.lCon.device.stick.x, 0, -rig.lCon.device.stick.y + fwd) * Time.Elapsedf;
|
||||
meshCube.Draw(matOriel,
|
||||
Matrix.TRS(playerPos, Quat.Identity, new Vec3(0.4f, 1f, 0.2f)) * orielSimMatrix * matrix.Inverse,
|
||||
new Color(1.0f, 0.0f, 0.05f)
|
||||
|
@ -242,7 +230,7 @@ public class Oriel {
|
|||
|
||||
// FULLSTICK
|
||||
// Vec3 Fullstick() {
|
||||
// Controller con = mono.lCon.device;
|
||||
// Controller con = rig.lCon.device;
|
||||
// Quat rot = Quat.FromAngles(con.stick.y * -90, 0, con.stick.x * 90);
|
||||
// Vec3 dir = Vec3.Up * (con.IsStickClicked ? -1 : 1);
|
||||
// return con.aim.orientation * rot * dir;
|
||||
|
@ -255,7 +243,7 @@ public class Oriel {
|
|||
// );
|
||||
|
||||
if (Time.Totalf > spawnTime) {
|
||||
enemies.Add(playerPos + Quat.FromAngles(0, mono.noise.value * 360f, 0) * Vec3.Forward * 8);
|
||||
enemies.Add(playerPos + Quat.FromAngles(0, Mono.inst.noise.value * 360f, 0) * Vec3.Forward * 8);
|
||||
spawnTime = Time.Totalf + 1;
|
||||
}
|
||||
|
||||
|
|
178
app/PullRequest.cs
Normal file
178
app/PullRequest.cs
Normal file
|
@ -0,0 +1,178 @@
|
|||
using System;
|
||||
using StereoKit;
|
||||
|
||||
public static class PullRequest {
|
||||
public static void BoundsDraw(Bounds b, float thickness, Color color) {
|
||||
Vec3 c = Vec3.One / 2;
|
||||
Vec3 ds = b.dimensions;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
Quat q = Quat.FromAngles(i * 90, 0, 0);
|
||||
Lines.Add(q * (new Vec3(0, 0, 0) - c) * ds, q * (new Vec3(0, 1, 0) - c) * ds, color, color, thickness);
|
||||
Lines.Add(q * (new Vec3(0, 1, 0) - c) * ds, q * (new Vec3(1, 1, 0) - c) * ds, color, color, thickness);
|
||||
Lines.Add(q * (new Vec3(1, 1, 0) - c) * ds, q * (new Vec3(1, 0, 0) - c) * ds, color, color, thickness);
|
||||
|
||||
// convert to linepoints
|
||||
}
|
||||
}
|
||||
|
||||
// amplify quaternions (q * q * lerp(q.i, q, %))
|
||||
|
||||
public static Vec3 AngularDisplacement(Quat q) {
|
||||
float angle; Vec3 axis;
|
||||
ToAngleAxis(q, out angle, out axis);
|
||||
return axis * angle;
|
||||
// * (float)(Math.PI / 180); // radians -> degrees
|
||||
// / Time.Elapsedf; // delta -> velocity
|
||||
}
|
||||
|
||||
public static void ToAngleAxis(Quat q, out float angle, out Vec3 axis) {
|
||||
q = q.Normalized;
|
||||
angle = 2 * (float)Math.Acos(q.w);
|
||||
float s = (float)Math.Sqrt(1 - q.w * q.w);
|
||||
axis = Vec3.Right;
|
||||
// avoid divide by zero
|
||||
// + if s is close to zero then direction of axis not important
|
||||
if (s > 0.001) {
|
||||
axis.x = q.x / s;
|
||||
axis.y = q.y / s;
|
||||
axis.z = q.z / s;
|
||||
}
|
||||
}
|
||||
|
||||
static Random r = new Random();
|
||||
public static int RandomRange(int min, int max) {
|
||||
return r.Next(min, max);
|
||||
}
|
||||
|
||||
public static Vec3 Direction(Vec3 to, Vec3 from) {
|
||||
return (to - from).Normalized;
|
||||
}
|
||||
|
||||
|
||||
static Mesh meshCube = Default.MeshCube;
|
||||
static Material matCube = Default.Material;
|
||||
public static void BlockOut(Matrix m, Color color, Material mat = null) {
|
||||
if (mat == null) {
|
||||
mat = matCube;
|
||||
mat.FaceCull = Cull.None;
|
||||
}
|
||||
meshCube.Draw(mat, m, color);
|
||||
}
|
||||
|
||||
public static Mesh GetMesh(this Model model, string name) {
|
||||
for (int i = 0; i < model.Nodes.Count; i++) {
|
||||
if (model.Nodes[i].Name == name) {
|
||||
return model.Nodes[i].Mesh;
|
||||
}
|
||||
}
|
||||
Console.WriteLine("Mesh not found: " + name);
|
||||
return Mesh.Quad;
|
||||
}
|
||||
|
||||
public static void SetMat(this Material mat, int offset, Cull cull, bool depthWrite) {
|
||||
mat.QueueOffset = offset;
|
||||
mat.FaceCull = cull;
|
||||
mat.DepthWrite = depthWrite;
|
||||
}
|
||||
|
||||
public static Vec3 RandomInCube(Vec3 center, float size) {
|
||||
Random r = new Random();
|
||||
return center + new Vec3(
|
||||
(r.NextSingle() - 0.5f) * size,
|
||||
(r.NextSingle() - 0.5f) * size,
|
||||
(r.NextSingle() - 0.5f) * size
|
||||
);
|
||||
}
|
||||
|
||||
public static float Lerp(float a, float b, float t) {
|
||||
return a + (b - a) * t;
|
||||
}
|
||||
|
||||
static Pose _pose = new Pose();
|
||||
public static Pose WorldPose(this Pose pose, float scale = 1) {
|
||||
return pose;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class Noise {
|
||||
const uint CAP = 4294967295;
|
||||
const uint BIT_NOISE1 = 0xB5297A4D;
|
||||
const uint BIT_NOISE2 = 0x68E31DA4;
|
||||
const uint BIT_NOISE3 = 0x1B56C4E9;
|
||||
|
||||
public uint seed;
|
||||
|
||||
public Noise(uint seed) {
|
||||
this.seed = seed;
|
||||
}
|
||||
|
||||
int position;
|
||||
public float value {
|
||||
get {
|
||||
float v = RNG(position, seed) / (float)CAP;
|
||||
position++;
|
||||
return v;
|
||||
}
|
||||
}
|
||||
|
||||
public float D1(int position) {
|
||||
return RNG(position, seed) / (float)CAP;
|
||||
}
|
||||
|
||||
public float D2(int x, int y) {
|
||||
// large prime number with non-boring bits
|
||||
const int PRIME = 198491317;
|
||||
return RNG(x + (PRIME * y), seed) / (float)CAP;
|
||||
}
|
||||
|
||||
public float D3(int x, int y, int z) {
|
||||
// large prime number with non-boring bits
|
||||
const int PRIME1 = 198491317;
|
||||
const int PRIME2 = 6542989;
|
||||
return RNG(x + (PRIME1 * y) + (PRIME2 * z), seed) / (float)CAP;
|
||||
}
|
||||
|
||||
public uint RNG(int position, uint seed) {
|
||||
uint mangled = (uint)position;
|
||||
mangled *= BIT_NOISE1;
|
||||
mangled += seed;
|
||||
mangled ^= mangled >> 8;
|
||||
mangled += BIT_NOISE2;
|
||||
mangled ^= mangled << 8;
|
||||
mangled *= BIT_NOISE3;
|
||||
mangled ^= mangled >> 8;
|
||||
return mangled;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class Lerper {
|
||||
public float t = 0;
|
||||
public float spring = 1;
|
||||
public float dampen = 1;
|
||||
float vel;
|
||||
|
||||
public void Step(float to = 1, bool bounce = false) {
|
||||
float dir = to - t;
|
||||
vel += dir * spring * Time.Elapsedf;
|
||||
|
||||
if (Math.Sign(vel) != Math.Sign(dir)) {
|
||||
vel *= 1 - (dampen * Time.Elapsedf);
|
||||
} else {
|
||||
vel *= 1 - (dampen * 0.33f * Time.Elapsedf);
|
||||
}
|
||||
|
||||
float newt = t + vel * Time.Elapsedf;
|
||||
if (bounce && (newt < 0 || newt > 1)) {
|
||||
vel *= -0.5f;
|
||||
newt = Math.Clamp(newt, 0, 1);
|
||||
}
|
||||
|
||||
t = newt;
|
||||
}
|
||||
|
||||
public void Reset() {
|
||||
t = vel = 0;
|
||||
}
|
||||
}
|
||||
}
|
77
app/Rig/Rig.cs
Normal file
77
app/Rig/Rig.cs
Normal file
|
@ -0,0 +1,77 @@
|
|||
using System;
|
||||
using StereoKit;
|
||||
|
||||
public class Rig {
|
||||
public Mic mic;
|
||||
|
||||
public Rig() {
|
||||
mic = new Mic();
|
||||
}
|
||||
|
||||
public Con rCon = new Con(), lCon = new Con();
|
||||
public Con Con(bool chirality) { return chirality ? rCon : lCon; }
|
||||
|
||||
public Pose rShoulder, lShoulder;
|
||||
public Pose Shoulder(bool chirality) { return chirality ? rShoulder : lShoulder; }
|
||||
|
||||
public Pose rWrist, lWrist;
|
||||
public Pose Wrist(bool chirality) { return chirality ? rWrist : lWrist; }
|
||||
|
||||
public void Step() {
|
||||
// Controllers
|
||||
rCon.Step(true);
|
||||
lCon.Step(false);
|
||||
|
||||
// Shoulders
|
||||
Vec3 headPos = Input.Head.position + Input.Head.Forward * -0.15f;
|
||||
Vec3 shoulderDir = (
|
||||
(lCon.pos.X0Z - headPos.X0Z).Normalized +
|
||||
(rCon.pos.X0Z - headPos.X0Z).Normalized
|
||||
).Normalized;
|
||||
|
||||
if (Vec3.Dot(shoulderDir, Input.Head.Forward) < 0) { shoulderDir = -shoulderDir; }
|
||||
rShoulder = new Pose(headPos + Quat.LookDir(shoulderDir) * new Vec3(0.2f, -0.2f, 0), Quat.LookDir(shoulderDir));
|
||||
lShoulder = new Pose(headPos + Quat.LookDir(shoulderDir) * new Vec3(-0.2f, -0.2f, 0), Quat.LookDir(shoulderDir));
|
||||
|
||||
// Wrists
|
||||
rWrist = new Pose(rCon.pos + rCon.ori * new Vec3(0, 0, 0.052f), rCon.ori);
|
||||
lWrist = new Pose(lCon.pos + lCon.ori * new Vec3(0, 0, 0.052f), lCon.ori);
|
||||
}
|
||||
|
||||
public Vec3 Fullstick(bool chirality) {
|
||||
Controller con = Con(chirality).device;
|
||||
Quat rot = Quat.FromAngles(con.stick.y * -90, 0, con.stick.x * 90);
|
||||
Vec3 dir = Vec3.Up * (con.IsStickClicked ? -1 : 1);
|
||||
return con.aim.orientation * rot * dir;
|
||||
}
|
||||
}
|
||||
|
||||
public class Con {
|
||||
public Controller device;
|
||||
public Vec3 pos;
|
||||
public Quat ori;
|
||||
public Btn gripBtn;
|
||||
public Btn triggerBtn;
|
||||
|
||||
public void Step(bool chirality) {
|
||||
device = Input.Controller(chirality ? Handed.Right : Handed.Left);
|
||||
pos = device.pose.position;
|
||||
ori = device.aim.orientation;
|
||||
gripBtn.Step(device.grip > 0.5f);
|
||||
triggerBtn.Step(device.trigger > 0.5f);
|
||||
}
|
||||
|
||||
public Pose Pose() {
|
||||
return new Pose(pos, ori);
|
||||
}
|
||||
}
|
||||
|
||||
public struct Btn {
|
||||
public bool frameDown, held, frameUp;
|
||||
|
||||
public void Step(bool down) {
|
||||
frameDown = down && !held;
|
||||
frameUp = !down && held;
|
||||
held = down;
|
||||
}
|
||||
}
|
23
app/Scene.cs
23
app/Scene.cs
|
@ -10,8 +10,6 @@ struct BufferData {
|
|||
}
|
||||
|
||||
public class Scene {
|
||||
Monolith mono;
|
||||
|
||||
MaterialBuffer<BufferData> buffer;
|
||||
BufferData data = new BufferData();
|
||||
|
||||
|
@ -21,9 +19,7 @@ public class Scene {
|
|||
|
||||
|
||||
Solid floor;
|
||||
public Scene(Monolith mono) {
|
||||
this.mono = mono;
|
||||
|
||||
public Scene() {
|
||||
// Shader.FromFile("room.hlsl")
|
||||
buffer = new MaterialBuffer<BufferData>(3); // index
|
||||
|
||||
|
@ -48,8 +44,9 @@ public class Scene {
|
|||
|
||||
|
||||
public void Step() {
|
||||
data.matrix = (Matrix)System.Numerics.Matrix4x4.Transpose(mono.oriel.matrix);
|
||||
data.dimensions = mono.oriel.bounds.dimensions;
|
||||
Oriel oriel = Mono.inst.oriel;
|
||||
data.matrix = (Matrix)System.Numerics.Matrix4x4.Transpose(oriel.matrix);
|
||||
data.dimensions = oriel.bounds.dimensions;
|
||||
|
||||
buffer.Set(data);
|
||||
|
||||
|
@ -58,18 +55,18 @@ public class Scene {
|
|||
|
||||
// Console.WriteLine(i + " - " + node.Name);
|
||||
|
||||
// node.Material.SetVector("_center", mono.oriel.bounds.center);
|
||||
// node.Material.SetVector("_dimensions", mono.oriel.bounds.dimensions);
|
||||
// node.Material["_matrix"] = (Matrix)System.Numerics.Matrix4x4.Transpose(mono.oriel.matrix);
|
||||
// node.Material.SetVector("_center", oriel.bounds.center);
|
||||
// node.Material.SetVector("_dimensions", oriel.bounds.dimensions);
|
||||
// node.Material["_matrix"] = (Matrix)System.Numerics.Matrix4x4.Transpose(oriel.matrix);
|
||||
|
||||
// Console.WriteLine("Shader: " + node.Material.Shader.Name);
|
||||
|
||||
// node.Mesh.Draw(matRoom, Matrix.TRS(new Vec3(0, World.BoundsPose.position.y, -1), Quat.Identity, Vec3.One));
|
||||
// Console.WriteLine(matRoom.ParamCount + " test " + node.Material.ParamCount);
|
||||
}
|
||||
// room.RootNode.Material.SetVector("_center", mono.oriel.bounds.center);
|
||||
// room.RootNode.Material.SetVector("_dimensions", mono.oriel.bounds.dimensions);
|
||||
// room.RootNode.Material["_matrix"] = (Matrix)System.Numerics.Matrix4x4.Transpose(mono.oriel.matrix);
|
||||
// room.RootNode.Material.SetVector("_center", oriel.bounds.center);
|
||||
// room.RootNode.Material.SetVector("_dimensions", oriel.bounds.dimensions);
|
||||
// room.RootNode.Material["_matrix"] = (Matrix)System.Numerics.Matrix4x4.Transpose(oriel.matrix);
|
||||
|
||||
// Shader.
|
||||
// World.BoundsPose.position.y
|
||||
|
|
|
@ -30,10 +30,8 @@ public class StretchCursor : SpatialCursor {
|
|||
}
|
||||
|
||||
public class ReachCursor : SpatialCursor {
|
||||
Monolith mono;
|
||||
bool chirality;
|
||||
public ReachCursor(Monolith mono, bool chirality) {
|
||||
this.mono = mono;
|
||||
public ReachCursor(bool chirality) {
|
||||
this.chirality = chirality;
|
||||
this.min = 1f;
|
||||
this.str = 3f;
|
||||
|
@ -44,8 +42,8 @@ public class ReachCursor : SpatialCursor {
|
|||
public float deadzone;
|
||||
public override void Step(Pose[] poses, float scalar) {
|
||||
Vec3 pos = poses[0].position;
|
||||
Vec3 wrist = mono.Wrist(chirality).position;
|
||||
Pose shoulder = mono.Shoulder(chirality);
|
||||
Vec3 wrist = Mono.inst.rig.Wrist(chirality).position;
|
||||
Pose shoulder = Mono.inst.rig.Shoulder(chirality);
|
||||
|
||||
Vec3 from = (shoulder.orientation * origin) + shoulder.position;
|
||||
|
||||
|
@ -61,17 +59,15 @@ public class ReachCursor : SpatialCursor {
|
|||
Lines.Add(pos, p0, new Color(0, 1, 1), 0.005f);
|
||||
}
|
||||
public override void Calibrate() {
|
||||
Vec3 wrist = mono.Wrist(chirality).position;
|
||||
Pose shoulder = mono.Shoulder(chirality);
|
||||
Vec3 wrist = Mono.inst.rig.Wrist(chirality).position;
|
||||
Pose shoulder = Mono.inst.rig.Shoulder(chirality);
|
||||
origin = shoulder.orientation.Inverse * (wrist - shoulder.position);
|
||||
}
|
||||
}
|
||||
|
||||
public class TwistCursor : SpatialCursor {
|
||||
Monolith mono;
|
||||
bool chirality;
|
||||
public TwistCursor(Monolith mono, bool chirality) {
|
||||
this.mono = mono;
|
||||
public TwistCursor(bool chirality) {
|
||||
this.chirality = chirality;
|
||||
this.min = 1f;
|
||||
this.str = 6f;
|
||||
|
@ -79,9 +75,8 @@ public class TwistCursor : SpatialCursor {
|
|||
}
|
||||
Vec3 twistFrom = -Vec3.Right;
|
||||
public override void Step(Pose[] poses, float scalar) {
|
||||
|
||||
Vec3 pos = poses[0].position;
|
||||
Quat quat = mono.Con(chirality).ori;
|
||||
Quat quat = Mono.inst.rig.Con(chirality).ori;
|
||||
Quat from = Quat.LookAt(Vec3.Zero, quat * Vec3.Forward, twistFrom);
|
||||
float twist = (float)(Math.Acos(Vec3.Dot(from * Vec3.Up, quat * Vec3.Up)) / Math.PI);
|
||||
outty = Vec3.Dot(from * Vec3.Up, quat * Vec3.Right * (chirality ? 1 : -1)) > 0;
|
||||
|
@ -104,7 +99,7 @@ public class TwistCursor : SpatialCursor {
|
|||
}
|
||||
}
|
||||
public override void Calibrate() {
|
||||
Quat quat = mono.Con(chirality).ori;
|
||||
Quat quat = Mono.inst.rig.Con(chirality).ori;
|
||||
twistFrom = quat * Vec3.Up;
|
||||
}
|
||||
|
||||
|
@ -112,40 +107,39 @@ public class TwistCursor : SpatialCursor {
|
|||
}
|
||||
|
||||
public class CubicFlow : SpatialCursor {
|
||||
Monolith mono;
|
||||
TwistCursor domTwist;
|
||||
TwistCursor subTwist;
|
||||
public CubicFlow(Monolith mono) {
|
||||
this.mono = mono;
|
||||
public CubicFlow() {
|
||||
this.min = 1f;
|
||||
this.str = 3f;
|
||||
this.max = 10f;
|
||||
this.domTwist = new TwistCursor(mono, true);
|
||||
this.subTwist = new TwistCursor(mono, false);
|
||||
this.domTwist = new TwistCursor(true);
|
||||
this.subTwist = new TwistCursor(false);
|
||||
}
|
||||
bool domTwisting = false; bool domUp = false;
|
||||
bool subTwisting = false; bool subUp = false;
|
||||
public override void Step(Pose[] poses, float scalar) {
|
||||
Pose dom = poses[0];
|
||||
Pose sub = poses[1];
|
||||
Rig rig = Mono.inst.rig;
|
||||
|
||||
if (mono.rCon.device.stick.y < 0.1f) {
|
||||
if (rig.rCon.device.stick.y < 0.1f) {
|
||||
domTwist.Calibrate();
|
||||
domTwisting = false;
|
||||
} else {
|
||||
if (!domTwisting) {
|
||||
domUp = mono.rCon.device.stick.x > 0;
|
||||
domUp = rig.rCon.device.stick.x > 0;
|
||||
domTwisting = true;
|
||||
}
|
||||
}
|
||||
domTwist.Step(new Pose[] { dom }, scalar);
|
||||
|
||||
if (mono.lCon.device.stick.y < 0.1f) {
|
||||
if (rig.lCon.device.stick.y < 0.1f) {
|
||||
subTwist.Calibrate();
|
||||
subTwisting = false;
|
||||
} else {
|
||||
if (!subTwisting) {
|
||||
subUp = mono.lCon.device.stick.x < 0;
|
||||
subUp = rig.lCon.device.stick.x < 0;
|
||||
subTwisting = true;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue