committing Ettore Pasquini 6DOF patch for linux
authorJean-Luc Peurière <jlp@nerim.net>
Tue, 10 Jul 2007 19:32:30 +0000 (19:32 +0000)
committerJean-Luc Peurière <jlp@nerim.net>
Tue, 10 Jul 2007 19:32:30 +0000 (19:32 +0000)
As previously the plugin itself is available
on his site :
http://cubelogic.org/blender/3dcnxplug-lin.c
or on mine (soon) :
http://jlp.nerim.net/dev/6dof/

Please let me know if any problem, i cannot
test.

We have now patches for our 3 main platforms
features are still minimal, but will follow
soon.

intern/ghost/intern/GHOST_NDOFManager.cpp
intern/ghost/intern/GHOST_NDOFManager.h
intern/ghost/intern/GHOST_SystemX11.cpp
intern/ghost/intern/GHOST_SystemX11.h

index 1bfaf390544a83ac1902164f67df257b066318ff..e4a3bc230d6b996bfa52c7c2f30b705ffa30bbcc 100644 (file)
@@ -22,7 +22,6 @@
 
 
 #include "GHOST_NDOFManager.h"
-//#include "GHOST_WindowWin32.h"
 
 
 // the variable is outside the class because it must be accessed from plugin
@@ -33,14 +32,8 @@ namespace
     GHOST_NDOFLibraryInit_fp ndofLibraryInit = 0;
     GHOST_NDOFLibraryShutdown_fp ndofLibraryShutdown = 0;
     GHOST_NDOFDeviceOpen_fp ndofDeviceOpen = 0;
-//    GHOST_NDOFEventHandler_fp ndofEventHandler = 0;
-    
-    
 }
 
-
-//typedef enum SpwRetVal (WINAPI *PFNSI_INIT) (void);
-
 GHOST_NDOFManager::GHOST_NDOFManager()
 {
     m_DeviceHandle = 0;
@@ -49,7 +42,6 @@ GHOST_NDOFManager::GHOST_NDOFManager()
     ndofLibraryInit = 0;
     ndofLibraryShutdown = 0;
     ndofDeviceOpen = 0;
- //   ndofEventHandler = 0;
 }
 
 GHOST_NDOFManager::~GHOST_NDOFManager()
@@ -66,31 +58,26 @@ GHOST_NDOFManager::deviceOpen(GHOST_IWindow* window,
         GHOST_NDOFLibraryInit_fp setNdofLibraryInit, 
         GHOST_NDOFLibraryShutdown_fp setNdofLibraryShutdown,
         GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen)
-//        GHOST_NDOFEventHandler_fp setNdofEventHandler)
 {
     ndofLibraryInit = setNdofLibraryInit;
     ndofLibraryShutdown = setNdofLibraryShutdown;
     ndofDeviceOpen = setNdofDeviceOpen;
-//      original patch    
-//    ndofEventHandler = setNdofEventHandler;
 
     if (ndofLibraryInit  && ndofDeviceOpen)
     {
        printf("%i client \n", ndofLibraryInit());
+               
                m_DeviceHandle = ndofDeviceOpen((void *)&currentNdofValues);    
+               
+               #if defined(_WIN32) || defined(__APPLE__)
+                       m_DeviceHandle = ndofDeviceOpen((void *)&currentNdofValues);    
+               #else
+                       GHOST_SystemX11 *sys;
+                       sys = static_cast<GHOST_SystemX11*>(GHOST_ISystem::getSystem());
+                       void *ndofInfo = sys->prepareNdofInfo(&currentNdofValues);
+                       m_DeviceHandle = ndofDeviceOpen(ndofInfo);
+               #endif
        }
-    
-    
-/*
-    if (ndofDeviceOpen)
-    {
-        GHOST_WindowWin32* win32 = (GHOST_WindowWin32*) window; // GHOST_IWindow doesn't have RTTI...
-        if (win32 != 0)
-        {
-            m_DeviceHandle = ndofDeviceOpen(win32->getHWND());
-        }
-    }
-    */
 }
 
 
@@ -111,45 +98,36 @@ GHOST_NDOFManager::handle(unsigned int message, unsigned int* wParam, unsigned l
 */
 
 bool 
-GHOST_NDOFManager::available() 
+GHOST_NDOFManager::available() const
 { 
     return m_DeviceHandle != 0; 
 }
 
 bool 
-GHOST_NDOFManager::event_present() 
+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);
+               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)
+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;
 }
-
-*/
index 2e905ed53d2d085b74ebcdf2aa44cad5b4ca2381..03037797e1eca0453697f4eefaf4cd530fd62622 100644 (file)
@@ -46,16 +46,10 @@ public:
         GHOST_NDOFLibraryShutdown_fp setNdofLibraryShutdown,
         GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen);
         
