From 76f23460805018535a6b2d9b0ab8a25f9b2074dd Mon Sep 17 00:00:00 2001 From: Ton Roosendaal Date: Thu, 24 Mar 2005 18:47:09 +0000 Subject: Transform fixes; - Camera translate in camera view, with MMB, works again. Code needs verification by Martin... it does it different now too. - Camera rotate in camera view works again. MMB switches to 'trackball', as formerly. Isn't consistant with other rotate+MMB though... - rotate camera in cameraview around cursor doesn't 'feedack' anymore Martin; I only use the TransInfo->persinv[4][4] now, but I think it's safe to use viewmat and viewinv too? --- source/blender/src/transform.c | 18 ++++++++++----- source/blender/src/transform.h | 4 ++++ source/blender/src/transform_constraints.c | 36 +++++++++++++++++++++++------- source/blender/src/transform_generics.c | 12 +++++++--- 4 files changed, 53 insertions(+), 17 deletions(-) diff --git a/source/blender/src/transform.c b/source/blender/src/transform.c index 72a69b68641..1de0ba2f178 100755 --- a/source/blender/src/transform.c +++ b/source/blender/src/transform.c @@ -1387,9 +1387,15 @@ void Transform(int mode) break; case MIDDLEMOUSE: - /* exception for switching to dolly, in camera view */ - if( (Trans.flag & T_OBJECT) && G.vd->camera==OBACT && G.vd->persp>1) { - // setLocalConstraint(&Trans, (CON_AXIS2), "along local Z"); + /* exception for switching to dolly, or trackball, in camera view */ + if((Trans.flag & T_OBJECT) && G.vd->camera==OBACT && G.vd->persp>1) { + if(Trans.mode==TFM_TRANSLATION) + setLocalConstraint(&Trans, (CON_AXIS2), "along local Z"); + else if(Trans.mode==TFM_ROTATION) { + restoreTransObjects(&Trans); + initTransModeFlags(&Trans, TFM_TRACKBALL); + initTrackball(&Trans); + } } else initSelectConstraint(&Trans); @@ -2362,7 +2368,7 @@ int Rotation(TransInfo *t, short mval[2]) float axis[3]; float mat[3][3]; - VECCOPY(axis, G.vd->persinv[2]); + VECCOPY(axis, t->persinv[2]); Normalise(axis); dphi = saacos(deler); @@ -2474,8 +2480,8 @@ int Trackball(TransInfo *t, short mval[2]) float mat[3][3], totmat[3][3], smat[3][3]; float phi[2]; - VECCOPY(axis1, G.vd->persinv[0]); - VECCOPY(axis2, G.vd->persinv[1]); + VECCOPY(axis1, t->persinv[0]); + VECCOPY(axis2, t->persinv[1]); Normalise(axis1); Normalise(axis2); diff --git a/source/blender/src/transform.h b/source/blender/src/transform.h index 459feb3d483..63f4091a158 100755 --- a/source/blender/src/transform.h +++ b/source/blender/src/transform.h @@ -126,6 +126,10 @@ typedef struct TransInfo { float val; /* init value for some transformations */ float fac; /* factor for distance based transform */ + float viewmat[4][4]; /* copy from G.vd, prevents feedback */ + float viewinv[4][4]; + float persinv[4][4]; + float vec[3]; /* translation, to show for widget */ float mat[3][3]; /* rot/rescale, to show for widget */ } TransInfo; diff --git a/source/blender/src/transform_constraints.c b/source/blender/src/transform_constraints.c index 8791f2b2d2f..5fc606acb98 100755 --- a/source/blender/src/transform_constraints.c +++ b/source/blender/src/transform_constraints.c @@ -200,17 +200,33 @@ static void axisProjection(TransInfo *t, float axis[3], float in[3], float out[3 n[2] = G.vd->viewmat[3][2]; Mat4MulVecfl(G.vd->viewinv, n); - if (Inpf(axis, norm) != 1.0f) { - Projf(vec, in, n); - factor = Normalise(vec); - factor /= Inpf(axis, vec); - - VecMulf(axis, factor); + /* For when view is parallel to constraint... will cause NaNs otherwise + So; we mix mouse motion with size of 'in' (unconstrainted motion), + which gives a sorta exponentional effect, nice for camera grab + MMB */ + if(n[0]*n[0] + n[1]*n[1] + n[2]*n[2] < 0.000001) { + short mval[2]; + getmouseco_areawin(mval); + VECCOPY(vec, in); + factor= Normalise(vec); // len original delta + factor*= 0.05*(t->imval[1] - mval[1]); // 5% of vertical mouse motion VECCOPY(out, axis); + Normalise(out); + VecMulf(out, factor); } else { - out[0] = out[1] = out[2] = 0.0f; - } + + if (Inpf(axis, norm) != 1.0f) { + Projf(vec, in, n); + factor = Normalise(vec); + factor /= Inpf(axis, vec); + + VecMulf(axis, factor); + VECCOPY(out, axis); + } + else { + out[0] = out[1] = out[2] = 0.0f; + } + } } static void planeProjection(TransInfo *t, float in[3], float out[3]) { @@ -616,6 +632,10 @@ void BIF_drawConstraint(void) return; if (t->flag & T_USES_MANIPULATOR) return; + + /* nasty exception for Z constraint in camera view */ + if( (t->flag & T_OBJECT) && G.vd->camera==OBACT && G.vd->persp>1) + return; if (tc->drawExtra) { tc->drawExtra(t); diff --git a/source/blender/src/transform_generics.c b/source/blender/src/transform_generics.c index cf82326e5ef..817b6255b66 100755 --- a/source/blender/src/transform_generics.c +++ b/source/blender/src/transform_generics.c @@ -406,6 +406,10 @@ void initTrans (TransInfo *t) t->vec[2] = 0.0f; Mat3One(t->mat); + + Mat4CpyMat4(t->viewmat, G.vd->viewmat); + Mat4CpyMat4(t->viewinv, G.vd->viewinv); + Mat4CpyMat4(t->persinv, G.vd->persinv); } /* Here I would suggest only TransInfo related issues, like free data & reset vars. Not redraws */ @@ -680,9 +684,11 @@ void calculateCenter(TransInfo *t) Normalise(axis); /* 6.0 = 6 grid units */ - t->center[0]+= -6.0f*axis[0]; - t->center[1]+= -6.0f*axis[1]; - t->center[2]+= -6.0f*axis[2]; + t->center[0]+= 6.0f*axis[0]; + t->center[1]+= 6.0f*axis[1]; + t->center[2]+= 6.0f*axis[2]; + + project_short_noclip(t->center, t->center2d); } } initgrabz(t->center[0], t->center[1], t->center[2]); -- cgit v1.2.3