OSVR-Core  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
TrackerCallback.c
Go to the documentation of this file.
1 
11 /*
12 // Copyright 2014 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 */
31 
32 /* Library/third-party includes */
33 /* none */
34 
35 /* Standard includes */
36 #include <stdio.h>
37 
38 void myTrackerCallback(void *userdata, const OSVR_TimeValue *timestamp,
39  const OSVR_PoseReport *report) {
40  printf("Got POSE report: Position = (%f, %f, %f), orientation = (%f, %f, "
41  "%f, %f)\n",
42  report->pose.translation.data[0], report->pose.translation.data[1],
43  report->pose.translation.data[2],
44  osvrQuatGetW(&(report->pose.rotation)),
45  osvrQuatGetX(&(report->pose.rotation)),
46  osvrQuatGetY(&(report->pose.rotation)),
47  osvrQuatGetZ(&(report->pose.rotation)));
48 }
49 
50 void myOrientationCallback(void *userdata, const OSVR_TimeValue *timestamp,
51  const OSVR_OrientationReport *report) {
52  printf("Got ORIENTATION report: Orientation = (%f, %f, %f, %f)\n",
53  osvrQuatGetW(&(report->rotation)), osvrQuatGetX(&(report->rotation)),
54  osvrQuatGetY(&(report->rotation)),
55  osvrQuatGetZ(&(report->rotation)));
56 }
57 
58 void myPositionCallback(void *userdata, const OSVR_TimeValue *timestamp,
59  const OSVR_PositionReport *report) {
60  printf("Got POSITION report: Position = (%f, %f, %f)\n",
61  report->xyz.data[0], report->xyz.data[1], report->xyz.data[2]);
62 }
63 
64 int main() {
65  OSVR_ClientContext ctx =
66  osvrClientInit("com.osvr.exampleclients.TrackerCallback", 0);
67 
68  /* This is just one of the paths. You can also use:
69  * /me/hands/right
70  * /me/head
71  */
72  OSVR_ClientInterface lefthand = NULL;
73  osvrClientGetInterface(ctx, "/me/hands/left", &lefthand);
74 
75  /* The coordinate system is right-handed, with X to the right, Y up, and Z
76  * near.
77  */
78  osvrRegisterPoseCallback(lefthand, &myTrackerCallback, NULL);
79 
80  /* If you just want orientation */
81  osvrRegisterOrientationCallback(lefthand, &myOrientationCallback, NULL);
82 
83  /* or position */
84  osvrRegisterPositionCallback(lefthand, &myPositionCallback, NULL);
85 
86  /* Pretend that this is your application's mainloop. */
87  int i;
88  for (i = 0; i < 1000000; ++i) {
89  osvrClientUpdate(ctx);
90  }
91 
92  osvrClientShutdown(ctx);
93  printf("Library shut down, exiting.\n");
94  return 0;
95 }
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.
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.
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.