Camera Sensor:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Fri, 18 Nov 2011 23:15:11 +0000 (23:15 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Fri, 18 Nov 2011 23:15:11 +0000 (23:15 +0000)
* Tweak description of sensor fit property.
* Fix sensor display for auto and vertical fit.
* Fix incorrect aspect ratio for camera frame drawing.

source/blender/blenkernel/intern/camera.c
source/blender/editors/space_view3d/view3d_draw.c
source/blender/makesrna/intern/rna_camera.c

index 29770e37ea19da2a76cf363389776bd0938dadf8..a8b1c2aa04f9d705648521049b30dcb38a455179 100644 (file)
@@ -364,25 +364,16 @@ void camera_view_frame_ex(Scene *scene, Camera *camera, float drawsize, const sh
        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;
index 82f60ac639ba45909a06b51d089f756321d5617d..cdd90b38d0af807495396aabefb44a370e0d0ae5 100644 (file)
@@ -1228,19 +1228,39 @@ static void drawviewborder(Scene *scene, ARegion *ar, View3D *v3d)
                        uiDrawBox(GL_LINE_LOOP, x1, y1, x2, y2, 12.0);
                }
                if (ca && (ca->flag & CAM_SHOWSENSOR)) {
-                       /* assume fixed sensor width for now */
-
-                       /* 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 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;
+
+                       /* determine sensor plane */
+                       rctf rect;
+
+                       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;
 
-                       float ymid = y1i + (y2i-y1i)/2.f;
-                       float sy1= ymid - sensor_height/2.f;
-                       float sy2= ymid + sensor_height/2.f;
+                               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);
                }
        }
 
index 77b41b507c6073fd6774d93649987160305567b0..6f6a4baec9245d9d78e459c49073bbc7186bc6ee 100644 (file)
@@ -113,9 +113,9 @@ void RNA_def_camera(BlenderRNA *brna)
                {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 @@ void RNA_def_camera(BlenderRNA *brna)
        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 */