A couple of wee transform featurettes;
- center of rotation for camera in cameraview rotate has to remain the camera center itself, drawing the dashed helpline then doesn't work, since it's behind the camera clipplane. Just disabled that line. - made MMB switch for cameraview grab to become quadratic, for a dolly this feels OK, and makes it possible to move in small and large scenes. - restored SHIFT modifier for translation and scaling. This based on old convention that allowed precision editing on top of the transform you already applied before pressing SHIFT. Solved it with a new flag (T_SHIFT_MOD), since the G.qual cannot be used. Transform() innerloop has to detect the SHIFT event itself. Also coded it with storing the mouseposition while SHIFT event happened. Hope Martin can approve! :) - Martin's last commit made Manipulator Translate not work, it passed on a zero translation to the constrainter, causing NaN's. Nicely catched the exception. - Fixed 'Trackball' to accept number input too
This commit is contained in:
@@ -244,6 +244,7 @@ static void draw_icon_centered(float *pos, unsigned int *rect, int rectsize)
|
|||||||
glDrawPixels(rectsize, rectsize, GL_RGBA, GL_UNSIGNED_BYTE, rect);
|
glDrawPixels(rectsize, rectsize, GL_RGBA, GL_UNSIGNED_BYTE, rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* bad frontbuffer call... because it is used in transform after force_draw() */
|
||||||
void helpline(float *vec)
|
void helpline(float *vec)
|
||||||
{
|
{
|
||||||
float vecrot[3], cent[2];
|
float vecrot[3], cent[2];
|
||||||
@@ -255,23 +256,24 @@ void helpline(float *vec)
|
|||||||
|
|
||||||
getmouseco_areawin(mval);
|
getmouseco_areawin(mval);
|
||||||
project_float(vecrot, cent); // no overflow in extreme cases
|
project_float(vecrot, cent); // no overflow in extreme cases
|
||||||
|
if(cent[0]!=3200.0f) {
|
||||||
|
persp(PERSP_WIN);
|
||||||
|
|
||||||
|
glDrawBuffer(GL_FRONT);
|
||||||
|
|
||||||
|
BIF_ThemeColor(TH_WIRE);
|
||||||
|
|
||||||
persp(PERSP_WIN);
|
setlinestyle(3);
|
||||||
|
glBegin(GL_LINE_STRIP);
|
||||||
glDrawBuffer(GL_FRONT);
|
glVertex2sv(mval);
|
||||||
|
glVertex2fv(cent);
|
||||||
BIF_ThemeColor(TH_WIRE);
|
glEnd();
|
||||||
|
setlinestyle(0);
|
||||||
setlinestyle(3);
|
|
||||||
glBegin(GL_LINE_STRIP);
|
persp(PERSP_VIEW);
|
||||||
glVertex2sv(mval);
|
glFlush(); // flush display for frontbuffer
|
||||||
glVertex2fv(cent);
|
glDrawBuffer(GL_BACK);
|
||||||
glEnd();
|
}
|
||||||
setlinestyle(0);
|
|
||||||
|
|
||||||
persp(PERSP_VIEW);
|
|
||||||
glFlush(); // flush display for frontbuffer
|
|
||||||
glDrawBuffer(GL_BACK);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawaxes(float size)
|
void drawaxes(float size)
|
||||||
|
|||||||
@@ -1385,8 +1385,13 @@ void Transform(int mode)
|
|||||||
/* enforce redraw of transform when modifiers are used */
|
/* enforce redraw of transform when modifiers are used */
|
||||||
case LEFTCTRLKEY:
|
case LEFTCTRLKEY:
|
||||||
case RIGHTCTRLKEY:
|
case RIGHTCTRLKEY:
|
||||||
|
Trans.redraw = 1;
|
||||||
|
break;
|
||||||
case LEFTSHIFTKEY:
|
case LEFTSHIFTKEY:
|
||||||
case RIGHTSHIFTKEY:
|
case RIGHTSHIFTKEY:
|
||||||
|
/* shift is modifier for higher resolution transform, works nice to store this mouse position */
|
||||||
|
getmouseco_areawin(Trans.shiftmval);
|
||||||
|
Trans.flag |= T_SHIFT_MOD;
|
||||||
Trans.redraw = 1;
|
Trans.redraw = 1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -1550,6 +1555,11 @@ void Transform(int mode)
|
|||||||
/* commented out, doesn't work for actions started with menu */
|
/* commented out, doesn't work for actions started with menu */
|
||||||
// ret_val = TRANS_CONFIRM;
|
// ret_val = TRANS_CONFIRM;
|
||||||
break;
|
break;
|
||||||
|
case LEFTSHIFTKEY:
|
||||||
|
case RIGHTSHIFTKEY:
|
||||||
|
/* shift is modifier for higher resolution transform */
|
||||||
|
Trans.flag &= ~T_SHIFT_MOD;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1665,9 +1675,17 @@ void ManipulatorTransform(int mode)
|
|||||||
/* enforce redraw of transform when modifiers are used */
|
/* enforce redraw of transform when modifiers are used */
|
||||||
case LEFTCTRLKEY:
|
case LEFTCTRLKEY:
|
||||||
case RIGHTCTRLKEY:
|
case RIGHTCTRLKEY:
|
||||||
|
if(val) Trans.redraw = 1;
|
||||||
|
break;
|
||||||
case LEFTSHIFTKEY:
|
case LEFTSHIFTKEY:
|
||||||
case RIGHTSHIFTKEY:
|
case RIGHTSHIFTKEY:
|
||||||
if(val) Trans.redraw = 1;
|
/* shift is modifier for higher resolution transform, works nice to store this mouse position */
|
||||||
|
if(val) {
|
||||||
|
getmouseco_areawin(Trans.shiftmval);
|
||||||
|
Trans.flag |= T_SHIFT_MOD;
|
||||||
|
Trans.redraw = 1;
|
||||||
|
}
|
||||||
|
else Trans.flag &= ~T_SHIFT_MOD;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ESCKEY:
|
case ESCKEY:
|
||||||
@@ -2018,12 +2036,23 @@ int Resize(TransInfo *t, short mval[2])
|
|||||||
ratio = 1.0f - ((t->imval[0] - mval[0]) + (t->imval[1] - mval[1]))/100.0f;
|
ratio = 1.0f - ((t->imval[0] - mval[0]) + (t->imval[1] - mval[1]))/100.0f;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ratio = (float)sqrt( (float)
|
|
||||||
(
|
if(t->flag & T_SHIFT_MOD) {
|
||||||
(t->center2d[1] - mval[1])*(t->center2d[1] - mval[1])
|
/* calculate ratio for shiftkey pos, and for total, and blend these for precision */
|
||||||
+
|
float dx= (float)(t->center2d[0] - t->shiftmval[0]);
|
||||||
(t->center2d[0] - mval[0])*(t->center2d[0] - mval[0])
|
float dy= (float)(t->center2d[1] - t->shiftmval[1]);
|
||||||
) ) / t->fac;
|
ratio = (float)sqrt( dx*dx + dy*dy)/t->fac;
|
||||||
|
|
||||||
|
dx= (float)(t->center2d[0] - mval[0]);
|
||||||
|
dy= (float)(t->center2d[1] - mval[1]);
|
||||||
|
ratio+= 0.1f*(sqrt( dx*dx + dy*dy)/t->fac -ratio);
|
||||||
|
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
float dx= (float)(t->center2d[0] - mval[0]);
|
||||||
|
float dy= (float)(t->center2d[1] - mval[1]);
|
||||||
|
ratio = (float)sqrt( dx*dx + dy*dy)/t->fac;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((t->center2d[0] - mval[0]) * (t->center2d[0] - t->imval[0]) < 0)
|
if ((t->center2d[0] - mval[0]) * (t->center2d[0] - t->imval[0]) < 0)
|
||||||
@@ -2486,7 +2515,7 @@ static void applyTrackball(TransInfo *t, float axis1[3], float axis2[3], float a
|
|||||||
|
|
||||||
int Trackball(TransInfo *t, short mval[2])
|
int Trackball(TransInfo *t, short mval[2])
|
||||||
{
|
{
|
||||||
char str[50];
|
char str[80];
|
||||||
float axis1[3], axis2[3];
|
float axis1[3], axis2[3];
|
||||||
float mat[3][3], totmat[3][3], smat[3][3];
|
float mat[3][3], totmat[3][3], smat[3][3];
|
||||||
float phi[2];
|
float phi[2];
|
||||||
@@ -2506,15 +2535,16 @@ int Trackball(TransInfo *t, short mval[2])
|
|||||||
snapGrid(t, phi);
|
snapGrid(t, phi);
|
||||||
|
|
||||||
if (hasNumInput(&t->num)) {
|
if (hasNumInput(&t->num)) {
|
||||||
//char c[20];
|
char c[40];
|
||||||
|
|
||||||
//applyNumInput(&t->num, phi);
|
applyNumInput(&t->num, phi);
|
||||||
|
|
||||||
//outputNumInput(&(t->num), c);
|
outputNumInput(&(t->num), c);
|
||||||
|
|
||||||
//sprintf(str, "Trackball: %s %s", &c[0], t->proptext);
|
sprintf(str, "Trackball: %s %s %s", &c[0], &c[20], t->proptext);
|
||||||
|
|
||||||
//final *= (float)(M_PI / 180.0);
|
phi[0] *= (float)(M_PI / 180.0);
|
||||||
|
phi[1] *= (float)(M_PI / 180.0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sprintf(str, "Trackball: %.2f %.2f %s", 180.0*phi[0]/M_PI, 180.0*phi[1]/M_PI, t->proptext);
|
sprintf(str, "Trackball: %.2f %.2f %s", 180.0*phi[0]/M_PI, 180.0*phi[1]/M_PI, t->proptext);
|
||||||
@@ -2626,8 +2656,16 @@ int Translation(TransInfo *t, short mval[2])
|
|||||||
{
|
{
|
||||||
float tvec[3];
|
float tvec[3];
|
||||||
char str[200];
|
char str[200];
|
||||||
|
|
||||||
window_to_3d(t->vec, (short)(mval[0] - t->imval[0]), (short)(mval[1] - t->imval[1]));
|
if(t->flag & T_SHIFT_MOD) {
|
||||||
|
float dvec[3];
|
||||||
|
/* calculate the main translation and the precise one separate */
|
||||||
|
window_to_3d(dvec, (short)(mval[0] - t->shiftmval[0]), (short)(mval[1] - t->shiftmval[1]));
|
||||||
|
VecMulf(dvec, 0.1f);
|
||||||
|
window_to_3d(t->vec, (short)(t->shiftmval[0] - t->imval[0]), (short)(t->shiftmval[1] - t->imval[1]));
|
||||||
|
VecAddf(t->vec, t->vec, dvec);
|
||||||
|
}
|
||||||
|
else window_to_3d(t->vec, (short)(mval[0] - t->imval[0]), (short)(mval[1] - t->imval[1]));
|
||||||
|
|
||||||
if (t->con.mode & CON_APPLY) {
|
if (t->con.mode & CON_APPLY) {
|
||||||
float pvec[3] = {0.0f, 0.0f, 0.0f};
|
float pvec[3] = {0.0f, 0.0f, 0.0f};
|
||||||
|
|||||||
@@ -117,6 +117,7 @@ typedef struct TransInfo {
|
|||||||
float center[3]; /* center of transformation */
|
float center[3]; /* center of transformation */
|
||||||
short center2d[2]; /* center in screen coordinates */
|
short center2d[2]; /* center in screen coordinates */
|
||||||
short imval[2]; /* initial mouse position */
|
short imval[2]; /* initial mouse position */
|
||||||
|
short shiftmval[2]; /* mouse position when shift was pressed */
|
||||||
short idx_max;
|
short idx_max;
|
||||||
float snap[3]; /* Snapping Gears */
|
float snap[3]; /* Snapping Gears */
|
||||||
TransData *data; /* transformed data (array) */
|
TransData *data; /* transformed data (array) */
|
||||||
@@ -151,6 +152,8 @@ typedef struct TransInfo {
|
|||||||
#define T_POSE 4
|
#define T_POSE 4
|
||||||
#define T_TEXTURE 8
|
#define T_TEXTURE 8
|
||||||
#define T_CAMERA 16
|
#define T_CAMERA 16
|
||||||
|
// when shift pressed, higher resolution transform. cannot rely on G.qual, need event!
|
||||||
|
#define T_SHIFT_MOD 32
|
||||||
// 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
|
||||||
|
|
||||||
|
|||||||
@@ -203,21 +203,27 @@ static void axisProjection(TransInfo *t, float axis[3], float in[3], float out[3
|
|||||||
/* For when view is parallel to constraint... will cause NaNs otherwise
|
/* For when view is parallel to constraint... will cause NaNs otherwise
|
||||||
So we take vertical motion in 3D space and apply it to the
|
So we take vertical motion in 3D space and apply it to the
|
||||||
constraint axis. 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.000001f) {
|
||||||
Projf(vec, in, t->viewinv[1]);
|
Projf(vec, in, t->viewinv[1]);
|
||||||
factor = Inpf(t->viewinv[1], vec) * 2.0f;
|
factor = Inpf(t->viewinv[1], vec) * 2.0f;
|
||||||
|
/* since camera distance is quite relative, use quadratic relationship. holding shift can compensate */
|
||||||
|
if(factor<0.0f) factor*= -factor;
|
||||||
|
else factor*= factor;
|
||||||
|
|
||||||
VECCOPY(out, axis);
|
VECCOPY(out, axis);
|
||||||
Normalise(out);
|
Normalise(out);
|
||||||
VecMulf(out, factor);
|
VecMulf(out, -factor); /* -factor makes move down going backwards */
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Projf(vec, in, n);
|
// prevent division by zero, happens on constrainting without initial delta transform */
|
||||||
factor = Normalise(vec);
|
if(in[0]!=0.0f || in[1]!=0.0f || in[2]!=0.0) {
|
||||||
factor /= Inpf(axis, vec);
|
Projf(vec, in, n);
|
||||||
|
factor = Normalise(vec);
|
||||||
|
factor /= Inpf(axis, vec);
|
||||||
|
|
||||||
VecMulf(axis, factor);
|
VecMulf(axis, factor);
|
||||||
VECCOPY(out, axis);
|
VECCOPY(out, axis);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -682,13 +682,16 @@ void calculateCenter(TransInfo *t)
|
|||||||
float axis[3];
|
float axis[3];
|
||||||
VECCOPY(axis, G.vd->persinv[2]);
|
VECCOPY(axis, G.vd->persinv[2]);
|
||||||
Normalise(axis);
|
Normalise(axis);
|
||||||
|
|
||||||
/* 6.0 = 6 grid units */
|
/* 6.0 = 6 grid units */
|
||||||
t->center[0]+= 6.0f*axis[0];
|
axis[0]= t->center[0]+ 6.0f*axis[0];
|
||||||
t->center[1]+= 6.0f*axis[1];
|
axis[1]= t->center[1]+ 6.0f*axis[1];
|
||||||
t->center[2]+= 6.0f*axis[2];
|
axis[2]= t->center[2]+ 6.0f*axis[2];
|
||||||
|
|
||||||
project_short_noclip(t->center, t->center2d);
|
project_short_noclip(axis, t->center2d);
|
||||||
|
|
||||||
|
/* rotate only needs correct 2d center, grab needs initgrabz() value */
|
||||||
|
if(t->mode==TFM_TRANSLATION) VECCOPY(t->center, axis);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
initgrabz(t->center[0], t->center[1], t->center[2]);
|
initgrabz(t->center[0], t->center[1], t->center[2]);
|
||||||
|
|||||||
Reference in New Issue
Block a user