first workable version on Os X
authorJean-Luc Peurière <jlp@nerim.net>
Tue, 12 Jun 2007 20:01:28 +0000 (20:01 +0000)
committerJean-Luc Peurière <jlp@nerim.net>
Tue, 12 Jun 2007 20:01:28 +0000 (20:01 +0000)
work only in non camera mode in 3D view

need the external plug-in to be compiled separately

line 894 of ghostwinlay.c must be replaced with
values adapted at your system

see mailing list for features planned and how
to use

14 files changed:
intern/ghost/GHOST_C-api.h
intern/ghost/GHOST_ISystem.h
intern/ghost/GHOST_Types.h
intern/ghost/intern/GHOST_C-api.cpp
intern/ghost/intern/GHOST_EventNDOF.h
intern/ghost/intern/GHOST_NDOFManager.cpp
intern/ghost/intern/GHOST_NDOFManager.h
intern/ghost/intern/GHOST_System.cpp
intern/ghost/intern/GHOST_System.h
intern/ghost/intern/GHOST_SystemCarbon.cpp
intern/ghost/intern/GHOST_SystemCarbon.h
source/blender/src/ghostwinlay.c
source/blender/src/space.c
source/blender/src/view.c

index d5fc87c16f6e8490cfe66611f2ca568fa17f69f2..568437b42317ce0f69511b94561595613272a269 100644 (file)
@@ -276,8 +276,11 @@ extern void GHOST_OpenNDOF(GHOST_SystemHandle systemhandle,
                            GHOST_WindowHandle windowhandle,
                           GHOST_NDOFLibraryInit_fp setNdofLibraryInit, 
                           GHOST_NDOFLibraryShutdown_fp setNdofLibraryShutdown,
-                          GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen,
-                          GHOST_NDOFEventHandler_fp setNdofEventHandler);
+                          GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen
+                          );
+ // original patch only 
+ //                         GHOST_NDOFEventHandler_fp setNdofEventHandler);
 
 /***************************************************************************************
  ** Cursor management functionality
index 9c0cef2b4f02e8495f6ecefb2c9c531d83be7a02..541a78cbaa9a1e489ed941864c38fbb52f21f54d 100644 (file)
@@ -305,8 +305,10 @@ public:
    virtual void openNDOF(GHOST_IWindow*,
        GHOST_NDOFLibraryInit_fp setNdofLibraryInit, 
        GHOST_NDOFLibraryShutdown_fp setNdofLibraryShutdown,
-       GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen,
-       GHOST_NDOFEventHandler_fp setNdofEventHandler) = 0;
+       GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen
+       // original patch only
+      // GHOST_NDOFEventHandler_fp setNdofEventHandler
+       ) = 0;
 
 
        /***************************************************************************************
index f8f9a8d4735d3cedd0f41872153213dc8d20786a..9b8a402a195c191e2b8c01a3824e6b7f5db62cc1 100644 (file)
@@ -338,19 +338,38 @@ typedef struct {
        GHOST_TInt32 z; 
 } GHOST_TEventWheelData;
 
-typedef int     (*GHOST_NDOFLibraryInit_fp)();
-typedef void    (*GHOST_NDOFLibraryShutdown_fp)(void* deviceHandle);
-typedef void*   (*GHOST_NDOFDeviceOpen_fp)(void* platformData);
-typedef int     (*GHOST_NDOFEventHandler_fp)(float* result7, void* deviceHandle, unsigned int message, unsigned int* wParam, unsigned long* lParam);
 
 /* original patch used floats, but the driver return ints and uns. We will calibrate in view, no sense on doing conversions twice */
