[Bf-blender-cvs] [a1562bb] HMD_viewport: Use modelview matrix from OpenHMD, get custom IPD to work

Julian Eisel noreply at git.blender.org
Wed Oct 12 20:00:16 CEST 2016


Commit: a1562bbb53ae78177074219e3f423baa653064a6
Author: Julian Eisel
Date:   Wed Oct 12 19:53:03 2016 +0200
Branches: HMD_viewport
https://developer.blender.org/rBa1562bbb53ae78177074219e3f423baa653064a6

Use modelview matrix from OpenHMD, get custom IPD to work

Also renamed interocular distance to IPD in UI (slightly different things), removed unused matrix getters and made sure enabling/disabling custom IPD behaves nicely. Note that both projection and modelview matrices from OpenHMD get the Blender equivalents applied on top, so they act as relative transformations. Rotating, zooming and panning in HMD view works properly too now.

===================================================================

M	intern/ghost/GHOST_C-api.h
M	intern/ghost/intern/GHOST_C-api.cpp
M	release/scripts/startup/bl_ui/properties_render_layer.py
M	source/blender/editors/space_view3d/view3d_draw.c
M	source/blender/makesdna/DNA_scene_types.h
M	source/blender/makesrna/intern/rna_scene.c
M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/intern/wm_device.c
M	source/blender/windowmanager/intern/wm_operators.c

===================================================================

diff --git a/intern/ghost/GHOST_C-api.h b/intern/ghost/GHOST_C-api.h
index a9d443d..c4b7001 100644
--- a/intern/ghost/GHOST_C-api.h
+++ b/intern/ghost/GHOST_C-api.h
@@ -939,6 +939,7 @@ extern int         GHOST_HMDgetOpenDeviceIndex(void);
 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 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 df31127..c58cc5c 100644
--- a/intern/ghost/intern/GHOST_C-api.cpp
+++ b/intern/ghost/intern/GHOST_C-api.cpp
@@ -1013,6 +1013,17 @@ float GHOST_HMDgetDeviceIPD()
 #endif
 }
 
+void GHOST_HMDsetDeviceIPD(float value)
+{
+#ifdef WITH_OPENHMD
+	GHOST_ISystem *system = GHOST_ISystem::getSystem();
+	GHOST_OpenHMDManager *ohmd = system->getOpenHMDManager();
+	ohmd->setEyeIPD(value);
+#else
+	(void)value;
+#endif
+}
+
 void GHOST_HMDgetLeftModelviewMatrix(float r_mat[4][4])
 {
 #ifdef WITH_OPENHMD
diff --git a/release/scripts/startup/bl_ui/properties_render_layer.py b/release/scripts/startup/bl_ui/properties_render_layer.py
index 316a439..970b95b 100644
--- a/release/scripts/startup/bl_ui/properties_render_layer.py
+++ b/release/scripts/startup/bl_ui/properties_render_layer.py
@@ -249,7 +249,7 @@ class RENDERLAYER_PT_views(RenderLayerButtonsPanel, Panel):
 
         col = layout.column()
         col.active = not scene.use_hmd_device_ipd
-        col.prop(scene, "hmd_interocular_distance")
+        col.prop(scene, "hmd_custom_ipd")
 
 
 if __name__ == "__main__":  # only for live edit.
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index 2f88d29..16c5e5d 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -3756,11 +3756,29 @@ static bool view3d_hmd_view_active(wmWindowManager *wm, wmWindow *win, Scene *sc
 
 static void view3d_hmd_view_setup(Scene *scene, View3D *v3d, ARegion *ar)
 {
+	RegionView3D *rv3d = ar->regiondata;
 	const bool is_left = v3d->multiview_eye == STEREO_LEFT_ID;
 	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);
-	view3d_main_region_setup_view(scene, v3d, ar, NULL, projmat);
+
+	/* 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);
+	add_m4_m4m4(projmat, projmat, rv3d->winmat);
+
+	if (rv3d->persp != RV3D_CAMOB) {
+		/* apply modelview zoom */
+		modelviewmat[3][2] -= rv3d->dist;
+	}
+
+	/* setup view with adjusted matrices */
+	view3d_main_region_setup_view(scene, v3d, ar, modelviewmat, projmat);
 }
 
 #endif /* WITH_INPUT_HMD */
diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h
index d9f9b40..7bf77d9 100644
--- a/source/blender/makesdna/DNA_scene_types.h
+++ b/source/blender/makesdna/DNA_scene_types.h
@@ -1574,7 +1574,9 @@ typedef struct DisplaySafeAreas {
 struct HMDViewSettings {
 	char view_shade; /* rna_enum_viewport_shade_items */
 	char flag, pad[2];
-	float interocular_distance;
+	float custom_ipd;
+	/* Set while using custom_ipd (HMDVIEW_USE_DEVICE_IPD) so we can reset to device IPD */
+	float init_ipd;
 };
 
 /* HMDViewSettings.flag */
@@ -1678,6 +1680,7 @@ typedef struct Scene {
 	struct PreviewImage *preview;
 
 	struct HMDViewSettings hmd_settings;
+	int pad2;
 } Scene;
 
 /* **************** RENDERDATA ********************* */
diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c
index 469df35..71f1d03 100644
--- a/source/blender/makesrna/intern/rna_scene.c
+++ b/source/blender/makesrna/intern/rna_scene.c
@@ -791,6 +791,20 @@ static void rna_Scene_hmd_view_lensdist_set(PointerRNA *ptr, int value)
 	}
 }
 
+void rna_Scene_use_hmd_device_ipd_set(PointerRNA *ptr, int value)
+{
+	Scene *scene = ptr->data;
+	if (value) {
+		scene->hmd_settings.flag |= HMDVIEW_USE_DEVICE_IPD;
+		WM_device_HMD_IPD_set(scene->hmd_settings.init_ipd);
+	}
+	else {
+		scene->hmd_settings.flag &= ~HMDVIEW_USE_DEVICE_IPD;
+		scene->hmd_settings.init_ipd = WM_device_HMD_IPD_get();
+		WM_device_HMD_IPD_set(scene->hmd_settings.custom_ipd);
+	}
+}
+
 static int rna_Scene_use_hmd_device_ipd_editeable(PointerRNA *ptr, const char **r_info)
 {
 	Scene *scene = ptr->data;
@@ -823,6 +837,16 @@ static int rna_Scene_use_hmd_device_ipd_editeable(PointerRNA *ptr, const char **
 
 	return PROP_EDITABLE;
 }
+
+void rna_Scene_hmd_custom_ipd_set(PointerRNA *ptr, float value)
+{
+	Scene *scene = ptr->data;
+	scene->hmd_settings.custom_ipd = value;
+	if ((scene->hmd_settings.flag & HMDVIEW_USE_DEVICE_IPD) == 0) {
+		WM_device_HMD_IPD_set(value);
+	}
+}
+
 #endif /* WITH_INPUT_HMD */
 
 static void rna_Scene_framelen_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *UNUSED(ptr))
