OpenXR - Camera height adjust added

This commit is contained in:
Lubos 2022-10-29 19:19:25 +02:00
parent 48f9c98559
commit b7da6f7e45
6 changed files with 26 additions and 2 deletions

View file

@ -344,9 +344,20 @@ bool StartVRRender() {
// Camera control
if (VR_GetConfig(VR_CONFIG_CAMERA_CONTROL)) {
//light joystick controls height
float height = g_Config.fCameraHeight;
int status = IN_VRGetButtonState(0);
if (status & ovrButton_Down) height -= 0.05f;
if (status & ovrButton_Up) height += 0.05f;
if (status & ovrButton_LThumb) {
height = 0;
}
g_Config.fCameraHeight = std::clamp(height, -10.0f, 10.0f);
//right joystick controls distance and fov
float dst = g_Config.fCameraDistance;
float fov = g_Config.fFieldOfViewPercentage;
int status = IN_VRGetButtonState(1);
status = IN_VRGetButtonState(1);
if (status & ovrButton_Left) fov -= 1.0f;
if (status & ovrButton_Right) fov += 1.0f;
if (status & ovrButton_Down) dst -= 0.1f;
@ -362,6 +373,7 @@ bool StartVRRender() {
// Set customizations
VR_SetConfig(VR_CONFIG_6DOF_ENABLED, g_Config.bEnable6DoF);
VR_SetConfig(VR_CONFIG_CAMERA_DISTANCE, g_Config.fCameraDistance * 1000);
VR_SetConfig(VR_CONFIG_CAMERA_HEIGHT, g_Config.fCameraHeight * 1000);
VR_SetConfig(VR_CONFIG_CANVAS_DISTANCE, g_Config.fCanvasDistance);
VR_SetConfig(VR_CONFIG_FOV_SCALE, g_Config.fFieldOfViewPercentage);
VR_SetConfig(VR_CONFIG_MIRROR_UPDATED, false);

View file

@ -346,6 +346,14 @@ bool VR_InitFrame( engine_t* engine ) {
vrMatrix[matrix].M[1][3] += forward.y;
vrMatrix[matrix].M[2][3] += forward.z;
}
if (abs(vrConfig[VR_CONFIG_CAMERA_HEIGHT]) > 0) {
XrVector3f up = {0.0f, -(float)vrConfig[VR_CONFIG_CAMERA_HEIGHT] * 0.001f * scale, 0.0f};
up = XrQuaternionf_Rotate(invView.orientation, up);
up = XrVector3f_ScalarMultiply(up, vrConfig[VR_CONFIG_MIRROR_AXIS_Y] ? -1.0f : 1.0f);
vrMatrix[matrix].M[0][3] += up.x;
vrMatrix[matrix].M[1][3] += up.y;
vrMatrix[matrix].M[2][3] += up.z;
}
if (vrConfig[VR_CONFIG_6DOF_PRECISE] && (matrix == VR_VIEW_MATRIX_RIGHT_EYE)) {
float dx = fabs(invViewTransform[1].position.x - invViewTransform[0].position.x);
float dy = fabs(invViewTransform[1].position.y - invViewTransform[0].position.y);

View file

@ -7,7 +7,8 @@ enum VRConfig {
//switching between 2D and 3D
VR_CONFIG_MODE, VR_CONFIG_3D_GEOMETRY_COUNT, VR_CONFIG_FORCE_2D,
//camera setup
VR_CONFIG_FOV_SCALE, VR_CONFIG_CAMERA_CONTROL, VR_CONFIG_CAMERA_DISTANCE, VR_CONFIG_CANVAS_DISTANCE,
VR_CONFIG_FOV_SCALE, VR_CONFIG_CAMERA_CONTROL, VR_CONFIG_CAMERA_DISTANCE,
VR_CONFIG_CAMERA_HEIGHT, VR_CONFIG_CANVAS_DISTANCE,
//6DoF
VR_CONFIG_6DOF_ENABLED, VR_CONFIG_6DOF_SCALE, VR_CONFIG_6DOF_PRECISE, VR_CONFIG_MIRROR_UPDATED,
VR_CONFIG_MIRROR_AXIS_X, VR_CONFIG_MIRROR_AXIS_Y, VR_CONFIG_MIRROR_AXIS_Z,

View file

@ -1209,6 +1209,7 @@ static ConfigSetting vrSettings[] = {
ConfigSetting("VREnable6DoF", &g_Config.bEnable6DoF, true),
ConfigSetting("VREnableStereo", &g_Config.bEnableStereo, false),
ConfigSetting("VRCameraDistance", &g_Config.fCameraDistance, 0.0f),
ConfigSetting("VRCameraHeight", &g_Config.fCameraHeight, 0.0f),
ConfigSetting("VRCanvasDistance", &g_Config.fCanvasDistance, 6.0f),
ConfigSetting("VRFieldOfView", &g_Config.fFieldOfViewPercentage, 100.0f),

View file

@ -464,6 +464,7 @@ public:
bool bEnable6DoF;
bool bEnableStereo;
float fCameraDistance;
float fCameraHeight;
float fCanvasDistance;
float fFieldOfViewPercentage;

View file

@ -1166,6 +1166,7 @@ void GameSettingsScreen::CreateViews() {
vrSettings->Add(new ItemHeader(vr->T("VR camera")));
vrSettings->Add(new PopupSliderChoiceFloat(&g_Config.fCameraDistance, -10.0f, 10.0f, vr->T("Camera distance adjust", "Camera distance adjust"), 1.0f, screenManager(), ""));
vrSettings->Add(new PopupSliderChoiceFloat(&g_Config.fCameraHeight, -10.0f, 10.0f, vr->T("Camera height adjust", "Camera height adjust"), 1.0f, screenManager(), ""));
vrSettings->Add(new PopupSliderChoiceFloat(&g_Config.fCanvasDistance, 1.0f, 10.0f, vr->T("Distance to 2D menus and scenes", "Distance to 2D menus and scenes"), 1.0f, screenManager(), ""));
vrSettings->Add(new PopupSliderChoiceFloat(&g_Config.fFieldOfViewPercentage, 100.0f, 200.0f, vr->T("Field of view scale", "Headset's field of view scale"), 10.0f, screenManager(), vr->T("% of native FoV")));
}