New feature, since long on todo;

The grid function (transform translate, snap-to) now uses the grid step as
displayed in the 3d window, so it depends on how much you zoomed in/out.

The threshold for it is a bit tricky... it follows the drawing, but the
blending in/out of grid makes it sometimes not obvious.  might need slight
tweak?
This commit is contained in:
Ton Roosendaal
2005-03-23 14:24:43 +00:00
parent 7e6a65bc62
commit 09ed2cef75
4 changed files with 29 additions and 22 deletions

View File

@@ -97,7 +97,7 @@ typedef struct View3D {
int lay, layact;
short scenelock, around, camzoom, flag;
float lens, grid, near, far;
float lens, grid, gridview, pad, near, far;
float ofs[3], cursor[3];
short mx, my; /* have to remain together, because used as single pointer */

View File

@@ -549,18 +549,23 @@ static void drawgrid(void)
if(dx==0) dx= fabs(y-(wy)*fy/fw);
glDepthMask(0); // disable write in zbuffer
/* check zoom out */
BIF_ThemeColor(TH_GRID);
persp(PERSP_WIN);
G.vd->gridview= G.vd->grid;
if(dx<6.0) {
G.vd->gridview*= 10.0;
dx*= 10.0;
if(dx<6.0) {
G.vd->gridview*= 10.0;
dx*= 10.0;
if(dx<6.0) {
G.vd->gridview*= 10.0;
dx*=10;
if(dx<6.0);
else {
@@ -586,8 +591,10 @@ static void drawgrid(void)
}
else {
if(dx>60.0) { // start blending in
G.vd->gridview/= 10.0;
dx/= 10.0;
if(dx>60.0) { // start blending in
G.vd->gridview/= 10.0;
dx/= 10.0;
if(dx>60.0) {
BIF_ThemeColor(TH_GRID);

View File

@@ -733,7 +733,7 @@ void snap_sel_to_grid()
float gridf, imat[3][3], bmat[3][3], vec[3];
int a;
gridf= G.vd->grid;
gridf= G.vd->gridview;
if(G.obedit) {
@@ -755,9 +755,9 @@ void snap_sel_to_grid()
VECCOPY(vec, tv->loc);
Mat3MulVecfl(bmat, vec);
VecAddf(vec, vec, G.obedit->obmat[3]);
vec[0]= G.vd->grid*floor(.5+ vec[0]/gridf);
vec[1]= G.vd->grid*floor(.5+ vec[1]/gridf);
vec[2]= G.vd->grid*floor(.5+ vec[2]/gridf);
vec[0]= G.vd->gridview*floor(.5+ vec[0]/gridf);
vec[1]= G.vd->gridview*floor(.5+ vec[1]/gridf);
vec[2]= G.vd->gridview*floor(.5+ vec[2]/gridf);
VecSubf(vec, vec, G.obedit->obmat[3]);
Mat3MulVecfl(imat, vec);
@@ -786,9 +786,9 @@ void snap_sel_to_grid()
if( ( ((base)->flag & SELECT) && ((base)->lay & G.vd->lay) && ((base)->object->id.lib==0))) {
ob= base->object;
vec[0]= -ob->obmat[3][0]+G.vd->grid*floor(.5+ ob->obmat[3][0]/gridf);
vec[1]= -ob->obmat[3][1]+G.vd->grid*floor(.5+ ob->obmat[3][1]/gridf);
vec[2]= -ob->obmat[3][2]+G.vd->grid*floor(.5+ ob->obmat[3][2]/gridf);
vec[0]= -ob->obmat[3][0]+G.vd->gridview*floor(.5+ ob->obmat[3][0]/gridf);
vec[1]= -ob->obmat[3][1]+G.vd->gridview*floor(.5+ ob->obmat[3][1]/gridf);
vec[2]= -ob->obmat[3][2]+G.vd->gridview*floor(.5+ ob->obmat[3][2]/gridf);
if(ob->parent) {
where_is_object(ob);
@@ -902,12 +902,12 @@ void snap_curs_to_grid()
{
float gridf, *curs;
gridf= G.vd->grid;
gridf= G.vd->gridview;
curs= give_cursor();
curs[0]= G.vd->grid*floor(.5+curs[0]/gridf);
curs[1]= G.vd->grid*floor(.5+curs[1]/gridf);
curs[2]= G.vd->grid*floor(.5+curs[2]/gridf);
curs[0]= G.vd->gridview*floor(.5+curs[0]/gridf);
curs[1]= G.vd->gridview*floor(.5+curs[1]/gridf);
curs[2]= G.vd->gridview*floor(.5+curs[2]/gridf);
allqueue(REDRAWVIEW3D, 0);

View File

@@ -1861,7 +1861,7 @@ void initShear(TransInfo *t)
t->idx_max = 0;
t->num.idx_max = 0;
t->snap[0] = 0.0f;
t->snap[1] = G.vd->grid * 0.1f;
t->snap[1] = 0.1f;
t->snap[2] = t->snap[1] * 0.1f;
t->transform = Shear;
t->fac = (float)(t->center2d[0] - t->imval[0]);
@@ -1954,7 +1954,7 @@ void initResize(TransInfo *t)
t->idx_max = 2;
t->num.idx_max = 2;
t->snap[0] = 0.0f;
t->snap[1] = G.vd->grid * 0.1f;
t->snap[1] = 0.1f;
t->snap[2] = t->snap[1] * 0.1f;
t->transform = Resize;
}
@@ -2140,7 +2140,7 @@ void initToSphere(TransInfo *t)
t->idx_max = 0;
t->num.idx_max = 0;
t->snap[0] = 0.0f;
t->snap[1] = G.vd->grid * 0.1f;
t->snap[1] = 0.1f;
t->snap[2] = t->snap[1] * 0.1f;
t->transform = ToSphere;
}
@@ -2218,7 +2218,7 @@ void initRotation(TransInfo *t)
t->idx_max = 0;
t->num.idx_max = 0;
t->snap[0] = 0.0f;
t->snap[1] = G.vd->grid * (float)((5.0/180)*M_PI);
t->snap[1] = (5.0/180)*M_PI;
t->snap[2] = t->snap[1] * 0.2f;
t->fac = 0;
t->transform = Rotation;
@@ -2431,7 +2431,7 @@ void initTrackball(TransInfo *t)
t->idx_max = 1;
t->num.idx_max = 1;
t->snap[0] = 0.0f;
t->snap[1] = G.vd->grid * (float)((5.0/180)*M_PI);
t->snap[1] = (5.0/180)*M_PI;
t->snap[2] = t->snap[1] * 0.2f;
t->fac = 0;
t->transform = Trackball;
@@ -2530,7 +2530,7 @@ void initTranslation(TransInfo *t)
t->idx_max = 2;
t->num.idx_max = 2;
t->snap[0] = 0.0f;
t->snap[1] = G.vd->grid * 1.0f;
t->snap[1] = G.vd->gridview * 1.0f;
t->snap[2] = t->snap[1] * 0.1f;
t->transform = Translation;
@@ -2648,7 +2648,7 @@ void initShrinkFatten(TransInfo *t)
t->idx_max = 0;
t->num.idx_max = 0;
t->snap[0] = 0.0f;
t->snap[1] = G.vd->grid * 1.0f;
t->snap[1] = 1.0f;
t->snap[2] = t->snap[1] * 0.1f;
t->transform = ShrinkFatten;
}
@@ -2715,7 +2715,7 @@ void initTilt(TransInfo *t)
t->idx_max = 0;
t->num.idx_max = 0;
t->snap[0] = 0.0f;
t->snap[1] = G.vd->grid * (float)((5.0/180)*M_PI);
t->snap[1] = ((5.0/180)*M_PI);
t->snap[2] = t->snap[1] * 0.2f;
t->fac = 0;
t->transform = Tilt;