-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathexample.cpp
More file actions
73 lines (64 loc) · 2.57 KB
/
example.cpp
File metadata and controls
73 lines (64 loc) · 2.57 KB
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
// Copyright Motion Workshop. All Rights Reserved.
#include <Client.hpp>
#include <Format.hpp>
#include <iostream>
// Example application for the Motion C++ SDK classes.
int main(int argc, char** argv)
{
using namespace Motion::SDK;
// Connect to a data service running in the Shadow software on your local
// computer. The SDK is network capable and uses TCP sockets for transport.
Client client("", 32076);
if (!client.isConnected()) {
std::cerr << "failed to connect data service at localhost:32076\n";
return -1;
}
// The Configurable service sends back any channels that we request at
// connection time.
{
// This is a typical setup for skeletal animation streaming. Local joint
// rotations and world space joint positions. Enable inactive nodes to
// get all joints in the skeleton.
// Lq = local quaternion rotation, 4 channels
// c = global positional constraint, 4 channels
const std::string xml =
"<?xml version=\"1.0\"?>"
"<configurable inactive=\"1\"><Lq/><c/></configurable>";
Client::data_type data(xml.begin(), xml.end());
if (!client.writeData(data)) {
std::cerr << "failed to write channel list to data service\n";
return -1;
}
}
// Block for up to 5 seconds. Wait for the first sample to arrive from the
// data service.
if (!client.waitForData()) {
std::cerr
<< "no data available after 5 seconds, device not connected\n";
return -1;
}
// Enter the sample loop. For this quick start, just read 5 samples.
for (int i = 0; i < 5; ++i) {
// Read a message. The SDK connections are stream oriented and messages
// arrive in sequence.
Client::data_type data;
if (!client.readData(data)) {
std::cerr << "failed to read sample, data stream interrupted\n";
return -1;
}
// We have a binary sample message from the data service. Parse it with
// the Format class. Returns a std::map from integer key to
// ConfigurableElement.
auto map = Format::Configurable(data.begin(), data.end());
for (auto& kvp : map) {
auto& item = kvp.second;
// The Configurable service sends a variable number of channels. We
// should have 8 per device since that is what we asked for.
for (std::size_t j = 0; j < item.size(); ++j) {
std::cout << item[j] << " ";
}
}
std::cout << "\n";
}
return 0;
}