HoviTron Video Pipeline
Public Member Functions
WindowOpenXR Class Reference

Class that take care of the tasks linked to OpenXR (input and display), is used when HMD support is requested.
More...

#include <WindowOpenXR.h>

Inheritance diagram for WindowOpenXR:
WindowAbstract

Public Member Functions

void initWindow () override
 
void continueInit () override
 
void cleanUp () override
 
void cleanUpSurface () override
 
void mainLoop (VulkanDrawing *vulkanDrawing) override
 
void createSurface () override
 
std::vector< const char * > getRequiredExtensions () override
 
VkBool32 isDeviceSupportingSufaceKHR (VkPhysicalDevice device, int i) override
 
std::vector< const char * > getRequiredDeviceExtensions () override
 
SwapChainSupportDetails querySwapChainSupport (vk::PhysicalDevice device) override
 
void getFrameBufferSize (int *w, int *h, vk::PhysicalDevice &pDevice) override
 
bool isSynchroWithSemaphore () override
 
bool isDepthRecquired () override
 
const bool useOpenXR () override
 
vk::Image getSwapchainImage (int view, int index) override
 
void resetOrigin () override
 
void framebufferResizeCallback ()
 
void checkForCorrectSize ()
 
std::vector< vk::Image > getBlitDestinations (int view, int elem) override
 
std::vector< vk::Extent2D > getBlitExtentDestinations (int view, int elem) override
 
virtual std::vector< vk::Semaphore > getSemaphoreWait (int view, int elem) override
 
virtual std::vector< vk::Semaphore > getSemaphoreSignal (int view, int elem) override
 
void getVulkanPhysicalDevice (VkInstance &vkInstance, VkPhysicalDevice *physicalDevice)
 
void createVulkanDevice (VkPhysicalDevice &physicalDevice, VkDeviceCreateInfo &info, VkDevice *device)
 
void pollEvents (bool *exitRenderLoop, bool *requestRestart)
 
bool isSessionRunning ()
 
void setRotation (glm::quat &q, int view)
 
void setMirror (bool mirrorActivated)
 
- Public Member Functions inherited from WindowAbstract
virtual void initWindow ()=0
 
virtual void continueInit ()=0
 
virtual void cleanUp ()=0
 
virtual void cleanUpSurface ()=0
 
virtual void mainLoop (VulkanDrawing *vulkanDrawing)=0
 
virtual void createSurface ()=0
 
virtual std::vector< const char * > getRequiredExtensions ()=0
 
const bool isValidationLayersEnabled ()
 
virtual VkBool32 isDeviceSupportingSufaceKHR (VkPhysicalDevice device, int i)=0
 
virtual std::vector< const char * > getRequiredDeviceExtensions ()=0
 
virtual SwapChainSupportDetails querySwapChainSupport (vk::PhysicalDevice device)=0
 
bool isSwapChainNeeded ()
 
bool isIndepFromWindowDimension ()
 
virtual const bool useOpenXR ()
 
virtual bool isDepthRecquired ()
 
virtual bool isSynchroWithSemaphore ()=0
 
virtual void getFrameBufferSize (int *w, int *h, vk::PhysicalDevice &pDevice)=0
 
void setWrapper (VulkanWrapper *wraps)
 
virtual void checkForCorrectSize ()=0
 
virtual vk::Buffer getRenderingDestination ()
 
virtual vk::Image getSwapchainImage (int view, int index)
 
virtual vk::Image getDepthSwapchainImage (int view, int index)
 
glm::vec3 getTranslation ()
 
void setRotation (float v0, float v1, float v3)
 
glm::vec3 getRotation ()
 
virtual std::vector< vk::Image > getBlitDestinations (int view, int elem)
 
virtual std::vector< vk::Extent2D > getBlitExtentDestinations (int view, int elem)
 
virtual std::vector< vk::Semaphore > getSemaphoreWait (int view, int elem)
 
virtual std::vector< vk::Semaphore > getSemaphoreSignal (int view, int elem)
 
vk::ImageView getSwapchainImageView (int view, int elem)
 
vk::ImageView getDepthSwapchainImageView (int view, int elem)
 
int getViewNumber ()
 
int getAttachmentSize ()
 
virtual vk::Extent2D getSwapchainExtent (int view)
 