+/* as all USB device controls are likely to use ints, this is also more future proof */
+//typedef struct {
+//   /** N-degree of freedom device data */
+//   float tx, ty, tz;   /** -x left, +y up, +z forward */
+//   float rx, ry, rz;
+//   float dt;
+//} GHOST_TEventNDOFData;
+
 typedef struct {
-   /** N-degree of freedom device data */
-   float tx, ty, tz;   /** -x left, +y up, +z forward */
-   float rx, ry, rz;
-   float dt;
+   /** 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 int     (*GHOST_NDOFLibraryInit_fp)();
+typedef void    (*GHOST_NDOFLibraryShutdown_fp)(void* deviceHandle);
+typedef void*   (*GHOST_NDOFDeviceOpen_fp)(void* platformData);
+
+// original patch windows callback. In mac os X version the callback is internal to the plug-in and post an event to main thead.
+// not necessary faster, but better integration with other events. 
+
+//typedef int     (*GHOST_NDOFEventHandler_fp)(float* result7, void* deviceHandle, unsigned int message, unsigned int* wParam, unsigned long* lParam);
+//typedef void     (*GHOST_NDOFCallBack_fp)(GHOST_TEventNDOFDataV2 *VolDatas);
+
 typedef struct {
        /** The key code. */
        GHOST_TKey              key;
index cbecb49c80b8de147a051a9d9e55020472f97902..8fa79261483ff38f8071cdd15526b9d87dc475e0 100644 (file)
@@ -262,13 +262,16 @@ GHOST_TSuccess GHOST_AddEventConsumer(GHOST_SystemHandle systemhandle, GHOST_Eve
 void GHOST_OpenNDOF(GHOST_SystemHandle systemhandle, GHOST_WindowHandle windowhandle,
    GHOST_NDOFLibraryInit_fp setNdofLibraryInit, 
     GHOST_NDOFLibraryShutdown_fp setNdofLibraryShutdown,
-    GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen,
-    GHOST_NDOFEventHandler_fp setNdofEventHandler)
+    GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen)
+  //original patch only
+  /*  GHOST_NDOFEventHandler_fp setNdofEventHandler)*/
 {
        GHOST_ISystem* system = (GHOST_ISystem*) systemhandle;
 
     system->openNDOF((GHOST_IWindow*) windowhandle,
-        setNdofLibraryInit, setNdofLibraryShutdown, setNdofDeviceOpen, setNdofEventHandler);
+        setNdofLibraryInit, setNdofLibraryShutdown, setNdofDeviceOpen);
+//     original patch
+//        setNdofLibraryInit, setNdofLibraryShutdown, setNdofDeviceOpen, setNdofEventHandler);
 }
 
 
index 1eadebd92ac7572524601718fcc15a4b4deab4e5..76f5a9e0894d209151ea4a95aaefde3408e2e034 100644 (file)
@@ -1,14 +1,10 @@
-/**
- * $Id: GHOST_EventNdof.h,v 1.6 2002/12/28 22:26:45 maarten Exp $
- * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
+/*
+ * ***** BEGIN GPL 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.
+ * of the License, or (at your option) any later version. 
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * 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 Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
  * Contributor(s): none yet.
  *
- * ***** END GPL/BL DUAL LICENSE BLOCK *****
- */
-/**
- * @file       GHOST_EventNdof.h
- * Declaration of GHOST_EventNdof class.
+ * ***** END GPL LICENSE BLOCK *****
  */
 
 #ifndef _GHOST_EVENT_NDOF_H_
 #define _GHOST_EVENT_NDOF_H_
index 3ac3d483d18b8e1bb7f20c7b20fe98af231edd6e..1bfaf390544a83ac1902164f67df257b066318ff 100644 (file)
@@ -1,21 +1,23 @@
-
-// Insert Blender compatible license here :-)
-
-// note: an implementation is currently only provided for Windows, but designed to be easy to move to Linux, etc.
-
-/**
-
-    To use this implemenation, you must specify the #define WITH_SPACEBALL for the ghost library.
-    Only this cpp file is affected by the macro, the header file and everything else are independent
-    of the spaceball libraries.
-
-    The 3dXWare SDK is available from the tab on the left side of -
-    http://www.3dconnexion.com/support/4a.php
-
-    The SDK is necessary to build this file with WITH_SPACEBALL defined.
-
-    For this stuff to work, siappdll.dll and spwini.dll must be in the executable path of blender
-
+/*
+ * ***** BEGIN GPL 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. 
+ *
+ * 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.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
  */
 
 
 //#include "GHOST_WindowWin32.h"
 
 
