rig data
This commit is contained in:
parent
3ed8438b03
commit
901e9112ce
2 changed files with 36 additions and 25 deletions
29
MonoNet.cs
29
MonoNet.cs
|
@ -4,7 +4,6 @@ using System.Net;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Text;
|
|
||||||
|
|
||||||
public class MonoNet {
|
public class MonoNet {
|
||||||
public MonoNet() {
|
public MonoNet() {
|
||||||
|
@ -40,34 +39,43 @@ public class MonoNet {
|
||||||
EndPoint serverEndPoint = new IPEndPoint(IPAddress.Parse(ip), 1234);
|
EndPoint serverEndPoint = new IPEndPoint(IPAddress.Parse(ip), 1234);
|
||||||
socket.Connect(serverEndPoint);
|
socket.Connect(serverEndPoint);
|
||||||
data = new byte[1024];
|
data = new byte[1024];
|
||||||
peers = new Peer[4];
|
peers = new Peer[64];
|
||||||
|
|
||||||
Thread.Sleep(1000);
|
Thread.Sleep(1000); // useful?
|
||||||
|
|
||||||
bool running = true;
|
bool running = true;
|
||||||
while (running) {
|
while (running) {
|
||||||
while (socket.Available > 0) {
|
while (socket.Available > 0) {
|
||||||
try {socket.Receive(data, 0, data.Length, SocketFlags.None);}
|
try {socket.Receive(data, 0, data.Length, SocketFlags.None);}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
Console.WriteLine("can't connect to the server");
|
Console.WriteLine($"can't connect to the server: {e}");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
head = 0;
|
head = 0;
|
||||||
int id = ReadInt();
|
int id = ReadInt();
|
||||||
if (id != 0) {
|
if (id != 0) {
|
||||||
|
int index = -1;
|
||||||
for (int i = 0; i < peers.Length; i++) {
|
for (int i = 0; i < peers.Length; i++) {
|
||||||
if (peers[i] != null) {
|
if (peers[i] != null) {
|
||||||
if (peers[i].id == id) {
|
if (peers[i].id == id) {
|
||||||
peers[i].cursor = ReadVec3();
|
index = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
peers[i] = new Peer(id);
|
peers[i] = new Peer(id);
|
||||||
peers[i].cursor = ReadVec3();
|
index = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (index == -1) {
|
||||||
|
Console.WriteLine("too many peers");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
peers[index].cursor = ReadVec3();
|
||||||
|
peers[index].headset = ReadPose();
|
||||||
|
peers[index].offHand = ReadPose();
|
||||||
|
peers[index].mainHand = ReadPose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,6 +83,9 @@ public class MonoNet {
|
||||||
head = 0;
|
head = 0;
|
||||||
WriteInt(me.id);
|
WriteInt(me.id);
|
||||||
WriteVec3(me.cursor);
|
WriteVec3(me.cursor);
|
||||||
|
WritePose(me.headset);
|
||||||
|
WritePose(me.offHand);
|
||||||
|
WritePose(me.mainHand);
|
||||||
socket.Send(data);
|
socket.Send(data);
|
||||||
|
|
||||||
await Task.Delay(1);
|
await Task.Delay(1);
|
||||||
|
@ -143,9 +154,9 @@ public class MonoNet {
|
||||||
{
|
{
|
||||||
public int id;
|
public int id;
|
||||||
public Vec3 cursor;
|
public Vec3 cursor;
|
||||||
// public Pose headset;
|
public Pose headset;
|
||||||
// public Pose offHand;
|
public Pose offHand;
|
||||||
// public Pose mainHand;
|
public Pose mainHand;
|
||||||
|
|
||||||
public Peer(int id) {
|
public Peer(int id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
|
|
32
Program.cs
32
Program.cs
|
@ -23,12 +23,12 @@ public static class Mono {
|
||||||
MonoNet net = new MonoNet();
|
MonoNet net = new MonoNet();
|
||||||
net.Start();
|
net.Start();
|
||||||
|
|
||||||
ColorCube cube = new ColorCube();
|
// ColorCube cube = new ColorCube();
|
||||||
OrbitalView.strength = 4;
|
// OrbitalView.strength = 4;
|
||||||
OrbitalView.distance = 0.4f;
|
// OrbitalView.distance = 0.4f;
|
||||||
cube.thickness = 0.01f;
|
// cube.thickness = 0.01f;
|
||||||
|
|
||||||
// StretchCursor stretchCursor = new StretchCursor();
|
StretchCursor stretchCursor = new StretchCursor();
|
||||||
// ReachCursor reachCursor = new ReachCursor();
|
// ReachCursor reachCursor = new ReachCursor();
|
||||||
// SupineCursor supineCursor = new SupineCursor();
|
// SupineCursor supineCursor = new SupineCursor();
|
||||||
// ClawCursor clawCursor = new ClawCursor();
|
// ClawCursor clawCursor = new ClawCursor();
|
||||||
|
@ -36,28 +36,28 @@ public static class Mono {
|
||||||
// Oriel oriel = new Oriel();
|
// Oriel oriel = new Oriel();
|
||||||
// oriel.Start();
|
// oriel.Start();
|
||||||
|
|
||||||
Lerper lerper = new Lerper();
|
// Lerper lerper = new Lerper();
|
||||||
|
|
||||||
while (SK.Step(() => {
|
while (SK.Step(() => {
|
||||||
offHand = Input.Controller(Handed.Left);
|
offHand = Input.Controller(Handed.Left);
|
||||||
mainHand = Input.Controller(Handed.Right);
|
mainHand = Input.Controller(Handed.Right);
|
||||||
|
|
||||||
mainHand.aim = Input.Hand(Handed.Right).palm;
|
// mainHand.aim = Input.Hand(Handed.Right).palm;
|
||||||
|
|
||||||
// stretchCursor.Step(offHand.aim, mainHand.aim);
|
|
||||||
|
|
||||||
|
|
||||||
net.me.cursor = Vec3.Up * (float)Math.Sin(Time.Total);
|
stretchCursor.Step(offHand.aim, mainHand.aim);
|
||||||
// net.me.headset = Input.Head;
|
net.me.cursor = stretchCursor.pos;
|
||||||
// net.me.offHand = offHand.aim;
|
// net.me.cursor = Vec3.Up * (float)Math.Sin(Time.Total);
|
||||||
// net.me.mainHand = mainHand.aim;
|
net.me.headset = Input.Head;
|
||||||
|
net.me.offHand = offHand.aim;
|
||||||
|
net.me.mainHand = mainHand.aim;
|
||||||
for (int i = 0; i < net.peers.Length; i++) {
|
for (int i = 0; i < net.peers.Length; i++) {
|
||||||
MonoNet.Peer peer = net.peers[i];
|
MonoNet.Peer peer = net.peers[i];
|
||||||
if (peer != null) {
|
if (peer != null) {
|
||||||
net.Cubee(Matrix.TRS(peer.cursor, Quat.Identity, Vec3.One * 0.05f));
|
net.Cubee(Matrix.TRS(peer.cursor, Quat.Identity, Vec3.One * 0.05f));
|
||||||
// Cubee(NetPose(peer.Head.Value).ToMatrix(Vec3.One * 0.3f));
|
net.Cubee(peer.headset.ToMatrix(Vec3.One * 0.3f));
|
||||||
// Cubee(NetPose(peer.LHand.Value).ToMatrix(Vec3.One * 0.1f));
|
net.Cubee(peer.offHand.ToMatrix(Vec3.One * 0.1f));
|
||||||
// Cubee(NetPose(peer.RHand.Value).ToMatrix(Vec3.One * 0.1f));
|
net.Cubee(peer.mainHand.ToMatrix(Vec3.One * 0.1f));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue