[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [41977] trunk/blender/source/blender: Camera Sensor:

Brecht Van Lommel brechtvanlommel at pandora.be
Sat Nov 19 00:15:12 CET 2011


Revision: 41977
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=41977
Author:   blendix
Date:     2011-11-18 23:15:11 +0000 (Fri, 18 Nov 2011)
Log Message:
-----------
Camera Sensor:
* Tweak description of sensor fit property.
* Fix sensor display for auto and vertical fit.
* Fix incorrect aspect ratio for camera frame drawing.

Modified Paths:
--------------
    trunk/blender/source/blender/blenkernel/intern/camera.c
    trunk/blender/source/blender/editors/space_view3d/view3d_draw.c
    trunk/blender/source/blender/makesrna/intern/rna_camera.c

Modified: trunk/blender/source/blender/blenkernel/intern/camera.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/camera.c	2011-11-18 23:10:56 UTC (rev 41976)
+++ trunk/blender/source/blender/blenkernel/intern/camera.c	2011-11-18 23:15:11 UTC (rev 41977)
@@ -364,25 +364,16 @@
 	if (scene) {
 		float aspx= (float) scene->r.xsch*scene->r.xasp;
 		float aspy= (float) scene->r.ysch*scene->r.yasp;
+		int sensor_fit= camera_sensor_fit(camera->sensor_fit, aspx, aspy);
 
-		if(camera->sensor_fit==CAMERA_SENSOR_FIT_AUTO) {
-			if(aspx < aspy) {
-				r_asp[0]= aspx / aspy;
-				r_asp[1]= 1.0;
-			}
-			else {
-				r_asp[0]= 1.0;
-				r_asp[1]= aspy / aspx;
-			}
+		if(sensor_fit==CAMERA_SENSOR_FIT_HOR) {
+			r_asp[0]= 1.0;
+			r_asp[1]= aspy / aspx;
 		}
-		else if(camera->sensor_fit==CAMERA_SENSOR_FIT_HOR) {
+		else {
 			r_asp[0]= aspx / aspy;
 			r_asp[1]= 1.0;
 		}
-		else {
-			r_asp[0]= 1.0;
-			r_asp[1]= aspy / aspx;
-		}
 	}
 	else {
 		r_asp[0]= 1.0f;

Modified: trunk/blender/source/blender/editors/space_view3d/view3d_draw.c
===================================================================
--- trunk/blender/source/blender/editors/space_view3d/view3d_draw.c	2011-11-18 23:10:56 UTC (rev 41976)
+++ trunk/blender/source/blender/editors/space_view3d/view3d_draw.c	2011-11-18 23:15:11 UTC (rev 41977)
@@ -1228,19 +1228,39 @@
 			uiDrawBox(GL_LINE_LOOP, x1, y1, x2, y2, 12.0);
 		}
 		if (ca && (ca->flag & CAM_SHOWSENSOR)) {
-			/* assume fixed sensor width for now */
+			/* determine sensor fit, and get sensor x/y, for auto fit we
+			   assume and square sensor and only use sensor_x */
+			float sizex= scene->r.xsch*scene->r.xasp;
+			float sizey= scene->r.ysch*scene->r.yasp;
+			int sensor_fit = camera_sensor_fit(ca->sensor_fit, sizex, sizey);
+			float sensor_x= ca->sensor_x;
+			float sensor_y= (ca->sensor_fit == CAMERA_SENSOR_FIT_AUTO)? ca->sensor_x: ca->sensor_y;
 
-			/* float sensor_aspect = ca->sensor_x / ca->sensor_y; */ /* UNUSED */
-			float sensor_scale = (x2i-x1i) / ca->sensor_x;
-			float sensor_height = sensor_scale * ca->sensor_y;
+			/* determine sensor plane */
+			rctf rect;
 
-			float ymid = y1i + (y2i-y1i)/2.f;
-			float sy1= ymid - sensor_height/2.f;
-			float sy2= ymid + sensor_height/2.f;
+			if(sensor_fit == CAMERA_SENSOR_FIT_HOR) {
+				float sensor_scale = (x2i-x1i) / sensor_x;
+				float sensor_height = sensor_scale * sensor_y;
 
+				rect.xmin= x1i;
+				rect.xmax= x2i;
+				rect.ymin= (y1i + y2i)*0.5f - sensor_height*0.5f;
+				rect.ymax= rect.ymin + sensor_height;
+			}
+			else {
+				float sensor_scale = (y2i-y1i) / sensor_y;
+				float sensor_width = sensor_scale * sensor_x;
+
+				rect.xmin= (x1i + x2i)*0.5f - sensor_width*0.5f;
+				rect.xmax= rect.xmin + sensor_width;
+				rect.ymin= y1i;
+				rect.ymax= y2i;
+			}
+
+			/* draw */
 			UI_ThemeColorShade(TH_WIRE, 100);
-
-			uiDrawBox(GL_LINE_LOOP, x1i, sy1, x2i, sy2, 2.0f);
+			uiDrawBox(GL_LINE_LOOP, rect.xmin, rect.ymin, rect.xmax, rect.ymax, 2.0f);
 		}
 	}
 

Modified: trunk/blender/source/blender/makesrna/intern/rna_camera.c
===================================================================
--- trunk/blender/source/blender/makesrna/intern/rna_camera.c	2011-11-18 23:10:56 UTC (rev 41976)
+++ trunk/blender/source/blender/makesrna/intern/rna_camera.c	2011-11-18 23:15:11 UTC (rev 41977)
@@ -113,9 +113,9 @@
 		{CAM_ANGLETOGGLE, "DEGREES", 0, "Degrees", ""},
 		{0, NULL, 0, NULL, NULL}};
 	static EnumPropertyItem sensor_fit_items[] = {
-		{CAMERA_SENSOR_FIT_AUTO, "AUTO", 0, "Auto", "Calculate field of view using sensor size, with direction depending on image resolution"},
-		{CAMERA_SENSOR_FIT_HOR, "HORIZONTAL", 0, "Horizontal", "Calculate field of view using sensor width"},
-		{CAMERA_SENSOR_FIT_VERT, "VERTICAL", 0, "Vertical", "Calculate field of view using sensor height"},
+		{CAMERA_SENSOR_FIT_AUTO, "AUTO", 0, "Auto", "Fit to the sensor width or height depending on image resolution"},
+		{CAMERA_SENSOR_FIT_HOR, "HORIZONTAL", 0, "Horizontal", "Fit to the sensor width"},
+		{CAMERA_SENSOR_FIT_VERT, "VERTICAL", 0, "Vertical", "Fit to the sensor height"},
 		{0, NULL, 0, NULL, NULL}};
 
 	srna= RNA_def_struct(brna, "Camera", "ID");
@@ -138,7 +138,7 @@
 	prop= RNA_def_property(srna, "sensor_fit", PROP_ENUM, PROP_NONE);
 	RNA_def_property_enum_sdna(prop, NULL, "sensor_fit");
 	RNA_def_property_enum_items(prop, sensor_fit_items);
-	RNA_def_property_ui_text(prop, "Sensor Fit", "Mode of calculating field of view from sensor dimensions and focal length");
+	RNA_def_property_ui_text(prop, "Sensor Fit", "Method to fit image and field of view angle inside the sensor");
 	RNA_def_property_update(prop, NC_OBJECT|ND_DRAW, "rna_Camera_update");
 
 	/* Number values */



More information about the Bf-blender-cvs mailing list