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:
@@ -1262,6 +1262,10 @@ static void createTransData(TransInfo *t)
|
|||||||
createTransObject();
|
createTransObject();
|
||||||
t->flag |= T_OBJECT;
|
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
|
#define TRANS_CANCEL 2
|
||||||
@@ -1376,7 +1380,7 @@ void Transform(int mode)
|
|||||||
while( qtest() ) {
|
while( qtest() ) {
|
||||||
event= extern_qread(&val);
|
event= extern_qread(&val);
|
||||||
|
|
||||||
if(val) {
|
if (val) {
|
||||||
switch (event){
|
switch (event){
|
||||||
/* enforce redraw of transform when modifiers are used */
|
/* enforce redraw of transform when modifiers are used */
|
||||||
case LEFTCTRLKEY:
|
case LEFTCTRLKEY:
|
||||||
@@ -1388,10 +1392,10 @@ void Transform(int mode)
|
|||||||
|
|
||||||
case MIDDLEMOUSE:
|
case MIDDLEMOUSE:
|
||||||
/* exception for switching to dolly, or trackball, in camera view */
|
/* 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.flag & T_CAMERA) {
|
||||||
if(Trans.mode==TFM_TRANSLATION)
|
if (Trans.mode==TFM_TRANSLATION)
|
||||||
setLocalConstraint(&Trans, (CON_AXIS2), "along local Z");
|
setLocalConstraint(&Trans, (CON_AXIS2), "along local Z");
|
||||||
else if(Trans.mode==TFM_ROTATION) {
|
else if (Trans.mode==TFM_ROTATION) {
|
||||||
restoreTransObjects(&Trans);
|
restoreTransObjects(&Trans);
|
||||||
initTransModeFlags(&Trans, TFM_TRACKBALL);
|
initTransModeFlags(&Trans, TFM_TRACKBALL);
|
||||||
initTrackball(&Trans);
|
initTrackball(&Trans);
|
||||||
@@ -1424,9 +1428,16 @@ void Transform(int mode)
|
|||||||
Trans.redraw = 1;
|
Trans.redraw = 1;
|
||||||
break;
|
break;
|
||||||
case RKEY:
|
case RKEY:
|
||||||
restoreTransObjects(&Trans);
|
if (Trans.mode == TFM_ROTATION) {
|
||||||
initTransModeFlags(&Trans, TFM_ROTATION);
|
restoreTransObjects(&Trans);
|
||||||
initRotation(&Trans);
|
initTransModeFlags(&Trans, TFM_TRACKBALL);
|
||||||
|
initTrackball(&Trans);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
restoreTransObjects(&Trans);
|
||||||
|
initTransModeFlags(&Trans, TFM_ROTATION);
|
||||||
|
initRotation(&Trans);
|
||||||
|
}
|
||||||
Trans.redraw = 1;
|
Trans.redraw = 1;
|
||||||
break;
|
break;
|
||||||
case XKEY:
|
case XKEY:
|
||||||
|
|||||||
@@ -150,6 +150,7 @@ typedef struct TransInfo {
|
|||||||
#define T_EDIT 2
|
#define T_EDIT 2
|
||||||
#define T_POSE 4
|
#define T_POSE 4
|
||||||
#define T_TEXTURE 8
|
#define T_TEXTURE 8
|
||||||
|
#define T_CAMERA 16
|
||||||
// for manipulator exceptions, like scaling using center point, drawing help lines
|
// for manipulator exceptions, like scaling using center point, drawing help lines
|
||||||
#define T_USES_MANIPULATOR 128
|
#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);
|
Normalise(axis);
|
||||||
|
|
||||||
VECCOPY(n, axis);
|
VECCOPY(n, axis);
|
||||||
Mat4MulVecfl(G.vd->viewmat, n);
|
Mat4MulVecfl(t->viewmat, n);
|
||||||
n[2] = G.vd->viewmat[3][2];
|
n[2] = t->viewmat[3][2];
|
||||||
Mat4MulVecfl(G.vd->viewinv, n);
|
Mat4MulVecfl(t->viewinv, n);
|
||||||
|
|
||||||
/* For when view is parallel to constraint... will cause NaNs otherwise
|
/* For when view is parallel to constraint... will cause NaNs otherwise
|
||||||
So; we mix mouse motion with size of 'in' (unconstrainted motion),
|
So we take vertical motion in 3D space and apply it to the
|
||||||
which gives a sorta exponentional effect, nice for camera grab + MMB */
|
constraint axis. Nice for camera grab + MMB */
|
||||||
if(n[0]*n[0] + n[1]*n[1] + n[2]*n[2] < 0.000001) {
|
if(n[0]*n[0] + n[1]*n[1] + n[2]*n[2] < 0.000001) {
|
||||||
short mval[2];
|
Projf(vec, in, t->viewinv[1]);
|
||||||
getmouseco_areawin(mval);
|
factor = Inpf(t->viewinv[1], vec) * 2.0f;
|
||||||
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);
|
VECCOPY(out, axis);
|
||||||
Normalise(out);
|
Normalise(out);
|
||||||
VecMulf(out, factor);
|
VecMulf(out, factor);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
Projf(vec, in, n);
|
||||||
|
factor = Normalise(vec);
|
||||||
|
factor /= Inpf(axis, vec);
|
||||||
|
|
||||||
if (Inpf(axis, norm) != 1.0f) {
|
VecMulf(axis, factor);
|
||||||
Projf(vec, in, n);
|
VECCOPY(out, axis);
|
||||||
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]) {
|
static void planeProjection(TransInfo *t, float in[3], float out[3]) {
|
||||||
|
|||||||
Reference in New Issue
Block a user