diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2011-11-19 22:35:42 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2011-11-19 22:35:42 +0400 |
commit | 5d2a155f2bcc2d6d77d3a3753c23027b06942540 (patch) | |
tree | f7516f66a00293452972ac009e4a40faeeccbe45 /source/blender/editors/space_view3d | |
parent | d9e99abe3753591d510dbb58813bbc29e3381b57 (diff) |
Camera: some more refactoring, mostly in the function that computes the camera
border, now we just get the border coordinates from comparing the viewport and
camera viewplanes.
Diffstat (limited to 'source/blender/editors/space_view3d')
-rw-r--r-- | source/blender/editors/space_view3d/view3d_draw.c | 105 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_edit.c | 4 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_intern.h | 1 | ||||
-rw-r--r-- | source/blender/editors/space_view3d/view3d_view.c | 12 |
4 files changed, 48 insertions, 74 deletions
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c index cdd90b38d0a..7dae02aba39 100644 --- a/source/blender/editors/space_view3d/view3d_draw.c +++ b/source/blender/editors/space_view3d/view3d_draw.c @@ -923,75 +923,48 @@ static void draw_selected_name(Scene *scene, Object *ob) BLF_draw_default(offset, 10, 0.0f, info, sizeof(info)-1); } -void view3d_viewborder_size_get(Scene *scene, Object *camob, ARegion *ar, float size_r[2]) +static void view3d_camera_border(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D *rv3d, rctf *viewborder_r, short no_shift, short no_zoom) { - float aspect= (scene->r.xsch*scene->r.xasp) / (scene->r.ysch*scene->r.yasp); - short sensor_fit= CAMERA_SENSOR_FIT_AUTO; - - if(camob && camob->type==OB_CAMERA) { - Camera *cam= (Camera *)camob->data; - sensor_fit= cam->sensor_fit; - } + CameraParams params; + rctf rect_view, rect_camera; + + /* get viewport viewplane */ + camera_params_init(¶ms); + camera_params_from_view3d(¶ms, v3d, rv3d); + if(no_zoom) + params.zoom= 1.0f; + camera_params_compute_viewplane(¶ms, ar->winx, ar->winy, 1.0f, 1.0f); + rect_view= params.viewplane; + + /* get camera viewplane */ + camera_params_init(¶ms); + camera_params_from_object(¶ms, v3d->camera); + if(no_shift) { + params.shiftx= 0.0f; + params.shifty= 0.0f; + } + camera_params_compute_viewplane(¶ms, scene->r.xsch, scene->r.ysch, scene->r.xasp, scene->r.yasp); + rect_camera= params.viewplane; + + /* get camera border within viewport */ + viewborder_r->xmin= ((rect_camera.xmin - rect_view.xmin)/(rect_view.xmax - rect_view.xmin))*ar->winx; + viewborder_r->xmax= ((rect_camera.xmax - rect_view.xmin)/(rect_view.xmax - rect_view.xmin))*ar->winx; + viewborder_r->ymin= ((rect_camera.ymin - rect_view.ymin)/(rect_view.ymax - rect_view.ymin))*ar->winy; + viewborder_r->ymax= ((rect_camera.ymax - rect_view.ymin)/(rect_view.ymax - rect_view.ymin))*ar->winy; +} - if(sensor_fit==CAMERA_SENSOR_FIT_AUTO) { - float winmax= MAX2(ar->winx, ar->winy); +void ED_view3d_calc_camera_border_size(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D *rv3d, float size_r[2]) +{ + rctf viewborder; - if(aspect > 1.0f) { - size_r[0]= winmax; - size_r[1]= winmax/aspect; - } else { - size_r[0]= winmax*aspect; - size_r[1]= winmax; - } - } - else if(sensor_fit==CAMERA_SENSOR_FIT_HOR) { - size_r[0]= ar->winx; - size_r[1]= ar->winx/aspect; - } - else { - size_r[0]= ar->winy*aspect; - size_r[1]= ar->winy; - } + view3d_camera_border(scene, ar, v3d, rv3d, &viewborder, TRUE, TRUE); + size_r[0]= viewborder.xmax - viewborder.xmin; + size_r[1]= viewborder.ymax - viewborder.ymin; } -void ED_view3d_calc_camera_border(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D *rv3d, rctf *viewborder_r, short do_shift) +void ED_view3d_calc_camera_border(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D *rv3d, rctf *viewborder_r, short no_shift) { - const float zoomfac= BKE_screen_view3d_zoom_to_fac((float)rv3d->camzoom); - float size[2]; - float dx= 0.0f, dy= 0.0f; - - view3d_viewborder_size_get(scene, v3d->camera, ar, size); - - size[0]= size[0]*zoomfac; - size[1]= size[1]*zoomfac; - - /* center in window */ - viewborder_r->xmin= 0.5f * ar->winx - 0.5f * size[0]; - viewborder_r->ymin= 0.5f * ar->winy - 0.5f * size[1]; - viewborder_r->xmax= viewborder_r->xmin + size[0]; - viewborder_r->ymax= viewborder_r->ymin + size[1]; - - dx= ar->winx*rv3d->camdx*zoomfac*2.0f; - dy= ar->winy*rv3d->camdy*zoomfac*2.0f; - - /* apply offset */ - viewborder_r->xmin-= dx; - viewborder_r->ymin-= dy; - viewborder_r->xmax-= dx; - viewborder_r->ymax-= dy; - - if(do_shift && v3d->camera && v3d->camera->type==OB_CAMERA) { - Camera *cam= v3d->camera->data; - float w = viewborder_r->xmax - viewborder_r->xmin; - float h = viewborder_r->ymax - viewborder_r->ymin; - float side = MAX2(w, h); - - if(do_shift == -1) side *= -1; - viewborder_r->xmin+= cam->shiftx*side; - viewborder_r->xmax+= cam->shiftx*side; - viewborder_r->ymin+= cam->shifty*side; - viewborder_r->ymax+= cam->shifty*side; - } + view3d_camera_border(scene, ar, v3d, rv3d, viewborder_r, no_shift, FALSE); } static void drawviewborder_grid3(float x1, float x2, float y1, float y2, float fac) @@ -2509,7 +2482,8 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(Scene *scene, View3D *v3d, ARegion *ar, in camera_params_init(¶ms); camera_params_from_object(¶ms, v3d->camera); - camera_params_compute(¶ms, sizex, sizey, scene->r.xasp, scene->r.yasp); + camera_params_compute_viewplane(¶ms, sizex, sizey, scene->r.xasp, scene->r.yasp); + camera_params_compute_matrix(¶ms); ED_view3d_draw_offscreen(scene, v3d, ar, sizex, sizey, NULL, params.winmat); } @@ -2568,7 +2542,8 @@ ImBuf *ED_view3d_draw_offscreen_imbuf_simple(Scene *scene, Object *camera, int w camera_params_init(¶ms); camera_params_from_object(¶ms, v3d.camera); - camera_params_compute(¶ms, width, height, scene->r.xasp, scene->r.yasp); + camera_params_compute_viewplane(¶ms, width, height, scene->r.xasp, scene->r.yasp); + camera_params_compute_matrix(¶ms); copy_m4_m4(rv3d.winmat, params.winmat); v3d.near= params.clipsta; diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c index 39ef6b3c84a..32e162fd09c 100644 --- a/source/blender/editors/space_view3d/view3d_edit.c +++ b/source/blender/editors/space_view3d/view3d_edit.c @@ -2266,7 +2266,7 @@ static int view3d_center_camera_exec(bContext *C, wmOperator *UNUSED(op)) /* was rv3d->camdx= rv3d->camdy= 0.0f; - view3d_viewborder_size_get(scene, v3d->camera, ar, size); + ED_view3d_calc_camera_border_size(scene, ar, v3d, rv3d, size); /* 4px is just a little room from the edge of the area */ xfac= (float)ar->winx / (float)(size[0] + 4); @@ -2534,7 +2534,7 @@ static void view3d_set_1_to_1_viewborder(Scene *scene, ARegion *ar, View3D *v3d) float size[2]; int im_width= (scene->r.size*scene->r.xsch)/100; - view3d_viewborder_size_get(scene, v3d->camera, ar, size); + ED_view3d_calc_camera_border_size(scene, ar, v3d, rv3d, size); rv3d->camzoom= BKE_screen_view3d_zoom_from_fac((float)im_width/size[0]); CLAMP(rv3d->camzoom, RV3D_CAMZOOM_MIN, RV3D_CAMZOOM_MAX); diff --git a/source/blender/editors/space_view3d/view3d_intern.h b/source/blender/editors/space_view3d/view3d_intern.h index 775cb45066a..42f58ba26f7 100644 --- a/source/blender/editors/space_view3d/view3d_intern.h +++ b/source/blender/editors/space_view3d/view3d_intern.h @@ -140,7 +140,6 @@ void draw_depth_gpencil(Scene *scene, ARegion *ar, View3D *v3d); void view3d_clr_clipping(void); void view3d_set_clipping(RegionView3D *rv3d); void add_view3d_after(ListBase *lb, Base *base, int flag); -void view3d_viewborder_size_get(struct Scene *scene, struct Object *camob, struct ARegion *ar, float size_r[2]); void circf(float x, float y, float rad); void circ(float x, float y, float rad); diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c index bb268203a33..90f617513a5 100644 --- a/source/blender/editors/space_view3d/view3d_view.c +++ b/source/blender/editors/space_view3d/view3d_view.c @@ -983,8 +983,8 @@ int ED_view3d_clip_range_get(View3D *v3d, RegionView3D *rv3d, float *clipsta, fl camera_params_init(¶ms); camera_params_from_view3d(¶ms, v3d, rv3d); - *clipsta= params.clipsta; - *clipend= params.clipend; + if(clipsta) *clipsta= params.clipsta; + if(clipend) *clipend= params.clipend; return params.is_ortho; } @@ -996,11 +996,11 @@ int ED_view3d_viewplane_get(View3D *v3d, RegionView3D *rv3d, int winx, int winy, camera_params_init(¶ms); camera_params_from_view3d(¶ms, v3d, rv3d); - camera_params_compute(¶ms, winx, winy, 1.0f, 1.0f); + camera_params_compute_viewplane(¶ms, winx, winy, 1.0f, 1.0f); - *viewplane= params.viewplane; - *clipsta= params.clipsta; - *clipend= params.clipend; + if(viewplane) *viewplane= params.viewplane; + if(clipsta) *clipsta= params.clipsta; + if(clipend) *clipend= params.clipend; return params.is_ortho; } |