[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11900] branches/ndof/source/blender: Some cleanup of the ndof functions:

Martin Poirier theeth at yahoo.com
Fri Aug 31 00:02:32 CEST 2007


Revision: 11900
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11900
Author:   theeth
Date:     2007-08-31 00:02:32 +0200 (Fri, 31 Aug 2007)

Log Message:
-----------
Some cleanup of the ndof functions:

	Moving filterNDOFvalues and getndof to editscreen.c/BIF_mywindow.h (this might not be the best spot but it matches table/mouse functions)
	Adding missing function definition in include files and fix declaration mixup (void functions used as int, short pointer used as float pointer)

New NDofInput model for transform (reusable externally in the future):
	Handles ndof events, accumulates values and enables remapping and rescaling values to fit any axis combinaison into a float[3] (this could be extended in the future, also, it doesn't support out of order axis right now).
	
	Compatible with "gears" (Ctrl key)

	New transform context for pure NDof input transform (entered when using Transform mode on the device).
		In this mode, transform "transactions" are automatically confirmed when the device returns to its rest position
		Rotation on Z triggers a rotation (axis is perpendicular to the screen as usual, constraints works as expected)
		Rotation on X/Y triggers trackball rotation
		Translation on X/Y/Z triggers translation (doesn't support constraints correctly).

	The device can also be used during a "normal" transform operation. In this case, there is no auto confirm but button 1 (right) can be used to confirm while button 2 is used to clear the NDof input (back to mouse input).

	NDof support was added to translation, rotation and trackball (as previously mentionned) but also to Tilt (same as rotation) and Push/Pull (move device along Z axis).

This is a bit preliminary work, so everyone should feel free to comment and send suggestions.

NOTE: this commit also merges revision 11523 from the trunk

Revision Links:
--------------
    http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11523

Modified Paths:
--------------
    branches/ndof/source/blender/include/BIF_mywindow.h
    branches/ndof/source/blender/include/BIF_transform.h
    branches/ndof/source/blender/include/transform.h
    branches/ndof/source/blender/src/editscreen.c
    branches/ndof/source/blender/src/space.c
    branches/ndof/source/blender/src/transform.c
    branches/ndof/source/blender/src/transform_conversions.c
    branches/ndof/source/blender/src/transform_generics.c
    branches/ndof/source/blender/src/view.c
    branches/ndof/source/blender/src/winlay.h

Added Paths:
-----------
    branches/ndof/source/blender/src/transform_ndofinput.c

Modified: branches/ndof/source/blender/include/BIF_mywindow.h
===================================================================
--- branches/ndof/source/blender/include/BIF_mywindow.h	2007-08-30 21:10:56 UTC (rev 11899)
+++ branches/ndof/source/blender/include/BIF_mywindow.h	2007-08-30 22:02:32 UTC (rev 11900)
@@ -123,6 +123,9 @@
 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

Modified: branches/ndof/source/blender/include/BIF_transform.h
===================================================================
--- branches/ndof/source/blender/include/BIF_transform.h	2007-08-30 21:10:56 UTC (rev 11899)
+++ branches/ndof/source/blender/include/BIF_transform.h	2007-08-30 22:02:32 UTC (rev 11900)
@@ -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_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);

Modified: branches/ndof/source/blender/include/transform.h
===================================================================
--- branches/ndof/source/blender/include/transform.h	2007-08-30 21:10:56 UTC (rev 11899)
+++ branches/ndof/source/blender/include/transform.h	2007-08-30 22:02:32 UTC (rev 11900)
@@ -46,6 +46,13 @@
 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 @@
     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 @@
     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 @@
 	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,39 +217,47 @@
 #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
 #define CON_AXIS0		2
@@ -287,6 +307,7 @@
 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 @@
 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
 

Modified: branches/ndof/source/blender/src/editscreen.c
===================================================================
--- branches/ndof/source/blender/src/editscreen.c	2007-08-30 21:10:56 UTC (rev 11899)
+++ branches/ndof/source/blender/src/editscreen.c	2007-08-30 22:02:32 UTC (rev 11900)
@@ -2163,12 +2163,25 @@
 	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)
 {
 

Modified: branches/ndof/source/blender/src/space.c
===================================================================
--- branches/ndof/source/blender/src/space.c	2007-08-30 21:10:56 UTC (rev 11899)
+++ branches/ndof/source/blender/src/space.c	2007-08-30 22:02:32 UTC (rev 11900)
@@ -1484,7 +1484,7 @@
 					viewmoveNDOFfly(1);
 				} else {
 					if (OBACT) {
-						ndof_transform();
+						NDofTransform();
 					}
 				}
                 break;
@@ -1599,7 +1599,7 @@
 					viewmoveNDOFfly(1);
 				} else {
 					if (OBACT) {
-						ndof_transform();
+						NDofTransform();
 					}
 				}
                 break;

Modified: branches/ndof/source/blender/src/transform.c
===================================================================
--- branches/ndof/source/blender/src/transform.c	2007-08-30 21:10:56 UTC (rev 11899)
+++ branches/ndof/source/blender/src/transform.c	2007-08-30 22:02:32 UTC (rev 11900)
@@ -541,7 +541,6 @@
 						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 @@
 			/* 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 @@
 			/* 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 @@
 				
 				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 @@
 //            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 @@
 			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 @@
 	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
 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list