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 <array>
4#include <glm/gtx/quaternion.hpp>
5#include <openxr/openxr.h>
6#include <stdexcept>
7#include <string>
8
9namespace EngineCore
10{
12{
13 public:
20 typedef struct posef
21 {
22 glm::quat orientation{};
23 glm::vec3 position{};
25
36 template <typename T>
37 static void LoadXrFunction(XrInstance xrInstance, const std::string& functionName, T& functionPointer)
38 {
39 XrResult result = xrGetInstanceProcAddr(xrInstance, functionName.c_str(), reinterpret_cast<PFN_xrVoidFunction*>(&functionPointer));
40 if (result != XR_SUCCESS)
41 {
42 functionPointer = nullptr;
43 throw std::runtime_error("Failed to load " + functionName + " with error code: " + std::to_string(result));
44 }
45
46 if (!functionPointer)
47 {
48 functionPointer = nullptr;
49 throw std::runtime_error("Failed to load " + functionName + ". The function was a nullptr");
50 }
51 }
52
61 static XrPosef makeIdentityPose();
62
73 static glm::mat4 poseToMatrix(const XrPosef& pose);
74
85 static glm::mat4 poseToMatrix(const OpenXrHelper::posef& pose);
86
87 // janhsimons math functions (found undocumented)
88 // Adjustments to naming have been made. Like changing all variables from being named src to
89 // something more descriptive.
90
101 static glm::quat xrQuaternionfToGlmQuat(const XrQuaternionf& xrQuaternion);
102
113 static XrQuaternionf glmQuatToXrQuaternionf(const glm::quat& glmQuaternion);
114
125 static glm::vec3 xrVector3fToGlmVec3(const XrVector3f& xrVector3);
126
137 static XrVector3f glmVec3ToXrVector3f(const glm::vec3& glmVector3);
138
150 static float dot(const glm::quat& a, const glm::quat& b);
151
164 static glm::quat lerpMix(const glm::quat& from, const glm::quat& to, float progress);
165
178 static glm::vec3 lerpMix(const glm::vec3& from, const glm::vec3& to, float progress);
179
194 static float lerpMix(float from, float to, float progress);
195
207 static float dot(const glm::vec3& a, const glm::vec3& b);
208 static glm::vec3 crossProductVector3(const glm::vec3& vector_a, const glm::vec3& vector_b);
209 static float clampf(float num, float left, float right);
210 static float lengthSquared(const glm::vec3& vec);
211 static float length(const glm::vec3& vec);
212 static glm::vec3 normalize(const glm::vec3& vec);
213 static float distanceSquared(const glm::vec3& vec1, const glm::vec3& vec2);
214 static float distance(const glm::vec3& vec1, const glm::vec3& vec2);
215 static glm::quat slerp(const glm::quat& start, const glm::quat& end, float percent);
216 static glm::vec3 slerp(const glm::vec3& start, const glm::vec3& end, float percent);
217 static float vectorAngleAroundNormal(const glm::vec3& vec1, const glm::vec3& vec2, const glm::vec3& norm);
218 static glm::mat4 rotationAroundPoint(glm::vec3 point, glm::mat4 rotationMatrix);
219 static void quaternionToAngleAxis(const glm::quat& quat, float& angle, glm::vec3& axis);
220 static glm::quat quaternionFromAngleAxis(const float& angle, const glm::vec3& axis);
221 static posef xrPosefToGlmPosef(const XrPosef& xrPosef);
222 static glm::mat4 createProjectionMatrix(XrFovf fov, float nearClip, float farClip);
223
224 static std::string sessionStateToString(XrSessionState state);
225 static const char* GetXrStructureTypeName(XrStructureType type);
226};
227} // namespace EngineCore
static float dot(const glm::quat &a, const glm::quat &b)
Calculates the dot product between two glm quaternions.
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 posef xrPosefToGlmPosef(const XrPosef &xrPosef)
static XrQuaternionf glmQuatToXrQuaternionf(const glm::quat &glmQuaternion)
Glm quaternion to xr quaternionf.
static std::string sessionStateToString(XrSessionState state)
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::quat quaternionFromAngleAxis(const float &angle, const glm::vec3 &axis)
static XrPosef makeIdentityPose()
Makes identity pose.
static glm::mat4 createProjectionMatrix(XrFovf fov, float nearClip, float farClip)
static float length(const glm::vec3 &vec)
static glm::vec3 crossProductVector3(const glm::vec3 &vector_a, const glm::vec3 &vector_b)
static void quaternionToAngleAxis(const glm::quat &quat, float &angle, glm::vec3 &axis)
static float distance(const glm::vec3 &vec1, const glm::vec3 &vec2)
static float vectorAngleAroundNormal(const glm::vec3 &vec1, const glm::vec3 &vec2, const glm::vec3 &norm)
static glm::mat4 poseToMatrix(const XrPosef &pose)
Converts an XrPosef to a glm::mat4.
static const char * GetXrStructureTypeName(XrStructureType type)
static glm::vec3 xrVector3fToGlmVec3(const XrVector3f &xrVector3)
Converts an OpenXR vector3 to a glm vector3.
struct EngineCore::OpenXrHelper::posef posef
A glm based posef struct.
static glm::quat lerpMix(const glm::quat &from, const glm::quat &to, float progress)
Linearly interpolate between two quaternions.
static XrVector3f glmVec3ToXrVector3f(const glm::vec3 &glmVector3)
Converts a glm::vec3 to a XrVector3f.
static float distanceSquared(const glm::vec3 &vec1, const glm::vec3 &vec2)
static float clampf(float num, float left, float right)
static float lengthSquared(const glm::vec3 &vec)
static glm::quat xrQuaternionfToGlmQuat(const XrQuaternionf &xrQuaternion)
Turns the OpenXR quaternion into an OpenXR quaternion.
static glm::vec3 normalize(const glm::vec3 &vec)
Log category system implementation.
A glm based posef struct.