virtual vk::Format getSwapchainFormat (int view)
 
virtual vk::Format getDepthSwapchainFormat (int view)
 
virtual void resetOrigin ()=0
 
virtual ~WindowAbstract ()=default
 

Additional Inherited Members

- Protected Attributes inherited from WindowAbstract
std::vector< std::unique_ptr< SwapchainAbstract > > swapchains
 
std::vector< std::unique_ptr< SwapchainAbstract > > depthSwapchains
 
bool separateFromWindowDim = false
 
const std::vector< const char * > deviceExtensions
 
VulkanWrapperwrapper = nullptr
 
glm::vec3 currentRotation = {0,0,0}
 
glm::vec3 currentTranslation = {0,0,0}
 
bool needSwapchain = true
 
bool initialised = false
 
const bool enableValidationLayers = false
 
bool qualibrationMode = false
 
int selectedCamera = -1
 

Detailed Description

Class that take care of the tasks linked to OpenXR (input and display), is used when HMD support is requested.

This class have to take care of all the task linked to OpenXR (initialization, main loop, input handling, ... ). To properly use the light field in Creal headset, 2 extensions of OpenXR should be supported: XR_VARJO_QUAD_VIEWS and XR_KHR_COMPOSITION_LAYER_DEPTH The management of the swapchain is delegated to SwapchainOpenXR class. This class is also able to create a "mirror" window that will show the result of the rendering of the first view (usually left eye) Contains a lot of platform dependent code. Android related code is present as a legacy, please don't use it.

Definition at line 52 of file WindowOpenXR.h.

Member Function Documentation

◆ checkForCorrectSize()

void WindowOpenXR::checkForCorrectSize ( )
virtual

Make no sense in this context

Implements WindowAbstract.

Definition at line 426 of file WindowOpenXR.cpp.

427 {
428 }

◆ cleanUp()

void WindowOpenXR::cleanUp ( )
overridevirtual

Clean up allocated ressources

Implements WindowAbstract.

Definition at line 171 of file WindowOpenXR.cpp.

172{
173 /*
174 for (Swapchain swapchain : xrSwapchains) {
175 xrDestroySwapchain(swapchain.handle);
176 }*/
177 for (int i = 0; i < swapchains.size(); i++) {
178 swapchains[i]->cleanup();
179 }
180 swapchains.clear();
181
182 for (XrSpace visualizedSpace : xrVisualizedSpaces) {
183 xrDestroySpace(visualizedSpace);
184 }
185
186 if (refSpace != XR_NULL_HANDLE) {
187 xrDestroySpace(refSpace);
188 }
189
190 xrDestroySession(xrSession);
191
192 wrapper->endCleanUp();
193
194 xrDestroyInstance(xrInstance);
195
196#ifdef __ANDROID__
197 appAndroid->activity->vm->DetachCurrentThread();
198#endif //
199#ifndef __ANDROID__
200 if (mirrorActivated) {
201 glfwDestroyWindow(window);
202 glfwTerminate();
203 }
204#endif //
205}
std::vector< std::unique_ptr< SwapchainAbstract > > swapchains
VulkanWrapper * wrapper

◆ cleanUpSurface()

void WindowOpenXR::cleanUpSurface ( )
overridevirtual

Clean up mirror swapchain if needed

Implements WindowAbstract.

Definition at line 233 of file WindowOpenXR.cpp.

234{
235 if (mirrorActivated) {
236 cleanUpMirrorSwapchain();
237 VkInstance instance = static_cast<VkInstance>(wrapper->context.instance);
238 vkDestroySurfaceKHR(instance, surface, nullptr);
239 }
240}
vk::Instance instance
Definition: VulkanContext.h:83
VulkanContext context

◆ continueInit()

void WindowOpenXR::continueInit ( )
overridevirtual

Continue initialisation after context

Implements WindowAbstract.

Definition at line 136 of file WindowOpenXR.cpp.