@@ -7394,17 +7418,19 @@ void RNA_def_scene(BlenderRNA *brna)
 
 	prop = RNA_def_property(srna, "use_hmd_device_ipd", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_sdna(prop, NULL, "hmd_settings.flag", HMDVIEW_USE_DEVICE_IPD);
-	RNA_def_property_ui_text(prop, "Interocular Distance from HMD",
-	                         "Request the interocular distance (distance between eyes) from the HMD driver");
+	RNA_def_property_boolean_funcs(prop, NULL, "rna_Scene_use_hmd_device_ipd_set");
+	RNA_def_property_ui_text(prop, "IPD from HMD", "Request the interpupillary distance (distance between the "
+	                         "eye pupil centers) from the HMD driver");
 	RNA_def_property_editable_func(prop, "rna_Scene_use_hmd_device_ipd_editeable");
 	RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
 
-	prop = RNA_def_property(srna, "hmd_interocular_distance", PROP_FLOAT, PROP_DISTANCE);
-	RNA_def_property_float_sdna(prop, NULL, "hmd_settings.interocular_distance");
+	prop = RNA_def_property(srna, "hmd_custom_ipd", PROP_FLOAT, PROP_DISTANCE);
+	RNA_def_property_float_sdna(prop, NULL, "hmd_settings.custom_ipd");
+	RNA_def_property_float_funcs(prop, NULL, "rna_Scene_hmd_custom_ipd_set", NULL);
 	RNA_def_property_range(prop, 0.0f, FLT_MAX);
 	RNA_def_property_ui_range(prop, 0.0f, 1e4f, 1, 3);
-	RNA_def_property_ui_text(prop, "Interocular Distance",
-	                         "Set the distance between the eyes - the stereo plane distance / 30 should be fine");
+	RNA_def_property_ui_text(prop, "Custom IPD", "Set the interpupillary distance (distance between the "
+	                         "eye pupil centers)");
 	RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
 #endif
 
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index d5d579d..6e34377 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -532,12 +532,10 @@ int         WM_device_HMD_current_get(void) ATTR_WARN_UNUSED_RESULT;
 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_left_modelview_matrix_get(float r_mat[4][4]) ATTR_NONNULL();
-void        WM_device_HMD_right_modelview_matrix_get(float r_mat[4][4]) ATTR_NONNULL();
-void        WM_device_HMD_left_projection_matrix_get(float r_mat[4][4]) ATTR_NONNULL();
-void        WM_device_HMD_right_projection_matrix_get(float r_mat[4][4]) ATTR_NONNULL();
+void        WM_device_HMD_IPD_set(float value);
 /* 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();
 void WM_device_HMD_projection_matrix_get(const bool is_left, float r_projmat[4][4]) ATTR_NONNULL();
 
 #endif /* WITH_INPUT_HMD */
diff --git a/source/blender/windowmanager/intern/wm_device.c b/source/blender/windowmanager/intern/wm_device.c
index 6a625a2..b1f8f5c 100644
--- a/source/blender/windowmanager/intern/wm_device.c
+++ b/source/blender/windowmanager/intern/wm_device.c
@@ -79,37 +79,9 @@ float WM_device_HMD_IPD_get(void)
 {
 	return GHOST_HMDgetDeviceIPD();
 }
-
-/**
- * Get left eye modelview matrix from currently opened HMD.
- */
-void WM_device_HMD_left_modelview_matrix_get(float r_mat[4][4])
-{
-	GHOST_HMDgetLeftModelviewMatrix(r_mat);
-}
-
-/**
- * Get right eye modelview matrix from currently opened HMD.
- */
-void WM_device_HMD_right_modelview_matrix_get(float r_mat[4][4])
+void WM_device_HMD_IPD_set(float value)
 {
-	GHOST_HMDgetRightModelviewMatrix(r_mat);
-}
-
-/**
- * Get left eye projection matrix from currently opened HMD.
- */
-void WM_device_HMD_left_projection_matrix_get(float r_mat[4][4])
-{
-	GHOST_HMDgetLeftProjectionMatrix(r_mat);
-}
-
-/**
- * Get right eye projection matrix from currently opened HMD.
- */
-void WM_device_HMD_right_projection_matrix_get(float r_mat[4][4])
-{
-	GHOST_HMDgetRightProjectionMatrix(r_mat);
+	GHOST_HMDsetDeviceIPD(value);
 }
 
 
@@ -130,6 +102,19 @@ 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])
+{
+	if (U.hmd_device == -1) {
+		r_modelviewmat = NULL;
+	}
+	else if (is_left) {
+		GHOST_HMDgetLeftModelviewMatrix(r_modelviewmat);
+	}
+	else {
+		GHOST_HMDgetRightModelviewMatrix(r_modelviewmat);
+	}
+}
+
 void WM_device_HMD_projection_matrix_get(const bool is_left, float r_projmat[4][4])
 {
 	if (U.hmd_device == -1) {
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index 973a163..fe23e24 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list