Index: source/blender/editors/space_view3d/view3d_edit.c =================================================================== --- source/blender/editors/space_view3d/view3d_edit.c (revision 41460) +++ source/blender/editors/space_view3d/view3d_edit.c (working copy) @@ -1246,7 +1246,7 @@ static void viewmove_apply(ViewOpsData *vod, int x, int y) { if((vod->rv3d->persp==RV3D_CAMOB) && !ED_view3d_camera_lock_check(vod->v3d, vod->rv3d)) { - const float zoomfac= BKE_screen_view3d_zoom_to_fac((float)vod->rv3d->camzoom) * 2.0f; + const float zoomfac= BKE_screen_view3d_zoom_to_fac((float)vod->rv3d->camzoom); vod->rv3d->camdx += (vod->oldx - x)/(vod->ar->winx * zoomfac); vod->rv3d->camdy += (vod->oldy - y)/(vod->ar->winy * zoomfac); CLAMP(vod->rv3d->camdx, -1.0f, 1.0f); Index: source/blender/editors/space_view3d/view3d_draw.c =================================================================== --- source/blender/editors/space_view3d/view3d_draw.c (revision 41460) +++ source/blender/editors/space_view3d/view3d_draw.c (working copy) @@ -952,8 +952,8 @@ 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; + dx= ar->winx*rv3d->camdx*zoomfac; + dy= ar->winy*rv3d->camdy*zoomfac; /* apply offset */ viewborder_r->xmin-= dx; Index: source/blender/editors/space_view3d/view3d_view.c =================================================================== --- source/blender/editors/space_view3d/view3d_view.c (revision 41460) +++ source/blender/editors/space_view3d/view3d_view.c (working copy) @@ -963,129 +963,89 @@ } /* also exposed in previewrender.c */ -int ED_view3d_viewplane_get(View3D *v3d, RegionView3D *rv3d, int winxi, int winyi, rctf *viewplane, float *clipsta, float *clipend, float *pixsize) +int ED_view3d_viewplane_get(View3D *v3d, RegionView3D *rv3d, int winx, int winy, rctf *viewplane, float *clipsta, float *clipend, float *pixsize) { - Camera *cam=NULL; - float lens, fac, x1, y1, x2, y2; - float winx= (float)winxi, winy= (float)winyi; - int orth= 0; + float const film_size = 32.0f; + + Camera *cam = NULL; + float fac = BKE_screen_view3d_zoom_to_fac(rv3d->camzoom); + int orth; + float size, sizex, sizey; + float shiftx = 0.0f, shifty = 0.0f; - lens= v3d->lens; + /* ratio == (size of the view plane) / (distance to the view plane) */ + float ratio = film_size / v3d->lens; + *clipsta = v3d->near; + *clipend = v3d->far; - *clipsta= v3d->near; - *clipend= v3d->far; - - if(rv3d->persp==RV3D_CAMOB) { + /* calculate the size of the view plane */ + if(rv3d->persp == RV3D_ORTHO) { + *clipsta = -v3d->far; + *clipend = +v3d->far * 0.5f; /* otherwise too extreme low zbuffer quality */ + size = rv3d->dist * ratio; + orth = 1; + } + else if(rv3d->persp == RV3D_PERSP) { + size = *clipsta * ratio; + orth = 0; + } + else /*rv3d->persp == RV3D_CAMOB*/ { if(v3d->camera) { - if(v3d->camera->type==OB_LAMP ) { - Lamp *la; - - la= v3d->camera->data; - fac= cosf(((float)M_PI)*la->spotsize/360.0f); - - x1= saacos(fac); - lens= 16.0f*fac/sinf(x1); - - *clipsta= la->clipsta; - *clipend= la->clipend; + if(v3d->camera->type == OB_LAMP) { + Lamp *la = v3d->camera->data; + float theta = ((float)M_PI / 360.0f) * la->spotsize; + /* assert(0.0 <= theta && theta < M_PI); */ + ratio = tanf(theta) * 2.0f; + *clipsta = la->clipsta; + *clipend = la->clipend; } - else if(v3d->camera->type==OB_CAMERA) { - cam= v3d->camera->data; - lens= cam->lens; - *clipsta= cam->clipsta; - *clipend= cam->clipend; + else if(v3d->camera->type == OB_CAMERA) { + cam = v3d->camera->data; + ratio = film_size / cam->lens; + *clipsta = cam->clipsta; + *clipend = cam->clipend; } } - } - - if(rv3d->persp==RV3D_ORTHO) { - if(winx>winy) x1= -rv3d->dist; - else x1= -winx*rv3d->dist/winy; - x2= -x1; - - if(winx>winy) y1= -winy*rv3d->dist/winx; - else y1= -rv3d->dist; - y2= -y1; - - *clipend *= 0.5f; // otherwise too extreme low zbuffer quality - *clipsta= - *clipend; - orth= 1; - } - else { - /* fac for zoom, also used for camdx */ - if(rv3d->persp==RV3D_CAMOB) { - fac= BKE_screen_view3d_zoom_to_fac((float)rv3d->camzoom) * 4.0f; - } - else { - fac= 2.0; - } - - /* viewplane size depends... */ - if(cam && cam->type==CAM_ORTHO) { + + if(cam && cam->type == CAM_ORTHO) { + shiftx += cam->shiftx * cam->ortho_scale; + shifty += cam->shifty * cam->ortho_scale; /* ortho_scale == 1 means exact 1 to 1 mapping */ - float dfac= 2.0f*cam->ortho_scale/fac; - - if(winx>winy) x1= -dfac; - else x1= -winx*dfac/winy; - x2= -x1; - - if(winx>winy) y1= -winy*dfac/winx; - else y1= -dfac; - y2= -y1; - orth= 1; + size = cam->ortho_scale / fac; + orth = 1; } else { - float dfac; - - if(winx>winy) dfac= 64.0f/(fac*winx*lens); - else dfac= 64.0f/(fac*winy*lens); - - x1= - *clipsta * winx*dfac; - x2= -x1; - y1= - *clipsta * winy*dfac; - y2= -y1; - orth= 0; + shiftx += cam->shiftx * (cam->clipsta * ratio); + shifty += cam->shifty * (cam->clipsta * ratio); + size = *clipsta * ratio / fac; + orth = 0; } - /* cam view offset */ - if(cam) { - float dx= 0.5f*fac*rv3d->camdx*(x2-x1); - float dy= 0.5f*fac*rv3d->camdy*(y2-y1); + } - /* shift offset */ - if(cam->type==CAM_ORTHO) { - dx += cam->shiftx * cam->ortho_scale; - dy += cam->shifty * cam->ortho_scale; - } - else { - dx += cam->shiftx * (cam->clipsta / cam->lens) * 32.0f; - dy += cam->shifty * (cam->clipsta / cam->lens) * 32.0f; - } + if(winx > winy) { + sizex = size; + sizey = size * winy / winx; + } + else { + sizex = size * winx / winy; + sizey = size; + } - x1+= dx; - x2+= dx; - y1+= dy; - y2+= dy; - } + /* cam view offset */ + if(cam) { + shiftx += fac * rv3d->camdx * sizex; + shifty += fac * rv3d->camdy * sizey; } + viewplane->xmin = -0.5f * sizex + shiftx; + viewplane->ymin = -0.5f * sizey + shifty; + viewplane->xmax = +0.5f * sizex + shiftx; + viewplane->ymax = +0.5f * sizey + shifty; + if(pixsize) { - float viewfac; - - if(orth) { - viewfac= (winx >= winy)? winx: winy; - *pixsize= 1.0f/viewfac; - } - else { - viewfac= (((winx >= winy)? winx: winy)*lens)/32.0f; - *pixsize= *clipsta/viewfac; - } + *pixsize = winx > winy ? sizex / winx : sizey / winy; } - viewplane->xmin= x1; - viewplane->ymin= y1; - viewplane->xmax= x2; - viewplane->ymax= y2; - return orth; }