-
-
+// 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};
 
 namespace
 {
     GHOST_NDOFLibraryInit_fp ndofLibraryInit = 0;
     GHOST_NDOFLibraryShutdown_fp ndofLibraryShutdown = 0;
     GHOST_NDOFDeviceOpen_fp ndofDeviceOpen = 0;
-    GHOST_NDOFEventHandler_fp ndofEventHandler = 0;
+//    GHOST_NDOFEventHandler_fp ndofEventHandler = 0;
+    
+    
 }
 
 
@@ -45,8 +49,7 @@ GHOST_NDOFManager::GHOST_NDOFManager()
     ndofLibraryInit = 0;
     ndofLibraryShutdown = 0;
     ndofDeviceOpen = 0;
-    ndofEventHandler = 0;
-   // available = 0;
+ //   ndofEventHandler = 0;
 }
 
 GHOST_NDOFManager::~GHOST_NDOFManager()
@@ -62,18 +65,22 @@ void
 GHOST_NDOFManager::deviceOpen(GHOST_IWindow* window,
         GHOST_NDOFLibraryInit_fp setNdofLibraryInit, 
         GHOST_NDOFLibraryShutdown_fp setNdofLibraryShutdown,
-        GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen,
-        GHOST_NDOFEventHandler_fp setNdofEventHandler)
+        GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen)
+//        GHOST_NDOFEventHandler_fp setNdofEventHandler)
 {
     ndofLibraryInit = setNdofLibraryInit;
     ndofLibraryShutdown = setNdofLibraryShutdown;
     ndofDeviceOpen = setNdofDeviceOpen;
-    ndofEventHandler = setNdofEventHandler;
+//      original patch    
+//    ndofEventHandler = setNdofEventHandler;
 
     if (ndofLibraryInit  && ndofDeviceOpen)
     {
        printf("%i client \n", ndofLibraryInit());
-    }
+               m_DeviceHandle = ndofDeviceOpen((void *)&currentNdofValues);    
+       }
+    
+    
 /*
     if (ndofDeviceOpen)
     {
@@ -87,7 +94,8 @@ GHOST_NDOFManager::deviceOpen(GHOST_IWindow* window,
 }
 
 
-
+/** original patch only */
+/*  
 GHOST_TEventNDOFData*
 GHOST_NDOFManager::handle(unsigned int message, unsigned int* wParam, unsigned long* lParam)
 {
@@ -100,7 +108,7 @@ GHOST_NDOFManager::handle(unsigned int message, unsigned int* wParam, unsigned l
     printf("handled %i\n", handled);
     return handled ? &sbdata : 0;
 }
-
+*/
 
 bool 
 GHOST_NDOFManager::available() 
@@ -108,3 +116,40 @@ GHOST_NDOFManager::available()
     return m_DeviceHandle != 0; 
 }
 