137{
138
139 graphicsBinding = wrapper->getGraphicsBinding();
140 XrSessionCreateInfo createInfoSession{ XR_TYPE_SESSION_CREATE_INFO };
141 createInfoSession.next = &graphicsBinding;
142 createInfoSession.systemId = systemId;
143
144 PRINT("Before session creation");
145 CHECK_XRCMD(xrCreateSession(xrInstance, &createInfoSession, &xrSession));
146 PRINT("Session created !");
147
148 LogReferenceSpaces();
149
150 //if we want to create actions, change it here
151
152 //create XRSpace
153 CreateSpaces();
154
155 PRINT("Space created!");
156 //create Swapchain
157
159 CreateSwapChain();
160 if (mirrorActivated) {
161 createMirrorSwapchain();
162 }
163
164}
void createSurface() override

◆ createSurface()

void WindowOpenXR::createSurface ( )
overridevirtual

Create surface for the mirror if needed

Implements WindowAbstract.

Definition at line 281 of file WindowOpenXR.cpp.

282{
283#ifndef __ANDROID__
284 if (mirrorActivated) {
285 if (auto res = glfwCreateWindowSurface(wrapper->context.instance, window, nullptr, &surface); res != VK_SUCCESS) {
286 throw std::runtime_error("failed to create window surface! (" + std::to_string(res) + ")");
287 }
288 }
289#endif
290}

◆ createVulkanDevice()

void WindowOpenXR::createVulkanDevice ( VkPhysicalDevice &  physicalDevice,
VkDeviceCreateInfo &  info,
VkDevice *  device 
)

Let OpenXR create the Vulkan Device

Definition at line 721 of file WindowOpenXR.cpp.

721 {
722 XrVulkanDeviceCreateInfoKHR deviceCreateInfo{ XR_TYPE_VULKAN_DEVICE_CREATE_INFO_KHR };
723 deviceCreateInfo.systemId = systemId;
724 deviceCreateInfo.pfnGetInstanceProcAddr = reinterpret_cast<PFN_vkGetInstanceProcAddr>(&vkGetInstanceProcAddr);
725 deviceCreateInfo.vulkanCreateInfo = &info;
726 deviceCreateInfo.vulkanPhysicalDevice = physicalDevice;
727 deviceCreateInfo.vulkanAllocator = nullptr;
728 VkResult err;
729 CHECK_XRCMD(CreateVulkanDeviceKHR(xrInstance, &deviceCreateInfo, device, &err));
730 if (err != VK_SUCCESS) {
731 throw std::runtime_error("Error creating the device");
732 }
733 }

◆ framebufferResizeCallback()

void WindowOpenXR::framebufferResizeCallback ( )

Callback to resize framebuffer

Definition at line 421 of file WindowOpenXR.cpp.

422 {
424 }
bool framebufferResized

◆ getBlitDestinations()

std::vector< vk::Image > WindowOpenXR::getBlitDestinations ( int  view,
int  elem 
)
overridevirtual

Obtain destination for blit operation

Reimplemented from WindowAbstract.

Definition at line 430 of file WindowOpenXR.cpp.

431 {
432 auto res = std::vector<vk::Image>();
433 if (mirrorActivated && view == 0 && elem < mirrorSwapchainSize && mirrorShouldRender) {
434 res.push_back(mirrorImages[elem]);
435 }
436 return res;
437 }

◆ getBlitExtentDestinations()

std::vector< vk::Extent2D > WindowOpenXR::getBlitExtentDestinations ( int  view,
int  elem 
)
overridevirtual

Obtain extent destination for blit operation

Reimplemented from WindowAbstract.

Definition at line 439 of file WindowOpenXR.cpp.

440 {
441 auto res = std::vector<vk::Extent2D>();
442 if (mirrorActivated && view == 0 && elem < mirrorSwapchainSize && mirrorShouldRender) {
443 res.push_back(vk::Extent2D{ width,height });
444 }
445 return res;
446 }

◆ getFrameBufferSize()

void WindowOpenXR::getFrameBufferSize ( int *  w,
int *  h,
vk::PhysicalDevice &  pDevice 
)
overridevirtual

return the framebuffer size

Implements WindowAbstract.

Definition at line 408 of file WindowOpenXR.cpp.

408 {
409
410 }

◆ getRequiredDeviceExtensions()

std::vector< const char * > WindowOpenXR::getRequiredDeviceExtensions ( )
overridevirtual

Return required extensions for the Vulkan Device

Implements WindowAbstract.

Definition at line 366 of file WindowOpenXR.cpp.