-    void GHOST_NDOFGetDatas(GHOST_TEventNDOFData &datas);
+    void GHOST_NDOFGetDatas(GHOST_TEventNDOFData &datas) const;
         
-//        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);
+    bool available() const;
+    bool event_present() const;
 
 protected:
     void* m_DeviceHandle;
index 14383ad36244ea78e830b1e0243c5f6fdc131562..6eefb48f6e831192993afb1b50fa6dc2e5cbb4d6 100755 (executable)
  * ***** END GPL/BL DUAL LICENSE BLOCK *****
  */
 
-/**
- * $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 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 *****
- */
-
 #ifdef HAVE_CONFIG_H
 #include <config.h>
 #endif
@@ -72,6 +41,8 @@
 #include "GHOST_EventKey.h"
 #include "GHOST_EventButton.h"
 #include "GHOST_EventWheel.h"
+#include "GHOST_EventNDOF.h"
+#include "GHOST_NDOFManager.h"
 #include "GHOST_DisplayManagerX11.h"
 
 #include "GHOST_Debug.h"
 
 #include <vector>
 
+typedef struct NDOFPlatformInfo {
+       Display *display;
+       Window window;
+       volatile GHOST_TEventNDOFData *currValues;
+} NDOFPlatformInfo;
+
+static NDOFPlatformInfo sNdofInfo = {NULL, 0, NULL};
+
 using namespace std;
 
 GHOST_SystemX11::
@@ -145,8 +124,6 @@ init(
 
        return GHOST_kFailure;
 }
-       
-
 
        GHOST_TUns64
 GHOST_SystemX11::
@@ -235,7 +212,6 @@ createWindow(
                }
        }
        return window;
-
 }
 
        GHOST_WindowX11 * 
@@ -483,6 +459,28 @@ GHOST_SystemX11::processEvent(XEvent *xe)
                                        GHOST_kEventWindowClose,
                                        window
                                );
+                       } else 
+#endif
+                       if (sNdofInfo.currValues) {
+                               sNdofInfo.currValues->changed = 1;
+                               sNdofInfo.currValues->delta = xcme.data.s[8] - sNdofInfo.currValues->time;
+                               sNdofInfo.currValues->time = xcme.data.s[8];
+                               sNdofInfo.currValues->tx = xcme.data.s[2] >> 4;
+                               sNdofInfo.currValues->ty = xcme.data.s[3] >> 4;
+                               sNdofInfo.currValues->tz = xcme.data.s[4] >> 4;
+                               sNdofInfo.currValues->rx = xcme.data.s[5];
+                               sNdofInfo.currValues->ry = xcme.data.s[6];
+                               sNdofInfo.currValues->rz = xcme.data.s[7];
+
+                               /*fprintf(stderr, "ClientMessage: [%d %d %d][%d %d %d] t=%llu\n",
+                                       sNdofInfo.currValues->tx, sNdofInfo.currValues->ty, 
+                                       sNdofInfo.currValues->tz, sNdofInfo.currValues->rx, 
+                                       sNdofInfo.currValues->ry, sNdofInfo.currValues->rz, 
+                                               sNdofInfo.currValues->time); */
+                               
+                               g_event = new GHOST_EventNDOF(getMilliSeconds(), 
+                                                             GHOST_kEventNDOFMotion, 
+                                                             window, *sNdofInfo.currValues);
                        } else {
                                /* Unknown client message, ignore */
                        }
@@ -539,6 +537,17 @@ GHOST_SystemX11::processEvent(XEvent *xe)
        }
 }
 
+       void *
+GHOST_SystemX11::
+prepareNdofInfo(volatile GHOST_TEventNDOFData *currentNdofValues)
+{
+       const vector<GHOST_IWindow*>& v(m_windowManager->getWindows());
+       if (v.size() > 0)
+       sNdofInfo.window = static_cast<GHOST_WindowX11*>(v[0])->getXWindow();
+       sNdofInfo.display = m_display;
+       sNdofInfo.currValues = currentNdofValues;
+       return (void*)&sNdofInfo;
+}
 
        GHOST_TSuccess 
 GHOST_SystemX11::
index c8d8d73404a531fbf62a373c9c84e5f320bdf168..e6adff44155a530759552a587b386307efc70862 100755 (executable)
@@ -196,7 +196,11 @@ public:
                return m_display;
        }       
 
-       
+               void *
+       prepareNdofInfo(
+               volatile GHOST_TEventNDOFData *current_values
+       );
+               
 private :
 
        Display * m_display;