+bool 
+GHOST_NDOFManager::event_present() 
+{ 
+    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)
+{
+               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;
+
+}
+
+/*
+//#ifdef
+OSStatus GHOST_SystemCarbon::blendEventHandlerProc(EventHandlerCallRef handler, EventRef event, void* userData)
+{
+}
+
+*/
index 69e7f8e25f00846cc4137be76d0551191400e972..2e905ed53d2d085b74ebcdf2aa44cad5b4ca2381 100644 (file)
@@ -1,4 +1,25 @@
-
+/*
+ * ***** BEGIN GPL 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. 
+ *
+ * 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.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
 #ifndef _GHOST_NDOFMANAGER_H_
 #define _GHOST_NDOFMANAGER_H_
 
@@ -23,13 +44,18 @@ public:
     void deviceOpen(GHOST_IWindow* window,
         GHOST_NDOFLibraryInit_fp setNdofLibraryInit, 
         GHOST_NDOFLibraryShutdown_fp setNdofLibraryShutdown,
-        GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen,
-        GHOST_NDOFEventHandler_fp setNdofEventHandler);
+        GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen);
+        
+    void GHOST_NDOFGetDatas(GHOST_TEventNDOFData &datas);
+        
+//        GHOST_NDOFEventHandler_fp setNdofEventHandler);
 
     bool available();
+    bool event_present();
 
+/* original patch. unused now */
     /* to do: abstract for Linux, MacOS, etc. */
-    GHOST_TEventNDOFData* handle(unsigned int message, unsigned int* wparam, unsigned long* lparam);
+//    GHOST_TEventNDOFData* handle(unsigned int message, unsigned int* wparam, unsigned long* lparam);
 
 protected:
     void* m_DeviceHandle;
index 7daeca9566bc9e2c03ca3fde9a9bcd980a0e809f..674b1f67d55b7f18ae90f32d5bac215a126d23aa 100644 (file)
@@ -243,14 +243,15 @@ GHOST_TSuccess GHOST_System::pushEvent(GHOST_IEvent* event)
 void GHOST_System::openNDOF(GHOST_IWindow* w,
         GHOST_NDOFLibraryInit_fp setNdofLibraryInit, 
         GHOST_NDOFLibraryShutdown_fp setNdofLibraryShutdown,
-        GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen,
-        GHOST_NDOFEventHandler_fp setNdofEventHandler)
+        GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen)
+// original patch only
+//        GHOST_NDOFEventHandler_fp setNdofEventHandler)
 {
     m_ndofManager->deviceOpen(w,
         setNdofLibraryInit, 
         setNdofLibraryShutdown,
-        setNdofDeviceOpen,
-        setNdofEventHandler);
+        setNdofDeviceOpen);
//       setNdofEventHandler);
 }
 
 
index e7014b14f51f08c66031bc39a89e51a67a3abcac..a45196ee3da90ab239ed8639f5bbe8e1037ca5ff 100644 (file)
@@ -197,8 +197,10 @@ public:
     virtual void openNDOF(GHOST_IWindow* w,        
         GHOST_NDOFLibraryInit_fp setNdofLibraryInit, 
         GHOST_NDOFLibraryShutdown_fp setNdofLibraryShutdown,
-        GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen,
-        GHOST_NDOFEventHandler_fp setNdofEventHandler);
+        GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen);
+        
+// original patch only        
+//        GHOST_NDOFEventHandler_fp setNdofEventHandler);
 
 
 
index e1e3853e8a86efa51107ecb7dc63c19c6f456f3c..056addddeb12f2a9f6d75f816efce886bed5eb72 100644 (file)
 #include "GHOST_EventButton.h"
 #include "GHOST_EventCursor.h"
 #include "GHOST_EventWheel.h"
+#include "GHOST_EventNDOF.h"
+
 #include "GHOST_TimerManager.h"
 #include "GHOST_TimerTask.h"
 #include "GHOST_WindowManager.h"
 #include "GHOST_WindowCarbon.h"
+#include "GHOST_NDOFManager.h"
 
 #define GHOST_KEY_SWITCH(mac, ghost) { case (mac): ghostKey = (ghost); break; }
 
