VR scenes are rotated

Whenever rendering with OpenVR, the scene is rotated. This is clearly visible with an vtkAxesActor. The Z axis is parallel to the floor… this is not expected.

import vtk

from vtkmodules.vtkRenderingOpenVR import (
    vtkOpenVRCamera,
    vtkOpenVRRenderer,
    vtkOpenVRRenderWindow,
    vtkOpenVRRenderWindowInteractor,
)


renderer = vtk.vtkOpenVRRenderer()
renderWindow =vtk.vtkOpenVRRenderWindow()
iren = vtk.vtkOpenVRRenderWindowInteractor()
cam = vtk.vtkOpenVRCamera()
renderer.SetShowFloor(True)
renderer.SetBackground(0.2, 0.3, 0.4);
renderWindow.AddRenderer(renderer);
iren.SetRenderWindow(renderWindow);
renderer.SetActiveCamera(cam);

light = vtk.vtkLight()
light.SetLightTypeToSceneLight();
light.SetPosition(1.0, 1.0, 1.0);
renderer.AddLight(light);

#crazy frame rate requirement
#need to look into that at some point
renderWindow.SetDesiredUpdateRate(350.0);
iren.SetDesiredUpdateRate(350.0);
iren.SetStillUpdateRate(350.0);

renderer.RemoveCuller(renderer.GetCullers().GetLastItem());

axes = vtk.vtkAxesActor()
renderer.AddActor(axes)

# the HMD may not be turned on/etc
renderWindow.Initialize();
# if renderWindow.GetHMD():

renderer.ResetCamera();
renderWindow.Render();

iren.Start()

Did you try this → https://vtk.org/doc/nightly/html/classvtkCamera.html#afa796c8d6a66e0c26515e30f47c8897d ?

Hope it helps

In VTK the default camera looks down the negative Z axis and the X axis points to the right. Y is up. So this looks like I would expect.

1 Like

Hi Bane,

The default is indeed the Y axis pointing up.
You can add the following line to your script to have the Z axis pointing up instead:

renderWindow.SetPhysicalViewUp([0.0, 0.0, 1.0])

Thank you @Tiffany_Chhim! I needed SetPhysicalViewUp and SetPhysicalViewDirection to get this working

renderWindow.SetPhysicalViewUp(0.0, 0.0, 1.0)
renderWindow.SetPhysicalViewDirection(0.0, -1.0, 0.0)