OSVR-Core  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
TrackerState.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>
29 
30 // Library/third-party includes
31 // - none
32 
33 // Standard includes
34 #include <iostream>
35 
36 int main() {
38  "com.osvr.exampleclients.TrackerState");
39 
40  // This is just one of the paths. You can also use:
41  // /me/hands/right
42  // /me/head
44  context.getInterface("/me/hands/left");
45 
46  // Pretend that this is your application's mainloop.
47  for (int i = 0; i < 1000000; ++i) {
48  context.update();
49  if (i % 100) {
50  // Every so often let's read the tracker state.
51  // Similar methods exist for all other stock report types.
52 
53  // Note that there is not currently a tidy C++ wrapper for
54  // state access, so we're using the C API call directly here.
55  OSVR_PoseState state;
56  OSVR_TimeValue timestamp;
57  OSVR_ReturnCode ret =
58  osvrGetPoseState(lefthand.get(), &timestamp, &state);
59  if (OSVR_RETURN_SUCCESS != ret) {
60  std::cout << "No pose state!" << std::endl;
61  } else {
62  std::cout << "Got POSE state: Position = ("
63  << state.translation.data[0] << ", "
64  << state.translation.data[1] << ", "
65  << state.translation.data[2] << "), orientation = ("
66  << osvrQuatGetW(&(state.rotation)) << ", ("
67  << osvrQuatGetX(&(state.rotation)) << ", "
68  << osvrQuatGetY(&(state.rotation)) << ", "
69  << osvrQuatGetZ(&(state.rotation)) << ")"
70  << std::endl;
71  }
72  }
73  }
74 
75  std::cout << "Library shut down, exiting." << std::endl;
76  return 0;
77 }
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.
double data[3]
Internal array data.
Definition: Vec3C.h:50
double osvrQuatGetX(OSVR_Quaternion const *q)
Accessor for quaternion component X.
Definition: QuaternionC.h:65
OSVR_ClientInterface get()
Get the raw OSVR_ClientInterface from this wrapper.
Definition: Interface.h:55
#define OSVR_RETURN_SUCCESS
The "success" value for an OSVR_ReturnCode.
Definition: ReturnCodesC.h:45
A structure defining a 3D (6DOF) rigid body pose: translation and rotation.
Definition: Pose3C.h:54
double osvrQuatGetW(OSVR_Quaternion const *q)
Accessor for quaternion component W.
Definition: QuaternionC.h:64
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
double osvrQuatGetZ(OSVR_Quaternion const *q)
Accessor for quaternion component Z.
Definition: QuaternionC.h:67
OSVR_Vec3 translation
Position vector.
Definition: Pose3C.h:56
OSVR_ReturnCode osvrGetPoseState(OSVR_ClientInterface iface, struct OSVR_TimeValue *timestamp, OSVR_PoseState *state)
Get Pose state from an interface, returning failure if none \ * exists.