+/* blender class and types events */
+enum {
+  kEventClassBlender              = 'blnd'
+};
+
+enum {
+       kEventBlenderNdofAxis                   = 1,
+       kEventBlenderNdofButtons                = 2
+};
+
 const EventTypeSpec    kEvents[] =
 {
        { kEventClassAppleEvent, kEventAppleEvent },
-       
 /*
        { kEventClassApplication, kEventAppActivated },
        { kEventClassApplication, kEventAppDeactivated },
 */     
-
        { kEventClassKeyboard, kEventRawKeyDown },
        { kEventClassKeyboard, kEventRawKeyRepeat },
        { kEventClassKeyboard, kEventRawKeyUp },
@@ -84,7 +95,12 @@ const EventTypeSpec  kEvents[] =
        { kEventClassWindow, kEventWindowActivated },
        { kEventClassWindow, kEventWindowDeactivated },
        { kEventClassWindow, kEventWindowUpdate },
-       { kEventClassWindow, kEventWindowBoundsChanged }
+       { kEventClassWindow, kEventWindowBoundsChanged },
+       
+       { kEventClassBlender, kEventBlenderNdofAxis },
+       { kEventClassBlender, kEventBlenderNdofButtons }
+       
+       
        
 };
 
@@ -416,7 +432,9 @@ GHOST_IWindow* GHOST_SystemCarbon::createWindow(
     return window;
 }
 
