Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source/blender/include/BIF_mywindow.h3
-rw-r--r--[-rwxr-xr-x]source/blender/include/BIF_transform.h5
-rw-r--r--[-rwxr-xr-x]source/blender/include/transform.h71
-rw-r--r--source/blender/src/editscreen.c17
-rw-r--r--source/blender/src/space.c4
-rwxr-xr-xsource/blender/src/transform.c401
-rw-r--r--[-rwxr-xr-x]source/blender/src/transform_conversions.c2
-rw-r--r--[-rwxr-xr-x]source/blender/src/transform_generics.c32
-rw-r--r--source/blender/src/transform_ndofinput.c156
-rw-r--r--source/blender/src/view.c34
-rw-r--r--source/blender/src/winlay.h1
11 files changed, 494 insertions, 232 deletions
diff --git a/source/blender/include/BIF_mywindow.h b/source/blender/include/BIF_mywindow.h
index 28de60d2bc0..2b3e732b027 100644
--- a/source/blender/include/BIF_mywindow.h
+++ b/source/blender/include/BIF_mywindow.h
@@ -123,6 +123,9 @@ short get_mbut(void);
short get_qual(void);
void getmouse(short *mval);
+void getndof(float *sbval);
+void filterNDOFvalues(float *sbval);
+
float get_pressure(void);
void get_tilt(float *xtilt, float *ytilt);
#define DEV_MOUSE 0
diff --git a/source/blender/include/BIF_transform.h b/source/blender/include/BIF_transform.h
index 3b5eeb6f35a..a8abcabc4cb 100755..100644
--- a/source/blender/include/BIF_transform.h
+++ b/source/blender/include/BIF_transform.h
@@ -62,10 +62,12 @@
#define CTX_EDGE 2
#define CTX_NO_PET 4
#define CTX_TWEAK 8
+#define CTX_NDOF 16
void initTransform(int mode, int context);
void Transform(void);
void Mirror(short mode);
+void NDofTransform();
/* Standalone call to get the transformation center corresponding to the current situation
* returns 1 if successful, 0 otherwise (usually means there's no selection)
@@ -81,9 +83,12 @@ void BIF_setSingleAxisConstraint(float vec[3], char *text);
void BIF_setDualAxisConstraint(float vec1[3], float vec2[3], char *text);
void BIF_setLocalAxisConstraint(char axis, char *text);
void BIF_setLocalLockConstraint(char axis, char *text);
+
+/* Drawing callbacks */
void BIF_drawConstraint(void);
void BIF_drawPropCircle(void);
void BIF_drawSnap(void);
+
void BIF_getPropCenter(float *center);
void BIF_TransformSetUndo(char *str);
diff --git a/source/blender/include/transform.h b/source/blender/include/transform.h
index e7650b2f72a..6f3ba36a497 100755..100644
--- a/source/blender/include/transform.h
+++ b/source/blender/include/transform.h
@@ -46,6 +46,13 @@ struct View3D;
struct ScrArea;
+typedef struct NDofInput {
+ int flag;
+ int axis;
+ float fval[7];
+ float factor[3];
+} NDofInput;
+
typedef struct NumInput {
short idx;
short idx_max;
@@ -160,6 +167,8 @@ typedef struct TransInfo {
float fac; /* factor for distance based transform */
int (*transform)(struct TransInfo *, short *);
/* transform function pointer */
+ int (*handleEvent)(struct TransInfo *, unsigned short event, short val);
+ /* event handler function pointer RETURN 1 if redraw is needed */
int total; /* total number of transformed data */
TransData *data; /* transformed data (array) */
TransDataExtension *ext; /* transformed data extension (array) */
@@ -167,6 +176,7 @@ typedef struct TransInfo {
TransCon con; /* transformed constraint */
TransSnap tsnap;
NumInput num; /* numerical input */
+ NDofInput ndof; /* ndof input */
char redraw; /* redraw flag */
float propsize; /* proportional circle radius */
char proptext[20]; /* proportional falloff text */
@@ -193,6 +203,8 @@ typedef struct TransInfo {
char spacename[32]; /* name of the current space */
struct Object *poseobj; /* if t->flag & T_POSE, this denotes pose object */
+
+ void *customData; /* Per Transform custom data */
} TransInfo;
@@ -205,38 +217,46 @@ typedef struct TransInfo {
#define NUM_NO_FRACTION 16
#define NUM_AFFECT_ALL 32
+/* NDOFINPUT FLAGS */
+#define NDOF_INIT 1
+
/* transinfo->state */
#define TRANS_RUNNING 0
#define TRANS_CONFIRM 1
#define TRANS_CANCEL 2
/* transinfo->flag */
-#define T_OBJECT 1
-#define T_EDIT 2
-#define T_POSE 4
-#define T_TEXTURE 8
-#define T_CAMERA 16
+#define T_OBJECT (1 << 0)
+#define T_EDIT (1 << 1)
+#define T_POSE (1 << 2)
+#define T_TEXTURE (1 << 3)
+#define T_CAMERA (1 << 4)
// when shift pressed, higher resolution transform. cannot rely on G.qual, need event!
-#define T_SHIFT_MOD 32
+#define T_SHIFT_MOD (1 << 5)
// trans on points, having no rotation/scale
-#define T_POINTS 64
+#define T_POINTS (1 << 6)
// for manipulator exceptions, like scaling using center point, drawing help lines
-#define T_USES_MANIPULATOR 128
+#define T_USES_MANIPULATOR (1 << 7)
/* restrictions flags */
-#define T_ALL_RESTRICTIONS (256|512|1024)
-#define T_NO_CONSTRAINT 256
-#define T_NULL_ONE 512
-#define T_NO_ZERO 1024
+#define T_ALL_RESTRICTIONS ((1 << 8)|(1 << 9)|(1 << 10))
+#define T_NO_CONSTRAINT (1 << 8)
+#define T_NULL_ONE (1 << 9)
+#define T_NO_ZERO (1 << 10)
-#define T_PROP_EDIT 2048
-#define T_PROP_CONNECTED 4096
+#define T_PROP_EDIT (1 << 11)
+#define T_PROP_CONNECTED (1 << 12)
/* if MMB is pressed or not */
-#define T_MMB_PRESSED 8192
-#define T_V3D_ALIGN 16384
-#define T_2D_EDIT 32768 /* for 2d views like uv or ipo */
-#define T_CLIP_UV 65536
+#define T_MMB_PRESSED (1 << 13)
+
+#define T_V3D_ALIGN (1 << 14)
+#define T_2D_EDIT (1 << 15) /* for 2d views like uv or ipo */
+#define T_CLIP_UV (1 << 16)
+
+#define T_FREE_CUSTOMDATA (1 << 17)
+
+/* ******************************************************************************** */
/* transinfo->con->mode */
#define CON_APPLY 1
@@ -287,6 +307,7 @@ void initWarp(TransInfo *t);
int Warp(TransInfo *t, short mval[2]);
void initShear(TransInfo *t);
+int handleEventShear(TransInfo *t, unsigned short evenl, short val);
int Shear(TransInfo *t, short mval[2]);
void initResize(TransInfo *t);
@@ -420,5 +441,19 @@ short hasNumInput(NumInput *n);
void applyNumInput(NumInput *n, float *vec);
char handleNumInput(NumInput *n, unsigned short event);
+/*********************** NDofInput ********************************/
+
+void initNDofInput(NDofInput *n);
+int hasNDofInput(NDofInput *n);
+void applyNDofInput(NDofInput *n, float *vec);
+int handleNDofInput(NDofInput *n, unsigned short event, short val);
+
+/* handleNDofInput return values */
+#define NDOF_REFRESH 1
+#define NDOF_NOMOVE 2
+#define NDOF_CONFIRM 3
+#define NDOF_CANCEL 4
+
+
#endif
diff --git a/source/blender/src/editscreen.c b/source/blender/src/editscreen.c
index 6069ca16312..15c3d8c6fec 100644
--- a/source/blender/src/editscreen.c
+++ b/source/blender/src/editscreen.c
@@ -2163,10 +2163,23 @@ short get_activedevice(void)
return window_get_activedevice(mainwin);
}
-short getndof(short *sbval)
+void getndof(float *sbval)
{
winlay_process_events(0);
- return window_get_ndof(mainwin, sbval);
+ window_get_ndof(mainwin, sbval);
+}
+
+void filterNDOFvalues(float *sbval)
+{
+ int i=0;
+ float max = 0.0;
+
+ for (i =0; i<5;i++)
+ if (fabs(sbval[i]) > max)
+ max = fabs(sbval[i]);
+ for (i =0; i<5;i++)
+ if (fabs(sbval[i]) != max )
+ sbval[i]=0.0;
}
void add_to_mainqueue(Window *win, void *user_data, short evt, short val, char ascii)
diff --git a/source/blender/src/space.c b/source/blender/src/space.c
index 31f458085db..9787d699b80 100644
--- a/source/blender/src/space.c
+++ b/source/blender/src/space.c
@@ -1484,7 +1484,7 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
viewmoveNDOFfly(1);
} else {
if (OBACT) {
- ndof_transform();
+ NDofTransform();
}
}
break;
@@ -1599,7 +1599,7 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
viewmoveNDOFfly(1);
} else {
if (OBACT) {
- ndof_transform();
+ NDofTransform();
}
}
break;
diff --git a/source/blender/src/transform.c b/source/blender/src/transform.c
index e6ee597db29..0d5868d9032 100755
--- a/source/blender/src/transform.c
+++ b/source/blender/src/transform.c
@@ -541,7 +541,6 @@ static void transformEvent(unsigned short event, short val) {
setLocalConstraint(&Trans, (CON_AXIS2), "along local Z");
else if (Trans.mode==TFM_ROTATION) {
restoreTransObjects(&Trans);
- initTransModeFlags(&Trans, TFM_TRACKBALL);
initTrackball(&Trans);
}
}
@@ -578,7 +577,6 @@ static void transformEvent(unsigned short event, short val) {
/* only switch when... */
if( ELEM3(Trans.mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL) ) {
restoreTransObjects(&Trans);
- initTransModeFlags(&Trans, TFM_TRANSLATION);
initTranslation(&Trans);
Trans.redraw = 1;
}
@@ -587,7 +585,6 @@ static void transformEvent(unsigned short event, short val) {
/* only switch when... */
if( ELEM3(Trans.mode, TFM_ROTATION, TFM_TRANSLATION, TFM_TRACKBALL) ) {
restoreTransObjects(&Trans);
- initTransModeFlags(&Trans, TFM_RESIZE);
initResize(&Trans);
Trans.redraw = 1;
}
@@ -598,12 +595,10 @@ static void transformEvent(unsigned short event, short val) {
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;
@@ -730,8 +725,48 @@ static void transformEvent(unsigned short event, short val) {
// viewmoveNDOF(1);
// break;
}
+
+ // Numerical input events
Trans.redraw |= handleNumInput(&(Trans.num), event);
+
+ // NDof input events
+ switch(handleNDofInput(&(Trans.ndof), event, val))
+ {
+ case NDOF_CONFIRM:
+ if ((Trans.context & CTX_NDOF) == 0)
+ {
+ /* Confirm on normal transform only */
+ Trans.state = TRANS_CONFIRM;
+ }
+ break;
+ case NDOF_CANCEL:
+ if (Trans.context & CTX_NDOF)
+ {
+ /* Cancel on pure NDOF transform */
+ Trans.state = TRANS_CANCEL;
+ }
+ else
+ {
+ /* Otherwise, just redraw, NDof input was cancelled */
+ Trans.redraw = 1;
+ }
+ break;
+ case NDOF_NOMOVE:
+ if (Trans.context & CTX_NDOF)
+ {
+ /* Confirm on pure NDOF transform */
+ Trans.state = TRANS_CONFIRM;
+ }
+ break;
+ case NDOF_REFRESH:
+ Trans.redraw = 1;
+ break;
+
+ }
+
+ // Snapping events
Trans.redraw |= handleSnapping(&Trans, event);
+
arrows_move_cursor(event);
}
else {
@@ -757,6 +792,10 @@ static void transformEvent(unsigned short event, short val) {
break;
}
}
+
+ // Per transform event, if present
+ if (Trans.handleEvent)
+ Trans.redraw |= Trans.handleEvent(&Trans, event, val);
}
int calculateTransformCenter(int centerMode, float *vec)
@@ -767,13 +806,13 @@ int calculateTransformCenter(int centerMode, float *vec)
Trans.state = TRANS_RUNNING;
Trans.context = CTX_NONE;
+
+ Trans.mode = TFM_DUMMY;
initTrans(&Trans); // internal data, mouse, vectors
createTransData(&Trans); // make TransData structs from selection
- initTransModeFlags(&Trans, TFM_DUMMY); // modal settings in struct Trans
-
Trans.around = centerMode; // override userdefined mode
if (Trans.total == 0) {
@@ -803,6 +842,8 @@ void initTransform(int mode, int context) {
Trans.state = TRANS_RUNNING;
Trans.context = context;
+
+ Trans.mode = mode;
initTrans(&Trans); // internal data, mouse, vectors
@@ -813,8 +854,6 @@ void initTransform(int mode, int context) {
else
Mat3One(Trans.spacemtx);
- initTransModeFlags(&Trans, mode); // modal settings in struct Trans
-
createTransData(&Trans); // make TransData structs from selection
initSnapping(&Trans); // Initialize snapping data AFTER mode flags
@@ -826,7 +865,7 @@ void initTransform(int mode, int context) {
/* EVIL! posemode code can switch translation to rotate when 1 bone is selected. will be removed (ton) */
/* EVIL2: we gave as argument also texture space context bit... was cleared */
- mode= Trans.mode;
+ mode = Trans.mode;
calculatePropRatio(&Trans);
calculateCenter(&Trans);
@@ -963,6 +1002,8 @@ void initManipulator(int mode)
Trans.context = CTX_NONE;
+ Trans.mode = mode;
+
/* automatic switch to scaling bone envelopes */
if(mode==TFM_RESIZE && G.obedit && G.obedit->type==OB_ARMATURE) {
bArmature *arm= G.obedit->data;
@@ -972,8 +1013,6 @@ void initManipulator(int mode)
initTrans(&Trans); // internal data, mouse, vectors
- initTransModeFlags(&Trans, mode); // modal settings in struct Trans
-
G.moving |= G_TRANSFORM_MANIP; // signal to draw manipuls while transform
createTransData(&Trans); // make TransData structs from selection
@@ -984,7 +1023,7 @@ void initManipulator(int mode)
/* EVIL! posemode code can switch translation to rotate when 1 bone is selected. will be removed (ton) */
/* EVIL2: we gave as argument also texture space context bit... was cleared */
- mode= Trans.mode;
+ mode = Trans.mode;
calculatePropRatio(&Trans);
calculateCenter(&Trans);
@@ -1182,20 +1221,24 @@ static void protectedQuaternionBits(short protectflag, float *quat, float *oldqu
/* ************************** WARP *************************** */
-/* warp is done fully in view space */
void initWarp(TransInfo *t)
{
float max[3], min[3];
int i;
- calculateCenterCursor(t);
+ t->mode = TFM_WARP;
+ t->transform = Warp;
+
t->idx_max = 0;
t->num.idx_max = 0;
- t->transform = Warp;
t->snap[0] = 0.0f;
t->snap[1] = 5.0f;
t->snap[2] = 1.0f;
+ t->flag |= T_NO_CONSTRAINT;
+
+/* warp is done fully in view space */
+ calculateCenterCursor(t);
t->fac = (float)(t->center2d[0] - t->imval[0]);
/* we need min/max in view space */
@@ -1220,7 +1263,6 @@ void initWarp(TransInfo *t)
t->val= (max[0]-min[0])/2.0f; // t->val is free variable
}
-
int Warp(TransInfo *t, short mval[2])
{
TransData *td = t->data;
@@ -1318,14 +1360,38 @@ int Warp(TransInfo *t, short mval[2])
void initShear(TransInfo *t)
{
+ t->mode = TFM_SHEAR;
+ t->transform = Shear;
+ t->handleEvent = handleEventShear;
+
t->idx_max = 0;
t->num.idx_max = 0;
t->snap[0] = 0.0f;
t->snap[1] = 0.1f;
t->snap[2] = t->snap[1] * 0.1f;
- t->transform = Shear;
+
+ t->flag |= T_NO_CONSTRAINT;
}
+int handleEventShear(TransInfo *t, unsigned short event, short val)
+{
+ int status = 0;
+
+ if (event == MIDDLEMOUSE && val)
+ {
+ // Use customData pointer to signal Shear direction
+ if (t->customData == 0)
+ t->customData = (void*)1;
+ else
+ t->customData = 0;
+
+ status = 1;
+ }
+
+ return status;
+}
+
+
int Shear(TransInfo *t, short mval[2])
{
TransData *td = t->data;
@@ -1338,7 +1404,11 @@ int Shear(TransInfo *t, short mval[2])
Mat3CpyMat4(persmat, t->viewmat);
Mat3Inv(persinv, persmat);
- value = 0.05f * InputHorizontalAbsolute(t, mval);
+ // Custom data signals shear direction
+ if (t->customData == 0)
+ value = 0.05f * InputHorizontalAbsolute(t, mval);
+ else
+ value = 0.05f * InputVerticalAbsolute(t, mval);
snapGrid(t, &value);
@@ -1358,7 +1428,13 @@ int Shear(TransInfo *t, short mval[2])
}
Mat3One(smat);
- smat[1][0] = value;
+
+ // Custom data signals shear direction
+ if (t->customData == 0)
+ smat[1][0] = value;
+ else
+ smat[0][1] = value;
+
Mat3MulMat3(tmat, smat, persmat);
Mat3MulMat3(totmat, persinv, tmat);
@@ -1401,6 +1477,23 @@ int Shear(TransInfo *t, short mval[2])
void initResize(TransInfo *t)
{
+ t->mode = TFM_RESIZE;
+ t->transform = Resize;
+
+ t->flag |= T_NULL_ONE;
+ t->num.flag |= NUM_NULL_ONE;
+ t->num.flag |= NUM_AFFECT_ALL;
+ if (!G.obedit) {
+ t->flag |= T_NO_ZERO;
+ t->num.flag |= NUM_NO_ZERO;
+ }
+
+ t->idx_max = 2;
+ t->num.idx_max = 2;
+ t->snap[0] = 0.0f;
+ t->snap[1] = 0.1f;
+ t->snap[2] = t->snap[1] * 0.1f;
+
t->fac = (float)sqrt(
(
((float)(t->center2d[1] - t->imval[1]))*((float)(t->center2d[1] - t->imval[1]))
@@ -1409,13 +1502,6 @@ void initResize(TransInfo *t)
) );
if(t->fac==0.0f) t->fac= 1.0f; // prevent Inf
-
- t->idx_max = 2;
- t->num.idx_max = 2;
- t->snap[0] = 0.0f;
- t->snap[1] = 0.1f;
- t->snap[2] = t->snap[1] * 0.1f;
- t->transform = Resize;
}
static void headerResize(TransInfo *t, float vec[3], char *str) {
@@ -1667,22 +1753,25 @@ void initToSphere(TransInfo *t)
TransData *td = t->data;
int i;
- // Calculate average radius
- for(i = 0 ; i < t->total; i++, td++) {
- t->val += VecLenf(t->center, td->iloc);
- }
-
- t->val /= (float)t->total;
+ t->mode = TFM_TOSPHERE;
+ t->transform = ToSphere;
t->idx_max = 0;
t->num.idx_max = 0;
t->snap[0] = 0.0f;
t->snap[1] = 0.1f;
t->snap[2] = t->snap[1] * 0.1f;
- t->transform = ToSphere;
-}
+
+ t->num.flag |= NUM_NULL_ONE | NUM_NO_NEGATIVE;
+ t->flag |= T_NO_CONSTRAINT;
+ // Calculate average radius
+ for(i = 0 ; i < t->total; i++, td++) {
+ t->val += VecLenf(t->center, td->iloc);
+ }
+ t->val /= (float)t->total;
+}
int ToSphere(TransInfo *t, short mval[2])
{
@@ -1747,13 +1836,19 @@ int ToSphere(TransInfo *t, short mval[2])
void initRotation(TransInfo *t)
{
+ t->mode = TFM_ROTATION;
+ t->transform = Rotation;
+
+ t->ndof.axis = 16;
+ /* Scale down and flip input for rotation */
+ t->ndof.factor[0] = -0.2f;
+
t->idx_max = 0;
t->num.idx_max = 0;
t->snap[0] = 0.0f;
t->snap[1] = (float)((5.0/180)*M_PI);
t->snap[2] = t->snap[1] * 0.2f;
t->fac = 0;
- t->transform = Rotation;
}
static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3]) {
@@ -2004,6 +2099,8 @@ int Rotation(TransInfo *t, short mval[2])
final = t->fac;
+ applyNDofInput(&t->ndof, &final);
+
snapGrid(t, &final);
t->imval[0] = mval[0];
@@ -2060,15 +2157,22 @@ int Rotation(TransInfo *t, short mval[2])
void initTrackball(TransInfo *t)
{
+ t->mode = TFM_TRACKBALL;
+ t->transform = Trackball;
+
+ t->ndof.axis = 40;
+ /* Scale down input for rotation */
+ t->ndof.factor[0] = 0.2f;
+ t->ndof.factor[1] = 0.2f;
+
t->idx_max = 1;
t->num.idx_max = 1;
t->snap[0] = 0.0f;
t->snap[1] = (float)((5.0/180)*M_PI);
t->snap[2] = t->snap[1] * 0.2f;
t->fac = 0;
- t->transform = Trackball;
- t->flag |= T_NO_CONSTRAINT; /* making sure the flag is always set */
+ t->flag |= T_NO_CONSTRAINT;
}
static void applyTrackball(TransInfo *t, float axis1[3], float axis2[3], float angles[2])
@@ -2121,6 +2225,8 @@ int Trackball(TransInfo *t, short mval[2])
//if(G.qual & LR_SHIFTKEY) t->fac += dphi/30.0f;
//else t->fac += dphi;
+ applyNDofInput(&t->ndof, phi);
+
snapGrid(t, phi);
if (hasNumInput(&t->num)) {
@@ -2163,10 +2269,15 @@ int Trackball(TransInfo *t, short mval[2])
void initTranslation(TransInfo *t)
{
+ t->mode = TFM_TRANSLATION;
+ t->transform = Translation;
+
t->idx_max = (t->flag & T_2D_EDIT)? 1: 2;
+ t->num.flag = 0;
t->num.idx_max = t->idx_max;
- t->transform = Translation;
+ t->ndof.axis = 7;
+
if(t->spacetype == SPACE_VIEW3D) {
/* initgrabz() defines a factor for perspective depth correction, used in window_to_3d() */
if(t->flag & (T_EDIT|T_POSE)) {
@@ -2177,7 +2288,9 @@ void initTranslation(TransInfo *t)
Mat4MulVecfl(ob->obmat, vec);
initgrabz(vec[0], vec[1], vec[2]);
}
- else initgrabz(t->center[0], t->center[1], t->center[2]);
+ else {
+ initgrabz(t->center[0], t->center[1], t->center[2]);
+ }
t->snap[0] = 0.0f;
t->snap[1] = G.vd->gridview * 1.0f;
@@ -2295,6 +2408,7 @@ int Translation(TransInfo *t, short mval[2])
headerTranslation(t, pvec, str);
}
else {
+ applyNDofInput(&t->ndof, t->vec);
snapGrid(t, t->vec);
applyNumInput(&t->num, t->vec);
applySnapping(t, t->vec);
@@ -2322,18 +2436,22 @@ int Translation(TransInfo *t, short mval[2])
void initShrinkFatten(TransInfo *t)
{
+ // If not in mesh edit mode, fallback to Resize
if (G.obedit==NULL || G.obedit->type != OB_MESH) {
- initTransModeFlags(t, TFM_RESIZE);
initResize(t);
- return;
}
-
- t->idx_max = 0;
- t->num.idx_max = 0;
- t->snap[0] = 0.0f;
- t->snap[1] = 1.0f;
- t->snap[2] = t->snap[1] * 0.1f;
- t->transform = ShrinkFatten;
+ else {
+ t->mode = TFM_SHRINKFATTEN;
+ t->transform = ShrinkFatten;
+
+ t->idx_max = 0;
+ t->num.idx_max = 0;
+ t->snap[0] = 0.0f;
+ t->snap[1] = 1.0f;
+ t->snap[2] = t->snap[1] * 0.1f;
+
+ t->flag |= T_NO_CONSTRAINT;
+ }
}
@@ -2390,13 +2508,21 @@ int ShrinkFatten(TransInfo *t, short mval[2])
void initTilt(TransInfo *t)
{
+ t->mode = TFM_TILT;
+ t->transform = Tilt;
+
+ t->ndof.axis = 16;
+ /* Scale down and flip input for rotation */
+ t->ndof.factor[0] = -0.2f;
+
t->idx_max = 0;
t->num.idx_max = 0;
t->snap[0] = 0.0f;
t->snap[1] = (float)((5.0/180)*M_PI);
t->snap[2] = t->snap[1] * 0.2f;
t->fac = 0;
- t->transform = Tilt;
+
+ t->flag |= T_NO_CONSTRAINT;
}
@@ -2432,6 +2558,8 @@ int Tilt(TransInfo *t, short mval[2])
else t->fac += dphi;
final = t->fac;
+
+ applyNDofInput(&t->ndof, &final);
snapGrid(t, &final);
@@ -2539,12 +2667,17 @@ int CurveShrinkFatten(TransInfo *t, short mval[2])
void initCurveShrinkFatten(TransInfo *t)
{
+ t->mode = TFM_CURVE_SHRINKFATTEN;
+ t->transform = CurveShrinkFatten;
+
t->idx_max = 0;
t->num.idx_max = 0;
t->snap[0] = 0.0f;
t->snap[1] = 0.1f;
t->snap[2] = t->snap[1] * 0.1f;
- t->transform = CurveShrinkFatten;
+
+ t->flag |= T_NO_CONSTRAINT;
+
t->fac = (float)sqrt( (
((float)(t->center2d[1] - t->imval[1]))*((float)(t->center2d[1] - t->imval[1]))
+
@@ -2556,16 +2689,21 @@ void initCurveShrinkFatten(TransInfo *t)
void initPushPull(TransInfo *t)
{
+ t->mode = TFM_PUSHPULL;
+ t->transform = PushPull;
+
+ t->ndof.axis = 4;
+ /* Flip direction */
+ t->ndof.factor[0] = -1.0f;
+
t->idx_max = 0;
t->num.idx_max = 0;
t->snap[0] = 0.0f;
t->snap[1] = 1.0f;
t->snap[2] = t->snap[1] * 0.1f;
- t->transform = PushPull;
}
-
int PushPull(TransInfo *t, short mval[2])
{
float vec[3], axis[3];
@@ -2575,6 +2713,8 @@ int PushPull(TransInfo *t, short mval[2])
TransData *td = t->data;
distance = InputVerticalAbsolute(t, mval);
+
+ applyNDofInput(&t->ndof, &distance);
snapGrid(t, &distance);
@@ -2633,12 +2773,17 @@ int PushPull(TransInfo *t, short mval[2])
void initCrease(TransInfo *t)
{
+ t->mode = TFM_CREASE;
+ t->transform = Crease;
+
t->idx_max = 0;
t->num.idx_max = 0;
t->snap[0] = 0.0f;
t->snap[1] = 0.1f;
t->snap[2] = t->snap[1] * 0.1f;
- t->transform = Crease;
+
+ t->flag |= T_NO_CONSTRAINT;
+
t->fac = (float)sqrt(
(
((float)(t->center2d[1] - t->imval[1]))*((float)(t->center2d[1] - t->imval[1]))
@@ -2726,12 +2871,17 @@ int Crease(TransInfo *t, short mval[2])
void initBoneSize(TransInfo *t)
{
+ t->mode = TFM_BONESIZE;
+ t->transform = BoneSize;
+
t->idx_max = 0;
t->num.idx_max = 0;
t->snap[0] = 0.0f;
t->snap[1] = 0.1f;
t->snap[2] = t->snap[1] * 0.1f;
- t->transform = BoneSize;
+
+ t->flag |= T_NO_CONSTRAINT;
+
t->fac = (float)sqrt( (
((float)(t->center2d[1] - t->imval[1]))*((float)(t->center2d[1] - t->imval[1]))
+
@@ -2840,12 +2990,17 @@ int BoneSize(TransInfo *t, short mval[2])
void initBoneEnvelope(TransInfo *t)
{
+ t->mode = TFM_BONE_ENVELOPE;
+ t->transform = BoneEnvelope;
+
t->idx_max = 0;
t->num.idx_max = 0;
t->snap[0] = 0.0f;
t->snap[1] = 0.1f;
t->snap[2] = t->snap[1] * 0.1f;
- t->transform = BoneEnvelope;
+
+ t->flag |= T_NO_CONSTRAINT;
+
t->fac = (float)sqrt( (
((float)(t->center2d[1] - t->imval[1]))*((float)(t->center2d[1] - t->imval[1]))
+
@@ -2917,6 +3072,9 @@ int BoneEnvelope(TransInfo *t, short mval[2])
void initBoneRoll(TransInfo *t)
{
+ t->mode = TFM_BONE_ROLL;
+ t->transform = BoneRoll;
+
t->idx_max = 0;
t->num.idx_max = 0;
t->snap[0] = 0.0f;
@@ -2925,7 +3083,7 @@ void initBoneRoll(TransInfo *t)
t->fac = 0.0f;
- t->transform = BoneRoll;
+ t->flag |= T_NO_CONSTRAINT;
}
int BoneRoll(TransInfo *t, short mval[2])
@@ -3017,8 +3175,6 @@ void Mirror(short mode)
Mat3CpyMat4(matview, Trans.viewinv); // t->viewinv was set in initTrans
Mat3Ortho(matview);
- initTransModeFlags(&Trans, TFM_MIRROR); // modal settings in struct Trans
-
createTransData(&Trans); // make TransData structs from selection
calculatePropRatio(&Trans);
@@ -3106,92 +3262,51 @@ void BIF_TransformSetUndo(char *str)
Trans.undostr= str;
}
-void ndof_do_transform(float *fval)
-{
- char str[200];
- float fvec[3] = {0.0,0.0,0.0};
- char change = 0;
-
-// fprintf(stderr,"passing here %f %f %f \n",fval[3],fval[4],fval[5]);
-
- if (fval[3] != 0.0 ) {
- fvec[0] = 1.0;
- initTransform(TFM_ROTATION, CTX_NONE);
- applyRotation(&Trans, fval[3], fvec);
- recalcData(&Trans);
- change =1;
- fvec[0] = 0.0;
- drawSnapping(&Trans);
- /* free data */
- postTrans(&Trans);
-
- /* aftertrans does insert ipos and action channels, and clears base flags, doesnt read transdata */
- special_aftertrans_update(&Trans);
-
- }
- if (fval[4] != 0.0 ) {
- fvec[1] = 1.0;
- initTransform(TFM_ROTATION, CTX_NONE);
- applyRotation(&Trans, fval[4], fvec);
- recalcData(&Trans);
- change =1;
- fvec[1] = 0.0;
- drawSnapping(&Trans);
- /* free data */
- postTrans(&Trans);
-
- /* aftertrans does insert ipos and action channels, and clears base flags, doesnt read transdata */
- special_aftertrans_update(&Trans);
-
- }
- if (fval[5] != 0.0 ) {
- fvec[2] = 1.0;
- initTransform(TFM_ROTATION, CTX_NONE);
- applyRotation(&Trans, fval[5], fvec);
- recalcData(&Trans);
- change =1;
- fvec[2] = 0.0;
- drawSnapping(&Trans);
- /* free data */
- postTrans(&Trans);
-
- /* aftertrans does insert ipos and action channels, and clears base flags, doesnt read transdata */
- special_aftertrans_update(&Trans);
-
+void NDofTransform()
+{
+ float fval[7];
+ float maxval = 50.0f; // also serves as threshold
+ int axis = -1;
+ int mode = 0;
+ int i;
+
+ getndof(fval);
+
+ for(i = 0; i < 7; i++)
+ {
+ float val = fabs(fval[i]);
+ if (val > maxval)
+ {
+ axis = i;
+ maxval = val;
+ }
}
+ switch(axis)
+ {
+ case -1:
+ /* No proper axis found */
+ break;
+ case 0:
+ case 1:
+ case 2:
+ mode = TFM_TRANSLATION;
+ break;
+ case 4:
+ mode = TFM_ROTATION;
+ break;
+ case 3:
+ case 5:
+ mode = TFM_TRACKBALL;
+ break;
+ default:
+ printf("ndof transform mode not impremented yet");
+ }
- if ((fval[0] != 0.0 )|( fval[1] != 0.0 )| (fval[2] != 0.0)) {
- initTransform(TFM_TRANSLATION, CTX_NONE);
- Trans.vec[0] = fval[0];
- Trans.vec[1] = fval[1];
- Trans.vec[2] = fval[2];
-
- applyTranslation(&Trans, Trans.vec);
-
- /* evil hack - redo translation if cliiping needeed */
- if (Trans.flag & T_CLIP_UV && clipUVTransform(&Trans, Trans.vec, 0))
- applyTranslation(&Trans, Trans.vec);
-
- recalcData(&Trans);
- change =1;
- drawSnapping(&Trans);
- /* free data */
- postTrans(&Trans);
-
- /* aftertrans does insert ipos and action channels, and clears base flags, doesnt read transdata */
- special_aftertrans_update(&Trans);
-
+ if (mode != 0)
+ {
+ initTransform(mode, CTX_NDOF);
+ Transform();
}
-
- /* send events out for redraws */
- viewRedrawPost(&Trans);
-
- if(Trans.undostr) BIF_undo_push(Trans.undostr);
- else BIF_undo_push(transform_to_undostr(&Trans));
-
- Trans.undostr= NULL;
-
-
-} \ No newline at end of file
+}
diff --git a/source/blender/src/transform_conversions.c b/source/blender/src/transform_conversions.c
index 18fc8c5862a..a115a0d207a 100755..100644
--- a/source/blender/src/transform_conversions.c
+++ b/source/blender/src/transform_conversions.c
@@ -2575,7 +2575,7 @@ void createTransData(TransInfo *t)
createTransArmatureVerts(t);
}
else {
- printf("not done yet! only have mesh surface curve\n");
+ printf("not done yet! only have mesh surface curve lattice mball armature\n");
}
if(t->data && t->flag & T_PROP_EDIT) {
diff --git a/source/blender/src/transform_generics.c b/source/blender/src/transform_generics.c
index abe2778518d..1d2699bc50d 100755..100644
--- a/source/blender/src/transform_generics.c
+++ b/source/blender/src/transform_generics.c
@@ -376,38 +376,6 @@ void recalcData(TransInfo *t)
}
-void initTransModeFlags(TransInfo *t, int mode)
-{
- t->mode = mode;
- t->num.flag = 0;
-
- /* REMOVING RESTRICTIONS FLAGS */
- t->flag &= ~T_ALL_RESTRICTIONS;
-
- switch (mode) {
- case TFM_RESIZE:
- t->flag |= T_NULL_ONE;
- t->num.flag |= NUM_NULL_ONE;
- t->num.flag |= NUM_AFFECT_ALL;
- if (!G.obedit) {
- t->flag |= T_NO_ZERO;
- t->num.flag |= NUM_NO_ZERO;
- }
- break;
- case TFM_TOSPHERE:
- t->num.flag |= NUM_NULL_ONE;
- t->num.flag |= NUM_NO_NEGATIVE;
- t->flag |= T_NO_CONSTRAINT;
- break;
- case TFM_SHEAR:
- case TFM_CREASE:
- case TFM_BONE_ENVELOPE:
- case TFM_CURVE_SHRINKFATTEN:
- t->flag |= T_NO_CONSTRAINT;
- break;
- }
-}
-
void drawLine(float *center, float *dir, char axis, short options)
{
extern void make_axis_color(char *col, char *col2, char axis); // drawview.c
diff --git a/source/blender/src/transform_ndofinput.c b/source/blender/src/transform_ndofinput.c
new file mode 100644
index 00000000000..34ab8b95e7b
--- /dev/null
+++ b/source/blender/src/transform_ndofinput.c
@@ -0,0 +1,156 @@
+/**
+ * $Id:
+ *
+ * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version. The Blender
+ * Foundation also sells licenses for use in proprietary software under
+ * the Blender License. See http://www.blender.org/BL/ for information
+ * about this.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Martin Poirier
+ *
+ * ***** END GPL/BL DUAL LICENSE BLOCK *****
+ */
+
+ #include <math.h> /* fabs */
+#include <stdio.h> /* for sprintf */
+
+#include "BKE_global.h" /* for G */
+#include "BKE_utildefines.h" /* ABS */
+
+#include "DNA_view3d_types.h" /* for G.vd (view3d) */
+
+#include "BIF_mywindow.h"
+
+#include "mydevice.h" /* for KEY defines */
+
+#include "transform.h"
+
+int updateNDofMotion(NDofInput *n); // return 0 when motion is null
+void resetNDofInput(NDofInput *n);
+
+void initNDofInput(NDofInput *n)
+{
+ int i;
+
+ n->flag = 0;
+ n->axis = 0;
+
+ resetNDofInput(n);
+
+ for(i = 0; i < 3; i++)
+ {
+ n->factor[i] = 1.0f;
+ }
+}
+
+void resetNDofInput(NDofInput *n)
+{
+ int i;
+ for(i = 0; i < 7; i++)
+ {
+ n->fval[i] = 0.0f;
+ }
+}
+
+
+int handleNDofInput(NDofInput *n, unsigned short event, short val)
+{
+ int retval = 0;
+
+ switch(event)
+ {
+ case NDOFMOTION:
+ if (updateNDofMotion(n) == 0)
+ {
+ retval = NDOF_NOMOVE;
+ }
+ else
+ {
+ retval = NDOF_REFRESH;
+ }
+ break;
+ case NDOFBUTTON:
+ if (val == 1)
+ {
+ retval = NDOF_CONFIRM;
+ }
+ else if (val == 2)
+ {
+ retval = NDOF_CANCEL;
+ resetNDofInput(n);
+ n->flag &= ~NDOF_INIT;
+ }
+ break;
+ }
+
+ return retval;
+}
+
+int hasNDofInput(NDofInput *n)
+{
+ return (n->flag & NDOF_INIT) == NDOF_INIT;
+}
+
+void applyNDofInput(NDofInput *n, float *vec)
+{
+ if (hasNDofInput(n))
+ {
+ int i, j;
+
+ for (i = 0, j = 0; i < 7; i++)
+ {
+ if (n->axis & (1 << i))
+ {
+ vec[j] = n->fval[i] * n->factor[j];
+ j++;
+ }
+ }
+ }
+}
+
+
+int updateNDofMotion(NDofInput *n)
+{
+ float fval[7];
+ int i;
+ int retval = 0;
+
+ getndof(fval);
+
+ if (G.vd->ndoffilter)
+ filterNDOFvalues(fval);
+
+ for(i = 0; i < 7; i++)
+ {
+ if (!retval && fval[i] != 0.0f)
+ {
+ retval = 1;
+ }
+
+ n->fval[i] += fval[i] / 1024.0f;
+ }
+
+ n->flag |= NDOF_INIT;
+
+ return retval;
+}
+
+
+
+
diff --git a/source/blender/src/view.c b/source/blender/src/view.c
index 75869c7c937..9c8f333e2f7 100644
--- a/source/blender/src/view.c
+++ b/source/blender/src/view.c
@@ -572,21 +572,6 @@ float ndof_axis_scale[6] = {
int dz_flag = 0;
float m_dist;
-void getndof(float *sbval);
-
-static void filterNDOFvalues(float *sbval)
-{
- int i=0;
- float max = 0.0;
-
- for (i =0; i<5;i++)
- if (fabs(sbval[i]) > max)
- max = fabs(sbval[i]);
- for (i =0; i<5;i++)
- if (fabs(sbval[i]) != max )
- sbval[i]=0.0;
-}
-
void viewmoveNDOFfly(int mode)
{
int i;
@@ -2229,22 +2214,3 @@ void smooth_view_to_camera(View3D *v3d)
v3d->persp=2;
}
}
-
-void ndof_transform(void)
-{
- float fval[7];
-
- getndof(fval);
-
- if (G.vd->ndoffilter)
- filterNDOFvalues(fval);
-
- fval[0] = fval[0] * (1.0f/1024.0f);
- fval[1] = -fval[1] * (1.0f/1024.0f); // axis inversion
- fval[2] = -fval[2] * (1.0f/1024.0f); // axis inversion
- fval[3] = fval[3] * (1.0f/8024.0f);
- fval[4] = fval[4] * (1.0f/8024.0f);
- fval[5] = fval[5] * (1.0f/8024.0f);
-
- ndof_do_transform(fval);
-}
diff --git a/source/blender/src/winlay.h b/source/blender/src/winlay.h
index 1734c0e2867..b9539897dbb 100644
--- a/source/blender/src/winlay.h
+++ b/source/blender/src/winlay.h
@@ -57,6 +57,7 @@ void window_lower (Window *win);
short window_get_qual (Window *win);
short window_get_mbut (Window *win);
void window_get_mouse (Window *win, short *mval);
+void window_get_ndof (Window* win, float* sbval);
float window_get_pressure(Window *win);
void window_get_tilt(Window *win, float *xtilt, float *ytilt);