OpenXR - Allow updating camera in realtime

This commit is contained in:
Lubos committed 2022-10-28 15:50:00 +02:00
1 parent f4f7dc570f
commit 96f89f4bd7
4 files changed
+25 -7

No files matched your search

+20 -2
View File
@@ -221,11 +221,16 @@ void UpdateVRInput(bool(*NativeKey)(const KeyInput &key), bool(*NativeTouch)(con
}
}
void UpdateVRScreenKey(const KeyInput &key) {
void UpdateVRSpecialKeys(const KeyInput &key) {
std::vector<int> nativeKeys;
if (KeyMap::KeyToPspButton(key.deviceId, key.keyCode, &nativeKeys)) {
for (int& nativeKey : nativeKeys) {
if (nativeKey == CTRL_SCREEN) {
// adjust camera parameters
if (nativeKey == CTRL_HOLD) {
VR_SetConfig(VR_CONFIG_CAMERA_CONTROL, key.flags & KEY_DOWN);
}
// force 2D rendering
else if (nativeKey == CTRL_SCREEN) {
VR_SetConfig(VR_CONFIG_FORCE_2D, key.flags & KEY_DOWN);
}
}
@@ -317,6 +322,19 @@ bool StartVRRender() {
// Set compatibility
vrCompat[VR_COMPAT_SKYPLANE] = PSP_CoreParameter().compat.vrCompat().Skyplane;
// Camera control
if (VR_GetConfig(VR_CONFIG_CAMERA_CONTROL)) {
float dst = g_Config.fCameraDistance;
float fov = g_Config.fFieldOfViewPercentage;
int 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;
g_Config.fCameraDistance = std::clamp(dst, -10.0f, 10.0f);
g_Config.fFieldOfViewPercentage = std::clamp(fov, 100.0f, 200.0f);
}
// Set customizations
VR_SetConfig(VR_CONFIG_6DOF_ENABLED, g_Config.bEnable6DoF);
VR_SetConfig(VR_CONFIG_CAMERA_DISTANCE, g_Config.fCameraDistance * 1000);
+2 -2
View File
@@ -25,7 +25,7 @@ void InitVROnAndroid(void* vm, void* activity, int version, const char* name);
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 UpdateVRScreenKey(const KeyInput &key);
void UpdateVRSpecialKeys(const KeyInput &key);
// VR games compatibility
void PreprocessStepVR(void* step);
@@ -53,7 +53,7 @@ inline void InitVROnAndroid(void* vm, void* activity, int version, const char* n
inline void EnterVR(bool firstTime, void* vulkanContext) {}
inline void GetVRResolutionPerEye(int* width, int* height) {}
inline void UpdateVRInput(bool(*NativeKey)(const KeyInput &key), bool(*NativeTouch)(const TouchInput &touch), bool haptics, float dp_xscale, float dp_yscale) {}
inline void UpdateVRScreenKey(const KeyInput &key) {}
inline void UpdateVRSpecialKeys(const KeyInput &key) {}
// VR games compatibility
inline void PreprocessStepVR(void* step) {}
+1 -1
View File
@@ -7,7 +7,7 @@ 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_DISTANCE, VR_CONFIG_CANVAS_DISTANCE,
VR_CONFIG_FOV_SCALE, VR_CONFIG_CAMERA_CONTROL, VR_CONFIG_CAMERA_DISTANCE, 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,
+2 -2
View File
@@ -1296,9 +1296,9 @@ bool NativeTouch(const TouchInput &touch) {
}
bool NativeKey(const KeyInput &key) {
// Hack to quickly enable 2D mode in VR game mode.
// Special key VR actions
if (IsVRBuild()) {
UpdateVRScreenKey(key);
UpdateVRSpecialKeys(key);
}
// INFO_LOG(SYSTEM, "Key code: %i flags: %i", key.keyCode, key.flags);