diff options
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/BKE_camera.h | 8 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/camera.c | 32 | ||||
-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 | ||||
-rw-r--r-- | source/blender/modifiers/intern/MOD_uvproject.c | 14 | ||||
-rw-r--r-- | source/blender/render/intern/source/initrender.c | 6 |
13 files changed, 88 insertions, 106 deletions
diff --git a/source/blender/blenkernel/BKE_camera.h b/source/blender/blenkernel/BKE_camera.h index 8aec576b963..72e22dc1583 100644 --- a/source/blender/blenkernel/BKE_camera.h +++ b/source/blender/blenkernel/BKE_camera.h @@ -92,20 +92,22 @@ typedef struct CameraParams { int field_second; int field_odd; - /* compute result */ + /* computed viewplane */ float ycor; - float viewdx; float viewdy; rctf viewplane; + /* computed matrix */ float winmat[4][4]; } CameraParams; void camera_params_init(CameraParams *params); void camera_params_from_object(CameraParams *params, struct Object *camera); void camera_params_from_view3d(CameraParams *params, struct View3D *v3d, struct RegionView3D *rv3d); -void camera_params_compute(CameraParams *params, int winx, int winy, float aspx, float aspy); + +void camera_params_compute_viewplane(CameraParams *params, int winx, int winy, float aspx, float aspy); +void camera_params_compute_matrix(CameraParams *params); /* Camera View Frame */ diff --git a/source/blender/blenkernel/intern/camera.c b/source/blender/blenkernel/intern/camera.c index 1bfeea727ec..da7c0ab1774 100644 --- a/source/blender/blenkernel/intern/camera.c +++ b/source/blender/blenkernel/intern/camera.c @@ -241,7 +241,7 @@ void camera_params_from_object(CameraParams *params, Object *ob) void camera_params_from_view3d(CameraParams *params, View3D *v3d, RegionView3D *rv3d) { - /* perspective view */ + /* common */ params->lens= v3d->lens; params->clipsta= v3d->near; params->clipend= v3d->far; @@ -250,28 +250,32 @@ void camera_params_from_view3d(CameraParams *params, View3D *v3d, RegionView3D * /* camera view */ camera_params_from_object(params, v3d->camera); - params->zoom= BKE_screen_view3d_zoom_to_fac((float)rv3d->camzoom) * 2.0f; - params->zoom= 1.0f/params->zoom; + params->zoom= BKE_screen_view3d_zoom_to_fac((float)rv3d->camzoom); + + params->offsetx= 2.0f*rv3d->camdx*params->zoom; + params->offsety= 2.0f*rv3d->camdy*params->zoom; - params->offsetx= rv3d->camdx; - params->offsety= rv3d->camdy; + params->shiftx *= params->zoom; + params->shifty *= params->zoom; - params->shiftx *= 0.5f; - params->shifty *= 0.5f; + params->zoom= 1.0f/params->zoom; } else if(rv3d->persp==RV3D_ORTHO) { /* orthographic view */ params->clipend *= 0.5f; // otherwise too extreme low zbuffer quality params->clipsta= - params->clipend; - params->is_ortho= 1; + params->is_ortho= TRUE; params->ortho_scale = rv3d->dist; + params->zoom= 2.0f; + } + else { + /* perspective view */ + params->zoom= 2.0f; } - - params->zoom *= 2.0f; } -void camera_params_compute(CameraParams *params, int winx, int winy, float xasp, float yasp) +void camera_params_compute_viewplane(CameraParams *params, int winx, int winy, float xasp, float yasp) { rctf viewplane; float pixsize, viewfac, sensor_size, dx, dy; @@ -344,6 +348,12 @@ void camera_params_compute(CameraParams *params, int winx, int winy, float xasp, params->viewdx= pixsize; params->viewdy= params->ycor * pixsize; params->viewplane= viewplane; +} + +/* viewplane is assumed to be already computed */ +void camera_params_compute_matrix(CameraParams *params) +{ + rctf viewplane= params->viewplane; /* compute projection matrix */ if(params->is_ortho) 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; } diff --git a/source/blender/modifiers/intern/MOD_uvproject.c b/source/blender/modifiers/intern/MOD_uvproject.c index df528a0cb11..6f0ba9259b8 100644 --- a/source/blender/modifiers/intern/MOD_uvproject.c +++ b/source/blender/modifiers/intern/MOD_uvproject.c @@ -195,20 +195,12 @@ static DerivedMesh *uvprojectModifier_do(UVProjectModifierData *umd, free_uci= 1; } else { - float sensor= (cam->sensor_fit == CAMERA_SENSOR_FIT_VERT) ? (cam->sensor_y) : cam->sensor_x; + float sensor= camera_sensor_size(cam->sensor_fit, cam->sensor_x, cam->sensor_y); + int sensor_fit= camera_sensor_fit(cam->sensor_fit, aspx, aspy); float scale= (cam->type == CAM_PERSP) ? cam->clipsta * sensor / cam->lens : cam->ortho_scale; float xmax, xmin, ymax, ymin; - if(cam->sensor_fit==CAMERA_SENSOR_FIT_AUTO) { - if(aspect > 1.0f) { - xmax = 0.5f * scale; - ymax = xmax / aspect; - } else { - ymax = 0.5f * scale; - xmax = ymax * aspect; - } - } - else if(cam->sensor_fit==CAMERA_SENSOR_FIT_HOR) { + if(sensor_fit==CAMERA_SENSOR_FIT_HOR) { xmax = 0.5f * scale; ymax = xmax / aspect; } diff --git a/source/blender/render/intern/source/initrender.c b/source/blender/render/intern/source/initrender.c index e7572302676..b7254cd1221 100644 --- a/source/blender/render/intern/source/initrender.c +++ b/source/blender/render/intern/source/initrender.c @@ -482,7 +482,8 @@ void RE_SetEnvmapCamera(Render *re, Object *cam_ob, float viewscale, float clips params.clipend= clipend; /* compute matrix, viewplane, .. */ - camera_params_compute(¶ms, re->winx, re->winy, 1.0f, 1.0f); + camera_params_compute_viewplane(¶ms, re->winx, re->winy, 1.0f, 1.0f); + camera_params_compute_matrix(¶ms); /* extract results */ re_camera_params_get(re, ¶ms, cam_ob); @@ -503,7 +504,8 @@ void RE_SetCamera(Render *re, Object *cam_ob) params.field_odd= (re->r.mode & R_ODDFIELD); /* compute matrix, viewplane, .. */ - camera_params_compute(¶ms, re->winx, re->winy, re->r.xasp, re->r.yasp); + camera_params_compute_viewplane(¶ms, re->winx, re->winy, re->r.xasp, re->r.yasp); + camera_params_compute_matrix(¶ms); /* extract results */ re_camera_params_get(re, ¶ms, cam_ob); |