Camera Sensor:

* Tweak description of sensor fit property.
* Fix sensor display for auto and vertical fit.
* Fix incorrect aspect ratio for camera frame drawing.
This commit is contained in:
2011-11-18 23:15:11 +00:00
parent 4d31654a61
commit 26e08e1b9d
3 changed files with 39 additions and 28 deletions

View 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;
}
}
else if(camera->sensor_fit==CAMERA_SENSOR_FIT_HOR) {
r_asp[0]= aspx / aspy;
r_asp[1]= 1.0;
}
else {
if(sensor_fit==CAMERA_SENSOR_FIT_HOR) {
r_asp[0]= 1.0;
r_asp[1]= aspy / aspx;
}
else {
r_asp[0]= aspx / aspy;
r_asp[1]= 1.0;
}
}
else {
r_asp[0]= 1.0f;

View 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 */
/* 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);
}
}

View 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 */