[Bf-blender-cvs] [91d0198] HMD_viewport: Make "Use Device Rotation" toggle work again
Julian Eisel
noreply at git.blender.org
Wed Nov 23 00:52:43 CET 2016
Commit: 91d0198d0e37524b2611b2af45dd635cd66c81aa
Author: Julian Eisel
Date: Wed Nov 23 00:07:32 2016 +0100
Branches: HMD_viewport
https://developer.blender.org/rB91d0198d0e37524b2611b2af45dd635cd66c81aa
Make "Use Device Rotation" toggle work again
When this is disabled we just manually calculate the camera offsets. Actually I have no idea if math is correct but it doesn't seem totally wrong at least :P Don't have an HMD to test right now.
===================================================================
M intern/ghost/GHOST_C-api.h
M intern/ghost/intern/GHOST_C-api.cpp
M source/blender/editors/space_view3d/view3d_draw.c
M source/blender/windowmanager/WM_api.h
M source/blender/windowmanager/intern/wm_device.c
===================================================================
diff --git a/intern/ghost/GHOST_C-api.h b/intern/ghost/GHOST_C-api.h
index c4b7001..218a07c 100644
--- a/intern/ghost/GHOST_C-api.h
+++ b/intern/ghost/GHOST_C-api.h
@@ -940,6 +940,7 @@ extern const char *GHOST_HMDgetDeviceName(int index);
extern const char *GHOST_HMDgetVendorName(int index);
extern float GHOST_HMDgetDeviceIPD(void);
extern void GHOST_HMDsetDeviceIPD(float value);
+extern float GHOST_HMDgetLensHorizontalSeparation(void);
extern void GHOST_HMDgetLeftModelviewMatrix(float r_mat[4][4]);
extern void GHOST_HMDgetRightModelviewMatrix(float r_mat[4][4]);
extern void GHOST_HMDgetLeftProjectionMatrix(float r_mat[4][4]);
diff --git a/intern/ghost/intern/GHOST_C-api.cpp b/intern/ghost/intern/GHOST_C-api.cpp
index 231fcf6..23a9a64 100644
--- a/intern/ghost/intern/GHOST_C-api.cpp
+++ b/intern/ghost/intern/GHOST_C-api.cpp
@@ -1024,6 +1024,17 @@ void GHOST_HMDsetDeviceIPD(float value)
#endif
}
+float GHOST_HMDgetLensHorizontalSeparation()
+{
+#ifdef WITH_OPENHMD
+ GHOST_ISystem *system = GHOST_ISystem::getSystem();
+ GHOST_OpenHMDManager *ohmd = system->getOpenHMDManager();
+ return ohmd->getLensHorizontalSeparation();
+#else
+ (void)value;
+#endif
+}
+
#ifndef WITH_OPENHMD
static void ghost_UnitMat(float r_mat[4][4])
{
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index bee4b6f..d1cde5b 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -3633,6 +3633,41 @@ static bool view3d_hmd_view_active(wmWindowManager *wm, wmWindow *win)
(U.hmd_settings.device > -1));
}
+static void view3d_hmd_view_get_matrices(
+ RegionView3D *rv3d, const bool is_left,
+ float r_modelviewmat[4][4], float r_projectionmat[4][4])
+{
+ const bool use_device_rot = U.hmd_settings.flag & USER_HMD_USE_DEVICE_ROT;
+
+ if (use_device_rot) {
+ WM_device_HMD_modelview_matrix_get(is_left, r_modelviewmat);
+ WM_device_HMD_projection_matrix_get(is_left, r_projectionmat);
+
+ /* apply modelview matrix from 3D View onto hmd device one */
+ mul_m4_m4m4(r_modelviewmat, r_modelviewmat, rv3d->viewmat);
+
+ if (rv3d->persp == RV3D_CAMOB) {
+ /* projection matrix contains camera zoom and camera view offset, needs to be applied */
+ add_m4_m4m4(r_projectionmat, r_projectionmat, rv3d->winmat);
+ }
+ else {
+ /* apply modelview zoom */
+ r_modelviewmat[3][2] -= rv3d->dist;
+ }
+ }
+ else {
+ const float shiftx = WM_device_HMD_lens_horizontal_separation_get();
+ const float ipd = WM_device_HMD_IPD_get();
+
+ copy_m4_m4(r_modelviewmat, rv3d->viewmat);
+ copy_m4_m4(r_projectionmat, rv3d->winmat);
+
+ /* apply ipd and lens shift */
+ r_modelviewmat[3][0] += (shiftx * 0.5f) * (is_left ? 1.0f : -1.0f);
+ r_projectionmat[3][0] += (ipd * 0.5f) * (is_left ? 1.0f : -1.0f);
+ }
+}
+
static void view3d_hmd_view_setup(Scene *scene, View3D *v3d, ARegion *ar)
{
RegionView3D *rv3d = ar->regiondata;
@@ -3640,27 +3675,19 @@ static void view3d_hmd_view_setup(Scene *scene, View3D *v3d, ARegion *ar)
float projmat[4][4];
float modelviewmat[4][4];
- WM_device_HMD_modelview_matrix_get(is_left, modelviewmat);
- WM_device_HMD_projection_matrix_get(is_left, projmat);
+ /* hmd view uses half screen width, this makes sure winmatrix is calculated correctly for that */
+ ar->winx /= 2;
/* update 3d view matrices before applying matrices from HMD */
view3d_viewmatrix_set(scene, v3d, rv3d);
view3d_winmatrix_set(ar, v3d, NULL);
- /* apply 3d view matrices on hmd device ones */
- mul_m4_m4m4(modelviewmat, modelviewmat, rv3d->viewmat);
-
- if (rv3d->persp == RV3D_CAMOB) {
- /* projection matrix contains camera zoom and camera view offset, needs to be applied */
- add_m4_m4m4(projmat, projmat, rv3d->winmat);
- }
- else {
- /* apply modelview zoom */
- modelviewmat[3][2] -= rv3d->dist;
- }
+ view3d_hmd_view_get_matrices(rv3d, is_left, modelviewmat, projmat);
/* setup view with adjusted matrices */
view3d_main_region_setup_view(scene, v3d, ar, modelviewmat, projmat);
+
+ ar->winx *= 2;
}
#endif /* WITH_INPUT_HMD */
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index c2003f6..cb588a2 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -534,6 +534,7 @@ const char *WM_device_HMD_name_get(int index) ATTR_WARN_UNUSED_RESULT;
const char *WM_device_HMD_vendor_get(int index) ATTR_WARN_UNUSED_RESULT;
float WM_device_HMD_IPD_get(void) ATTR_WARN_UNUSED_RESULT;
void WM_device_HMD_IPD_set(float value);
+float WM_device_HMD_lens_horizontal_separation_get(void) ATTR_WARN_UNUSED_RESULT;
/* Utils */
void WM_device_HMD_state_set(const int device, const bool enable);
void WM_device_HMD_modelview_matrix_get(const bool is_left, float r_modelviewmat[4][4]) ATTR_NONNULL();
diff --git a/source/blender/windowmanager/intern/wm_device.c b/source/blender/windowmanager/intern/wm_device.c
index 656d44b..0c16fba 100644
--- a/source/blender/windowmanager/intern/wm_device.c
+++ b/source/blender/windowmanager/intern/wm_device.c
@@ -86,6 +86,10 @@ void WM_device_HMD_IPD_set(float value)
GHOST_HMDsetDeviceIPD(value);
}
+float WM_device_HMD_lens_horizontal_separation_get(void)
+{
+ return GHOST_HMDgetLensHorizontalSeparation();
+}
/* ------ Utilities ------ */
More information about the Bf-blender-cvs
mailing list