-
+/* this is an old style low level event queue.
+  As we want to handle our own timers, this is ok.
+  the full screen hack should be removed */
 bool GHOST_SystemCarbon::processEvents(bool waitForEvent)
 {
        bool anyProcessed = false;
@@ -424,7 +442,7 @@ bool GHOST_SystemCarbon::processEvents(bool waitForEvent)
        
        do {
                GHOST_TimerManager* timerMgr = getTimerManager();
-
+               
                if (waitForEvent) {
                        GHOST_TUns64 curtime = getMilliSeconds();
                        GHOST_TUns64 next = timerMgr->nextFireTime();
@@ -455,6 +473,8 @@ bool GHOST_SystemCarbon::processEvents(bool waitForEvent)
                        }
                }
 
+               
+               /* end loop when no more events available */
                while (::ReceiveNextEvent(0, NULL, 0, true, &event)==noErr) {
                        OSStatus status= ::SendEventToEventTarget(event, ::GetEventDispatcherTarget());
                        if (status==noErr) {
@@ -466,7 +486,7 @@ bool GHOST_SystemCarbon::processEvents(bool waitForEvent)
                                         * are, but we get a lot of them
                                         */
                                if (i!='cgs ') {
-                                       //printf("Missed - Class: '%.4s', Kind: %d\n", &i, ::GetEventKind(event));
+                                       printf("Missed - Class: '%.4s', Kind: %d\n", &i, ::GetEventKind(event));
                                }
                        }
                        ::ReleaseEvent(event);
@@ -610,6 +630,7 @@ OSErr GHOST_SystemCarbon::sAEHandlerQuit(const AppleEvent *event, AppleEvent *re
 
 GHOST_TSuccess GHOST_SystemCarbon::init()
 {
     GHOST_TSuccess success = GHOST_System::init();
     if (success) {
                /*
@@ -629,6 +650,7 @@ GHOST_TSuccess GHOST_SystemCarbon::init()
                ::AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, sAEHandlerOpenDocs, (SInt32) this, false);
                ::AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, sAEHandlerPrintDocs, (SInt32) this, false);
                ::AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, sAEHandlerQuit, (SInt32) this, false);
+               
     }
     return success;
 }
@@ -765,6 +787,7 @@ OSStatus GHOST_SystemCarbon::handleTabletEvent(EventRef event)
                }
        err = noErr;
        }
+
 }
 
 OSStatus GHOST_SystemCarbon::handleMouseEvent(EventRef event)
@@ -1039,11 +1062,14 @@ bool GHOST_SystemCarbon::handleMenuCommand(GHOST_TInt32 menuResult)
     return handled;
 }
 
+
 OSStatus GHOST_SystemCarbon::sEventHandlerProc(EventHandlerCallRef handler, EventRef event, void* userData)
 {
        GHOST_SystemCarbon* sys = (GHOST_SystemCarbon*) userData;
     OSStatus err = eventNotHandledErr;
-
+       GHOST_IWindow* window;
+       GHOST_TEventNDOFData data;
+       
     switch (::GetEventClass(event))
     {
                case kEventClassAppleEvent:
@@ -1061,7 +1087,16 @@ OSStatus GHOST_SystemCarbon::sEventHandlerProc(EventHandlerCallRef handler, Even
                case kEventClassKeyboard:
                        err = sys->handleKeyEvent(event);
                        break;
-    }
+               case kEventClassBlender :
+                       window = sys->m_windowManager->getActiveWindow();
+                       sys->m_ndofManager->GHOST_NDOFGetDatas(data);
+                       sys->m_eventManager->pushEvent(new GHOST_EventNDOF(sys->getMilliSeconds(), GHOST_kEventNDOFMotion, window, data));
+                       err = noErr;
+                       break;
+               default : 
+                       ;
+                       break;
+   }
 
     return err;
 }
index 93022aa78ff479b17e687815d6da3461a4cf950a..f2e3a775701a1ccd3d94898f28823dc239dbdf9c 100644 (file)
@@ -224,6 +224,10 @@ protected:
      */
     bool handleMenuCommand(GHOST_TInt32 menuResult);
     
+    /* callback for blender generated events */
+//     static OSStatus blendEventHandlerProc(EventHandlerCallRef handler, EventRef event, void* userData);
+
+
     /**
      * Callback for Carbon when it has events.
      */
index 19e858a9f59640b5d02248ead7dd3c217a851ff3..0a04b0b8003faac190751f0ce8af03cafaa74f84 100644 (file)
@@ -556,25 +556,35 @@ static int event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr private)
 
         case GHOST_kEventNDOFMotion: {
             // update ndof device data, and dispatch motion event
-            GHOST_TEventNDOFData *sb= data;
 
-            win->ndof[0] = sb->tx;
-            win->ndof[1] = sb->ty;
-            win->ndof[2] = sb->tz;
-            win->ndof[3] = sb->rx;
-            win->ndof[4] = sb->ry;
-            win->ndof[5] = sb->rz;
-            win->ndof[6] = sb->dt;
-
-            // start interaction for larger than teeny-tiny motions
-            if ((fabsf(sb->tx) > 0.03f) ||
-                (fabsf(sb->ty) > 0.03f) ||
-                (fabsf(sb->tz) > 0.03f) ||
-                (fabsf(sb->rx) > 0.03f) ||
-                (fabsf(sb->ry) > 0.03f) ||
-                (fabsf(sb->rz) > 0.03f)) {
-                    window_handle(win, NDOFMOTION, sb->dt * 255);
-            }
+            GHOST_TEventNDOFData *sb= data;
+                       
+                       // the multipliers are arbitrary values
+                       // they could be ajustable in the future
+            win->ndof[0] = sb->tx  * (1.0f/1024.0f);
+            win->ndof[1] = sb->ty  * (1.0f/1024.0f);
+            win->ndof[2] = sb->tz  * (1.0f/1024.0f);
+            win->ndof[3] = sb->rx  * 0.00003f;
+            win->ndof[4] = sb->ry  * 0.00003f;
+            win->ndof[5] = sb->rz  * 0.00003f;
+            win->ndof[6] = sb->delta  / 1000000.0f;
+ //            printf(" motion capted %f %f %f %f %f %f %f \n", win->ndof[0], win->ndof[1], win->ndof[2],
+ //                                                             win->ndof[3], win->ndof[4], win->ndof[5], win->ndof[6]);
+
+
+ //          window_handle(win, NDOFMOTION, win->ndof[6]);
+
+ //       start interaction for larger than teeny-tiny motions
+ //         if (fabs(win->ndof[0] > 0.003f) ||
+ //             fabs(win->ndof[1] > 0.003f) ||
+ //          fabs(win->ndof[2] > 0.003f) ||
+ //               fabs(win->ndof[3] > 0.003f) ||
+ //               fabs(win->ndof[4] > 0.003f) ||
+ //              fabs(win->ndof[5] > 0.003f)) {
+                    window_handle(win, NDOFMOTION, 1);
+ //    printf("ok\n");
+ //    }
+;
           break;
         }
 
@@ -881,16 +891,19 @@ Window *winlay_get_active_window(void) {
 
 void window_open_ndof(Window* win)
 {
-    PILdynlib* ndofLib = PIL_dynlib_open("spaceplug.plug");
+    PILdynlib* ndofLib = PIL_dynlib_open("XXXXXXX-PUT-HERE-YOUR-PATH-TO-THE-PLUG--/spaceplug.plug");
     if (ndofLib) {
 
         GHOST_OpenNDOF(g_system, win->ghostwin, 
             PIL_dynlib_find_symbol(ndofLib, "ndofInit"),
             PIL_dynlib_find_symbol(ndofLib, "ndofShutdown"),
-            PIL_dynlib_find_symbol(ndofLib, "ndofOpen"),
-            PIL_dynlib_find_symbol(ndofLib, "ndofEventHandler"));
+            PIL_dynlib_find_symbol(ndofLib, "ndofOpen"));
+
+// original patch only
+//            PIL_dynlib_find_symbol(ndofLib, "ndofEventHandler"));
     }
     else {
-        GHOST_OpenNDOF(g_system, win->ghostwin, 0, 0, 0, 0);
+//        GHOST_OpenNDOF(g_system, win->ghostwin, 0, 0, 0, 0);
+        GHOST_OpenNDOF(g_system, win->ghostwin, 0, 0, 0);
     }
  }
index bcb3a2784d6d44fbefe561b5c8f8e599f95f82da..c09f2e792431ac198b7cbf6dbe48ee4336066bec 100644 (file)
@@ -1568,7 +1568,7 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                break;
 
             case NDOFMOTION:
-                viewmoveNDOF(0);
+                viewmoveNDOF(1);
                 break;
 
                        case ONEKEY:
index e26b4526ebef67d6a78096dbcca80f12e0b978cb..287f86796c544a02da76135de3a7bf5faf6b5042 100644 (file)
@@ -827,6 +827,8 @@ void viewmoveNDOF(int mode)
     float diff[4];
     float d, curareaX, curareaY;
 
+//printf("passing here \n");
+
     /* Sensitivity will control how fast the view rotates.  The value was
      * obtained experimentally by tweaking until the author didn't get dizzy watching.
      * Perhaps this should be a configurable user parameter. 
@@ -852,16 +854,18 @@ void viewmoveNDOF(int mode)
      * record how much time has passed. clamp at 10 Hz
      * pretend the previous frame occured at the clamped time 
      */
-    now = PIL_check_seconds_timer();
-    frametime = (now - prevTime);
-    if (frametime > 0.1f){        /* if more than 1/10s */
-        frametime = 1.0f/60.0;      /* clamp at 1/60s so no jumps when starting to move */
-    }
-    prevTime = now;
-    sbadjust *= 60 * frametime;             /* normalize ndof device adjustments to 100Hz for framerate independence */
+//    now = PIL_check_seconds_timer();
//   frametime = (now - prevTime);
//   if (frametime > 0.1f){        /* if more than 1/10s */
//       frametime = 1.0f/60.0;      /* clamp at 1/60s so no jumps when starting to move */
+//    }
+//    prevTime = now;
//   sbadjust *= 60 * frametime;             /* normalize ndof device adjustments to 100Hz for framerate independence */
 
     /* fetch the current state of the ndof device */
     getndof(fval);
+   //         printf(" motion command %f %f %f %f %f %f %f \n", fval[0], fval[1], fval[2],
+   //                                                           fval[3], fval[4], fval[5], fval[6]);
 
     /* set object offset */
        if (ob) {