Merge pull request #16356 from lvonasek/cleanup_camera_control

OpenXR - Camera adjust using any controller
This commit is contained in:
Henrik Rydgård 2022-11-08 12:28:44 +01:00 committed by GitHub
commit 87bd7aaccc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 41 additions and 61 deletions

View file

@ -201,18 +201,6 @@ void UpdateVRInput(bool(*NativeKey)(const KeyInput &key), bool(*NativeTouch)(con
int status = IN_VRGetButtonState(j);
for (ButtonMapping& m : controllerMapping[j]) {
//check if camera key was pressed
bool cameraKey = false;
std::vector<int> nativeKeys;
if (KeyMap::KeyToPspButton(controllerIds[j], m.keycode, &nativeKeys)) {
for (int& nativeKey : nativeKeys) {
if (nativeKey == VIRTKEY_VR_CAMERA_ADJUST) {
cameraKey = true;
break;
}
}
}
//fill KeyInput structure
bool pressed = status & m.ovr;
keyInput.flags = pressed ? KEY_DOWN : KEY_UP;
@ -224,16 +212,12 @@ void UpdateVRInput(bool(*NativeKey)(const KeyInput &key), bool(*NativeTouch)(con
if (pressed && haptics) {
INVR_Vibrate(100, j, 1000);
}
if (!pspKeys[VIRTKEY_VR_CAMERA_ADJUST] || cameraKey) {
NativeKey(keyInput);
}
NativeKey(keyInput);
m.pressed = pressed;
m.repeat = 0;
} else if (pressed && (m.repeat > 30)) {
keyInput.flags |= KEY_IS_REPEAT;
if (!pspKeys[VIRTKEY_VR_CAMERA_ADJUST] || cameraKey) {
NativeKey(keyInput);
}
NativeKey(keyInput);
m.repeat = 0;
} else {
m.repeat++;
@ -341,13 +325,14 @@ void UpdateVRInput(bool(*NativeKey)(const KeyInput &key), bool(*NativeTouch)(con
}
}
void UpdateVRSpecialKeys(const KeyInput &key) {
bool UpdateVRSpecialKeys(const KeyInput &key) {
std::vector<int> nativeKeys;
if (KeyMap::KeyToPspButton(key.deviceId, key.keyCode, &nativeKeys)) {
for (int& nativeKey : nativeKeys) {
pspKeys[nativeKey] = key.flags & KEY_DOWN;
}
}
return !pspKeys[VIRTKEY_VR_CAMERA_ADJUST];
}
/*
@ -579,34 +564,30 @@ bool StartVRRender() {
// Camera control
if (pspKeys[VIRTKEY_VR_CAMERA_ADJUST]) {
//left joystick controls height and side
float height = g_Config.fCameraHeight;
float side = g_Config.fCameraSide;
int status = IN_VRGetButtonState(0);
if (status & ovrButton_Left) side -= 0.05f;
if (status & ovrButton_Right) side += 0.05f;
if (status & ovrButton_Down) height -= 0.05f;
if (status & ovrButton_Up) height += 0.05f;
if (status & ovrButton_LThumb) {
height = 0;
side = 0;
}
g_Config.fCameraHeight = clampFloat(height, -10.0f, 10.0f);
g_Config.fCameraSide = clampFloat(side, -10.0f, 10.0f);
if (pspKeys[CTRL_LEFT]) g_Config.fCameraSide -= 0.05f;
if (pspKeys[CTRL_RIGHT]) g_Config.fCameraSide += 0.05f;
if (pspKeys[CTRL_DOWN]) g_Config.fCameraHeight -= 0.05f;
if (pspKeys[CTRL_UP]) g_Config.fCameraHeight += 0.05f;
//right joystick controls distance and fov
float dst = g_Config.fCameraDistance;
float fov = g_Config.fFieldOfViewPercentage;
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;
if (status & ovrButton_Up) dst += 0.1f;
if (status & ovrButton_RThumb) {
fov = 100;
dst = 0;
if (pspKeys[VIRTKEY_AXIS_X_MIN]) g_Config.fFieldOfViewPercentage -= 1.0f;
if (pspKeys[VIRTKEY_AXIS_X_MAX]) g_Config.fFieldOfViewPercentage += 1.0f;
if (pspKeys[VIRTKEY_AXIS_Y_MIN]) g_Config.fCameraDistance -= 0.1f;
if (pspKeys[VIRTKEY_AXIS_Y_MAX]) g_Config.fCameraDistance += 0.1f;
// Reset values
if (pspKeys[VIRTKEY_VR_CAMERA_RESET]) {
g_Config.fCameraHeight = 0;
g_Config.fCameraSide = 0;
g_Config.fCameraDistance = 0;
g_Config.fFieldOfViewPercentage = 100;
}
g_Config.fCameraDistance = clampFloat(dst, -10.0f, 10.0f);
g_Config.fFieldOfViewPercentage = clampFloat(fov, 100.0f, 200.0f);
// Clamp values
g_Config.fCameraHeight = clampFloat(g_Config.fCameraHeight, -50.0f, 50.0f);
g_Config.fCameraSide = clampFloat(g_Config.fCameraSide, -50.0f, 50.0f);
g_Config.fCameraDistance = clampFloat(g_Config.fCameraDistance, -50.0f, 50.0f);
g_Config.fFieldOfViewPercentage = clampFloat(g_Config.fFieldOfViewPercentage, 100.0f, 200.0f);
}
// Set customizations

View file

@ -23,7 +23,7 @@ void InitVROnAndroid(void* vm, void* activity, const char* system, int version,
void EnterVR(bool firstStart, void* vulkanContext);
void GetVRResolutionPerEye(int* width, int* height);
void UpdateVRInput(bool(*NativeKey)(const KeyInput &key), bool(*NativeTouch)(const TouchInput &touch), bool haptics, float dp_xscale, float dp_yscale);
void UpdateVRSpecialKeys(const KeyInput &key);
bool UpdateVRSpecialKeys(const KeyInput &key);
// VR games compatibility
void PreprocessStepVR(void* step);

View file

@ -408,6 +408,7 @@ const KeyMap_IntStrPair psp_button_names[] = {
#ifdef OPENXR
{VIRTKEY_VR_CAMERA_ADJUST, "VR camera adjust"},
{VIRTKEY_VR_CAMERA_RESET, "VR camera reset"},
#else
{VIRTKEY_SCREEN_ROTATION_VERTICAL, "Display Portrait"},
{VIRTKEY_SCREEN_ROTATION_VERTICAL180, "Display Portrait Reversed"},

View file

@ -69,6 +69,7 @@ enum {
VIRTKEY_SCREEN_ROTATION_HORIZONTAL180 = 0x40000023,
VIRTKEY_SPEED_ANALOG = 0x40000024,
VIRTKEY_VR_CAMERA_ADJUST = 0x40000025,
VIRTKEY_VR_CAMERA_RESET = 0x40000026,
VIRTKEY_LAST,
VIRTKEY_COUNT = VIRTKEY_LAST - VIRTKEY_FIRST
};

View file

@ -1304,7 +1304,7 @@ bool GenerateVertexShader(const VShaderID &id, char *buffer, const ShaderLanguag
WRITE(p, " }\n");
}
if (vertexRangeCulling && !gstate_c.Use(GPU_USE_VIRTUAL_REALITY)) {
if (vertexRangeCulling) {
WRITE(p, " vec3 projPos = outPos.xyz / outPos.w;\n");
WRITE(p, " float projZ = (projPos.z - u_depthRange.z) * u_depthRange.w;\n");

View file

@ -3338,7 +3338,7 @@ u32 GPUCommon::CheckGPUFeatures() const {
bool canClipOrCull = draw_->GetDeviceCaps().clipDistanceSupported || draw_->GetDeviceCaps().cullDistanceSupported;
bool canDiscardVertex = draw_->GetBugs().Has(Draw::Bugs::BROKEN_NAN_IN_CONDITIONAL);
if (canClipOrCull || canDiscardVertex) {
if (!gstate_c.Use(GPU_USE_VIRTUAL_REALITY) && (canClipOrCull || canDiscardVertex)) {
// We'll dynamically use the parts that are supported, to reduce artifacts as much as possible.
features |= GPU_USE_VS_RANGE_CULLING;
}

View file

@ -1144,9 +1144,6 @@ void GameSettingsScreen::CreateViews() {
vrSettings->Add(new CheckBox(&g_Config.bForce72Hz, vr->T("Force 72Hz update")));
vrSettings->Add(new ItemHeader(vr->T("VR camera")));
vrSettings->Add(new PopupSliderChoiceFloat(&g_Config.fCameraDistance, -10.0f, 10.0f, vr->T("Camera distance adjust"), 1.0f, screenManager(), ""));
vrSettings->Add(new PopupSliderChoiceFloat(&g_Config.fCameraHeight, -10.0f, 10.0f, vr->T("Camera height adjust"), 1.0f, screenManager(), ""));
vrSettings->Add(new PopupSliderChoiceFloat(&g_Config.fCameraSide, -10.0f, 10.0f, vr->T("Camera side adjust"), 1.0f, screenManager(), ""));
vrSettings->Add(new PopupSliderChoiceFloat(&g_Config.fCanvasDistance, 1.0f, 10.0f, vr->T("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"), 10.0f, screenManager(), vr->T("% of native FoV")));

View file

@ -1297,8 +1297,8 @@ bool NativeTouch(const TouchInput &touch) {
bool NativeKey(const KeyInput &key) {
// Special key VR actions
if (IsVREnabled()) {
UpdateVRSpecialKeys(key);
if (IsVREnabled() && !UpdateVRSpecialKeys(key)) {
return false;
}
// INFO_LOG(SYSTEM, "Key code: %i flags: %i", key.keyCode, key.flags);

View file

@ -758,15 +758,15 @@ ULJM05604 = 1.0
ULUS10490 = 1.0
# Grand Theft Auto: Liberty City Stories
NPJH50825 = 1.0
ULES00051 = 1.0
ULES00151 = 1.0
ULES00181 = 1.0
ULES00182 = 1.0
ULJM05255 = 1.0
ULJM05359 = 1.0
ULJM05885 = 1.0
ULUS10041 = 1.0
NPJH50825 = 0.5
ULES00051 = 0.5
ULES00151 = 0.5
ULES00181 = 0.5
ULES00182 = 0.5
ULJM05255 = 0.5
ULJM05359 = 0.5
ULJM05885 = 0.5
ULUS10041 = 0.5
# Grand Theft Auto: Vice City Stories
NPJH50827 = 1.0