API Documentation
Loading...
Searching...
No Matches
XRFunctions.h
Go to the documentation of this file.
1#pragma once
2#include "openxr/openxr.h"
5namespace NDEVR
6{
7 /**--------------------------------------------------------------------------------------------------
8 \brief Common helper functions for easier interfacing with the OpenXR engine.
9 **/
11 {
12 public:
13 static Vertex<3, fltp04> ConvertVertex(const XrVector3f& position)
14 {
15 return Vertex<3, fltp04>(-position.z, -position.x, position.y);
16 }
18 {
19 return Vertex<3, fltp08>(-z, -x, y);
20 }
21 static Vector<3, Angle<fltp08>> ConvertFromQuaternion(const XrQuaternionf& quaternion)
22 {
23 return ConvertFromQuaternion(quaternion.x, quaternion.y, quaternion.z, quaternion.w);
24 }
26 {
28 fltp08 val = qx * qy + qz * qw;
29 if (val >= .49999)
30 {
31 angles[YAW] = 2.0 * Angle<fltp08>::atan2(qx, qw);
32 angles[PITCH] = Angle<fltp08>(DEGREES, 90.0);
33 }
34 else if (val <= -.49999)
35 {
36 angles[YAW] = -2.0 * Angle<fltp08>::atan2(qx, qw);
37 angles[PITCH] = Angle<fltp08>(DEGREES, -90.0);
38 }
39 else
40 {
41 angles[YAW] = Angle<fltp08>::atan2(2 * qy * qw - 2 * qx * qz, 1 - 2 * pow(qy, 2.0) - 2 * pow(qz, 2.0));
42 angles[ROLL] = Angle<fltp08>::asin(2 * qx * qy + 2.0 * qz * qw);
43 angles[PITCH] = Angle<fltp08>::atan2(2 * qx * qw - 2 * qy * qz, 1 - 2 * pow(qx, 2.0) - 2 * pow(qz, 2));
44 }
45 return angles;
46 }
47 };
48}
The primary angle storage class for this API. Stores an angle in an optimized format.
Definition StringStream.h:540
static Angle asin(t_value_type value)
Computes the principal value of the arc sine of the given value.
Definition Angle.h:305
static Angle atan2(t_value_type x, t_value_type y)
measures the counterclockwise angle between the positive x-axis and the point (x, y)
Definition Angle.h:328
A fixed-size array with better performance compared to dynamic containers.
Definition Vector.hpp:60
A vertex or point. A specific type of Vector used primarily for spacial location information.
Definition Vertex.hpp:48
Common helper functions for easier interfacing with the OpenXR engine.
Definition XRFunctions.h:11
static Vector< 3, Angle< fltp08 > > ConvertFromQuaternion(const XrQuaternionf &quaternion)
Definition XRFunctions.h:21
static Vertex< 3, fltp04 > ConvertVertex(const XrVector3f &position)
Definition XRFunctions.h:13
static Vector< 3, Angle< fltp08 > > ConvertFromQuaternion(fltp08 qx, fltp08 qy, fltp08 qz, fltp08 qw)
Definition XRFunctions.h:25
static Vertex< 3, fltp08 > ConvertVertex(fltp08 x, fltp08 y, fltp08 z)
Definition XRFunctions.h:17
Definition ACIColor.h:37
@ ROLL
Definition Angle.h:45
@ YAW
Definition Angle.h:47
@ PITCH
Definition Angle.h:46
@ DEGREES
Definition Angle.h:58
double fltp08
Defines an alias representing an 8 byte floating-point number.
Definition BaseValues.hpp:149