-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
105 lines (76 loc) · 2.24 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include "main.h"
#include <windows.h>
#include "UI.h"
#include "VRChatOSC.h"
#include "NatNet.h"
#include "NatNetCollections.h"
#include "NatNetMath.h"
bool running = true;
int oscHeadOptiTrackId = 5;
int oscOptiTrackIds[8] = {
1, // hip
3, // chest
16, // left foot
20, // right foot
15, // left knee
19, // right knee
8, // left elbow
12, // right elbow
};
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
UI::CreateUI();
while (running)
{
UI::RenderEnvironment();
for (int i = 0; i < NatNetRigidBodyCollection::GetCount(); i++)
{
NatNet::RigidBody activeRigidBody = NatNetRigidBodyCollection::Get(i);
UI::RenderRigidBody(activeRigidBody);
VRChatOSC::NewMessage();
for (int j = 0; j < 8; j++)
{
if (activeRigidBody.id == oscOptiTrackIds[j])
{
VRChatOSC::WritePosition(j, -activeRigidBody.x, activeRigidBody.y, activeRigidBody.z);
NatNetMath::EulerAngles convertedAngles = trackerToVRChat(activeRigidBody);
VRChatOSC::WriteRotation(j, convertedAngles.x, convertedAngles.y, convertedAngles.z);
}
}
VRChatOSC::SendMessage();
}
for (int i = 0; i < NatNetMarkerCollection::GetCount(); i++)
{
UI::RenderMarker(NatNetMarkerCollection::Get(i));
}
UI::RenderUI();
}
VRChatOSC::Disconnect();
NatNet::Disconnect();
UI::DestroyUI();
return 0;
}
void mainExit()
{
running = false;
}
void setOSCTrackerNumber(int oscId, int optitrackId)
{
if (oscId == 0) oscHeadOptiTrackId = optitrackId;
oscOptiTrackIds[oscId - 1] = optitrackId;
}
int getOSCTrackerNumber(int oscId)
{
if (oscId == 0) return oscHeadOptiTrackId;
return oscOptiTrackIds[oscId - 1];
}
NatNetMath::EulerAngles trackerToVRChat(NatNet::RigidBody rigidbody)
{
NatNetMath::Quaternion rotation = { // this had odd negatives because we need a left-handed rotation
rigidbody.rx,
-rigidbody.ry,
-rigidbody.rz,
rigidbody.rw
};
return NatNetMath::Eul_FromQuat(rotation);
}