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:
authorMartin Poirier <theeth@yahoo.com>2007-08-31 02:02:32 +0400
committerMartin Poirier <theeth@yahoo.com>2007-08-31 02:02:32 +0400
commit800c6db46fd3d45c1ef16f1ba5f2ce4ab0fd9307 (patch)
tree851ae596f87b455c3051a1189f9ebe07de1a912a /source/blender/src/transform_ndofinput.c
parent7f6bb8d8ccd49b3f14f9799962bfa37d47beef68 (diff)
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
Diffstat (limited to 'source/blender/src/transform_ndofinput.c')
-rw-r--r--source/blender/src/transform_ndofinput.c156
1 files changed, 156 insertions, 0 deletions
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;
+}
+
+
+
+