367 {
368 PFN_xrGetVulkanDeviceExtensionsKHR pfnGetVulkanDeviceExtensionsKHR = nullptr;
369 CHECK_XRCMD(xrGetInstanceProcAddr(xrInstance, "xrGetVulkanDeviceExtensionsKHR",
370 reinterpret_cast<PFN_xrVoidFunction*>(&pfnGetVulkanDeviceExtensionsKHR)));
371
372 uint32_t deviceExtensionNamesSize = 0;
373 CHECK_XRCMD(pfnGetVulkanDeviceExtensionsKHR(xrInstance, systemId, 0, &deviceExtensionNamesSize, nullptr));
374 deviceExtension = std::vector<char>(deviceExtensionNamesSize);
375 CHECK_XRCMD(pfnGetVulkanDeviceExtensionsKHR(xrInstance, systemId, deviceExtensionNamesSize,
376 &deviceExtensionNamesSize, &deviceExtension[0]));
377
378 std::vector<const char*> extensions = additionalDeviceExtensions;
379 for (int i = 0; i < deviceExtension.size(); i++) {
380 extensions.push_back(&deviceExtension[i]);
381 while (i < deviceExtension.size()) {
382 if (deviceExtension[i] == ' ') {
383 deviceExtension[i] = '\0';
384 break;
385 }
386 i++;
387 }
388 }
389
390
391
392 return extensions;
393
394 //return deviceExtensions;
395
396
397 }

◆ getRequiredExtensions()

std::vector< const char * > WindowOpenXR::getRequiredExtensions ( )
overridevirtual

Return required extensions for Vulkan Instance

Implements WindowAbstract.

Definition at line 292 of file WindowOpenXR.cpp.

293{
294 auto extensions = instanceExtensions;
295
296#ifndef __ANDROID__
297 PFN_xrGetVulkanInstanceExtensionsKHR pfnGetVulkanInstanceExtensionsKHR = nullptr;
298 CHECK_XRCMD(xrGetInstanceProcAddr(xrInstance, "xrGetVulkanInstanceExtensionsKHR",
299 reinterpret_cast<PFN_xrVoidFunction*>(&pfnGetVulkanInstanceExtensionsKHR)));
300
301 uint32_t extensionNamesSize = 0;
302 CHECK_XRCMD(pfnGetVulkanInstanceExtensionsKHR(xrInstance, systemId, 0, &extensionNamesSize, nullptr));
303
304 extensionNames = std::vector<char>(extensionNamesSize);
305 CHECK_XRCMD(pfnGetVulkanInstanceExtensionsKHR(xrInstance, systemId, extensionNamesSize, &extensionNamesSize,
306 &extensionNames[0]));
307
308
309 std::vector<const char*> requestedExt;
310
311 for (int i = 0; i < extensionNames.size(); i++) {
312 extensions.push_back(&extensionNames[i]);
313 while (i < extensionNames.size()) {
314 if (extensionNames[i] == ' ') {
315 extensionNames[i] = '\0';
316 break;
317 }
318 i++;
319 }
320 }
321 //extensions.resize(extensions.size() - 1);
322#endif
323 if (mirrorActivated) {
324 uint32_t glfwExtensionCount = 0;
325 const char** glfwExtensions;
326 glfwExtensions = glfwGetRequiredInstanceExtensions(&glfwExtensionCount);
327 std::vector<const char*> mirrorExtensions(glfwExtensions, glfwExtensions + glfwExtensionCount);
328
329 for (auto glfwext : mirrorExtensions) {
330 bool found = false;
331 for (auto ext : extensions) {
332 if (std::strcmp(glfwext, ext) == 0) {
333 found = true;
334 break;
335 }
336 }
337 if (!found) {
338 extensions.push_back(glfwext);
339 }
340 }
341 }
342
344 extensions.push_back(VK_EXT_DEBUG_UTILS_EXTENSION_NAME);
345 }
346 else {
347 extensions.push_back("VK_EXT_debug_report");
348 extensions.push_back(VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME);
349 }
350 return extensions;
351 }
const bool enableValidationLayers

◆ getSemaphoreSignal()

std::vector< vk::Semaphore > WindowOpenXR::getSemaphoreSignal ( int  view,
int  elem 
)
overridevirtual

Return semaphore to signal end of rendering

Reimplemented from WindowAbstract.

Definition at line 457 of file WindowOpenXR.cpp.

