[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [14447] branches/apricot/source/blender: Option improved view navigation with large scenes.
Campbell Barton
ideasman42 at gmail.com
Thu Apr 17 11:49:15 CEST 2008
Revision: 14447
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=14447
Author: campbellbarton
Date: 2008-04-17 11:49:15 +0200 (Thu, 17 Apr 2008)
Log Message:
-----------
Option improved view navigation with large scenes. - "Auto Depth" in the view settings.
This works around the annoying problem where you cant zoom in any further by using the depth under the mouse to set the zoom endpoint.
It also sets the view rotation pivot to be under the mouse and works well with "Zoom to Mouse Position"
Modified Paths:
--------------
branches/apricot/source/blender/makesdna/DNA_userdef_types.h
branches/apricot/source/blender/src/space.c
branches/apricot/source/blender/src/view.c
Modified: branches/apricot/source/blender/makesdna/DNA_userdef_types.h
===================================================================
--- branches/apricot/source/blender/makesdna/DNA_userdef_types.h 2008-04-17 08:43:22 UTC (rev 14446)
+++ branches/apricot/source/blender/makesdna/DNA_userdef_types.h 2008-04-17 09:49:15 UTC (rev 14447)
@@ -260,6 +260,7 @@
#define USER_GLOBALUNDO (1 << 13)
#define USER_ORBIT_SELECTION (1 << 14)
// old flag for #define USER_KEYINSERTAVAI (1 << 15)
+#define USER_ORBIT_ZBUF (1 << 15)
#define USER_HIDE_DOT (1 << 16)
#define USER_SHOW_ROTVIEWICON (1 << 17)
#define USER_SHOW_VIEWPORTNAME (1 << 18)
Modified: branches/apricot/source/blender/src/space.c
===================================================================
--- branches/apricot/source/blender/src/space.c 2008-04-17 08:43:22 UTC (rev 14446)
+++ branches/apricot/source/blender/src/space.c 2008-04-17 09:49:15 UTC (rev 14447)
@@ -3670,6 +3670,11 @@
"Snap objects and sub-objects to grid units when scaling");
uiBlockEndAlign(block);
+ uiDefButBitI(block, TOG, USER_ORBIT_ZBUF, B_DRAWINFO, "Auto Depth",
+ (xpos+edgsp+mpref+spref+(2*midsp)),y2,spref,buth,
+ &(U.uiflag), 0, 0, 0, 0,
+ "Use the depth under the mouse to improve view pan/rotate/zoom functionality");
+
uiDefButBitI(block, TOG, USER_LOCKAROUND, B_DRAWINFO, "Global Pivot",
(xpos+edgsp+mpref+spref+(2*midsp)),y1,spref,buth,
&(U.uiflag), 0, 0, 0, 0,
Modified: branches/apricot/source/blender/src/view.c
===================================================================
--- branches/apricot/source/blender/src/view.c 2008-04-17 08:43:22 UTC (rev 14446)
+++ branches/apricot/source/blender/src/view.c 2008-04-17 09:49:15 UTC (rev 14447)
@@ -717,6 +717,82 @@
BIF_view3d_previewrender_signal(curarea, PR_DBASE|PR_DISPRECT);
}
+int view_autodist( float mouse_worldloc[3] ) //, float *autodist )
+{
+ View3D *v3d = G.vd;
+
+ /* Zooms in on a border drawn by the user */
+ short mval[2];
+ rcti rect;
+
+ /* ZBuffer depth vars */
+ bglMats mats;
+ float depth, depth_close= MAXFLOAT;
+ int had_depth = 0;
+ double cent[2], p[3];
+ int xs, ys;
+
+ getmouseco_areawin(mval);
+
+ persp(PERSP_VIEW);
+
+ rect.xmax = mval[0] + 4;
+ rect.ymax = mval[1] + 4;
+
+ rect.xmin = mval[0] - 4;
+ rect.ymin = mval[1] - 4;
+
+ /* Get Z Depths, needed for perspective, nice for ortho */
+ bgl_get_mats(&mats);
+ draw_depth(curarea, (void *)v3d);
+
+ /* force updating */
+ if (v3d->depths) {
+ had_depth = 1;
+ v3d->depths->damaged = 1;
+ }
+
+ view3d_update_depths(v3d);
+
+ /* Constrain rect to depth bounds */
+ if (rect.xmin < 0) rect.xmin = 0;
+ if (rect.ymin < 0) rect.ymin = 0;
+ if (rect.xmax >= v3d->depths->w) rect.xmax = v3d->depths->w-1;
+ if (rect.ymax >= v3d->depths->h) rect.ymax = v3d->depths->h-1;
+
+ /* Find the closest Z pixel */
+ for (xs=rect.xmin; xs < rect.xmax; xs++) {
+ for (ys=rect.ymin; ys < rect.ymax; ys++) {
+ depth= v3d->depths->depths[ys*v3d->depths->w+xs];
+ if(depth < v3d->depths->depth_range[1] && depth > v3d->depths->depth_range[0]) {
+ if (depth_close > depth) {
+ depth_close = depth;
+ }
+ }
+ }
+ }
+
+ if (depth_close==MAXFLOAT)
+ return 0;
+
+ if (had_depth==0) {
+ MEM_freeN(v3d->depths->depths);
+ v3d->depths->depths = NULL;
+ }
+ v3d->depths->damaged = 1;
+
+ cent[0] = (double)mval[0];
+ cent[1] = (double)mval[1];
+
+ if (!gluUnProject(cent[0], cent[1], depth_close, mats.modelview, mats.projection, mats.viewport, &p[0], &p[1], &p[2]))
+ return 0;
+
+ mouse_worldloc[0] = (float)p[0];
+ mouse_worldloc[1] = (float)p[1];
+ mouse_worldloc[2] = (float)p[2];
+ return 1;
+}
+
void viewmove(int mode)
{
static float lastofs[3] = {0,0,0};
@@ -750,15 +826,11 @@
Mat3MulVecfl(mat, upvec);
VecAddf(G.vd->ofs, G.vd->ofs, upvec);
}
-
-
/* sometimes this routine is called from headerbuttons */
areawinset(curarea->win);
- initgrabz(-G.vd->ofs[0], -G.vd->ofs[1], -G.vd->ofs[2]);
-
QUATCOPY(oldquat, G.vd->viewquat);
getmouseco_areawin(mval_area); /* for zoom to mouse loc */
@@ -792,9 +864,43 @@
VECCOPY(obofs, lastofs);
VecMulf(obofs, -1.0f);
}
+ else if (U.uiflag & USER_ORBIT_ZBUF) {
+ if (use_sel = view_autodist(obofs)) {
+ float my_origin[3]; /* original G.vd->ofs */
+ float my_pivot[3]; /* view */
+
+ VECCOPY(my_origin, G.vd->ofs);
+ VecMulf(my_origin, -1.0f); /* ofs is flipped */
+
+ /* Set the dist value to be the distance from this 3d point */
+ /* this means youll always be able to zoom into it and panning wont go bad when dist was zero */
+
+ /* remove dist value */
+ upvec[0] = upvec[1] = 0;
+ upvec[2] = G.vd->dist;
+ Mat3CpyMat4(mat, G.vd->viewinv);
+ Mat3MulVecfl(mat, upvec);
+ VecSubf(my_pivot, G.vd->ofs, upvec);
+ VecMulf(my_pivot, -1.0f); /* ofs is flipped */
+
+ /* find a new ofs value that is allong the view axis (rather then the mouse location) */
+ lambda_cp_line_ex(obofs, my_pivot, my_origin, dvec);
+ dist0 = G.vd->dist = VecLenf(my_pivot, dvec);
+
+ VecMulf(dvec, -1.0f);
+ VecMulf(obofs, -1.0f);
+
+ VECCOPY(G.vd->ofs, dvec);
+ VECCOPY(ofs, G.vd->ofs);
+ } else {
+ ofs[0] = ofs[1] = ofs[2] = 0.0f;
+ }
+ }
else
ofs[0] = ofs[1] = ofs[2] = 0.0f;
-
+
+ initgrabz(-G.vd->ofs[0], -G.vd->ofs[1], -G.vd->ofs[2]);
+
reverse= 1.0f;
if (G.vd->persmat[2][1] < 0.0f)
reverse= -1.0f;
More information about the Bf-blender-cvs
mailing list