[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [30690] branches/soc-2010-merwin/intern/ ghost/intern: Activated NDOF capture for Windows.

Mike Erwin significant.bit at gmail.com
Sat Jul 24 13:06:08 CEST 2010


Revision: 30690
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30690
Author:   merwin
Date:     2010-07-24 13:06:08 +0200 (Sat, 24 Jul 2010)

Log Message:
-----------
Activated NDOF capture for Windows. Robust++ for generic NDOF manager. Removed experimental Win32 mouse and NDOF code now that good solutions are in place. Cleaned up formatting.

Modified Paths:
--------------
    branches/soc-2010-merwin/intern/ghost/intern/GHOST_NDOFManager.cpp
    branches/soc-2010-merwin/intern/ghost/intern/GHOST_SystemWin32.cpp
    branches/soc-2010-merwin/intern/ghost/intern/GHOST_SystemWin32.h

Modified: branches/soc-2010-merwin/intern/ghost/intern/GHOST_NDOFManager.cpp
===================================================================
--- branches/soc-2010-merwin/intern/ghost/intern/GHOST_NDOFManager.cpp	2010-07-24 10:07:22 UTC (rev 30689)
+++ branches/soc-2010-merwin/intern/ghost/intern/GHOST_NDOFManager.cpp	2010-07-24 11:06:08 UTC (rev 30690)
@@ -15,21 +15,26 @@
  * along with this program; if not, write to the Free Software Foundation,
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
- * Contributor(s): none yet.
+ * Contributor(s): Mike Erwin, July 2010.
  *
  * ***** END GPL LICENSE BLOCK *****
  */
 
 #include "GHOST_NDOFManager.h"
 #include "GHOST_EventNDOF.h"
+#include <string.h> // for memory functions
+#include <stdio.h> // for debug tracing
 
 GHOST_NDOFManager::GHOST_NDOFManager(GHOST_System& sys)
 	: m_system(sys)
-//	, m_translation((short[]){0,0,0})
-//	, m_rotation((short[]){0,0,0})
 	, m_buttons(0)
 	, m_atRest(true)
-	{ }
+	{
+	// to avoid the rare situation where one triple is updated and
+	// the other is not, initialize them both here:
+	memset(m_translation, 0, sizeof(m_translation));
+	memset(m_rotation, 0, sizeof(m_rotation));
+	}
 
 void GHOST_NDOFManager::updateTranslation(short t[3], GHOST_TUns64 time)
 	{
@@ -68,7 +73,9 @@
 	GHOST_TEventNDOFData* data = (GHOST_TEventNDOFData*) event->getData();
 
 	const float scale = 1.f / 350.f; // SpaceNavigator sends +/- 350 usually
+	// 350 according to their developer's guide; others recommend 500 as comfortable
 
+	// possible future enhancement
 	// scale *= m_sensitivity;
 
 	data->tx = scale * m_translation[0];
@@ -80,7 +87,6 @@
 	data->rz = scale * m_rotation[2];
 
 	printf("sending T=(%.2f,%.2f,%.2f) R=(%.2f,%.2f,%.2f)\n", data->tx, data->ty, data->tz, data->rx, data->ry, data->rz);
-	fflush(stdout);
 
 	m_system.pushEvent(event);
 

Modified: branches/soc-2010-merwin/intern/ghost/intern/GHOST_SystemWin32.cpp
===================================================================
--- branches/soc-2010-merwin/intern/ghost/intern/GHOST_SystemWin32.cpp	2010-07-24 10:07:22 UTC (rev 30689)
+++ branches/soc-2010-merwin/intern/ghost/intern/GHOST_SystemWin32.cpp	2010-07-24 11:06:08 UTC (rev 30690)
@@ -27,7 +27,6 @@
  */
 
 /**
-
  * $Id$
  * Copyright (C) 2001 NaN Technologies B.V.
  * @author	Maarten Gribnau
@@ -47,28 +46,12 @@
 #endif
 #endif
 
-/*
- * According to the docs the mouse wheel message is supported from windows 98 
- * upwards. Leaving WINVER at default value, the WM_MOUSEWHEEL message and the 
- * wheel detent value are undefined.
-
- [mce] able to remove this too?
-
-#ifndef WM_MOUSEWHEEL
-#define WM_MOUSEWHEEL 0x020A
-#endif // WM_MOUSEWHEEL
-#ifndef WHEEL_DELTA
-#define WHEEL_DELTA 120	// Value for rolling one detent, (old convention! MS changed it)
-#endif // WHEEL_DELTA
- */
-
 #include "GHOST_Debug.h"
 #include "GHOST_DisplayManagerWin32.h"
 #include "GHOST_EventButton.h"
 #include "GHOST_EventCursor.h"
 #include "GHOST_EventKey.h"
 #include "GHOST_EventWheel.h"
-#include "GHOST_EventNDOF.h"
 #include "GHOST_TimerTask.h"
 #include "GHOST_TimerManager.h"
 #include "GHOST_WindowManager.h"
@@ -130,13 +113,7 @@
 
 	// register for RawInput devices
 	RAWINPUTDEVICE devices[1];
-/*
-	// standard HID mouse
-	devices[0].usUsagePage = 0x01;
-	devices[0].usUsage = 0x02;
-	devices[0].dwFlags = 0; // RIDEV_NOLEGACY; // ignore legacy mouse messages
-	devices[0].hwndTarget = NULL;
-*/
+
 	// multi-axis mouse (SpaceNavigator)
 	devices[0].usUsagePage = 0x01;
 	devices[0].usUsage = 0x08;
@@ -396,6 +373,7 @@
 
 GHOST_TSuccess GHOST_SystemWin32::exit()
 {
+	// [mce] since this duplicates its super, why bother?
 	return GHOST_System::exit();
 }
 
@@ -522,15 +500,10 @@
 }
 
 
-GHOST_EventCursor* GHOST_SystemWin32::processCursorEvent(GHOST_TEventType type, GHOST_IWindow *Iwindow, int x, int y)
+GHOST_EventCursor* GHOST_SystemWin32::processCursorEvent(GHOST_TEventType type, GHOST_IWindow *Iwindow, int x_screen, int y_screen)
 {
-	GHOST_TInt32 x_screen, y_screen;
 	GHOST_SystemWin32 * system = ((GHOST_SystemWin32 * ) getSystem());
 	GHOST_WindowWin32 * window = ( GHOST_WindowWin32 * ) Iwindow;
-	
-//	system->getCursorPosition(x_screen, y_screen);
-	x_screen = x;
-	y_screen = y;
 
 	if(window->getCursorGrabMode() != GHOST_kGrabDisable && window->getCursorGrabMode() != GHOST_kGrabNormal)
 	{
@@ -639,81 +612,10 @@
 	minmax->ptMinTrackSize.y=240;
 }
 
-bool GHOST_SystemWin32::processRawInput(RAWINPUT const& raw, GHOST_WindowWin32* window /*, int& x, int& y */ )
+bool GHOST_SystemWin32::processRawInput(RAWINPUT const& raw, GHOST_WindowWin32* window)
 {
-	GHOST_IEvent* event = NULL;
 	bool eventSent = false;
 
-	puts("BEGIN");
-
-#if 0 // now using the existing mouse button handlers, improved movement handler
-				if (raw.header.dwType == RIM_TYPEMOUSE)
-					{
-					USHORT const& buttonFlags = raw.data.mouse.usButtonFlags;
-					if (buttonFlags)
-						{
-						printf("button flags: %04X\n", buttonFlags);
-
-						if (buttonFlags & RI_MOUSE_LEFT_BUTTON_DOWN)
-							{
-							puts("left button down");
-							window->registerMouseClickEvent(true);
-							event = processButtonEvent(GHOST_kEventButtonDown, window, GHOST_kButtonMaskLeft);
-							}
-						else if (buttonFlags & RI_MOUSE_LEFT_BUTTON_UP)
-							{
-							puts("left button up");
-							window->registerMouseClickEvent(false);
-							event = processButtonEvent(GHOST_kEventButtonUp, window, GHOST_kButtonMaskLeft);
-							}
-
-						if (buttonFlags & RI_MOUSE_RIGHT_BUTTON_DOWN)
-							{
-							puts("right button down");
-							window->registerMouseClickEvent(true);
-							event = processButtonEvent(GHOST_kEventButtonDown, window, GHOST_kButtonMaskRight);
-							}
-						else if (buttonFlags & RI_MOUSE_RIGHT_BUTTON_UP)
-							{
-							puts("right button up");
-							window->registerMouseClickEvent(false);
-							event = processButtonEvent(GHOST_kEventButtonUp, window, GHOST_kButtonMaskRight);
-							}
-
-						if (buttonFlags & RI_MOUSE_MIDDLE_BUTTON_DOWN)
-							{
-							puts("middle button down");
-							window->registerMouseClickEvent(true);
-							event = processButtonEvent(GHOST_kEventButtonDown, window, GHOST_kButtonMaskMiddle);
-							}
-						else if (buttonFlags & RI_MOUSE_MIDDLE_BUTTON_UP)
-							{
-							puts("middle button up");
-							window->registerMouseClickEvent(false);
-							event = processButtonEvent(GHOST_kEventButtonUp, window, GHOST_kButtonMaskMiddle);
-							}
-
-						// similar for BUTTON_4 and BUTTON_5
-
-						if (buttonFlags & RI_MOUSE_WHEEL)
-							{
-							signed short wheelDelta = raw.data.mouse.usButtonData;
-							printf("wheel moved %+d\n", wheelDelta);
-							}
-						}
-
-					int dx = raw.data.mouse.lLastX; // These might be in Mickeys, not pixels.
-					int dy = raw.data.mouse.lLastY;
-					if (dx || dy)
-						{
-						printf("mouse moved <%+d,%+d>\n", dx, dy);
-						x += dx;
-						x += dy;
-						event = processCursorEvent(GHOST_kEventCursorMove, window, x, y);
-						}
-					}
-#endif // unused experimental mouse code
-
 	if (raw.header.dwType == RIM_TYPEHID)
 		{
 //		RID_DEVICE_INFO info;
@@ -738,16 +640,20 @@
 No other registered devices use the c62_ space, so a simple mask will work!
 */
 
+		// The NDOF manager sends button changes immediately, and *pretends* to
+		// send motion. Mark as 'sent' so motion will always get dispatched.
+		eventSent = true;
+
 		// multiple events per RAWHID? MSDN hints at this.
-		printf("%d events\n", raw.data.hid.dwCount);
+		printf("%d events\n", (int)raw.data.hid.dwCount);
 
 		BYTE const* data = &raw.data.hid.bRawData;
-// MinGW's definition (below) doesn't agree with MSDN reference for bRawData:
-// typedef struct tagRAWHID {
-// 	DWORD dwSizeHid;
-// 	DWORD dwCount;
-// 	BYTE bRawData;
-// } RAWHID,*PRAWHID,*LPRAWHID;
+		// MinGW's definition (below) doesn't agree with MSDN reference for bRawData:
+		// typedef struct tagRAWHID {
+		// 	DWORD dwSizeHid;
+		// 	DWORD dwCount;
+		// 	BYTE bRawData; // <== isn't this s'posed to be a BYTE*?
+		// } RAWHID,*PRAWHID,*LPRAWHID;
 
 		BYTE packetType = data[0];
 		switch (packetType)
@@ -756,16 +662,20 @@
 				{
 				short t[3];
 				memcpy(t, data + 1, sizeof(t));
-				printf("T: %+5d %+5d %+5d\n", t[0], t[1], t[2]);
-				m_ndofManager->updateTranslation(t, getMilliseconds());
+				// too much noise -- disable for now
+				// printf("T: %+5d %+5d %+5d\n", t[0], t[1], t[2]);
+				m_ndofManager->updateTranslation(t, getMilliSeconds());
+				// wariness of alignment issues prevents me from saying it this way:
+				// m_ndofManager->updateTranslation((short*)(data + 1), getMilliSeconds());
+				// though it probably (94.7%) works fine
 				break;
 				}
 			case 2: // rotation
 				{
 				short r[3];
 				memcpy(r, data + 1, sizeof(r));
-				printf("R: %+5d %+5d %+5d\n", r[0], r[1], r[2]);
-				m_ndofManager->updateRotation(r, getMilliseconds());
+				// printf("R: %+5d %+5d %+5d\n", r[0], r[1], r[2]);
+				m_ndofManager->updateRotation(r, getMilliSeconds());
 				break;
 				}
 			case 3: // buttons
@@ -783,24 +693,11 @@
 					}
 				else
 					printf(" none\n");
-				m_ndofManager->updateButtons(buttons, getMilliseconds());
+				m_ndofManager->updateButtons(buttons, getMilliSeconds());
 				break;
 				}
 			}
 		}