458 {
459 auto res = std::vector<vk::Semaphore>();
460 if (mirrorActivated && view == 0 && elem < mirrorSwapchainSize) {
461 res.push_back(mirrorFinnishedSemaphore[elem]);
462 }
463 return res;
464 }

◆ getSemaphoreWait()

std::vector< vk::Semaphore > WindowOpenXR::getSemaphoreWait ( int  view,
int  elem 
)
overridevirtual

Return semaphore to wait for mirror image acquisition

Reimplemented from WindowAbstract.

Definition at line 448 of file WindowOpenXR.cpp.

449 {
450 auto res = std::vector<vk::Semaphore>();
451 if (mirrorActivated && view == 0 && elem < mirrorSwapchainSize) {
452 res.push_back(mirrorAvailableSemaphore[elem]);
453 }
454 return res;
455 }

◆ getSwapchainImage()

vk::Image WindowOpenXR::getSwapchainImage ( int  view,
int  index 
)
overridevirtual

Return the image of the swapchain image at a certain index

Reimplemented from WindowAbstract.

Definition at line 1409 of file WindowOpenXR.cpp.

1409 {
1410 assert(view < swapchains.size());
1411 return swapchains[view]->getSwapchainImage(index);//swapChainImagesXr[view][index].image;
1412}

◆ getVulkanPhysicalDevice()

void WindowOpenXR::getVulkanPhysicalDevice ( VkInstance &  vkInstance,
VkPhysicalDevice *  physicalDevice 
)

Let OpenXR choose the device

Definition at line 705 of file WindowOpenXR.cpp.

705 {
706 XrVulkanGraphicsDeviceGetInfoKHR deviceGetInfo{ XR_TYPE_VULKAN_GRAPHICS_DEVICE_GET_INFO_KHR };
707 deviceGetInfo.systemId = systemId;
708 deviceGetInfo.vulkanInstance = vkInstance;
709 CHECK_XRCMD(GetVulkanGraphicsDevice2KHR(xrInstance, &deviceGetInfo, physicalDevice));
710 }

◆ initWindow()

void WindowOpenXR::initWindow ( )
overridevirtual

Start the initialization of OpenXR

Implements WindowAbstract.

Definition at line 110 of file WindowOpenXR.cpp.

111{
112 currentTranslation = {0,0,0};
113 currentRotation = {0,0,0};
114 initialised = true;
115
116
117#ifndef __ANDROID__
118 if (mirrorActivated) {
119 glfwInit();
120 glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
121 glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE);
122 glfwWindowHint(GLFW_SCALE_TO_MONITOR, GLFW_FALSE);
123 glfwWindowHint(GLFW_DECORATED, GLFW_TRUE);
124 window = glfwCreateWindow(width, height, "Mirror", nullptr, nullptr);
125 glfwSetWindowUserPointer(window, this);
126 auto funKey = [](GLFWwindow* w, int key, int scancode, int action, int mods) {
127 static_cast<WindowOpenXR*>(glfwGetWindowUserPointer(w))->inputKeyCallback(w, key, scancode, action, mods);
128 };
129 glfwSetKeyCallback(window, funKey);
130 }
131#endif
132
133 initOpenXR();
134}
glm::vec3 currentTranslation
glm::vec3 currentRotation
Class that take care of the tasks linked to OpenXR (input and display), is used when HMD support is r...
Definition: WindowOpenXR.h:52

◆ isDepthRecquired()

bool WindowOpenXR::isDepthRecquired ( )
overridevirtual

return true if depth is needed by the window

Reimplemented from WindowAbstract.

Definition at line 917 of file WindowOpenXR.cpp.

918{
919 if (depthExtensionAvailable) {
920 return true;
921 }
922 else {
923 return false;
924 }
925}

◆ isDeviceSupportingSufaceKHR()

VkBool32 WindowOpenXR::isDeviceSupportingSufaceKHR ( VkPhysicalDevice  device,
int  i 
)
overridevirtual

Return true if the device support the surface

Implements WindowAbstract.

Definition at line 353 of file WindowOpenXR.cpp.

354 {
355 if (!mirrorActivated) {
356 return false;
357 }
358 else {
359 VkBool32 presentSupport = false;
360 vkGetPhysicalDeviceSurfaceSupportKHR(device, i, surface, &presentSupport);
361 return presentSupport;
362 }
363
364 }

