OSVR-Core  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
ServerAutoStart.c
Go to the documentation of this file.
1 
11 /*
12 // Copyright 2016 Sensics, Inc.
13 //
14 // Licensed under the Apache License, Version 2.0 (the "License");
15 // you may not use this file except in compliance with the License.
16 // You may obtain a copy of the License at
17 //
18 // http://www.apache.org/licenses/LICENSE-2.0
19 //
20 // Unless required by applicable law or agreed to in writing, software
21 // distributed under the License is distributed on an "AS IS" BASIS,
22 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 // See the License for the specific language governing permissions and
24 // limitations under the License.
25 */
26 
27 /* Internal Includes */
32 
33 /* Library/third-party includes */
34 /* none */
35 
36 /* Standard includes */
37 #include <stdio.h>
38 
39 void myTrackerCallback(void *userdata, const OSVR_TimeValue *timestamp,
40  const OSVR_PoseReport *report) {
41  printf("Got POSE report: Position = (%f, %f, %f), orientation = (%f, %f, "
42  "%f, %f)\n",
43  report->pose.translation.data[0], report->pose.translation.data[1],
44  report->pose.translation.data[2],
45  osvrQuatGetW(&(report->pose.rotation)),
46  osvrQuatGetX(&(report->pose.rotation)),
47  osvrQuatGetY(&(report->pose.rotation)),
48  osvrQuatGetZ(&(report->pose.rotation)));
49 }
50 
51 void myOrientationCallback(void *userdata, const OSVR_TimeValue *timestamp,
52  const OSVR_OrientationReport *report) {
53  printf("Got ORIENTATION report: Orientation = (%f, %f, %f, %f)\n",
54  osvrQuatGetW(&(report->rotation)), osvrQuatGetX(&(report->rotation)),
55  osvrQuatGetY(&(report->rotation)),
56  osvrQuatGetZ(&(report->rotation)));
57 }
58 
59 void myPositionCallback(void *userdata, const OSVR_TimeValue *timestamp,
60  const OSVR_PositionReport *report) {
61  printf("Got POSITION report: Position = (%f, %f, %f)\n",
62  report->xyz.data[0], report->xyz.data[1], report->xyz.data[2]);
63 }
64 
65 int main() {
66  /* This call attempts to auto-start the OSVR server in a platform-specific way.
67  * This only needs to be called once for a given process, though the function is idempotent.
68  * There is no way to determine if the server started successfully except to check that
69  * the OSVR_ClientContext successfully connected to it.
70  */
72 
73  OSVR_ClientContext ctx =
74  osvrClientInit("com.osvr.exampleclients.TrackerCallback", 0);
75 
76  /* This is just one of the paths. You can also use:
77  * /me/hands/right
78  * /me/head
79  */
80  OSVR_ClientInterface lefthand = NULL;
81  osvrClientGetInterface(ctx, "/me/hands/left", &lefthand);
82 
83  /* The coordinate system is right-handed, with X to the right, Y up, and Z
84  * near.
85  */
86  osvrRegisterPoseCallback(lefthand, &myTrackerCallback, NULL);
87 
88  /* If you just want orientation */
89  osvrRegisterOrientationCallback(lefthand, &myOrientationCallback, NULL);
90 
91  /* or position */
92  osvrRegisterPositionCallback(lefthand, &myPositionCallback, NULL);
93 
94  /* Pretend that this is your application's mainloop. */
95  int i;
96  for (i = 0; i < 1000000; ++i) {
97  osvrClientUpdate(ctx);
98  }
99 
100  /* Call this once per process. This cleans up any platform-specific resources related
101  * to the server auto-start functionality. While this function is idempotent, calling it may
102  * shut down the server on some platforms.
103  */
104  osvrClientShutdown(ctx);
105 
106  printf("Library shut down, exiting.\n");
107  return 0;
108 }
OSVR_PoseState pose
The pose structure, containing a position vector and a rotation quaternion.
OSVR_ReturnCode osvrClientGetInterface(OSVR_ClientContext ctx, const char path[], OSVR_ClientInterface *iface)
Get the interface associated with the given path.
OSVR_ReturnCode osvrRegisterOrientationCallback(OSVR_ClientInterface iface, OSVR_OrientationCallback cb, void *userdata)
Register a callback for Orientation reports on an interface.
double osvrQuatGetY(OSVR_Quaternion const *q)
Accessor for quaternion component Y.
Definition: QuaternionC.h:66
OSVR_ReturnCode osvrRegisterPoseCallback(OSVR_ClientInterface iface, OSVR_PoseCallback cb, void *userdata)
Register a callback for Pose reports on an interface.
OSVR_ClientContext osvrClientInit(const char applicationIdentifier[], uint32_t flags=0)
Initialize the library.
OSVR_Quaternion rotation
Orientation as a unit quaternion.
Definition: Pose3C.h:58
double data[3]
Internal array data.
Definition: Vec3C.h:50
OSVR_ReturnCode osvrRegisterPositionCallback(OSVR_ClientInterface iface, OSVR_PositionCallback cb, void *userdata)
Register a callback for Position reports on an interface.
double osvrQuatGetX(OSVR_Quaternion const *q)
Accessor for quaternion component X.
Definition: QuaternionC.h:65
OSVR_ReturnCode osvrClientShutdown(OSVR_ClientContext ctx)
Shutdown the library.
void osvrClientAttemptServerAutoStart()
Ensures the OSVR server process/thread is running. Call once per process. The server may or may not a...
struct OSVR_ClientContextObject * OSVR_ClientContext
Opaque handle that should be retained by your application. You need only and exactly one...
OSVR_ReturnCode osvrClientUpdate(OSVR_ClientContext ctx)
Updates the state of the context - call regularly in your mainloop.
Report type for an orientation callback on a tracker interface.
Header.
double osvrQuatGetW(OSVR_Quaternion const *q)
Accessor for quaternion component W.
Definition: QuaternionC.h:64
OSVR_PositionState xyz
The position vector.
Report type for a position callback on a tracker interface.
struct OSVR_ClientInterfaceObject * OSVR_ClientInterface
Opaque handle to an interface used for registering callbacks and getting status.
Standardized, portable parallel to struct timeval for representing both absolute times and time inter...
Definition: TimeValueC.h:81
OSVR_OrientationState rotation
The rotation unit quaternion.
API to attempt OSVR server auto-start.
double osvrQuatGetZ(OSVR_Quaternion const *q)
Accessor for quaternion component Z.
Definition: QuaternionC.h:67
OSVR_Vec3 translation
Position vector.
Definition: Pose3C.h:56
Header.
Report type for a pose (position and orientation) callback on a tracker interface.