-
-	// assume only one event will come from this RawInput report
-	// test and adjust assumptions as needed!
-
-	if (event)
-		{
-		pushEvent(event);
-		event = NULL;
-		eventSent = true;
-		}
-
-	puts("END");
-
 	return eventSent;
 }
 
@@ -823,6 +720,7 @@
 		}
 
 	// search for 'prev' point (we want only newer points)
+	// TODO: detect & ignore points that don't belong to our window
 	for (int i = 1; i < n; ++i)
 		if (morePoints[i].x == xPrev && morePoints[i].y == yPrev)
 			{
@@ -835,13 +733,14 @@
 		signed short x = morePoints[i].x;
 		signed short y = morePoints[i].y;
 
-		printf("> (%d,%d)\n", x, y);
-		
+		// uncomment here and in WM_MOUSEMOVE handler to show effectiveness of hi-fi input
+		// printf("> (%d,%d)\n", x, y);
+
 		pushEvent(processCursorEvent(GHOST_kEventCursorMove, window, x, y));
 		}
 
 	return n;
-	} // END getMoreMousePoints
+	}
 
 LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 {
@@ -901,480 +800,427 @@
 
 	static int mousePosX = 0, mousePosY = 0; // track mouse position between calls
 
-			switch (msg) {
-				////////////////////////////////////////////////////////////////////////
-				// Keyboard events, processed

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list