◆ isSessionRunning()

bool WindowOpenXR::isSessionRunning ( )

Return true if the session is still running

Definition at line 1349 of file WindowOpenXR.cpp.

1349 {
1350 return runningSession;
1351}

◆ isSynchroWithSemaphore()

bool WindowOpenXR::isSynchroWithSemaphore ( )
overridevirtual

return true if semaphore are used for synchronization

Implements WindowAbstract.

Definition at line 412 of file WindowOpenXR.cpp.

413 {
414 return false;
415 }

◆ mainLoop()

void WindowOpenXR::mainLoop ( VulkanDrawing vulkanDrawing)
overridevirtual

Main rendering loop

Implements WindowAbstract.

Definition at line 242 of file WindowOpenXR.cpp.

243{
244#ifdef __ANDROID__
245 //For the moment the loop is on the mainOculus when using the standalone mode
246#else
247 bool requestRestart = false;
248 while (!requestRestart) {
249#ifndef __ANDROID__
250 if (mirrorActivated) {
251 glfwPollEvents();
252 if (glfwWindowShouldClose(window)) {
253 xrRequestExitSession(xrSession);
254 }
255 }
256#endif //
257 bool exitRenderLoop = false;
258 pollEvents(&exitRenderLoop, &requestRestart);
259 if (exitRenderLoop) {
260 break;
261 }
262 if (isSessionRunning()) {
263 if (pauseRendering) {
264 std::this_thread::sleep_for(std::chrono::milliseconds(1000));
265 pauseRendering = false;
266 }
267 else {
268 renderFrame(vulkanDrawing);
269 }
270 }
271 else {
272 // Throttle loop since xrWaitFrame won't be called.
273 std::this_thread::sleep_for(std::chrono::milliseconds(250));
274 }
275
276
277 }
278#endif
279}
bool isSessionRunning()
void pollEvents(bool *exitRenderLoop, bool *requestRestart)

◆ pollEvents()

void WindowOpenXR::pollEvents ( bool *  exitRenderLoop,
bool *  requestRestart 
)

Process OpenXR events

Definition at line 928 of file WindowOpenXR.cpp.

928 {
929 *exitRenderLoop = *requestRestart = false;
930
931 // Process all pending messages.
932 while (const XrEventDataBaseHeader* event = TryReadNextEvent()) {
933 switch (event->type) {
934 case XR_TYPE_EVENT_DATA_INSTANCE_LOSS_PENDING: {
935 const auto& instanceLossPending = *reinterpret_cast<const XrEventDataInstanceLossPending*>(event);
936 PRINT("%s", Fmt("XrEventDataInstanceLossPending by %lld", instanceLossPending.lossTime).c_str());
937 *exitRenderLoop = true;
938 *requestRestart = true;
939 return;
940 }
941 case XR_TYPE_EVENT_DATA_SESSION_STATE_CHANGED: {
942 auto sessionStateChangedEvent = *reinterpret_cast<const XrEventDataSessionStateChanged*>(event);
943 PRINT("sesion state change");
944 HandleSessionStateChangedEvent(sessionStateChangedEvent, exitRenderLoop, requestRestart);
945 //TODO
946 break;
947 }
948 case XR_TYPE_EVENT_DATA_INTERACTION_PROFILE_CHANGED:
949 //no in
950 break;
951 case XR_TYPE_EVENT_DATA_REFERENCE_SPACE_CHANGE_PENDING:
952 default: {
953 PRINT( "%s", Fmt("Ignoring event type %d", event->type).c_str());
954 break;
955 }
956 }
957 }
958}

◆ querySwapChainSupport()

SwapChainSupportDetails WindowOpenXR::querySwapChainSupport ( vk::PhysicalDevice  device)
overridevirtual

Check for what format and present mode the swapchain support

Implements WindowAbstract.

Definition at line 399 of file WindowOpenXR.cpp.

400 {
401
403 throw std::runtime_error("not autorised with open xr implementation");
404 return details;
405 }
Struct that contains the capability for the sapchain, the formats and the present mode supported.
Definition: commonVulkan.h:87

◆ resetOrigin()

void WindowOpenXR::resetOrigin ( )
overridevirtual

