Vulkan Schnee 0.0.1
High-performance rendering engine
Loading...
Searching...
No Matches
OpenXrHelper.h
Go to the documentation of this file.
1#pragma once
2
3#include <glm/gtx/quaternion.hpp>
4#include <openxr/openxr.h>
5#include <stdexcept>
6#include <string>
7
8namespace Engine
9{
11 {
12 public:
16 typedef struct posef
17 {
18 glm::quat orientation{};
19 glm::vec3 position{};
21
33 template <typename T>
34 static void
35 LoadXrFunction( XrInstance xrInstance, const std::string & functionName, T & functionPointer )
36 {
37 XrResult result = xrGetInstanceProcAddr(
38 xrInstance, functionName.c_str(), reinterpret_cast<PFN_xrVoidFunction *>( &functionPointer )
39 );
40 if ( result != XR_SUCCESS )
41 {
42 functionPointer = nullptr;
43 throw std::runtime_error(
44 "Failed to load " + functionName + " with error code: " + std::to_string( result )
45 );
46 }
47
48 if ( !functionPointer )
49 {
50 functionPointer = nullptr;
51 throw std::runtime_error( "Failed to load " + functionName + ". The function was a nullptr" );
52 }
53 }
54
63 static XrPosef makeIdentityPose();
64
75 static glm::mat4 poseToMatrix( const XrPosef & pose );
76
84 static glm::mat4 poseToMatrix( const OpenXrHelper::posef & pose );
85
86 // janhsimons math functions (found undocumented)
87 // Adjustments to naming have been made. Like changing all variables from being named src to
88 // something more descriptive.
89
100 static glm::quat xrQuaternionfToGlmQuat( const XrQuaternionf & xrQuaternion );
101
109 static XrQuaternionf glmQuatToXrQuaternionf( const glm::quat & glmQuaternion );
110
121 static glm::vec3 xrVector3fToGlmVec3( const XrVector3f & xrVector3 );
122
133 static XrVector3f glmVec3ToXrVector3f( const glm::vec3 & glmVector3 );
134
146 static float dot( const glm::quat & a, const glm::quat & b );
147
160 static glm::quat lerpMix( const glm::quat & from, const glm::quat & to, float progress );
161
174 static glm::vec3 lerpMix( const glm::vec3 & from, const glm::vec3 & to, float progress );
175
190 static float lerpMix( float from, float to, float progress );
191
203 static float dot( const glm::vec3 & a, const glm::vec3 & b );
204 static glm::vec3 crossProductVector3( const glm::vec3 & vector_a, const glm::vec3 & vector_b );
205 static float clampf( float num, float left, float right );
206 static float lengthSquared( const glm::vec3 & vec );
207 static float length( const glm::vec3 & vec );
208 static glm::vec3 normalize( const glm::vec3 & vec );
209 static float distanceSquared( const glm::vec3 & vec1, const glm::vec3 & vec2 );
210 static float distance( const glm::vec3 & vec1, const glm::vec3 & vec2 );
211 static glm::quat slerp( const glm::quat & start, const glm::quat & end, float percent );
212 static glm::vec3 slerp( const glm::vec3 & start, const glm::vec3 & end, float percent );
213 static float vectorAngleAroundNormal( const glm::vec3 & vec1, const glm::vec3 & vec2, const glm::vec3 & norm );
214 static glm::mat4 rotationAroundPoint( glm::vec3 point, glm::mat4 rotationMatrix );
215 static void quaternionToAngleAxis( const glm::quat & quat, float & angle, glm::vec3 & axis );
216 static glm::quat quaternionFromAngleAxis( const float & angle, const glm::vec3 & axis );
217 static posef xrPosefToGlmPosef( const XrPosef & xrPosef );
218 static glm::mat4 createProjectionMatrix( XrFovf fov, float nearClip, float farClip );
219
220 static std::string sessionStateToString( XrSessionState state );
221 static const char * GetXrStructureTypeName( XrStructureType type );
222 };
223} // namespace Engine
static float vectorAngleAroundNormal(const glm::vec3 &vec1, const glm::vec3 &vec2, const glm::vec3 &norm)
static glm::quat xrQuaternionfToGlmQuat(const XrQuaternionf &xrQuaternion)
Turns the OpenXR quaternion into an OpenXR quaternion.
static glm::mat4 createProjectionMatrix(XrFovf fov, float nearClip, float farClip)
static void LoadXrFunction(XrInstance xrInstance, const std::string &functionName, T &functionPointer)
Loads a function from openxr which is not loaded at compile time. Retrieves function pointer.
static glm::vec3 normalize(const glm::vec3 &vec)
static float dot(const glm::vec3 &a, const glm::vec3 &b)
The dot product between two glm vector3's.
static float distanceSquared(const glm::vec3 &vec1, const glm::vec3 &vec2)
static glm::vec3 crossProductVector3(const glm::vec3 &vector_a, const glm::vec3 &vector_b)
static float lerpMix(float from, float to, float progress)
Linearly interpolate between two float values.
static float lengthSquared(const glm::vec3 &vec)
static const char * GetXrStructureTypeName(XrStructureType type)
static float clampf(float num, float left, float right)
static void quaternionToAngleAxis(const glm::quat &quat, float &angle, glm::vec3 &axis)
static float distance(const glm::vec3 &vec1, const glm::vec3 &vec2)
static glm::vec3 xrVector3fToGlmVec3(const XrVector3f &xrVector3)
Converts an OpenXR vector3 to a glm vector3.
static glm::quat slerp(const glm::quat &start, const glm::quat &end, float percent)
static glm::mat4 rotationAroundPoint(glm::vec3 point, glm::mat4 rotationMatrix)
static glm::mat4 poseToMatrix(const OpenXrHelper::posef &pose)
Pose of glm components to glm::mat4.
static float length(const glm::vec3 &vec)
static XrPosef makeIdentityPose()
Makes identity pose.
static glm::vec3 slerp(const glm::vec3 &start, const glm::vec3 &end, float percent)
static float dot(const glm::quat &a, const glm::quat &b)
Calculates the dot product between two glm quaternions.
struct Engine::OpenXrHelper::posef posef
A glm based posef struct.
static posef xrPosefToGlmPosef(const XrPosef &xrPosef)
static XrVector3f glmVec3ToXrVector3f(const glm::vec3 &glmVector3)
Converts a glm::vec3 to a XrVector3f.
static std::string sessionStateToString(XrSessionState state)
static glm::vec3 lerpMix(const glm::vec3 &from, const glm::vec3 &to, float progress)
Linearly interpolate between two glm vector3's.
static glm::quat lerpMix(const glm::quat &from, const glm::quat &to, float progress)
Linearly interpolate between two quaternions.
static glm::quat quaternionFromAngleAxis(const float &angle, const glm::vec3 &axis)
static XrQuaternionf glmQuatToXrQuaternionf(const glm::quat &glmQuaternion)
Glm quaternion to xr quaternionf.
static glm::mat4 poseToMatrix(const XrPosef &pose)
Converts an XrPosef to a glm::mat4.
A glm based posef struct.