full body test
This commit is contained in:
parent
5e6f555bb3
commit
2791f26484
1 changed files with 116 additions and 19 deletions
135
Program.cs
135
Program.cs
|
@ -4,6 +4,7 @@ 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;
|
||||||
|
|
||||||
class Program {
|
class Program {
|
||||||
static void Main(string[] args) {
|
static void Main(string[] args) {
|
||||||
|
@ -27,9 +28,10 @@ public static class Mono {
|
||||||
public static Model model = Model.FromFile("cursor.glb", Shader.Default);
|
public static Model model = Model.FromFile("cursor.glb", Shader.Default);
|
||||||
|
|
||||||
public static void Run() {
|
public static void Run() {
|
||||||
|
string publicIP, localIP;
|
||||||
|
GetIPs();
|
||||||
void GetIPs()
|
void GetIPs()
|
||||||
{
|
{
|
||||||
string localIP;
|
|
||||||
using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, 0))
|
using (Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, 0))
|
||||||
{
|
{
|
||||||
socket.Connect("8.8.8.8", 65530);
|
socket.Connect("8.8.8.8", 65530);
|
||||||
|
@ -37,11 +39,14 @@ public static class Mono {
|
||||||
localIP = endPoint.Address.ToString();
|
localIP = endPoint.Address.ToString();
|
||||||
}
|
}
|
||||||
// Console.WriteLine("Your local IP is: " + localIP);
|
// Console.WriteLine("Your local IP is: " + localIP);
|
||||||
string publicIP = new WebClient().DownloadString("https://ipv4.icanhazip.com/").TrimEnd();
|
publicIP = new WebClient().DownloadString("https://ipv4.icanhazip.com/").TrimEnd();
|
||||||
// Console.WriteLine("Your IP is: " + publicIP);
|
// Console.WriteLine("Your IP is: " + publicIP);
|
||||||
}
|
}
|
||||||
|
|
||||||
Peer peer = new Peer("ego");
|
// byte[] bytes = Encoding.UTF8.GetBytes(publicIP);
|
||||||
|
// Console.WriteLine(bytes.Length);
|
||||||
|
MonoNet net = new MonoNet(publicIP); // temp, until unique usernames
|
||||||
|
net.Start(false);
|
||||||
|
|
||||||
ColorCube cube = new ColorCube();
|
ColorCube cube = new ColorCube();
|
||||||
OrbitalView.strength = 4;
|
OrbitalView.strength = 4;
|
||||||
|
@ -64,8 +69,12 @@ public static class Mono {
|
||||||
mainHand = Input.Controller(Handed.Right);
|
mainHand = Input.Controller(Handed.Right);
|
||||||
|
|
||||||
stretchCursor.Step(offHand.aim, mainHand.aim);
|
stretchCursor.Step(offHand.aim, mainHand.aim);
|
||||||
peer.cursor = stretchCursor.pos;
|
net.cursor = stretchCursor.pos;
|
||||||
model.Draw(Matrix.TS(peer.peerCursor, 0.1f));
|
net.head = Input.Head;
|
||||||
|
net.offHand = offHand.aim;
|
||||||
|
net.mainHand = mainHand.aim;
|
||||||
|
|
||||||
|
// domHand subHand ?? :3
|
||||||
|
|
||||||
// if (offHand.trigger.) {
|
// if (offHand.trigger.) {
|
||||||
// lerper.t = 0;
|
// lerper.t = 0;
|
||||||
|
@ -136,24 +145,45 @@ public class Lerper
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Peer {
|
public class Peer {
|
||||||
public string name;
|
public string id;
|
||||||
public Peer(string name) {
|
public Vec3 cursor;
|
||||||
this.name = name;
|
public Pose head;
|
||||||
|
public Pose offHand;
|
||||||
|
public Pose mainHand;
|
||||||
|
public Peer() {
|
||||||
|
id = "";
|
||||||
|
cursor = Vec3.Zero;
|
||||||
|
head = new Pose();
|
||||||
|
offHand = new Pose();
|
||||||
|
mainHand = new Pose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class MonoNet {
|
||||||
|
public string myID;
|
||||||
|
public MonoNet(string name) {
|
||||||
|
this.myID = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vec3 cursor; // is this stored here???
|
public Vec3 cursor; // are these stored here???
|
||||||
public Vec3 peerCursor;
|
public Pose head;
|
||||||
|
public Pose offHand;
|
||||||
|
public Pose mainHand;
|
||||||
|
public Peer[] peers;
|
||||||
|
|
||||||
public async void Start(bool log) {
|
public async void Start(bool log) {
|
||||||
int port = 1234;
|
int port = 1234;
|
||||||
string serverIP = "139.177.201.219";
|
string serverIP = "139.177.201.219";
|
||||||
serverIP = "192.168.1.70";
|
// serverIP = "192.168.1.70";
|
||||||
// try connecting to the server
|
// try connecting to the server
|
||||||
if (log) Console.WriteLine($"{name} attempting to connect to server...");
|
if (log) Console.WriteLine($"{myID} attempting to connect to server...");
|
||||||
|
|
||||||
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
|
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
|
||||||
EndPoint serverEndPoint = new IPEndPoint(IPAddress.Parse(serverIP), port);
|
EndPoint serverEndPoint = new IPEndPoint(IPAddress.Parse(serverIP), port);
|
||||||
socket.Connect(serverEndPoint);
|
socket.Connect(serverEndPoint);
|
||||||
|
|
||||||
|
peers = new Peer[1];
|
||||||
|
peers[0] = new Peer();
|
||||||
|
|
||||||
// send every 0.1 seconds
|
// send every 0.1 seconds
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -162,24 +192,91 @@ public class Peer {
|
||||||
|
|
||||||
// send a message to the server
|
// send a message to the server
|
||||||
dataPos = 0;
|
dataPos = 0;
|
||||||
BitConverter.GetBytes(cursor.x).CopyTo(data, dataPos); dataPos += 4;
|
Encoding.UTF8.GetBytes(myID).CopyTo(data, dataPos); dataPos += 16;
|
||||||
BitConverter.GetBytes(cursor.y).CopyTo(data, dataPos); dataPos += 4;
|
WriteVec3(ref data, ref dataPos, cursor);
|
||||||
BitConverter.GetBytes(cursor.z).CopyTo(data, dataPos); dataPos += 4;
|
WritePose(ref data, ref dataPos, head);
|
||||||
|
WritePose(ref data, ref dataPos, offHand);
|
||||||
|
WritePose(ref data, ref dataPos, mainHand);
|
||||||
socket.SendTo(data, serverEndPoint);
|
socket.SendTo(data, serverEndPoint);
|
||||||
|
|
||||||
// receive a message from the server
|
// receive a message from the server
|
||||||
while (socket.Available > 0){
|
while (socket.Available > 0){
|
||||||
dataPos = 0;
|
dataPos = 0;
|
||||||
socket.ReceiveFrom(data, ref serverEndPoint);
|
socket.ReceiveFrom(data, ref serverEndPoint);
|
||||||
peerCursor.x = BitConverter.ToSingle(data, dataPos); dataPos += 4;
|
string id = Encoding.UTF8.GetString(data, dataPos, 16); dataPos += 16;
|
||||||
peerCursor.y = BitConverter.ToSingle(data, dataPos); dataPos += 4;
|
// recieve text
|
||||||
peerCursor.z = BitConverter.ToSingle(data, dataPos); dataPos += 4;
|
for (int i = 0; i < peers.Length; i++){
|
||||||
|
if (peers[i].id == id) {
|
||||||
|
Peer peer = peers[i];
|
||||||
|
peer.cursor = ReadVec3(data, ref dataPos);
|
||||||
|
peer.head = ReadPose(data, ref dataPos);
|
||||||
|
peer.offHand = ReadPose(data, ref dataPos);
|
||||||
|
peer.mainHand = ReadPose(data, ref dataPos);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// sleep for 0.1 seconds
|
// sleep for 0.1 seconds
|
||||||
await Task.Delay(100);
|
await Task.Delay(100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vec3 ReadVec3(byte[] data, ref int dataPos) {
|
||||||
|
dataPos += 12;
|
||||||
|
return new Vec3(
|
||||||
|
BitConverter.ToSingle(data, dataPos),
|
||||||
|
BitConverter.ToSingle(data, dataPos + 4),
|
||||||
|
BitConverter.ToSingle(data, dataPos + 8)
|
||||||
|
);
|
||||||
|
} void WriteVec3(ref byte[] data, ref int dataPos, Vec3 vec) {
|
||||||
|
BitConverter.GetBytes(vec.x).CopyTo(data, dataPos);
|
||||||
|
BitConverter.GetBytes(vec.y).CopyTo(data, dataPos + 4);
|
||||||
|
BitConverter.GetBytes(vec.z).CopyTo(data, dataPos + 8);
|
||||||
|
dataPos += 12;
|
||||||
|
}
|
||||||
|
|
||||||
|
Quat ReadQuat(byte[] data, ref int dataPos) {
|
||||||
|
dataPos += 16;
|
||||||
|
return new Quat(
|
||||||
|
BitConverter.ToSingle(data, dataPos),
|
||||||
|
BitConverter.ToSingle(data, dataPos + 4),
|
||||||
|
BitConverter.ToSingle(data, dataPos + 8),
|
||||||
|
BitConverter.ToSingle(data, dataPos + 12)
|
||||||
|
);
|
||||||
|
} void WriteQuat(ref byte[] data, ref int dataPos, Quat quat) {
|
||||||
|
BitConverter.GetBytes(quat.x).CopyTo(data, dataPos);
|
||||||
|
BitConverter.GetBytes(quat.y).CopyTo(data, dataPos + 4);
|
||||||
|
BitConverter.GetBytes(quat.z).CopyTo(data, dataPos + 8);
|
||||||
|
BitConverter.GetBytes(quat.w).CopyTo(data, dataPos + 12);
|
||||||
|
dataPos += 16;
|
||||||
|
}
|
||||||
|
|
||||||
|
Pose ReadPose(byte[] data, ref int dataPos) {
|
||||||
|
dataPos += 24;
|
||||||
|
return new Pose(
|
||||||
|
ReadVec3(data, ref dataPos),
|
||||||
|
ReadQuat(data, ref dataPos)
|
||||||
|
);
|
||||||
|
} void WritePose(ref byte[] data, ref int dataPos, Pose pose) {
|
||||||
|
WriteVec3(ref data, ref dataPos, pose.position);
|
||||||
|
WriteQuat(ref data, ref dataPos, pose.orientation);
|
||||||
|
}
|
||||||
|
|
||||||
|
Mesh meshCube = Default.MeshCube;
|
||||||
|
Material matCube = Default.Material;
|
||||||
|
public void Render() {
|
||||||
|
for (int i = 0; i < peers.Length; i++) {
|
||||||
|
Peer p = peers[i];
|
||||||
|
Cubee(Matrix.TRS(p.cursor, p.offHand.orientation, Vec3.One * 0.05f));
|
||||||
|
Cubee(p.head.ToMatrix(Vec3.One * 0.3f));
|
||||||
|
Cubee(p.offHand.ToMatrix(Vec3.One * 0.1f));
|
||||||
|
Cubee(p.mainHand.ToMatrix(Vec3.One * 0.1f));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void Cubee(Matrix m) {
|
||||||
|
meshCube.Draw(matCube, m);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Oriel {
|
public class Oriel {
|
||||||
|
|
Loading…
Add table
Reference in a new issue