Reset the origin, Which means that we will store some offset values to cancel the rotation and translation return by the OpenXR runtime.

Implements WindowAbstract.

Definition at line 1491 of file WindowOpenXR.cpp.

1492{
1493 glm::vec3 averagePos = { 0,0,0 };
1494 for (int i = 0; i < translationsOpenXR.size(); i++) {
1495 averagePos += translationsOpenXR[i];
1496 }
1497 averagePos /= translationsOpenXR.size();
1498 glm::quat q = quaternionsList[quaternionsList.size() - 1];
1499
1500#ifdef HVT_UDP_CONTROL
1501 mutex.lock();
1502#endif
1503
1504 deltaPos = -1.0f * averagePos;
1505 deltaQuat = glm::inverse(q);
1506
1507#ifdef HVT_UDP_CONTROL
1508 mutex.unlock();
1509#endif
1510
1511}

◆ setMirror()

void WindowOpenXR::setMirror ( bool  mirrorActivated)

activate the glfw mirror

Definition at line 909 of file WindowOpenXR.cpp.

910{
911#ifdef __ANDROID__
912 throw std::runtime_error("Not supported when the headset is in standalone mode");
913#endif //
914 this->mirrorActivated = mirrorActivated;
915}

◆ setRotation()

void WindowOpenXR::setRotation ( glm::quat &  q,
int  view 
)

Use the quaternion to set the current rotation (euler angles)

Definition at line 1353 of file WindowOpenXR.cpp.

1353 {
1354
1355 //Math from https://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles
1356
1357
1358
1359 assert(quaternionsList.size() == rotationsOMAF.size());
1360 assert(quaternionsList.size() == rotationsOpenXR.size());
1361 if (quaternionsList.size() != swapchains.size()) {
1362 const int s = swapchains.size();
1363 quaternionsList.resize(s);
1364 rotationsOMAF.resize(s);
1365 rotationsOpenXR.resize(s);
1366 }
1367
1368 quaternionsList[view] = qR;
1369
1370#ifdef HVT_UDP_CONTROL
1371 mutex.lock();
1372#endif
1373 auto q = deltaQuat * qR;
1374
1375#ifdef HVT_UDP_CONTROL
1376 mutex.unlock();
1377#endif
1378
1379 //roll
1380 double siny_cosp = 2 * (q.w * q.z + q.x * q.y);
1381 double cosy_cosp = 1 - 2 * (q.y * q.y + q.z * q.z);
1382 rotationsOMAF[view][0] = -1 * std::atan2(siny_cosp, cosy_cosp) * (180.0 / M_PI);
1383 rotationsOpenXR[view][2] = std::atan2(siny_cosp, cosy_cosp) * (180.0 / M_PI);
1384
1385 // pitch
1386 double sinp = 2 * (q.w * q.y - q.z * q.x);
1387 if (std::abs(sinp) >= 1) {
1388 rotationsOMAF[view][2] = std::copysign(M_PI / 2, sinp) * (180.0 / M_PI); // use 90 degrees if out of range
1389 rotationsOpenXR[view][1] = std::copysign(M_PI / 2, sinp) * (180.0 / M_PI); // use 90 degrees if out of range
1390 }
1391 else {
1392 rotationsOMAF[view][2] = std::asin(sinp) * (180.0 / M_PI);
1393 rotationsOpenXR[view][1] = std::asin(sinp) * (180.0 / M_PI);
1394 }
1395
1396 // Roll
1397 double sinr_cosp = 2 * (q.w * q.x + q.y * q.z);
1398 double cosr_cosp = 1 - 2 * (q.x * q.x + q.y * q.y);
1399 rotationsOMAF[view][1] = -1 * std::atan2(sinr_cosp, cosr_cosp) * (180.0 / M_PI);
1400 rotationsOpenXR[view][0] = std::atan2(sinr_cosp, cosr_cosp) * (180.0 / M_PI);
1401
1402 currentRotation = rotationsOpenXR[view];
1403
1404
1405}

◆ useOpenXR()

const bool WindowOpenXR::useOpenXR ( )
overridevirtual

Return true (because OpenXr is used)

Reimplemented from WindowAbstract.

Definition at line 166 of file WindowOpenXR.cpp.

166 {
167 return true;
168}

The documentation for this class was generated from the following files: