NDEVR
API Documentation
XRFunctions.h
1#pragma once
2#include "openxr/openxr.h"
3#include "Base/Headers/Vertex.hpp"
4#include "Base/Headers/Angle.h"
5namespace NDEVR
6{
11 {
12 public:
16 static Vertex<3, fltp04> ConvertVertex(const XrVector3f& position)
17 {
18 return Vertex<3, fltp04>(-position.z, -position.x, position.y);
19 }
20
26 {
27 return Vertex<3, fltp08>(-z, -x, y);
28 }
29
32 static Vector<3, Angle<fltp08>> ConvertFromQuaternion(const XrQuaternionf& quaternion)
33 {
34 return ConvertFromQuaternion(quaternion.x, quaternion.y, quaternion.z, quaternion.w);
35 }
36
43 {
45 fltp08 val = qx * qy + qz * qw;
46 if (val >= .49999)
47 {
48 angles[YAW] = 2.0 * Angle<fltp08>::atan2(qx, qw);
49 angles[PITCH] = Angle<fltp08>(DEGREES, 90.0);
50 }
51 else if (val <= -.49999)
52 {
53 angles[YAW] = -2.0 * Angle<fltp08>::atan2(qx, qw);
54 angles[PITCH] = Angle<fltp08>(DEGREES, -90.0);
55 }
56 else
57 {
58 angles[YAW] = Angle<fltp08>::atan2(2 * qy * qw - 2 * qx * qz, 1 - 2 * pow(qy, 2.0) - 2 * pow(qz, 2.0));
59 angles[ROLL] = Angle<fltp08>::asin(2 * qx * qy + 2.0 * qz * qw);
60 angles[PITCH] = Angle<fltp08>::atan2(2 * qx * qw - 2 * qy * qz, 1 - 2 * pow(qx, 2.0) - 2 * pow(qz, 2));
61 }
62 return angles;
63 }
64 };
65}
Stores an angle in an optimized internal format with support for efficient trigonometric operations.
Definition Angle.h:83
static Angle asin(t_value_type value)
Computes the principal value of the arc sine of the given value.
Definition Angle.h:277
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:300
A fixed-size array with N dimensions used as the basis for geometric and mathematical types.
Definition Vector.hpp:62
A point in N-dimensional space, used primarily for spatial location information.
Definition Vertex.hpp:44
Common helper functions for easier interfacing with the OpenXR engine.
Definition XRFunctions.h:11
static Vertex< 3, fltp04 > ConvertVertex(const XrVector3f &position)
Convert an OpenXR position vector to the NDEVR coordinate system.
Definition XRFunctions.h:16
static Vector< 3, Angle< fltp08 > > ConvertFromQuaternion(fltp08 qx, fltp08 qy, fltp08 qz, fltp08 qw)
Convert quaternion components to Euler angles.
Definition XRFunctions.h:42
static Vector< 3, Angle< fltp08 > > ConvertFromQuaternion(const XrQuaternionf &quaternion)
Convert an OpenXR quaternion to Euler angles.
Definition XRFunctions.h:32
static Vertex< 3, fltp08 > ConvertVertex(fltp08 x, fltp08 y, fltp08 z)
Convert XYZ coordinates to the NDEVR coordinate system.
Definition XRFunctions.h:25
The primary namespace for the NDEVR SDK.
@ YAW
Rotation about the vertical axis (Z).
Definition Angle.h:47
@ PITCH
Rotation about the lateral axis (Y).
Definition Angle.h:46
@ ROLL
Rotation about the forward axis (X).
Definition Angle.h:45
double fltp08
Defines an alias representing an 8 byte floating-point number.
@ DEGREES
Angle measured in degrees (0 to 360 for a full circle).
Definition Angle.h:58