-
-
Notifications
You must be signed in to change notification settings - Fork 29
An application made with RaZ can easily be used in VR mode. All you have to do is add a Raz::XrSystem
in your world, then enable XR in the render system.
#include <RaZ/XR/XrSystem.hpp>
// ...
Raz::Application app;
Raz::World& world = app.addWorld();
// Creating the XR system *will* fail if no XR runtime or device is found. Make sure both are available
Raz::XrSystem& xrSystem = world.addSystem<Raz::XrSystem>("Your application's name");
// You can give whichever dimensions you want for the window. Do note though that you *should* use the
// same aspect ratio as the XR device's views to have an undistorted image. Currently, the view that
// will be displayed in the window is the latest rendered one, which should be the right eye's
// You should also keep the window non-resizable, as at the time of writing resizing it will also resize
// the rendering viewport, breaking the VR visualization
Raz::RenderSystem& renderSystem = world.addSystem<Raz::RenderSystem>(xr.getOptimalViewWidth() / 3,
xr.getOptimalViewHeight() / 3,
"Your window's title",
Raz::WindowSetting::NON_RESIZABLE);
// Now that's done, all you need to do is to enable XR rendering:
renderSystem.enableXr(xrSystem);
// The rest of the application is the same as usual
local app = Application.new()
local world = app:addWorld()
local xrSystem = world:addXrSystem("Your application's name")
-- Using // to do an integer division (a single slash yields a float, which makes the call fail)
-- Another possibility is to explicitly do math.floor(xr:getOptimalViewWidth() / 3)
local renderSystem = world:addRenderSystem(xr:getOptimalViewWidth() // 3,
xr:getOptimalViewHeight() // 3,
"Your window's title",
WindowSetting.NON_RESIZABLE)
renderSystem:enableXr(xrSystem)
-- The rest of the application is the same as usual
Note that although adding a camera is optional, as it isn't used for rendering per se (all view information is given by the XR device), its transform still is. It can be very useful to, for example, move around the scene without actually putting the headset on, and still visualize what is rendered from the window.
For more information, see the XR demo. It has been tested with a Meta Quest 2 and using SteamVR as the runtime.
- Home
- How to build RaZ
- Getting started
- General usage knowledge
- Some examples...
- Playground
- Tutorials
- File formats
- Modules
- Debug