[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [38026] branches/merwin-spacenav: implemented ndof 'dead zone' around home position, fixed X11 active window determination, removed old X11 ndof code

Mike Erwin significant.bit at gmail.com
Fri Jul 1 23:51:46 CEST 2011


Revision: 38026
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=38026
Author:   merwin
Date:     2011-07-01 21:51:44 +0000 (Fri, 01 Jul 2011)
Log Message:
-----------
implemented ndof 'dead zone' around home position, fixed X11 active window determination, removed old X11 ndof code

Modified Paths:
--------------
    branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManager.cpp
    branches/merwin-spacenav/intern/ghost/intern/GHOST_SystemX11.cpp
    branches/merwin-spacenav/intern/ghost/intern/GHOST_SystemX11.h
    branches/merwin-spacenav/source/blender/windowmanager/intern/wm_operators.c

Modified: branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManager.cpp
===================================================================
--- branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManager.cpp	2011-07-01 18:21:46 UTC (rev 38025)
+++ branches/merwin-spacenav/intern/ghost/intern/GHOST_NDOFManager.cpp	2011-07-01 21:51:44 UTC (rev 38026)
@@ -27,6 +27,7 @@
 #include "GHOST_WindowManager.h"
 #include <string.h> // for memory functions
 #include <stdio.h> // for error/info reporting
+#include <math.h>
 
 #ifdef DEBUG_NDOF_BUTTONS
 static const char* ndof_button_names[] = {
@@ -301,6 +302,12 @@
 		}
 	}
 
+static bool atHomePosition(GHOST_TEventNDOFMotionData* ndof, float threshold)
+	{
+	#define HOME(foo) (fabsf(ndof->foo) < threshold)
+	return HOME(tx) && HOME(ty) && HOME(tz) && HOME(rx) && HOME(ry) && HOME(rz);
+	}
+
 bool GHOST_NDOFManager::sendMotionEvent()
 	{
 	if (m_atRest)
@@ -336,9 +343,7 @@
 	m_system.pushEvent(event);
 
 	// 'at rest' test goes at the end so that the first 'rest' event gets sent
-	m_atRest = m_rotation[0] == 0 && m_rotation[1] == 0 && m_rotation[2] == 0 &&
-		m_translation[0] == 0 && m_translation[1] == 0 && m_translation[2] == 0;
-	// this needs to be aware of calibration -- 0.01 0.01 0.03 might be 'rest'
+	m_atRest = atHomePosition(data, 0.05f);
 
 	return true;
 	}

Modified: branches/merwin-spacenav/intern/ghost/intern/GHOST_SystemX11.cpp
===================================================================
--- branches/merwin-spacenav/intern/ghost/intern/GHOST_SystemX11.cpp	2011-07-01 18:21:46 UTC (rev 38025)
+++ branches/merwin-spacenav/intern/ghost/intern/GHOST_SystemX11.cpp	2011-07-01 21:51:44 UTC (rev 38026)
@@ -75,22 +75,6 @@
 #include <stdio.h> // for fprintf only
 #include <cstdlib> // for exit
 
-#if 0 // obsolete SpaceNav code
-
-typedef struct NDOFPlatformInfo {
-	Display *display;
-	Window window;
-	volatile GHOST_TEventNDOFData *currValues;
-	Atom cmdAtom;
-	Atom motionAtom;
-	Atom btnPressAtom;
-	Atom btnRelAtom;
-} NDOFPlatformInfo;
-
-static NDOFPlatformInfo sNdofInfo = {NULL, 0, NULL, 0, 0, 0, 0};
-
-#endif
-
 //these are for copy and select copy
 static char *txt_cut_buffer= NULL;
 static char *txt_select_buffer= NULL;
@@ -612,6 +596,8 @@
 		case FocusOut:
 		{
 			XFocusChangeEvent &xfe = xe->xfocus;
+
+			printf("X: focus %s for window %d\n", xfe.type == FocusIn ? "in" : "out", (int) xfe.window);
 		
 			// May have to look at the type of event and filter some
 			// out.
@@ -643,36 +629,6 @@
 			} else 
 #endif
 
-#if 0 // obsolete SpaceNav code
-
-			if (sNdofInfo.currValues) {
-				static GHOST_TEventNDOFData data = {0,0,0,0,0,0,0,0,0,0,0};
-				if (xcme.message_type == sNdofInfo.motionAtom)
-				{
-					data.changed = 1;
-					data.delta = xcme.data.s[8] - data.time;
-					data.time = xcme.data.s[8];
-					data.tx = xcme.data.s[2] >> 2;
-					data.ty = xcme.data.s[3] >> 2;
-					data.tz = xcme.data.s[4] >> 2;
-					data.rx = xcme.data.s[5];
-					data.ry = xcme.data.s[6];
-					data.rz =-xcme.data.s[7];
-					g_event = new GHOST_EventNDOF(getMilliSeconds(),
-					                              GHOST_kEventNDOFMotion,
-					                              window, data);
-				} else if (xcme.message_type == sNdofInfo.btnPressAtom) {
-					data.changed = 2;
-					data.delta = xcme.data.s[8] - data.time;
-					data.time = xcme.data.s[8];
-					data.buttons = xcme.data.s[2];
-					g_event = new GHOST_EventNDOF(getMilliSeconds(),
-					                              GHOST_kEventNDOFButton,
-					                              window, data);
-				}
-
-#endif
-
 			if (((Atom)xcme.data.l[0]) == m_wm_take_focus) {
 				XWindowAttributes attr;
 				Window fwin;
@@ -730,6 +686,14 @@
 					xce.y_root
 				);
 			}
