[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [30619] branches/soc-2010-merwin/intern/ ghost: revamped NDOF event system for ghost, added (untested) Mac support
Mike Erwin
significant.bit at gmail.com
Thu Jul 22 09:23:42 CEST 2010
Revision: 30619
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=30619
Author: merwin
Date: 2010-07-22 09:23:41 +0200 (Thu, 22 Jul 2010)
Log Message:
-----------
revamped NDOF event system for ghost, added (untested) Mac support
Modified Paths:
--------------
branches/soc-2010-merwin/intern/ghost/GHOST_Types.h
branches/soc-2010-merwin/intern/ghost/intern/GHOST_EventNDOF.h
branches/soc-2010-merwin/intern/ghost/intern/GHOST_NDOFManager.cpp
branches/soc-2010-merwin/intern/ghost/intern/GHOST_NDOFManager.h
Added Paths:
-----------
branches/soc-2010-merwin/intern/ghost/intern/GHOST_NDOFManagerCocoa.cpp
branches/soc-2010-merwin/intern/ghost/intern/GHOST_NDOFManagerCocoa.h
Modified: branches/soc-2010-merwin/intern/ghost/GHOST_Types.h
===================================================================
--- branches/soc-2010-merwin/intern/ghost/GHOST_Types.h 2010-07-22 07:18:12 UTC (rev 30618)
+++ branches/soc-2010-merwin/intern/ghost/GHOST_Types.h 2010-07-22 07:23:41 UTC (rev 30619)
@@ -154,7 +154,8 @@
GHOST_kEventTrackpad, /// Trackpad event
GHOST_kEventNDOFMotion, /// N degree of freedom device motion event
- GHOST_kEventNDOFButton, /// N degree of freedom device button event
+ GHOST_kEventNDOFButtonDown,/// N degree of freedom device button events
+ GHOST_kEventNDOFButtonUp,
GHOST_kEventKeyDown,
GHOST_kEventKeyUp,
@@ -432,17 +433,17 @@
// float dt;
//} GHOST_TEventNDOFData;
-typedef struct {
- /** N-degree of freedom device data v2*/
- int changed;
- GHOST_TUns64 client;
- GHOST_TUns64 address;
- GHOST_TInt16 tx, ty, tz; /** -x left, +y up, +z forward */
- GHOST_TInt16 rx, ry, rz;
- GHOST_TInt16 buttons;
- GHOST_TUns64 time;
- GHOST_TUns64 delta;
-} GHOST_TEventNDOFData;
+// typedef struct {
+// /** N-degree of freedom device data v2*/
+// int changed;
+// GHOST_TUns64 client;
+// GHOST_TUns64 address;
+// GHOST_TInt16 tx, ty, tz; /** -x left, +y up, +z forward */
+// GHOST_TInt16 rx, ry, rz;
+// GHOST_TInt16 buttons;
+// GHOST_TUns64 time;
+// GHOST_TUns64 delta;
+// } GHOST_TEventNDOFData;
typedef struct {
/** N-degree of freedom device data v3 [GSoC 2010]*/
@@ -454,13 +455,8 @@
float tx, ty, tz; /** -x left, +y forward, -z up */
float rx, ry, rz;
- GHOST_TInt16 buttons;
-} GHOST_TEventNDOFData_3;
+} GHOST_TEventNDOFData;
-// [mce] consider scrapping these, in favor of built-in SpaceNav handling.
-typedef int (*GHOST_NDOFLibraryInit_fp)();
-typedef void (*GHOST_NDOFLibraryShutdown_fp)(void* deviceHandle);
-typedef void* (*GHOST_NDOFDeviceOpen_fp)(void* platformData);
typedef struct {
/** The key code. */
Modified: branches/soc-2010-merwin/intern/ghost/intern/GHOST_EventNDOF.h
===================================================================
--- branches/soc-2010-merwin/intern/ghost/intern/GHOST_EventNDOF.h 2010-07-22 07:18:12 UTC (rev 30618)
+++ branches/soc-2010-merwin/intern/ghost/intern/GHOST_EventNDOF.h 2010-07-22 07:23:41 UTC (rev 30619)
@@ -26,32 +26,35 @@
#include "GHOST_Event.h"
-/**
- * N-degree of freedom device event.
- */
-class GHOST_EventNDOF : public GHOST_Event
+
+class GHOST_EventNDOFMotion : public GHOST_Event
{
+protected:
+ GHOST_TEventNDOFData m_axisData;
+
public:
- /**
- * Constructor.
- * @param msec The time this event was generated.
- * @param type The type of this event.
- * @param x The x-coordinate of the location the cursor was at at the time of the event.
- * @param y The y-coordinate of the location the cursor was at at the time of the event.
- */
- GHOST_EventNDOF(GHOST_TUns64 msec, GHOST_TEventType type, GHOST_IWindow* window,
- GHOST_TEventNDOFData data)
- : GHOST_Event(msec, type, window)
- {
- m_ndofEventData = data;
- m_data = &m_ndofEventData;
- }
+ GHOST_EventNDOFMotion(GHOST_TUns64 time)
+ : GHOST_Event(time, GHOST_kEventNDOFMotion, NULL)
+// , m_data(&m_axisData)
+ {
+ m_data = &m_axisData;
+ }
+};
+class GHOST_EventNDOFButton : public GHOST_Event
+{
protected:
- /** translation & rotation from the device. */
- GHOST_TEventNDOFData m_ndofEventData;
+ GHOST_TUns16 m_buttonNumber;
+
+public:
+ GHOST_EventNDOFButton(GHOST_TUns64 time, GHOST_TUns16 buttonNumber, GHOST_TEventType upOrDown)
+ : GHOST_Event(time, upOrDown, NULL)
+ , m_buttonNumber(buttonNumber)
+// , m_data(&m_buttonNumber)
+ {
+ m_data = &m_buttonNumber;
+ }
};
#endif // _GHOST_EVENT_NDOF_H_
-
Modified: branches/soc-2010-merwin/intern/ghost/intern/GHOST_NDOFManager.cpp
===================================================================
--- branches/soc-2010-merwin/intern/ghost/intern/GHOST_NDOFManager.cpp 2010-07-22 07:18:12 UTC (rev 30618)
+++ branches/soc-2010-merwin/intern/ghost/intern/GHOST_NDOFManager.cpp 2010-07-22 07:23:41 UTC (rev 30619)
@@ -20,108 +20,70 @@
* ***** END GPL LICENSE BLOCK *****
*/
-#include <stdio.h> /* just for printf */
-
#include "GHOST_NDOFManager.h"
+#include "GHOST_EventNDOF.h"
+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)
+ { }
-// the variable is outside the class because it must be accessed from plugin
-static volatile GHOST_TEventNDOFData currentNdofValues = {0,0,0,0,0,0,0,0,0,0,0};
+void GHOST_NDOFManager::updateTranslation(short t[3], GHOST_TUns64 time)
+ {
+ memcpy(m_translation, t, sizeof(m_translation));
+ m_motionTime = time;
+ m_atRest = false;
+ }
-#if !defined(_WIN32) && !defined(__APPLE__)
-#include "GHOST_SystemX11.h"
-#endif
+void GHOST_NDOFManager::updateRotation(short r[3], GHOST_TUns64 time)
+ {
+ memcpy(m_rotation, r, sizeof(m_rotation));
+ m_motionTime = time;
+ m_atRest = false;
+ }
-namespace
-{
- GHOST_NDOFLibraryInit_fp ndofLibraryInit = 0;
- GHOST_NDOFLibraryShutdown_fp ndofLibraryShutdown = 0;
- GHOST_NDOFDeviceOpen_fp ndofDeviceOpen = 0;
-}
+void GHOST_NDOFManager::updateButtons(unsigned short buttons, GHOST_TUns64 time)
+ {
+ unsigned short diff = m_buttons ^ buttons;
+ for (int i = 0; i < 16; ++i)
+ {
+ unsigned short mask = 1 << i;
+ if (diff & mask)
+ m_system.pushEvent(new GHOST_EventNDOFButton(time, i + 1,
+ (buttons & mask) ? GHOST_kEventNDOFButtonDown : GHOST_kEventNDOFButtonUp));
+ }
-GHOST_NDOFManager::GHOST_NDOFManager()
-{
- m_DeviceHandle = 0;
+ m_buttons = buttons;
+ }
- // discover the API from the plugin
- ndofLibraryInit = 0;
- ndofLibraryShutdown = 0;
- ndofDeviceOpen = 0;
-}
+bool GHOST_NDOFManager::sendMotionEvent()
+ {
+ if (m_atRest)
+ return false;
-GHOST_NDOFManager::~GHOST_NDOFManager()
-{
- if (ndofLibraryShutdown)
- ndofLibraryShutdown(m_DeviceHandle);
+ GHOST_EventNDOFMotion* event = new GHOST_EventNDOFMotion(m_motionTime);
+ GHOST_TEventNDOFData* data = (GHOST_TEventNDOFData*) event->getData();
- m_DeviceHandle = 0;
-}
+ const float scale = 1.f / 350.f; // SpaceNavigator sends +/- 350 usually
+ // scale *= m_sensitivity;
-int
-GHOST_NDOFManager::deviceOpen(GHOST_IWindow* window,
- GHOST_NDOFLibraryInit_fp setNdofLibraryInit,
- GHOST_NDOFLibraryShutdown_fp setNdofLibraryShutdown,
- GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen)
-{
- int Pid;
-
- ndofLibraryInit = setNdofLibraryInit;
- ndofLibraryShutdown = setNdofLibraryShutdown;
- ndofDeviceOpen = setNdofDeviceOpen;
+ data->tx = scale * m_translation[0];
+ data->ty = scale * m_translation[1];
+ data->tz = scale * m_translation[2];
- if (ndofLibraryInit && ndofDeviceOpen)
- {
- Pid= ndofLibraryInit();
-#if 0
- printf("%i client \n", Pid);
-#endif
- #if defined(_WIN32) || defined(__APPLE__)
- m_DeviceHandle = ndofDeviceOpen((void *)¤tNdofValues);
- #else
- GHOST_SystemX11 *sys;
- sys = static_cast<GHOST_SystemX11*>(GHOST_ISystem::getSystem());
- void *ndofInfo = sys->prepareNdofInfo(¤tNdofValues);
- m_DeviceHandle = ndofDeviceOpen(ndofInfo);
- #endif
- return (Pid > 0) ? 0 : 1;
-
- } else
- return 1;
-}
+ data->rx = scale * m_rotation[0];
+ data->ry = scale * m_rotation[1];
+ data->rz = scale * m_rotation[2];
+ m_system.pushEvent(event);
-bool
-GHOST_NDOFManager::available() const
-{
- return m_DeviceHandle != 0;
-}
-
-bool
-GHOST_NDOFManager::event_present() const
-{
- if( currentNdofValues.changed >0) {
- printf("time %llu but%u x%i y%i z%i rx%i ry%i rz%i \n" ,
- currentNdofValues.time, currentNdofValues.buttons,
- currentNdofValues.tx,currentNdofValues.ty,currentNdofValues.tz,
- currentNdofValues.rx,currentNdofValues.ry,currentNdofValues.rz);
- return true;
- }else
- return false;
-
-}
-
-void GHOST_NDOFManager::GHOST_NDOFGetDatas(GHOST_TEventNDOFData &datas) const
-{
- datas.tx = currentNdofValues.tx;
- datas.ty = currentNdofValues.ty;
- datas.tz = currentNdofValues.tz;
- datas.rx = currentNdofValues.rx;
- datas.ry = currentNdofValues.ry;
- datas.rz = currentNdofValues.rz;
- datas.buttons = currentNdofValues.buttons;
- datas.client = currentNdofValues.client;
- datas.address = currentNdofValues.address;
- datas.time = currentNdofValues.time;
- datas.delta = currentNdofValues.delta;
-}
+ // '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;
+
+ return true;
+ }
Modified: branches/soc-2010-merwin/intern/ghost/intern/GHOST_NDOFManager.h
===================================================================
--- branches/soc-2010-merwin/intern/ghost/intern/GHOST_NDOFManager.h 2010-07-22 07:18:12 UTC (rev 30618)
+++ branches/soc-2010-merwin/intern/ghost/intern/GHOST_NDOFManager.h 2010-07-22 07:23:41 UTC (rev 30619)
@@ -24,28 +24,38 @@
#define _GHOST_NDOFMANAGER_H_
#include "GHOST_System.h"
-#include "GHOST_IWindow.h"
-
class GHOST_NDOFManager
{
public:
- GHOST_NDOFManager();
- virtual ~GHOST_NDOFManager();
+ GHOST_NDOFManager(GHOST_System&);
- int deviceOpen(GHOST_IWindow* window,
- GHOST_NDOFLibraryInit_fp setNdofLibraryInit,
- GHOST_NDOFLibraryShutdown_fp setNdofLibraryShutdown,
- GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen);
-
- void GHOST_NDOFGetDatas(GHOST_TEventNDOFData &datas) const;
-
- bool available() const;
- bool event_present() const;
+ virtual ~GHOST_NDOFManager() {};
+ // whether multi-axis functionality is available (via the OS or driver)
+ // does not imply that a device is plugged in or being used
+ virtual bool available() = 0;
+
+ // the latest raw data from the device
+ void updateTranslation(short t[3], GHOST_TUns64 time);
+ void updateRotation(short r[3], GHOST_TUns64 time);
+ // this one sends events immediately for changed buttons
+ void updateButtons(unsigned short b, GHOST_TUns64 time);
+
+ // processes most recent raw data into an NDOFMotion event and sends it
+ // returns whether an event was sent
+ bool sendMotionEvent();
+
protected:
- void* m_DeviceHandle;
+ GHOST_System& m_system;
+
+ short m_translation[3];
+ short m_rotation[3];
+ unsigned short m_buttons;
+
+ GHOST_TUns64 m_motionTime;
+ bool m_atRest;
};
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list