diff --git a/CMakeLists.txt b/CMakeLists.txt index 43c3907..3ab3901 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -60,3 +60,12 @@ if (ANDROID_NDK_FOUND) DEPENDS RemoteCaptury.cpp RemoteCaptury.h ) endif(ANDROID_NDK_FOUND) + +# +# add examples +# +find_package(Threads REQUIRED) + +add_executable(PollingExample examples/polling.cpp) +target_include_directories(PollingExample PRIVATE ".") +target_link_libraries(PollingExample RemoteCapturyStatic Threads::Threads) diff --git a/README.md b/README.md index e2410ac..eaded4f 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ cmake --build . -- RemoteCaptury ## Using There are primarily two ways of using the library: -1. A polling interface allows you to query the most recent pose of a given skeleton. This is fairly straight-forward but like all polling based interfaces introduces either more latency or excessive CPU usage. Use `Captury_getCurrentPose(int actorId)`. +1. A polling interface allows you to query the most recent pose of a given skeleton. This is fairly straight-forward but like all polling based interfaces introduces either more latency or excessive CPU usage. Use `Captury_getCurrentPose(int actorId)`. This is shown in the `PollingExample`. 2. You can also register a callback that gets called as soon as a new pose becomes available. This is the recommended way of using RemoteCaptury but can be a bit more complicated as the callback is called from a different thread. Register the callback with `Captury_registerNewPoseCallback(CapturyNewPoseCallback callback)` and be sure your callback finishes quickly because this runs on the socket-communication thread. If this blocks for too long packets may get dropped. The library also provides a mechanism for synchronizing the clocks of the machine running CapturyLive and the machine running RemoteCaptury. It is recommended that both machines are either not synchronized to NTP or that the NTP client does not do "large" jumps. As this will get the clock synchronization out of step for a few seconds. Enable clock synchronization by calling `Captury_startTimeSynchronizationLoop()` once. Once the clock has locked you can call `Captury_getTime()` to get the current time of the machine running CapturyLive. This is implemented without sending a packet to the machine every time you call this function. diff --git a/examples/polling.cpp b/examples/polling.cpp new file mode 100644 index 0000000..48b8eab --- /dev/null +++ b/examples/polling.cpp @@ -0,0 +1,48 @@ +#include +#include "RemoteCaptury.h" + +// this example uses the polling interface to get the current pose of all actors from CapturyLive +int main(int argc, char** argv) +{ + // this is cheating a little as we're not connecting to a remote machine + // but you can change the IP. It should work just as well. + int ret = Captury_connect("127.0.0.1", 2101); + if (ret == 0) + return -1; + + // this is optional but sometimes it's quite useful to know the exact time on the CapturyLive machine. + // The accuracy of the synchronization depends primarily on your OS and the network topology between + // the CapturyLive machine and this machine. On a LAN running Windows on the target machine you can + // expect about 100us accuracy. + Captury_startTimeSynchronizationLoop(); + + // start streaming + // The recommended features are CAPTURY_STREAM_POSES and CAPTURY_STREAM_COMPRESSED. + // Additional flags should be added as required. + Captury_startStreaming(CAPTURY_STREAM_POSES | CAPTURY_STREAM_COMPRESSED); + + while (true) { + // get list of actors - otherwise we won't know whom to poll + const CapturyActor* actors; + int numActors = Captury_getActors(&actors); + + for (int i = 0; i < numActors; ++i) { + CapturyPose* pose = Captury_getCurrentPose(actors[i].id); + if (pose == NULL) + continue; + + + + // make sure to free the pose using the provided function - potential binary incompatibilities between different Microsoft compilers + Captury_freePose(pose); + } + } + + // this is never called - I know. + // Your code will obviously do this right and always clean everything up. + Captury_stopStreaming(); + + Captury_disconnect(); + + return 0; +}