- added helper lines in rotation widget

- switched to Local mode for widgets by default, will be a key/button later
This commit is contained in:
Ton Roosendaal
2005-03-19 22:03:14 +00:00
parent c0ebb826fa
commit 52417aeb6e
3 changed files with 135 additions and 202 deletions

View File

@@ -33,7 +33,7 @@
#ifndef BIF_TRANSFORM_H
#define BIF_TRANSFORM_H
#define NEWTRANSFORM 1
// #define NEWTRANSFORM 1
/* ******************** Macros & Prototypes *********************** */

View File

@@ -2176,6 +2176,102 @@ int ToSphere(TransInfo *t, short mval[2])
/* ************************** ROTATION *************************** */
static void ApplyRotation(TransInfo *t, float mat[][3])
{
TransData *td = t->data;
float vec[3], totmat[3][3], smat[3][3];
int i;
for(i = 0 ; i < t->total; i++, td++) {
if (td->flag & TD_NOACTION)
break;
if (G.vd->around == V3D_LOCAL) {
VECCOPY(t->center, td->center);
}
if (t->flag & T_EDIT) {
Mat3MulMat3(totmat, mat, td->mtx);
Mat3MulMat3(smat, td->smtx, totmat);
VecSubf(vec, td->iloc, t->center);
Mat3MulVecfl(smat, vec);
VecAddf(td->loc, vec, t->center);
}
else {
float eul[3], fmat[3][3];
/* translation */
VecSubf(vec, td->center, t->center);
Mat3MulVecfl(mat, vec);
VecAddf(vec, vec, t->center);
/* vec now is the location where the object has to be */
VecSubf(vec, vec, td->center);
Mat3MulVecfl(td->smtx, vec);
VecAddf(td->loc, td->iloc, vec);
if(td->flag & TD_USEQUAT) {
float quat[4];
Mat3MulSerie(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0);
Mat3ToQuat(fmat, quat); // Actual transform
QuatMul(td->ext->quat, quat, td->ext->iquat);
}
else if ((G.vd->flag & V3D_ALIGN)==0) { // align mode doesn't rotate objects itself
float obmat[3][3];
/* are there ipo keys? */
if(td->tdi) {
TransDataIpokey *tdi= td->tdi;
float rot[3];
/* calculate the total rotatation in eulers */
VecAddf(eul, td->ext->irot, td->ext->drot);
EulToMat3(eul, obmat);
/* mat = transform, obmat = object rotation */
Mat3MulMat3(fmat, mat, obmat);
Mat3ToEul(fmat, eul);
compatible_eul(eul, td->ext->irot);
/* correct back for delta rot */
if(tdi->flag & TOB_IPODROT) {
VecSubf(rot, eul, td->ext->irot);
}
else {
VecSubf(rot, eul, td->ext->drot);
}
VecMulf(rot, (float)(9.0/M_PI_2));
VecSubf(rot, rot, tdi->oldrot);
add_tdi_poin(tdi->rotx, tdi->oldrot, rot[0]);
add_tdi_poin(tdi->roty, tdi->oldrot+1, rot[1]);
add_tdi_poin(tdi->rotz, tdi->oldrot+2, rot[2]);
}
else {
/* calculate the total rotatation in eulers */
VecAddf(eul, td->ext->irot, td->ext->drot); /* we have to correct for delta rot */
EulToMat3(eul, obmat);
/* mat = transform, obmat = object rotation */
Mat3MulMat3(fmat, mat, obmat);
Mat3ToEul(fmat, eul);
compatible_eul(eul, td->ext->irot);
/* correct back for delta rot */
VecSubf(eul, eul, td->ext->drot);
/* and apply */
VECCOPY(td->ext->rot, eul);
}
}
}
}
}
void initRotation(TransInfo *t)
{
t->idx_max = 0;
@@ -2190,7 +2286,6 @@ void initRotation(TransInfo *t)
int Rotation(TransInfo *t, short mval[2])
{
TransData *td = t->data;
int i;
char str[50];
float final;
@@ -2211,8 +2306,8 @@ int Rotation(TransInfo *t, short mval[2])
float dphi;
float vec[3], axis[3];
float mat[3][3], totmat[3][3], smat[3][3];
float axis[3];
float mat[3][3];
VECCOPY(axis, G.vd->persinv[2]);
Normalise(axis);
@@ -2262,103 +2357,8 @@ int Rotation(TransInfo *t, short mval[2])
Mat3CpyMat3(t->mat, mat); // used in manipulator
for(i = 0 ; i < t->total; i++, td++) {
if (td->flag & TD_NOACTION)
break;
if (t->con.applyRot) {
t->con.applyRot(t, td, axis);
VecRotToMat3(axis, final * td->factor, mat);
}
else if (G.f & G_PROPORTIONAL) {
VecRotToMat3(axis, final * td->factor, mat);
}
if (G.vd->around == V3D_LOCAL) {
VECCOPY(t->center, td->center);
}
if (t->flag & T_EDIT) {
Mat3MulMat3(totmat, mat, td->mtx);
Mat3MulMat3(smat, td->smtx, totmat);
VecSubf(vec, td->iloc, t->center);
Mat3MulVecfl(smat, vec);
VecAddf(td->loc, vec, t->center);
}
else {
float eul[3], fmat[3][3];
/* translation */
VecSubf(vec, td->center, t->center);
Mat3MulVecfl(mat, vec);
VecAddf(vec, vec, t->center);
/* vec now is the location where the object has to be */
VecSubf(vec, vec, td->center);
Mat3MulVecfl(td->smtx, vec);
VecAddf(td->loc, td->iloc, vec);
if(td->flag & TD_USEQUAT) {
float quat[4];
Mat3MulSerie(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0);
Mat3ToQuat(fmat, quat); // Actual transform
QuatMul(td->ext->quat, quat, td->ext->iquat);
}
else if ((G.vd->flag & V3D_ALIGN)==0) { // align mode doesn't rotate objects itself
float obmat[3][3];
/* are there ipo keys? */
if(td->tdi) {
TransDataIpokey *tdi= td->tdi;
float rot[3];
/* calculate the total rotatation in eulers */
VecAddf(eul, td->ext->irot, td->ext->drot);
EulToMat3(eul, obmat);
/* mat = transform, obmat = object rotation */
Mat3MulMat3(fmat, mat, obmat);
Mat3ToEul(fmat, eul);
compatible_eul(eul, td->ext->irot);
/* correct back for delta rot */
if(tdi->flag & TOB_IPODROT) {
VecSubf(rot, eul, td->ext->irot);
}
else {
VecSubf(rot, eul, td->ext->drot);
}
VecMulf(rot, (float)(9.0/M_PI_2));
VecSubf(rot, rot, tdi->oldrot);
add_tdi_poin(tdi->rotx, tdi->oldrot, rot[0]);
add_tdi_poin(tdi->roty, tdi->oldrot+1, rot[1]);
add_tdi_poin(tdi->rotz, tdi->oldrot+2, rot[2]);
}
else {
/* calculate the total rotatation in eulers */
VecAddf(eul, td->ext->irot, td->ext->drot); /* we have to correct for delta rot */
EulToMat3(eul, obmat);
/* mat = transform, obmat = object rotation */
Mat3MulMat3(fmat, mat, obmat);
Mat3ToEul(fmat, eul);
compatible_eul(eul, td->ext->irot);
/* correct back for delta rot */
VecSubf(eul, eul, td->ext->drot);
/* and apply */
VECCOPY(td->ext->rot, eul);
}
}
}
}
ApplyRotation(t, mat);
recalcData(t);
headerprint(str);
@@ -2386,10 +2386,8 @@ void initTrackball(TransInfo *t)
int Trackball(TransInfo *t, short mval[2])
{
TransData *td = t->data;
int i;
char str[50];
float vec[3], axis1[3], axis2[3];
float axis1[3], axis2[3];
float mat[3][3], totmat[3][3], smat[3][3];
float phi[2];
@@ -2429,94 +2427,7 @@ int Trackball(TransInfo *t, short mval[2])
Mat3CpyMat3(t->mat, mat); // used in manipulator
for(i = 0 ; i < t->total; i++, td++) {
if (td->flag & TD_NOACTION)
break;
if (G.vd->around == V3D_LOCAL) {
VECCOPY(t->center, td->center);
}
if (t->flag & T_EDIT) {
Mat3MulMat3(totmat, mat, td->mtx);
Mat3MulMat3(smat, td->smtx, totmat);
VecSubf(vec, td->iloc, t->center);
Mat3MulVecfl(smat, vec);
VecAddf(td->loc, vec, t->center);
}
else {
float eul[3], fmat[3][3];
/* translation */
VecSubf(vec, td->center, t->center);
Mat3MulVecfl(mat, vec);
VecAddf(vec, vec, t->center);
/* vec now is the location where the object has to be */
VecSubf(vec, vec, td->center);
Mat3MulVecfl(td->smtx, vec);
VecAddf(td->loc, td->iloc, vec);
if(td->flag & TD_USEQUAT) {
float quat[4];
Mat3MulSerie(fmat, td->mtx, mat, td->smtx, 0, 0, 0, 0, 0);
Mat3ToQuat(fmat, quat); // Actual transform
QuatMul(td->ext->quat, quat, td->ext->iquat);
}
else if ((G.vd->flag & V3D_ALIGN)==0) { // align mode doesn't rotate objects itself
float obmat[3][3];
/* are there ipo keys? */
if(td->tdi) {
TransDataIpokey *tdi= td->tdi;
float rot[3];
/* calculate the total rotatation in eulers */
VecAddf(eul, td->ext->irot, td->ext->drot);
EulToMat3(eul, obmat);
/* mat = transform, obmat = object rotation */
Mat3MulMat3(fmat, mat, obmat);
Mat3ToEul(fmat, eul);
compatible_eul(eul, td->ext->irot);
/* correct back for delta rot */
if(tdi->flag & TOB_IPODROT) {
VecSubf(rot, eul, td->ext->irot);
}
else {
VecSubf(rot, eul, td->ext->drot);
}
VecMulf(rot, (float)(9.0/M_PI_2));
VecSubf(rot, rot, tdi->oldrot);
add_tdi_poin(tdi->rotx, tdi->oldrot, rot[0]);
add_tdi_poin(tdi->roty, tdi->oldrot+1, rot[1]);
add_tdi_poin(tdi->rotz, tdi->oldrot+2, rot[2]);
}
else {
/* calculate the total rotatation in eulers */
VecAddf(eul, td->ext->irot, td->ext->drot); /* we have to correct for delta rot */
EulToMat3(eul, obmat);
/* mat = transform, obmat = object rotation */
Mat3MulMat3(fmat, mat, obmat);
Mat3ToEul(fmat, eul);
compatible_eul(eul, td->ext->irot);
/* correct back for delta rot */
VecSubf(eul, eul, td->ext->drot);
/* and apply */
VECCOPY(td->ext->rot, eul);
}
}
}
}
ApplyRotation(t, mat);
recalcData(t);

View File

@@ -281,8 +281,8 @@ static int calc_manipulator(ScrArea *sa)
if(ob) {
// local....
if(totsel==1 || v3d->around==V3D_LOCAL || G.obedit || G.obpose) {
//Mat4CpyMat4(v3d->twmat, ob->obmat);
//Mat4Ortho(v3d->twmat);
Mat4CpyMat4(v3d->twmat, ob->obmat);
Mat4Ortho(v3d->twmat);
}
}
@@ -352,7 +352,7 @@ static void draw_manipulator_rotate(float mat[][4])
glShadeModel(GL_SMOOTH);
/* Screen aligned help circle */
/* prepare for screen aligned draw */
VECCOPY(vec, mat[0]);
size= Normalise(vec);
glPushMatrix();
@@ -364,9 +364,10 @@ static void draw_manipulator_rotate(float mat[][4])
plane[3]= -0.001; // clip full circle
glClipPlane(GL_CLIP_PLANE0, plane);
}
/* sets view screen aligned */
glRotatef( -360.0*saacos(G.vd->viewquat[0])/M_PI, G.vd->viewquat[1], G.vd->viewquat[2], G.vd->viewquat[3]);
/* Screen aligned help circle */
if(arcs) {
if((G.f & G_PICKSEL)==0) {
BIF_ThemeColorShade(TH_BACK, -30);
@@ -378,6 +379,19 @@ static void draw_manipulator_rotate(float mat[][4])
if(G.f & G_PICKSEL) glLoadName(MAN_ROT_V);
BIF_ThemeColor(TH_TRANSFORM);
drawcircball(unitmat[3], 1.2*size, unitmat);
if(G.moving) {
float vec[3];
vec[0]= Trans.imval[0] - Trans.center2d[0];
vec[1]= Trans.imval[1] - Trans.center2d[1];
vec[2]= 0.0;
Normalise(vec);
VecMulf(vec, 1.2*size);
glBegin(GL_LINES);
glVertex3f(0.0, 0.0, 0.0);
glVertex3fv(vec);
glEnd();
}
}
glPopMatrix();
@@ -395,17 +409,17 @@ static void draw_manipulator_rotate(float mat[][4])
if(!(G.f & G_PICKSEL)) {
/* axis */
glBegin(GL_LINES);
if(Gval & MAN_ROT_X) {
if( (Gval & MAN_ROT_X) || (G.moving && (Gval & MAN_ROT_Y)) ) {
manipulator_setcolor('x');
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(1.0, 0.0, 0.0);
}
if(Gval & MAN_ROT_Y) {
if( (Gval & MAN_ROT_Y) || (G.moving && (Gval & MAN_ROT_Z)) ) {
manipulator_setcolor('y');
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(0.0, 1.0, 0.0);
}
if(Gval & MAN_ROT_Z) {
if( (Gval & MAN_ROT_Z) || (G.moving && (Gval & MAN_ROT_X)) ) {
manipulator_setcolor('z');
glVertex3f(0.0, 0.0, 0.0);
glVertex3f(0.0, 0.0, 1.0);
@@ -416,24 +430,32 @@ static void draw_manipulator_rotate(float mat[][4])
/* Trackball center */
if(Gval & MAN_ROT_T) {
float smat[3][3], imat[3][3], tmat[3][3];
if(G.f & G_PICKSEL) glLoadName(MAN_ROT_T);
Mat3CpyMat4(smat, mat);
Mat3Inv(imat, smat);
Mat3CpyMat4(smat, G.vd->viewinv);
Mat3MulMat3(tmat, imat, smat);
Normalise(tmat[2]);
BIF_ThemeColor(TH_TRANSFORM);
glBegin(GL_LINES);
glVertex3f(0.0, 0.0, 0.0);
glVertex3fv(G.vd->viewinv[2]);
glVertex3fv(tmat[2]);
glEnd();
glEnable(GL_LIGHTING);
BIF_GetThemeColor3fv(TH_TRANSFORM, vec);
glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, vec);
glTranslatef(G.vd->viewinv[2][0], G.vd->viewinv[2][1], G.vd->viewinv[2][2]);
VECCOPY(vec, tmat[2]);
glTranslatef(vec[0], vec[1], vec[2]);
gluSphere(qobj, CYWID, 8, 6);
/* restore */
glTranslatef(-G.vd->viewinv[2][0], -G.vd->viewinv[2][1], -G.vd->viewinv[2][2]);
glTranslatef(-vec[0], -vec[1], -vec[2]);
glDisable(GL_LIGHTING);
}