Reworked the camera dolly/parallel axis constraint code a bit. Works pretty much like the Shrink/Fatten code, meaning pull the mouse toward you pulls the camera, push pushes it away.
Also added a T_CAMERA flag for camera grab, which gets set on TransData conversion.
This commit is contained in:
parent
9e90f1407e
commit
4bcf80bf4f
@ -1262,6 +1262,10 @@ static void createTransData(TransInfo *t)
|
||||
createTransObject();
|
||||
t->flag |= T_OBJECT;
|
||||
}
|
||||
|
||||
if((t->flag & T_OBJECT) && G.vd->camera==OBACT && G.vd->persp>1) {
|
||||
t->flag |= T_CAMERA;
|
||||
}
|
||||
}
|
||||
|
||||
#define TRANS_CANCEL 2
|
||||
@ -1376,7 +1380,7 @@ void Transform(int mode)
|
||||
while( qtest() ) {
|
||||
event= extern_qread(&val);
|
||||
|
||||
if(val) {
|
||||
if (val) {
|
||||
switch (event){
|
||||
/* enforce redraw of transform when modifiers are used */
|
||||
case LEFTCTRLKEY:
|
||||
@ -1388,10 +1392,10 @@ void Transform(int mode)
|
||||
|
||||
case MIDDLEMOUSE:
|
||||
/* 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)
|
||||
if (Trans.flag & T_CAMERA) {
|
||||
if (Trans.mode==TFM_TRANSLATION)
|
||||
setLocalConstraint(&Trans, (CON_AXIS2), "along local Z");
|
||||
else if(Trans.mode==TFM_ROTATION) {
|
||||
else if (Trans.mode==TFM_ROTATION) {
|
||||
restoreTransObjects(&Trans);
|
||||
initTransModeFlags(&Trans, TFM_TRACKBALL);
|
||||
initTrackball(&Trans);
|
||||
@ -1424,9 +1428,16 @@ void Transform(int mode)
|
||||
Trans.redraw = 1;
|
||||
break;
|
||||
case RKEY:
|
||||
restoreTransObjects(&Trans);
|
||||
initTransModeFlags(&Trans, TFM_ROTATION);
|
||||
initRotation(&Trans);
|
||||
if (Trans.mode == TFM_ROTATION) {
|
||||
restoreTransObjects(&Trans);
|
||||
initTransModeFlags(&Trans, TFM_TRACKBALL);
|
||||
initTrackball(&Trans);
|
||||
}
|
||||
else {
|
||||
restoreTransObjects(&Trans);
|
||||
initTransModeFlags(&Trans, TFM_ROTATION);
|
||||
initRotation(&Trans);
|
||||
}
|
||||
Trans.redraw = 1;
|
||||
break;
|
||||
case XKEY:
|
||||
|
@ -150,6 +150,7 @@ typedef struct TransInfo {
|
||||
#define T_EDIT 2
|
||||
#define T_POSE 4
|
||||
#define T_TEXTURE 8
|
||||
#define T_CAMERA 16
|
||||
// for manipulator exceptions, like scaling using center point, drawing help lines
|
||||
#define T_USES_MANIPULATOR 128
|
||||
|
||||
|
@ -196,37 +196,29 @@ static void axisProjection(TransInfo *t, float axis[3], float in[3], float out[3
|
||||
Normalise(axis);
|
||||
|
||||
VECCOPY(n, axis);
|
||||
Mat4MulVecfl(G.vd->viewmat, n);
|
||||
n[2] = G.vd->viewmat[3][2];
|
||||
Mat4MulVecfl(G.vd->viewinv, n);
|
||||
Mat4MulVecfl(t->viewmat, n);
|
||||
n[2] = t->viewmat[3][2];
|
||||
Mat4MulVecfl(t->viewinv, n);
|
||||
|
||||
/* 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 */
|
||||
So we take vertical motion in 3D space and apply it to the
|
||||
constraint axis. 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
|
||||
Projf(vec, in, t->viewinv[1]);
|
||||
factor = Inpf(t->viewinv[1], vec) * 2.0f;
|
||||
|
||||
VECCOPY(out, axis);
|
||||
Normalise(out);
|
||||
VecMulf(out, factor);
|
||||
}
|
||||
else {
|
||||
Projf(vec, in, n);
|
||||
factor = Normalise(vec);
|
||||
factor /= Inpf(axis, vec);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
VecMulf(axis, factor);
|
||||
VECCOPY(out, axis);
|
||||
}
|
||||
}
|
||||
|
||||
static void planeProjection(TransInfo *t, float in[3], float out[3]) {
|
||||
|
Loading…
Reference in New Issue
Block a user