net is back
This commit is contained in:
parent
5c2ddd546d
commit
f5088a8304
7 changed files with 224 additions and 264 deletions
|
@ -2,23 +2,21 @@ using System;
|
||||||
using StereoKit;
|
using StereoKit;
|
||||||
|
|
||||||
public class Block {
|
public class Block {
|
||||||
public static Mesh mesh = Default.MeshCube;
|
public bool active;
|
||||||
public static Material mat = Default.Material;
|
public Color color;
|
||||||
|
public Vec3 scale;
|
||||||
public bool active = false;
|
|
||||||
public Solid solid;
|
public Solid solid;
|
||||||
|
|
||||||
public float size = 0.5f;
|
|
||||||
|
|
||||||
// if you grab someone else's it becomes your own
|
// if you grab someone else's it becomes your own
|
||||||
// how to communicate to the other peer that you have grabbed it?
|
// how to communicate to the other peer that you have grabbed it?
|
||||||
// public int request; // request ownership
|
// public int request; // request ownership
|
||||||
// public int owner; // then if owner continue as usual
|
// public int owner; // then if owner continue as usual
|
||||||
// public bool busy; // marked as held so no fighting
|
// public bool busy; // marked as held so no fighting
|
||||||
public Block(SolidType type) {
|
public Block(SolidType type = SolidType.Normal) {
|
||||||
|
color = Color.White;
|
||||||
|
this.scale = new Vec3(0.2f, 0.2f, 0.34f);
|
||||||
this.solid = new Solid(Vec3.Zero, Quat.Identity, type);
|
this.solid = new Solid(Vec3.Zero, Quat.Identity, type);
|
||||||
this.size = 0.5f;
|
this.solid.AddBox(scale, 3);
|
||||||
this.solid.AddBox(Vec3.One * size, 3);
|
|
||||||
Disable();
|
Disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -32,12 +30,6 @@ public class Block {
|
||||||
public void Disable() {
|
public void Disable() {
|
||||||
solid.Enabled = active = false;
|
solid.Enabled = active = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Draw() {
|
|
||||||
if (active) {
|
|
||||||
mesh.Draw(mat, solid.GetPose().ToMatrix(Vec3.One * size));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class BlockCon {
|
public class BlockCon {
|
||||||
|
@ -108,7 +100,7 @@ public class BlockCon {
|
||||||
|
|
||||||
for (int i = 0; i < blocks.Length; i++) {
|
for (int i = 0; i < blocks.Length; i++) {
|
||||||
Pose blockPose = blocks[i].solid.GetPose();
|
Pose blockPose = blocks[i].solid.GetPose();
|
||||||
Bounds bounds = new Bounds(Vec3.Zero, Vec3.One * blocks[i].size);
|
Bounds bounds = new Bounds(Vec3.Zero, blocks[i].scale);
|
||||||
if (blocks[i].active && bounds.Contains(blockPose.orientation.Inverse * (cursor - blockPose.position))) {
|
if (blocks[i].active && bounds.Contains(blockPose.orientation.Inverse * (cursor - blockPose.position))) {
|
||||||
index = i;
|
index = i;
|
||||||
if (otherBlockCon.index == i) {
|
if (otherBlockCon.index == i) {
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using StereoKit;
|
using StereoKit;
|
||||||
|
|
||||||
class ColorCube {
|
public class ColorCube {
|
||||||
static Mesh cube = Default.MeshCube;
|
static Mesh cube = Default.MeshCube;
|
||||||
static Material mat = new Material(Shader.FromFile("colorcube.hlsl"));
|
static Material mat = new Material(Shader.FromFile("colorcube.hlsl"));
|
||||||
static Material unlit = Default.MaterialUnlit;
|
static Material unlit = Default.MaterialUnlit;
|
||||||
|
|
|
@ -10,12 +10,6 @@ public class Cubic {
|
||||||
color = Color.White;
|
color = Color.White;
|
||||||
active = false;
|
active = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Draw() {
|
|
||||||
if (active) {
|
|
||||||
Bezier.Draw(p0, p1, p2, p3, color);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class CubicCon {
|
public class CubicCon {
|
||||||
|
@ -28,15 +22,26 @@ public class CubicCon {
|
||||||
Con rCon = mono.rCon;
|
Con rCon = mono.rCon;
|
||||||
Con lCon = mono.lCon;
|
Con lCon = mono.lCon;
|
||||||
Peer peer = mono.net.me;
|
Peer peer = mono.net.me;
|
||||||
|
|
||||||
bool place = rCon.device.IsStickJustClicked || lCon.device.IsStickJustClicked;
|
bool place = rCon.device.IsStickJustClicked || lCon.device.IsStickJustClicked;
|
||||||
if (place) {
|
if (place) {
|
||||||
for (int i = 0; i < cubics.Length; i++) {
|
for (int i = 0; i < mono.cubics.Length; i++) {
|
||||||
if (!cubics[i].active) {
|
if (!mono.cubics[i].active) {
|
||||||
cubics[i].Enable(peer.cursor0, peer.cursor1, peer.cursor2, peer.cursor3, peer.color);
|
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;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
cubics[PullRequest.RandomRange(0, cubics.Length)].Enable(peer.cursor0, peer.cursor1, peer.cursor2, peer.cursor3, peer.color);
|
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.color = Color.White;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
25
app/Glove.cs
25
app/Glove.cs
|
@ -157,28 +157,11 @@ public class Glove {
|
||||||
|
|
||||||
mesh.Draw(mat, glove.ToMatrix(new Vec3(0.025f, 0.025f, 0.025f) / 3));
|
mesh.Draw(mat, glove.ToMatrix(new Vec3(0.025f, 0.025f, 0.025f) / 3));
|
||||||
mesh.Draw(mat, virtualGlove.ToMatrix(new Vec3(0.025f, 0.1f, 0.1f) / 3));
|
mesh.Draw(mat, virtualGlove.ToMatrix(new Vec3(0.025f, 0.1f, 0.1f) / 3));
|
||||||
// Lines.AddAxis(glove);
|
|
||||||
// Handed handed = chirality ? Handed.Right : Handed.Left;
|
|
||||||
// Hand hand = Input.Hand(handed);
|
|
||||||
// HandJoint[] joints = hand.fingers;
|
|
||||||
// for (int i = 0; i < joints.Length; i++) {
|
|
||||||
// joints[i].position = (joints[i].position - glove.position) + virtualGlove.position;
|
|
||||||
// }
|
|
||||||
// Input.HandOverride(chirality ? Handed.Right : Handed.Left, joints);
|
|
||||||
// Input.HandClearOverride(handed);
|
|
||||||
|
|
||||||
|
|
||||||
ModelNode top = model.FindNode("Top");
|
|
||||||
top.LocalTransform = Matrix.R(Quat.FromAngles(Vec3.Right * 45));
|
|
||||||
Console.WriteLine(top.Name);
|
|
||||||
|
|
||||||
model.Draw(glove.ToMatrix(Vec3.One / 10));
|
|
||||||
|
|
||||||
// get "Top" node
|
|
||||||
// Console.WriteLine(nodes[].Name);
|
|
||||||
// ? for stereo kit nick "can i directly update bone transforms on a skinned mesh"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// ModelNode top = model.FindNode("Top");
|
||||||
|
// top.LocalTransform = Matrix.R(Quat.FromAngles(Vec3.Right * 45));
|
||||||
|
// Console.WriteLine(top.Name);
|
||||||
|
// model.Draw(glove.ToMatrix(Vec3.One / 10));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
118
app/MonoNet.cs
118
app/MonoNet.cs
|
@ -13,7 +13,7 @@ public class MonoNet {
|
||||||
this.mono = mono;
|
this.mono = mono;
|
||||||
this.send = false;
|
this.send = false;
|
||||||
Random rnd = new Random();
|
Random rnd = new Random();
|
||||||
me = new Peer(rnd.Next(1, 1024 * 8)); // let the server determine the id
|
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);
|
// me.block = new Block(new Vec3((float)rnd.NextDouble() * 0.5f, 10, -4), Quat.Identity, SolidType.Normal, Color.White);
|
||||||
}
|
}
|
||||||
public Socket socket;
|
public Socket socket;
|
||||||
|
@ -67,7 +67,7 @@ public class MonoNet {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
peers[i] = new Peer(id);
|
peers[i] = new Peer(this, id);
|
||||||
index = i;
|
index = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -96,12 +96,11 @@ public class MonoNet {
|
||||||
bool running = true;
|
bool running = true;
|
||||||
while (running) {
|
while (running) {
|
||||||
Thread.Sleep(60);
|
Thread.Sleep(60);
|
||||||
if (send)
|
if (send) {
|
||||||
continue;
|
wHead = 0;
|
||||||
|
me.Write();
|
||||||
wHead = 0;
|
socket.Send(wData);
|
||||||
me.Write();
|
}
|
||||||
socket.Send(wData);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,10 +214,9 @@ public class Peer {
|
||||||
MonoNet net;
|
MonoNet net;
|
||||||
public int id; // on connect: wait on server sending your peer id
|
public int id; // on connect: wait on server sending your peer id
|
||||||
public Color color;
|
public Color color;
|
||||||
public Vec3 cursor0, cursor1, cursor2, cursor3;
|
|
||||||
public Pose headset;
|
public Pose headset;
|
||||||
public Pose offHand;
|
public Pose rHand, lHand;
|
||||||
public Pose mainHand;
|
public Pose rCursor, lCursor;
|
||||||
NetBlock[] blocks;
|
NetBlock[] blocks;
|
||||||
NetCubic[] cubics;
|
NetCubic[] cubics;
|
||||||
// public Sound voice;
|
// public Sound voice;
|
||||||
|
@ -231,27 +229,25 @@ public class Peer {
|
||||||
// voiceInst = voice.Play(Vec3.Zero, 0.5f);
|
// voiceInst = voice.Play(Vec3.Zero, 0.5f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vec3 vGlovePos;
|
|
||||||
|
|
||||||
|
|
||||||
public void Step(Monolith mono) { // CLIENT SIDE
|
public void Step(Monolith mono) { // CLIENT SIDE
|
||||||
|
color = mono.colorCube.color;
|
||||||
// too much in this networking class
|
headset = Input.Head;
|
||||||
// only contain a copy of network related data
|
rHand = mono.rCon.Pose();
|
||||||
// and not be a weird pitstop for game logic
|
lHand = mono.lCon.Pose();
|
||||||
|
rCursor = mono.rGlove.virtualGlove;
|
||||||
|
lCursor = mono.lGlove.virtualGlove;
|
||||||
|
|
||||||
// game logic driven for write, flexible for read (SolidType.Immovable)
|
if (blocks == null || blocks.Length != mono.blocks.Length) {
|
||||||
|
blocks = new NetBlock[mono.blocks.Length];
|
||||||
vGlovePos = mono.rGlove.virtualGlove.position;
|
}
|
||||||
|
|
||||||
|
|
||||||
if (blocks.Length != mono.blocks.Length) { blocks = new NetBlock[mono.blocks.Length]; }
|
|
||||||
for (int i = 0; i < blocks.Length; i++) {
|
for (int i = 0; i < blocks.Length; i++) {
|
||||||
blocks[i].active = mono.blocks[i].active;
|
blocks[i].active = mono.blocks[i].active;
|
||||||
|
blocks[i].color = mono.blocks[i].color;
|
||||||
blocks[i].pose = mono.blocks[i].solid.GetPose();
|
blocks[i].pose = mono.blocks[i].solid.GetPose();
|
||||||
|
blocks[i].scale = mono.blocks[i].scale;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cubics.Length != mono.cubics.Length) { cubics = new NetCubic[mono.cubics.Length]; }
|
if (cubics == null || cubics.Length != mono.cubics.Length) { cubics = new NetCubic[mono.cubics.Length]; }
|
||||||
for (int i = 0; i < cubics.Length; i++) {
|
for (int i = 0; i < cubics.Length; i++) {
|
||||||
cubics[i].active = mono.cubics[i].active;
|
cubics[i].active = mono.cubics[i].active;
|
||||||
cubics[i].color = mono.cubics[i].color;
|
cubics[i].color = mono.cubics[i].color;
|
||||||
|
@ -274,38 +270,40 @@ public class Peer {
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
Draw(false);
|
for (int i = 0; i < net.peers.Length; i++) {
|
||||||
|
Peer peer = net.peers[i];
|
||||||
|
if (peer != null) { peer.Draw(mono, true); }
|
||||||
|
}
|
||||||
|
Draw(mono, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Write() {
|
public void Write() {
|
||||||
net.WriteInt(id);
|
net.WriteInt(id);
|
||||||
net.WriteColor(color);
|
net.WriteColor(color);
|
||||||
net.WriteVec3(cursor0);
|
|
||||||
net.WriteVec3(cursor1);
|
|
||||||
net.WriteVec3(cursor2);
|
|
||||||
net.WriteVec3(cursor3);
|
|
||||||
net.WritePose(headset);
|
net.WritePose(headset);
|
||||||
net.WritePose(offHand);
|
net.WritePose(rHand);
|
||||||
net.WritePose(mainHand);
|
net.WritePose(lHand);
|
||||||
|
net.WritePose(rCursor);
|
||||||
|
net.WritePose(lCursor);
|
||||||
WriteBlock();
|
WriteBlock();
|
||||||
WriteCubic();
|
WriteCubic();
|
||||||
}
|
}
|
||||||
public void Read() {
|
public void Read() {
|
||||||
color = net.ReadColor();
|
color = net.ReadColor();
|
||||||
cursor0 = net.ReadVec3();
|
|
||||||
cursor1 = net.ReadVec3();
|
|
||||||
cursor2 = net.ReadVec3();
|
|
||||||
cursor3 = net.ReadVec3();
|
|
||||||
headset = net.ReadPose();
|
headset = net.ReadPose();
|
||||||
offHand = net.ReadPose();
|
rHand = net.ReadPose();
|
||||||
mainHand = net.ReadPose();
|
lHand = net.ReadPose();
|
||||||
|
rCursor = net.ReadPose();
|
||||||
|
lCursor = net.ReadPose();
|
||||||
ReadBlock();
|
ReadBlock();
|
||||||
ReadCubic();
|
ReadCubic();
|
||||||
}
|
}
|
||||||
|
|
||||||
struct NetBlock {
|
struct NetBlock {
|
||||||
public bool active;
|
public bool active;
|
||||||
|
public Color color;
|
||||||
public Pose pose;
|
public Pose pose;
|
||||||
|
public Vec3 scale;
|
||||||
}
|
}
|
||||||
void ReadBlock() {
|
void ReadBlock() {
|
||||||
int length = net.ReadInt();
|
int length = net.ReadInt();
|
||||||
|
@ -313,7 +311,9 @@ public class Peer {
|
||||||
for (int i = 0; i < length; i++) {
|
for (int i = 0; i < length; i++) {
|
||||||
NetBlock netBlock = blocks[i];
|
NetBlock netBlock = blocks[i];
|
||||||
netBlock.active = net.ReadBool();
|
netBlock.active = net.ReadBool();
|
||||||
|
netBlock.color = net.ReadColor();
|
||||||
netBlock.pose = net.ReadPose();
|
netBlock.pose = net.ReadPose();
|
||||||
|
netBlock.scale = net.ReadVec3();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void WriteBlock() {
|
void WriteBlock() {
|
||||||
|
@ -321,7 +321,9 @@ public class Peer {
|
||||||
for (int i = 0; i < blocks.Length; i++) {
|
for (int i = 0; i < blocks.Length; i++) {
|
||||||
NetBlock netBlock = blocks[i];
|
NetBlock netBlock = blocks[i];
|
||||||
net.WriteBool(netBlock.active);
|
net.WriteBool(netBlock.active);
|
||||||
|
net.WriteColor(netBlock.color);
|
||||||
net.WritePose(netBlock.pose);
|
net.WritePose(netBlock.pose);
|
||||||
|
net.WriteVec3(netBlock.scale);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -355,39 +357,31 @@ public class Peer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Draw(Monolith mono, bool body) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void Draw(bool body) {
|
|
||||||
if (body) {
|
if (body) {
|
||||||
Cube(Matrix.TRS(headset.position + Input.Head.Forward * -0.15f, headset.orientation, Vec3.One * 0.3f), color);
|
PullRequest.BlockOut(Matrix.TRS(headset.position + Input.Head.Forward * -0.15f, headset.orientation, Vec3.One * 0.3f), color);
|
||||||
}
|
}
|
||||||
|
|
||||||
Bezier.Draw(cursor0, cur Color.White); // overlap
|
Bezier.Draw(
|
||||||
// Cube(offHand.ToMatrix(new Vec3(0.1f, 0.025f, 0.1f)), color);
|
mono.rGlove.virtualGlove.position,
|
||||||
// Cube(mainHand.ToMatrix(new Vec3(0.1f, 0.025f, 0.1f)), color);
|
mono.rCon.pos,
|
||||||
|
mono.lCon.pos,
|
||||||
Cube(Matrix.TRS(cursor0, mainHand.orientation, new Vec3(0.025f, 0.1f, 0.1f)), color);
|
mono.lGlove.virtualGlove.position,
|
||||||
Cube(Matrix.TRS(cursor3, offHand.orientation, new Vec3(0.025f, 0.1f, 0.1f)), color);
|
Color.White
|
||||||
|
);
|
||||||
|
|
||||||
for (int i = 0; i < blocks.Length; i++) {
|
for (int i = 0; i < blocks.Length; i++) {
|
||||||
if (blocks[i].solid.GetPose().position.y < -10) {
|
NetBlock block = blocks[i];
|
||||||
blocks[i].Disable();
|
if (block.active) {
|
||||||
} else {
|
PullRequest.BlockOut(block.pose.ToMatrix(block.scale), block.color);
|
||||||
blocks[i].Draw();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < cubics.Length; i++) {
|
for (int i = 0; i < cubics.Length; i++) {
|
||||||
cubics[i].Draw();
|
NetCubic cubic = cubics[i];
|
||||||
|
if (cubic.active) {
|
||||||
|
Bezier.Draw(cubic.p0, cubic.p1, cubic.p2, cubic.p3, color);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static Mesh meshCube = Default.MeshCube;
|
|
||||||
static Material matCube = Default.Material;
|
|
||||||
public void Cube(Matrix m, Color color) {
|
|
||||||
matCube.FaceCull = Cull.None;
|
|
||||||
meshCube.Draw(matCube, m, color);
|
|
||||||
}
|
|
||||||
}
|
}
|
261
app/Monolith.cs
261
app/Monolith.cs
|
@ -49,6 +49,7 @@ public struct Btn {
|
||||||
|
|
||||||
public class Monolith {
|
public class Monolith {
|
||||||
public MonoNet net;
|
public MonoNet net;
|
||||||
|
public Scene scene;
|
||||||
public Mic mic;
|
public Mic mic;
|
||||||
|
|
||||||
public Con rCon = new Con(), lCon = new Con();
|
public Con rCon = new Con(), lCon = new Con();
|
||||||
|
@ -67,6 +68,7 @@ public class Monolith {
|
||||||
public Glove Glove(bool chirality) {
|
public Glove Glove(bool chirality) {
|
||||||
return chirality ? rGlove : lGlove;
|
return chirality ? rGlove : lGlove;
|
||||||
}
|
}
|
||||||
|
public ColorCube colorCube = new ColorCube();
|
||||||
public Block[] blocks;
|
public Block[] blocks;
|
||||||
public BlockCon rBlock, lBlock;
|
public BlockCon rBlock, lBlock;
|
||||||
public BlockCon BlockCon(bool chirality) {
|
public BlockCon BlockCon(bool chirality) {
|
||||||
|
@ -85,14 +87,15 @@ public class Monolith {
|
||||||
public void Run() {
|
public void Run() {
|
||||||
Renderer.SetClip(0.02f, 1000f);
|
Renderer.SetClip(0.02f, 1000f);
|
||||||
|
|
||||||
|
scene = new Scene(this);
|
||||||
net = new MonoNet(this);
|
net = new MonoNet(this);
|
||||||
net.Start();
|
net.Start();
|
||||||
// mic = new Mic();
|
// mic = new Mic();
|
||||||
rGlove = new Glove(this, true);
|
rGlove = new Glove(this, true);
|
||||||
lGlove = new Glove(this, false);
|
lGlove = new Glove(this, false);
|
||||||
blocks = new Block[] {
|
blocks = new Block[] {
|
||||||
new Block(SolidType.Normal), new Block(type), new Block(type),
|
new Block(), new Block(), new Block(),
|
||||||
new Block(type), new Block(type), new Block(type)
|
new Block(), new Block(), new Block()
|
||||||
};
|
};
|
||||||
rBlock = new BlockCon(this, true);
|
rBlock = new BlockCon(this, true);
|
||||||
lBlock = new BlockCon(this, false);
|
lBlock = new BlockCon(this, false);
|
||||||
|
@ -106,41 +109,13 @@ public class Monolith {
|
||||||
Vec3 pos = new Vec3(0, 0, 0);
|
Vec3 pos = new Vec3(0, 0, 0);
|
||||||
Vec3 vel = new Vec3(0, 0, 0);
|
Vec3 vel = new Vec3(0, 0, 0);
|
||||||
|
|
||||||
Solid floor = new Solid(Vec3.Up * -1.5f, Quat.Identity, SolidType.Immovable);
|
|
||||||
float scale = 64f;
|
|
||||||
Vec3 floorScale = new Vec3(scale, 0.1f, scale);
|
|
||||||
floor.AddBox(floorScale);
|
|
||||||
// box on each side
|
|
||||||
floor.AddBox(new Vec3(scale, scale / 2, 0.1f), 1, new Vec3(0, scale / 4, -scale / 2));
|
|
||||||
floor.AddBox(new Vec3(scale, scale / 2, 0.1f), 1, new Vec3(0, scale / 4, scale / 2));
|
|
||||||
floor.AddBox(new Vec3(0.1f, scale / 2, scale), 1, new Vec3(-scale / 2, scale / 4, 0));
|
|
||||||
floor.AddBox(new Vec3(0.1f, scale / 2, scale), 1, new Vec3(scale / 2, scale / 4, 0));
|
|
||||||
// and ceiling
|
|
||||||
floor.AddBox(new Vec3(scale, 0.1f, scale), 1, new Vec3(0, scale / 2, 0));
|
|
||||||
Material matFloor = new Material(Shader.Default);
|
|
||||||
matFloor.SetTexture("diffuse", Tex.FromFile("floor.png"));
|
|
||||||
matFloor.SetFloat("tex_scale", 32);
|
|
||||||
|
|
||||||
|
|
||||||
Oriel oriel = new Oriel();
|
Oriel oriel = new Oriel();
|
||||||
oriel.Start(3);
|
oriel.Start(3);
|
||||||
// Oriel otherOriel = new Oriel();
|
// Oriel otherOriel = new Oriel();
|
||||||
// otherOriel.Start(4);
|
// otherOriel.Start(4);
|
||||||
|
|
||||||
ColorCube colorCube = new ColorCube();
|
|
||||||
Vec3 oldLPos = Vec3.Zero;
|
Vec3 oldLPos = Vec3.Zero;
|
||||||
|
|
||||||
SpatialCursor cubicFlow = new CubicFlow(this);
|
|
||||||
|
|
||||||
Vec3 gripPos = Vec3.Zero;
|
|
||||||
|
|
||||||
|
|
||||||
float grindDir = 1f;
|
|
||||||
bool grinding = false;
|
|
||||||
bool grinded = false;
|
|
||||||
Vec3 grindVel = Vec3.Forward;
|
|
||||||
Vec3[] grindRail = new Vec3[4];
|
|
||||||
|
|
||||||
while (SK.Step(() => {
|
while (SK.Step(() => {
|
||||||
Renderer.CameraRoot = Matrix.T(pos);
|
Renderer.CameraRoot = Matrix.T(pos);
|
||||||
|
|
||||||
|
@ -171,25 +146,13 @@ public class Monolith {
|
||||||
lBlock.Step();
|
lBlock.Step();
|
||||||
|
|
||||||
// Cubic
|
// Cubic
|
||||||
cubicCon.Step(rCon, lCon, this);
|
cubicCon.Step();
|
||||||
|
|
||||||
|
|
||||||
// cubicFlow.Step(new Pose[] { new Pose(rightReachCursor.p0, rCon.ori), new Pose(leftReachCursor.p0, lCon.ori) }, 1);
|
|
||||||
// if (rCon.stick.y > 0.1f || lCon.stick.y > 0.1f) {
|
|
||||||
// Bezier.Draw(cubicFlow.p0, cubicFlow.p1, cubicFlow.p2, cubicFlow.p3, Color.White);
|
|
||||||
// net.me.cursor0 = cubicFlow.p0; net.me.cursor1 = cubicFlow.p1; net.me.cursor2 = cubicFlow.p2; net.me.cursor3 = cubicFlow.p3;
|
|
||||||
// } else {
|
|
||||||
// net.me.cursor0 = rightReachCursor.p0; net.me.cursor1 = rightReachCursor.p0; net.me.cursor2 = leftReachCursor.p0; net.me.cursor3 = leftReachCursor.p0;
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// boolean over network to determine if a peers cubic flow should be drawn
|
||||||
|
|
||||||
|
|
||||||
// throw yourself (delta -> vel -> momentum)
|
// throw yourself (delta -> vel -> momentum)
|
||||||
// bring rails back
|
// bring rails back
|
||||||
// boolean over network to determine if a peers cubic flow should be drawn
|
|
||||||
|
|
||||||
|
|
||||||
// FULLSTICK
|
// FULLSTICK
|
||||||
// Quat rot = Quat.FromAngles(subCon.stick.y * -90, 0, subCon.stick.x * 90);
|
// Quat rot = Quat.FromAngles(subCon.stick.y * -90, 0, subCon.stick.x * 90);
|
||||||
|
@ -201,8 +164,8 @@ public class Monolith {
|
||||||
|
|
||||||
|
|
||||||
// DRAG DRIFT
|
// DRAG DRIFT
|
||||||
Vec3 rPos = net.me.cursor0;
|
// Vec3 rPos = net.me.cursor0;
|
||||||
Vec3 lPos = net.me.cursor3;
|
// Vec3 lPos = net.me.cursor3;
|
||||||
|
|
||||||
// use grip grab reach cursor origin it then becoming a backhanded stretch cursor
|
// use grip grab reach cursor origin it then becoming a backhanded stretch cursor
|
||||||
// if (rCon.grip > 0.5f) {
|
// if (rCon.grip > 0.5f) {
|
||||||
|
@ -239,96 +202,95 @@ public class Monolith {
|
||||||
|
|
||||||
|
|
||||||
// CUBIC BEZIER RAIL
|
// CUBIC BEZIER RAIL
|
||||||
// Vec3[] rail = new Vec3[] {
|
|
||||||
// new Vec3(0, 0, -1),
|
|
||||||
// new Vec3(0, 0, -2),
|
|
||||||
// new Vec3(1, 2, -3),
|
|
||||||
// new Vec3(0, 1, -4),
|
|
||||||
// };
|
|
||||||
// Bezier.Draw(rail);
|
|
||||||
|
|
||||||
if (rCon.device.grip > 0.5f) {
|
// float grindDir = 1f;
|
||||||
if (!grinded) {
|
// bool grinding = false;
|
||||||
if (!grinding) {
|
// bool grinded = false;
|
||||||
int closest = 0;
|
// Vec3 grindVel = Vec3.Forward;
|
||||||
float closestDist = float.MaxValue;
|
// Vec3[] grindRail = new Vec3[4];
|
||||||
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) {
|
// if (rCon.device.grip > 0.5f) {
|
||||||
Vec3 grindPos = Bezier.Sample(grindRail[0], grindRail[1], grindRail[2], grindRail[3], railT);
|
// if (!grinded) {
|
||||||
Vec3 nextPos = Bezier.Sample(grindRail[0], grindRail[1], grindRail[2], grindRail[3], railT + 0.1f * grindDir);
|
// 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;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
// vel += (toPos - fromPos);
|
// 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);
|
||||||
|
|
||||||
pos = -(rCon.pos - Input.Head.position) + grindPos - (Input.Head.position - pos);
|
// // vel += (toPos - fromPos);
|
||||||
vel = Vec3.Zero;
|
|
||||||
|
|
||||||
railT += Time.Elapsedf * grindVel.Magnitude * grindDir; // scale based on length of rail * calculate and cache on place
|
// pos = -(rCon.pos - Input.Head.position) + grindPos - (Input.Head.position - pos);
|
||||||
// bool clamped = false;
|
// vel = Vec3.Zero;
|
||||||
// float railTpreClamp = railT;
|
|
||||||
// if
|
|
||||||
railT = Math.Clamp(railT, 0, 1);
|
|
||||||
|
|
||||||
grindVel = (nextPos - grindPos).Normalized * grindVel.Magnitude;
|
// 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);
|
||||||
|
|
||||||
if (railT == 1 || railT == 0) {
|
// grindVel = (nextPos - grindPos).Normalized * grindVel.Magnitude;
|
||||||
vel = grindVel;
|
|
||||||
grinding = false;
|
// if (railT == 1 || railT == 0) {
|
||||||
grinded = true;
|
// vel = grindVel;
|
||||||
railT = 0f;
|
// 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(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));
|
// // 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);
|
// // 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)
|
// // how to reliably determine and control which direction to go? (velocity)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
} else {
|
// } else {
|
||||||
grinded = false;
|
// grinded = false;
|
||||||
if (grinding) {
|
// if (grinding) {
|
||||||
vel = grindVel;
|
// vel = grindVel;
|
||||||
grinding = false;
|
// grinding = false;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
// Console.WriteLine(World.RefreshInterval.ToString());
|
// Console.WriteLine(World.RefreshInterval.ToString());
|
||||||
|
|
||||||
|
@ -342,30 +304,18 @@ public class Monolith {
|
||||||
// not cursor dependent
|
// not cursor dependent
|
||||||
|
|
||||||
// pos.x = (float)Math.Sin(Time.Total * 0.1f) * 0.5f;
|
// pos.x = (float)Math.Sin(Time.Total * 0.1f) * 0.5f;
|
||||||
if (!grinding) {
|
|
||||||
pos += vel * Time.Elapsedf;
|
pos += vel * Time.Elapsedf;
|
||||||
}
|
|
||||||
|
|
||||||
float preX = pos.x; pos.x = Math.Clamp(pos.x, -scale / 2, scale / 2); if (pos.x != preX) { vel.x = 0; }
|
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, scale / 2); if (pos.y != preY) { vel.y = 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, -scale / 2, scale / 2); if (pos.z != preZ) { vel.z = 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;
|
vel *= 1 - Time.Elapsedf * 0.2f;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Scene
|
|
||||||
cube.Draw(matFloor, floor.GetPose().ToMatrix(floorScale), Color.White * 0.666f);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// COLOR CUBE
|
// COLOR CUBE
|
||||||
// reveal when palm up
|
// reveal when palm up
|
||||||
float reveal = lCon.device.pose.Right.y * 1.666f;
|
float reveal = lCon.device.pose.Right.y * 1.666f;
|
||||||
|
@ -388,21 +338,13 @@ public class Monolith {
|
||||||
oldLPos = lCon.device.pose.position;
|
oldLPos = lCon.device.pose.position;
|
||||||
|
|
||||||
|
|
||||||
oriel.Step(net.me.cursor0, net.me.cursor3);
|
oriel.Step(rGlove.virtualGlove.position, lGlove.virtualGlove.position);
|
||||||
// Matrix orbitMatrix = OrbitalView.transform;
|
// Matrix orbitMatrix = OrbitalView.transform;
|
||||||
// cube.Step(Matrix.S(Vec3.One * 0.2f) * orbitMatrix);
|
// cube.Step(Matrix.S(Vec3.One * 0.2f) * orbitMatrix);
|
||||||
// Default.MaterialHand["color"] = cube.color;
|
// Default.MaterialHand["color"] = cube.color;
|
||||||
|
|
||||||
|
scene.Step();
|
||||||
|
|
||||||
|
|
||||||
net.me.color = colorCube.color;
|
|
||||||
net.me.headset = Input.Head;
|
|
||||||
net.me.mainHand = rCon.Pose();
|
|
||||||
net.me.offHand = lCon.Pose();
|
|
||||||
for (int i = 0; i < net.peers.Length; i++) {
|
|
||||||
Peer peer = net.peers[i];
|
|
||||||
if (peer != null) { peer.Draw(true); }
|
|
||||||
}
|
|
||||||
net.me.Step(this);
|
net.me.Step(this);
|
||||||
net.send = true;
|
net.send = true;
|
||||||
|
|
||||||
|
@ -487,4 +429,15 @@ public static class PullRequest {
|
||||||
public static Vec3 Direction(Vec3 to, Vec3 from) {
|
public static Vec3 Direction(Vec3 to, Vec3 from) {
|
||||||
return (to - from).Normalized;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
33
app/Scene.cs
Normal file
33
app/Scene.cs
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
using System;
|
||||||
|
using StereoKit;
|
||||||
|
|
||||||
|
public class Scene {
|
||||||
|
Monolith mono;
|
||||||
|
Material matFloor = new Material(Shader.Default);
|
||||||
|
Solid floor;
|
||||||
|
public Scene(Monolith mono) {
|
||||||
|
this.mono = mono;
|
||||||
|
|
||||||
|
floor = new Solid(Vec3.Up * -1.5f, Quat.Identity, SolidType.Immovable);
|
||||||
|
scale = 64f;
|
||||||
|
floorScale = new Vec3(scale, 0.1f, scale);
|
||||||
|
floor.AddBox(floorScale);
|
||||||
|
// box on each side
|
||||||
|
floor.AddBox(new Vec3(scale, scale / 2, 0.1f), 1, new Vec3(0, scale / 4, -scale / 2));
|
||||||
|
floor.AddBox(new Vec3(scale, scale / 2, 0.1f), 1, new Vec3(0, scale / 4, scale / 2));
|
||||||
|
floor.AddBox(new Vec3(0.1f, scale / 2, scale), 1, new Vec3(-scale / 2, scale / 4, 0));
|
||||||
|
floor.AddBox(new Vec3(0.1f, scale / 2, scale), 1, new Vec3(scale / 2, scale / 4, 0));
|
||||||
|
// and ceiling
|
||||||
|
floor.AddBox(new Vec3(scale, 0.1f, scale), 1, new Vec3(0, scale / 2, 0));
|
||||||
|
matFloor.SetTexture("diffuse", Tex.FromFile("floor.png"));
|
||||||
|
matFloor.SetFloat("tex_scale", 32);
|
||||||
|
}
|
||||||
|
|
||||||
|
public float scale;
|
||||||
|
public Vec3 floorScale;
|
||||||
|
|
||||||
|
|
||||||
|
public void Step() {
|
||||||
|
PullRequest.BlockOut(floor.GetPose().ToMatrix(floorScale), Color.White * 0.666f, matFloor);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue