diff options
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/gpencil/drawgpencil.c | 2 | ||||
-rw-r--r-- | source/blender/editors/gpencil/gpencil_edit.c | 2 | ||||
-rw-r--r-- | source/blender/editors/gpencil/gpencil_paint.c | 2 | ||||
-rw-r--r-- | source/blender/editors/include/ED_view3d.h | 3 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_image.c | 3 | ||||
-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 |
9 files changed, 55 insertions, 79 deletions
diff --git a/source/blender/editors/gpencil/drawgpencil.c b/source/blender/editors/gpencil/drawgpencil.c index 081d604819d..def6cd61370 100644 --- a/source/blender/editors/gpencil/drawgpencil.c +++ b/source/blender/editors/gpencil/drawgpencil.c @@ -794,7 +794,7 @@ void draw_gpencil_view3d (Scene *scene, View3D *v3d, ARegion *ar, short only3d) * deal with the camera border, otherwise map the coords to the camera border. */ if ((rv3d->persp == RV3D_CAMOB) && !(G.f & G_RENDER_OGL)) { rctf rectf; - ED_view3d_calc_camera_border(scene, ar, v3d, rv3d, &rectf, -1); /* negative shift */ + ED_view3d_calc_camera_border(scene, ar, v3d, rv3d, &rectf, TRUE); /* no shift */ BLI_copy_rcti_rctf(&rect, &rectf); } else { diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c index 65db5e27ed7..9a492153b7f 100644 --- a/source/blender/editors/gpencil/gpencil_edit.c +++ b/source/blender/editors/gpencil/gpencil_edit.c @@ -468,7 +468,7 @@ static int gp_camera_view_subrect(bContext *C, rctf *subrect) /* for camera view set the subrect */ if (rv3d->persp == RV3D_CAMOB) { Scene *scene= CTX_data_scene(C); - ED_view3d_calc_camera_border(scene, ar, v3d, rv3d, subrect, -1); /* negative shift */ + ED_view3d_calc_camera_border(scene, ar, v3d, rv3d, subrect, TRUE); /* no shift */ return 1; } } diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c index 2dd8ef4da94..f09797bf6f1 100644 --- a/source/blender/editors/gpencil/gpencil_paint.c +++ b/source/blender/editors/gpencil/gpencil_paint.c @@ -1258,7 +1258,7 @@ static void gp_paint_initstroke (tGPsdata *p, short paintmode) /* for camera view set the subrect */ if (rv3d->persp == RV3D_CAMOB) { - ED_view3d_calc_camera_border(p->scene, p->ar, v3d, rv3d, &p->subrect_data, -1); /* negative shift */ + ED_view3d_calc_camera_border(p->scene, p->ar, v3d, rv3d, &p->subrect_data, TRUE); /* no shift */ p->subrect= &p->subrect_data; } } diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h index a90e91a7242..c2390d41d8c 100644 --- a/source/blender/editors/include/ED_view3d.h +++ b/source/blender/editors/include/ED_view3d.h @@ -210,7 +210,8 @@ int ED_view3d_clip_range_get(struct View3D *v3d, struct RegionView3D *rv3d, floa int ED_view3d_viewplane_get(struct View3D *v3d, struct RegionView3D *rv3d, int winxi, int winyi, struct rctf *viewplane, float *clipsta, float *clipend); void ED_view3d_ob_project_mat_get(struct RegionView3D *v3d, struct Object *ob, float pmat[4][4]); void ED_view3d_project_float(struct ARegion *a, const float vec[3], float adr[2], float mat[4][4]); -void ED_view3d_calc_camera_border(struct Scene *scene, struct ARegion *ar, struct View3D *v3d, struct RegionView3D *rv3d, struct rctf *viewborder_r, short do_shift); +void ED_view3d_calc_camera_border(struct Scene *scene, struct ARegion *ar, struct View3D *v3d, struct RegionView3D *rv3d, struct rctf *viewborder_r, short no_shift); +void ED_view3d_calc_camera_border_size(struct Scene *scene, struct ARegion *ar, struct View3D *v3d, struct RegionView3D *rv3d, float size_r[2]); /* drawobject.c iterators */ void mesh_foreachScreenVert(struct ViewContext *vc, void (*func)(void *userData, struct EditVert *eve, int x, int y, int index), void *userData, int clipVerts); diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c index a856f959b49..9b256acbca9 100644 --- a/source/blender/editors/sculpt_paint/paint_image.c +++ b/source/blender/editors/sculpt_paint/paint_image.c @@ -3068,7 +3068,8 @@ static void project_paint_begin(ProjPaintState *ps) /* window matrix, clipping and ortho */ camera_params_init(¶ms); camera_params_from_object(¶ms, cam_ob); - camera_params_compute(¶ms, ps->winx, ps->winy, 1.0f, 1.0f); + camera_params_compute_viewplane(¶ms, ps->winx, ps->winy, 1.0f, 1.0f); + camera_params_compute_matrix(¶ms); copy_m4_m4(winmat, params.winmat); ps->clipsta= params.clipsta; 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; } |