OSVR-Core  0.6-1962-g59773924
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
TrackerState.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 int main() {
39  OSVR_ClientContext ctx =
40  osvrClientInit("com.osvr.exampleclients.TrackerState", 0);
41 
42  OSVR_ClientInterface lefthand = NULL;
43  /* This is just one of the paths. You can also use:
44  * /me/hands/right
45  * /me/head
46  */
47  osvrClientGetInterface(ctx, "/me/hands/left", &lefthand);
48 
49  // Pretend that this is your application's mainloop.
50  int i;
51  for (i = 0; i < 1000000; ++i) {
52  osvrClientUpdate(ctx);
53  if (i % 100) {
54  // Every so often let's read the tracker state.
55  // Similar methods exist for all other stock report types.
56  OSVR_PoseState state;
57  OSVR_TimeValue timestamp;
58  OSVR_ReturnCode ret =
59  osvrGetPoseState(lefthand, &timestamp, &state);
60  if (ret != OSVR_RETURN_SUCCESS) {
61  printf("No pose state!\n");
62  } else {
63  printf("Got POSE state: Position = (%f, %f, %f), orientation = "
64  "(%f, %f, "
65  "%f, %f)\n",
66  state.translation.data[0], state.translation.data[1],
67  state.translation.data[2],
68  osvrQuatGetW(&(state.rotation)),
69  osvrQuatGetX(&(state.rotation)),
70  osvrQuatGetY(&(state.rotation)),
71  osvrQuatGetZ(&(state.rotation)));
72  }
73  }
74  }
75 
76  osvrClientShutdown(ctx);
77  printf("Library shut down, exiting.\n");
78  return 0;
79 }
OSVR_ReturnCode osvrClientGetInterface(OSVR_ClientContext ctx, const char path[], OSVR_ClientInterface *iface)
Get the interface associated with the given path.
double osvrQuatGetY(OSVR_Quaternion const *q)
Accessor for quaternion component Y.
Definition: QuaternionC.h:66
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
double osvrQuatGetX(OSVR_Quaternion const *q)
Accessor for quaternion component X.
Definition: QuaternionC.h:65
OSVR_ReturnCode osvrClientShutdown(OSVR_ClientContext ctx)
Shutdown the library.
#define OSVR_RETURN_SUCCESS
The "success" value for an OSVR_ReturnCode.
Definition: ReturnCodesC.h:45
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.
Header.
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
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
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.
OSVR_ReturnCode osvrGetPoseState(OSVR_ClientInterface iface, struct OSVR_TimeValue *timestamp, OSVR_PoseState *state)
Get Pose state from an interface, returning failure if none \ * exists.