[Bf-blender-cvs] [86d768e] wiggly-widgets: Draw focal length widget with camera aspect

Julian Eisel noreply at git.blender.org
Sun Sep 20 15:56:42 CEST 2015


Commit: 86d768efc584e20a7970a144dcded7d749500264
Author: Julian Eisel
Date:   Sun Sep 20 15:51:22 2015 +0200
Branches: wiggly-widgets
https://developer.blender.org/rB86d768efc584e20a7970a144dcded7d749500264

Draw focal length widget with camera aspect

A bit stupid that we mix some special stuff for cone (plane in fact) style drawing into regular arrow widget drawing, still would like to use plane widget for this, but first need to pack arrow handling into more generic functions, since arrow & plane widgets would need almost the same handling.

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

M	source/blender/editors/space_view3d/space_view3d.c
M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/intern/wm_generic_widgets.c

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

diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c
index a592f59..c42c046 100644
--- a/source/blender/editors/space_view3d/space_view3d.c
+++ b/source/blender/editors/space_view3d/space_view3d.c
@@ -48,6 +48,7 @@
 #include "BLI_utildefines.h"
 
 #include "BKE_action.h"
+#include "BKE_camera.h"
 #include "BKE_context.h"
 #include "BKE_depsgraph.h"
 #include "BKE_icons.h"
@@ -768,23 +769,32 @@ static void WIDGETGROUP_camera_create(const struct bContext *C, struct wmWidgetG
 	/* focal length
 	 * - logic/calculations are similar to BKE_camera_view_frame_ex, better keep in sync */
 	if (focallen_widget) {
+		const Scene *scene = CTX_data_scene(C);
 		const bool is_ortho = (ca->type == CAM_ORTHO);
 		const float scale_fac = ca->drawsize;
 		const float half_sensor = 0.5f * ((ca->sensor_fit == CAMERA_SENSOR_FIT_VERT) ? ca->sensor_y : ca->sensor_x);
 		const float scale[3] = {1.0f / len_v3(ob->obmat[0]), 1.0f / len_v3(ob->obmat[1]), 1.0f / len_v3(ob->obmat[2])};
 		const float drawsize = is_ortho ? (0.5f * ca->ortho_scale) :
 		                                  (scale_fac / ((scale[0] + scale[1] + scale[2]) / 3.0f));
+		const float aspx = (float)scene->r.xsch * scene->r.xasp;
+		const float aspy = (float)scene->r.ysch * scene->r.yasp;
+		const int sensor_fit = BKE_camera_sensor_fit(ca->sensor_fit, aspx, aspy);
 		const char *propname = is_ortho ? "ortho_scale" : "lens";
+		const bool fit_hor = (sensor_fit == CAMERA_SENSOR_FIT_HOR);
 
 		const float color[4] = {1.0f, 1.0, 0.27f, 0.5f};
 		const float color_hi[4] = {1.0f, 1.0, 0.27f, 1.0f};
 
 		PropertyRNA *prop;
-		float offset[3];
+		float offset[3], asp[2];
 		float min, max, range;
 		float step, precision; /* dummys, unused */
 
 
+		/* get aspect */
+		asp[0] = fit_hor ? 1.0 : aspx / aspy;
+		asp[1] = fit_hor ? aspy / aspx : 1.0f;
+
 		/* account for lens shifting */
 		offset[0] = ((ob->size[0] > 0.0f) ? -2.0f : 2.0f) * ca->shiftx;
 		offset[1] = 2.0f * ca->shifty;
@@ -803,6 +813,7 @@ static void WIDGETGROUP_camera_create(const struct bContext *C, struct wmWidgetG
 		WIDGET_arrow_set_range_fac(widget, is_ortho ? (scale_fac * range) : (drawsize * range / half_sensor));
 		WIDGET_arrow_set_direction(widget, dir);
 		WIDGET_arrow_set_up_vector(widget, ob->obmat[1]);
+		WIDGET_arrow_cone_set_aspect(widget, asp);
 		WM_widget_set_property(widget, ARROW_SLOT_OFFSET_WORLD_SPACE, &cameraptr, propname);
 		WM_widget_set_origin(widget, ob->obmat[3]);
 		WM_widget_set_offset(widget, offset);
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index d8453af..6ac838f 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -593,6 +593,7 @@ void WIDGET_arrow_set_up_vector(struct wmWidget *widget, const float direction[3
 void WIDGET_arrow_set_line_len(struct wmWidget *widget, const float len);
 void WIDGET_arrow_set_ui_range(struct wmWidget *widget, const float min, const float max);
 void WIDGET_arrow_set_range_fac(struct wmWidget *widget, const float range_fac);
+void WIDGET_arrow_cone_set_aspect(struct wmWidget *widget, const float aspect[2]);
 
 struct wmWidget *WIDGET_dial_new(struct wmWidgetGroup *wgroup, const char *name, const int style);
 void WIDGET_dial_set_up_vector(struct wmWidget *widget, const float direction[3]);
diff --git a/source/blender/windowmanager/intern/wm_generic_widgets.c b/source/blender/windowmanager/intern/wm_generic_widgets.c
index bfc0556..ff95c24 100644
--- a/source/blender/windowmanager/intern/wm_generic_widgets.c
+++ b/source/blender/windowmanager/intern/wm_generic_widgets.c
@@ -180,6 +180,7 @@ typedef struct ArrowWidget {
 	float len;          /* arrow line length */
 	float direction[3];
 	float up[3];
+	float aspect[2];    /* cone style only */
 
 	float range_fac;      /* factor for arrow min/max distance */
 	float offset;
@@ -224,11 +225,13 @@ static void arrow_draw_geom(const ArrowWidget *arrow, const bool select)
 		glPopAttrib();
 	}
 	else if (arrow->style & WIDGET_ARROW_STYLE_CONE) {
-		static float vec[4][3] = {
-			{-1, -1, 0},
-			{ 1, -1, 0},
-			{ 1,  1, 0},
-			{-1,  1, 0},
+		const float unitx = arrow->aspect[0];
+		const float unity = arrow->aspect[1];
+		const float vec[4][3] = {
+			{-unitx, -unity, 0},
+			{ unitx, -unity, 0},
+			{ unitx,  unity, 0},
+			{-unitx,  unity, 0},
 		};
 
 		glLineWidth(arrow->widget.line_width);
@@ -716,6 +719,16 @@ void WIDGET_arrow_set_range_fac(wmWidget *widget, const float range_fac)
 	arrow->range_fac = range_fac;
 }
 
+/**
+ * Define xy-aspect for arrow cone
+ */
+void WIDGET_arrow_cone_set_aspect(wmWidget *widget, const float aspect[2])
+{
+	ArrowWidget *arrow = (ArrowWidget *)widget;
+
+	copy_v2_v2(arrow->aspect, aspect);
+}
+
 /** \} */ // Arrow Widget API
 /** \} */ // Arrow Widget




More information about the Bf-blender-cvs mailing list