+
+			printf("X: %s window %d\n", xce.type == EnterNotify ? "entering" : "leaving", (int) xce.window);
+
+			if (xce.type == EnterNotify)
+				m_windowManager->setActiveWindow(window);
+			else
+				m_windowManager->setWindowInactive(window);
+
 			break;
 		}
 		case MapNotify:

Modified: branches/merwin-spacenav/intern/ghost/intern/GHOST_SystemX11.h
===================================================================
--- branches/merwin-spacenav/intern/ghost/intern/GHOST_SystemX11.h	2011-07-01 18:21:46 UTC (rev 38025)
+++ branches/merwin-spacenav/intern/ghost/intern/GHOST_SystemX11.h	2011-07-01 21:51:44 UTC (rev 38026)
@@ -203,15 +203,6 @@
 		return m_display;
 	}	
 
-#if 0 // obsolete SpaceNav code
-
-		void *
-	prepareNdofInfo(
-		volatile GHOST_TEventNDOFData *current_values
-	);
-
-#endif
-
 	/* Helped function for get data from the clipboard. */
 	void getClipboard_xcout(XEvent evt, Atom sel, Atom target,
 			 unsigned char **txt, unsigned long *len,

Modified: branches/merwin-spacenav/source/blender/windowmanager/intern/wm_operators.c
===================================================================
--- branches/merwin-spacenav/source/blender/windowmanager/intern/wm_operators.c	2011-07-01 18:21:46 UTC (rev 38025)
+++ branches/merwin-spacenav/source/blender/windowmanager/intern/wm_operators.c	2011-07-01 21:51:44 UTC (rev 38026)
@@ -1376,6 +1376,7 @@
 
 // BEGIN ndof menu -- experimental!
 
+#if 0
 static uiBlock* wm_block_ndof_menu_1st(bContext* C, ARegion* ar, void* UNUSED(arg_op))
 {
 	uiBlock* block;
@@ -1448,9 +1449,17 @@
 	puts("ndof: menu exec");
 	return OPERATOR_FINISHED;	
 }
+#endif
 
 static int wm_ndof_menu_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
 {
+//	uiPupMenuNotice(C, "Hello!"); // <-- this works
+//	uiPupBlock(C, wm_block_ndof_menu, op); // <-- no luck!
+//	ui_popup_menu_create(C, NULL, NULL, NULL, NULL, "Hello!"); // <-- this works
+
+	uiPopupMenu* pup = uiPupMenuBegin(C,"3D mouse settings",ICON_NDOF_TURN);
+	uiLayout* layout = uiPupMenuLayout(pup);
+
 	printf("ndof: menu invoked in ");
 
 	switch (CTX_wm_area(C)->spacetype) // diff spaces can have diff 3d mouse options
@@ -1465,13 +1474,7 @@
 			puts("some iNDOFferent area");
 		}
 
-//	uiPupMenuNotice(C, "Hello!"); // <-- this works
-//	uiPupBlock(C, wm_block_ndof_menu, op); // <-- no luck!
-//	ui_popup_menu_create(C, NULL, NULL, NULL, NULL, "Hello!"); // <-- this works
 
-	uiPopupMenu* pup = uiPupMenuBegin(C,"3D mouse settings",ICON_NDOF_TURN);
-	uiLayout* layout = uiPupMenuLayout(pup);
-
 	//uiBlock* block = uiLayoutGetBlock(layout);
 	//int foo = 1;
 	//uiDefButI(block, TOG, 0, "foo", 10, 10, 9*UI_UNIT_X, UI_UNIT_Y, &foo, 0.f, 1.f, 0.1f, 0.9f, "15%");
@@ -1495,12 +1498,11 @@
 static void WM_OT_ndof_menu(wmOperatorType *ot)
 {
 	puts("ndof: registering menu operator");
-	ot->name= "NDOF Menu";
-	ot->idname= "WM_OT_ndof_menu";
+
+	ot->name = "NDOF Menu";
+	ot->idname = "WM_OT_ndof_menu";
 	
-	ot->invoke= wm_ndof_menu_invoke;
-//	ot->exec= wm_ndof_menu_exec;
-//	ot->poll= wm_ndof_menu_poll;
+	ot->invoke = wm_ndof_menu_invoke;
 }
 
 // END ndof menu




More information about the Bf-blender-cvs mailing list