OSVR-Core  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
TrackerCallback.cpp
Go to the documentation of this file.
1 
11 // Copyright 2014 Sensics, Inc.
12 //
13 // Licensed under the Apache License, Version 2.0 (the "License");
14 // you may not use this file except in compliance with the License.
15 // You may obtain a copy of the License at
16 //
17 // http://www.apache.org/licenses/LICENSE-2.0
18 //
19 // Unless required by applicable law or agreed to in writing, software
20 // distributed under the License is distributed on an "AS IS" BASIS,
21 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 // See the License for the specific language governing permissions and
23 // limitations under the License.
24 
25 // Internal Includes
26 #include <osvr/ClientKit/Context.h>
28 
29 // Library/third-party includes
30 // - none
31 
32 // Standard includes
33 #include <iostream>
34 
35 void myTrackerCallback(void * /*userdata*/,
36  const OSVR_TimeValue * /*timestamp*/,
37  const OSVR_PoseReport *report) {
38  std::cout << "Got POSE report: Position = ("
39  << report->pose.translation.data[0] << ", "
40  << report->pose.translation.data[1] << ", "
41  << report->pose.translation.data[2] << "), orientation = ("
42  << osvrQuatGetW(&(report->pose.rotation)) << ", ("
43  << osvrQuatGetX(&(report->pose.rotation)) << ", "
44  << osvrQuatGetY(&(report->pose.rotation)) << ", "
45  << osvrQuatGetZ(&(report->pose.rotation)) << "))" << std::endl;
46 }
47 
48 void myOrientationCallback(void * /*userdata*/,
49  const OSVR_TimeValue * /*timestamp*/,
50  const OSVR_OrientationReport *report) {
51  std::cout << "Got ORIENTATION report: Orientation = ("
52  << osvrQuatGetW(&(report->rotation)) << ", ("
53  << osvrQuatGetX(&(report->rotation)) << ", "
54  << osvrQuatGetY(&(report->rotation)) << ", "
55  << osvrQuatGetZ(&(report->rotation)) << "))" << std::endl;
56 }
57 
58 void myPositionCallback(void * /*userdata*/,
59  const OSVR_TimeValue * /*timestamp*/,
60  const OSVR_PositionReport *report) {
61  std::cout << "Got POSITION report: Position = (" << report->xyz.data[0]
62  << ", " << report->xyz.data[1] << ", " << report->xyz.data[2]
63  << ")" << std::endl;
64 }
65 
66 int main() {
68  "com.osvr.exampleclients.TrackerCallback");
69 
70  // This is just one of the paths. You can also use:
71  // /me/hands/right
72  // /me/head
74  context.getInterface("/me/hands/left");
75 
76  // The coordinate system is right-handed, with X to the right, Y up, and Z
77  // near.
78  lefthand.registerCallback(&myTrackerCallback, NULL);
79 
81  lefthand.registerCallback(&myOrientationCallback, NULL);
82 
84  lefthand.registerCallback(&myPositionCallback, NULL);
85 
86  // Pretend that this is your application's mainloop.
87  for (int i = 0; i < 1000000; ++i) {
88  context.update();
89  }
90 
91  std::cout << "Library shut down, exiting." << std::endl;
92  return 0;
93 }
OSVR_PoseState pose
The pose structure, containing a position vector and a rotation quaternion.
Interface handle object. Typically acquired from a ClientContext.
Client context object: Create and keep one in your application. Handles lifetime management and provi...
Definition: Context_decl.h:57
double osvrQuatGetY(OSVR_Quaternion const *q)
Accessor for quaternion component Y.
Definition: QuaternionC.h:66
OSVR_Quaternion rotation
Orientation as a unit quaternion.
Definition: Pose3C.h:58
Header.
int main()
double data[3]
Internal array data.
Definition: Vec3C.h:50
Interface getInterface(const std::string &path)
Get the interface associated with the given path.
Definition: Context.h:61
double osvrQuatGetX(OSVR_Quaternion const *q)
Accessor for quaternion component X.
Definition: QuaternionC.h:65
Report type for an orientation callback on a tracker interface.
void update()
Updates the state of the context - call regularly in your mainloop.
Definition: Context.h:54
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.
Header containing the inline implementation of Interface.
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
Report type for a pose (position and orientation) callback on a tracker interface.