first workable version on Os X

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
This commit is contained in:
2007-06-12 20:01:28 +00:00
parent 6cc1269d97
commit edc6512ba6
14 changed files with 252 additions and 107 deletions

View File

@@ -276,8 +276,11 @@ extern void GHOST_OpenNDOF(GHOST_SystemHandle systemhandle,
GHOST_WindowHandle windowhandle, GHOST_WindowHandle windowhandle,
GHOST_NDOFLibraryInit_fp setNdofLibraryInit, GHOST_NDOFLibraryInit_fp setNdofLibraryInit,
GHOST_NDOFLibraryShutdown_fp setNdofLibraryShutdown, GHOST_NDOFLibraryShutdown_fp setNdofLibraryShutdown,
GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen, GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen
GHOST_NDOFEventHandler_fp setNdofEventHandler); );
// original patch only
// GHOST_NDOFEventHandler_fp setNdofEventHandler);
/*************************************************************************************** /***************************************************************************************
** Cursor management functionality ** Cursor management functionality

View File

@@ -305,8 +305,10 @@ public:
virtual void openNDOF(GHOST_IWindow*, virtual void openNDOF(GHOST_IWindow*,
GHOST_NDOFLibraryInit_fp setNdofLibraryInit, GHOST_NDOFLibraryInit_fp setNdofLibraryInit,
GHOST_NDOFLibraryShutdown_fp setNdofLibraryShutdown, GHOST_NDOFLibraryShutdown_fp setNdofLibraryShutdown,
GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen, GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen
GHOST_NDOFEventHandler_fp setNdofEventHandler) = 0; // original patch only
// GHOST_NDOFEventHandler_fp setNdofEventHandler
) = 0;
/*************************************************************************************** /***************************************************************************************

View File

@@ -338,18 +338,37 @@ typedef struct {
GHOST_TInt32 z; GHOST_TInt32 z;
} GHOST_TEventWheelData; } GHOST_TEventWheelData;
/* 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 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 int (*GHOST_NDOFLibraryInit_fp)();
typedef void (*GHOST_NDOFLibraryShutdown_fp)(void* deviceHandle); typedef void (*GHOST_NDOFLibraryShutdown_fp)(void* deviceHandle);
typedef void* (*GHOST_NDOFDeviceOpen_fp)(void* platformData); 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 */ // original patch windows callback. In mac os X version the callback is internal to the plug-in and post an event to main thead.
typedef struct { // not necessary faster, but better integration with other events.
/** N-degree of freedom device data */
float tx, ty, tz; /** -x left, +y up, +z forward */ //typedef int (*GHOST_NDOFEventHandler_fp)(float* result7, void* deviceHandle, unsigned int message, unsigned int* wParam, unsigned long* lParam);
float rx, ry, rz; //typedef void (*GHOST_NDOFCallBack_fp)(GHOST_TEventNDOFDataV2 *VolDatas);
float dt;
} GHOST_TEventNDOFData;
typedef struct { typedef struct {
/** The key code. */ /** The key code. */

View File

@@ -262,13 +262,16 @@ GHOST_TSuccess GHOST_AddEventConsumer(GHOST_SystemHandle systemhandle, GHOST_Eve
void GHOST_OpenNDOF(GHOST_SystemHandle systemhandle, GHOST_WindowHandle windowhandle, void GHOST_OpenNDOF(GHOST_SystemHandle systemhandle, GHOST_WindowHandle windowhandle,
GHOST_NDOFLibraryInit_fp setNdofLibraryInit, GHOST_NDOFLibraryInit_fp setNdofLibraryInit,
GHOST_NDOFLibraryShutdown_fp setNdofLibraryShutdown, GHOST_NDOFLibraryShutdown_fp setNdofLibraryShutdown,
GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen, GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen)
GHOST_NDOFEventHandler_fp setNdofEventHandler) //original patch only
/* GHOST_NDOFEventHandler_fp setNdofEventHandler)*/
{ {
GHOST_ISystem* system = (GHOST_ISystem*) systemhandle; GHOST_ISystem* system = (GHOST_ISystem*) systemhandle;
system->openNDOF((GHOST_IWindow*) windowhandle, system->openNDOF((GHOST_IWindow*) windowhandle,
setNdofLibraryInit, setNdofLibraryShutdown, setNdofDeviceOpen, setNdofEventHandler); setNdofLibraryInit, setNdofLibraryShutdown, setNdofDeviceOpen);
// original patch
// setNdofLibraryInit, setNdofLibraryShutdown, setNdofDeviceOpen, setNdofEventHandler);
} }

View File

@@ -1,14 +1,10 @@
/** /*
* $Id: GHOST_EventNdof.h,v 1.6 2002/12/28 22:26:45 maarten Exp $ * ***** BEGIN GPL LICENSE BLOCK *****
* ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2 * as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. The Blender * of the License, or (at your option) any later version.
* 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, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -19,20 +15,12 @@
* along with this program; if not, write to the Free Software Foundation, * along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 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. * Contributor(s): none yet.
* *
* ***** END GPL/BL DUAL LICENSE BLOCK ***** * ***** END GPL LICENSE BLOCK *****
*/
/**
* @file GHOST_EventNdof.h
* Declaration of GHOST_EventNdof class.
*/ */
#ifndef _GHOST_EVENT_NDOF_H_ #ifndef _GHOST_EVENT_NDOF_H_
#define _GHOST_EVENT_NDOF_H_ #define _GHOST_EVENT_NDOF_H_

View File

@@ -1,21 +1,23 @@
/*
// Insert Blender compatible license here :-) * ***** BEGIN GPL LICENSE BLOCK *****
*
// note: an implementation is currently only provided for Windows, but designed to be easy to move to Linux, etc. * 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.
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 * This program is distributed in the hope that it will be useful,
of the spaceball libraries. * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
The 3dXWare SDK is available from the tab on the left side of - * GNU General Public License for more details.
http://www.3dconnexion.com/support/4a.php *
* You should have received a copy of the GNU General Public License
The SDK is necessary to build this file with WITH_SPACEBALL defined. * along with this program; if not, write to the Free Software Foundation,
* Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
For this stuff to work, siappdll.dll and spwini.dll must be in the executable path of blender *
* Contributor(s): none yet.
*
* ***** END GPL LICENSE BLOCK *****
*/ */
@@ -23,15 +25,17 @@
//#include "GHOST_WindowWin32.h" //#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 namespace
{ {
GHOST_NDOFLibraryInit_fp ndofLibraryInit = 0; GHOST_NDOFLibraryInit_fp ndofLibraryInit = 0;
GHOST_NDOFLibraryShutdown_fp ndofLibraryShutdown = 0; GHOST_NDOFLibraryShutdown_fp ndofLibraryShutdown = 0;
GHOST_NDOFDeviceOpen_fp ndofDeviceOpen = 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; ndofLibraryInit = 0;
ndofLibraryShutdown = 0; ndofLibraryShutdown = 0;
ndofDeviceOpen = 0; ndofDeviceOpen = 0;
ndofEventHandler = 0; // ndofEventHandler = 0;
// available = 0;
} }
GHOST_NDOFManager::~GHOST_NDOFManager() GHOST_NDOFManager::~GHOST_NDOFManager()
@@ -62,18 +65,22 @@ void
GHOST_NDOFManager::deviceOpen(GHOST_IWindow* window, GHOST_NDOFManager::deviceOpen(GHOST_IWindow* window,
GHOST_NDOFLibraryInit_fp setNdofLibraryInit, GHOST_NDOFLibraryInit_fp setNdofLibraryInit,
GHOST_NDOFLibraryShutdown_fp setNdofLibraryShutdown, GHOST_NDOFLibraryShutdown_fp setNdofLibraryShutdown,
GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen, GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen)
GHOST_NDOFEventHandler_fp setNdofEventHandler) // GHOST_NDOFEventHandler_fp setNdofEventHandler)
{ {
ndofLibraryInit = setNdofLibraryInit; ndofLibraryInit = setNdofLibraryInit;
ndofLibraryShutdown = setNdofLibraryShutdown; ndofLibraryShutdown = setNdofLibraryShutdown;
ndofDeviceOpen = setNdofDeviceOpen; ndofDeviceOpen = setNdofDeviceOpen;
ndofEventHandler = setNdofEventHandler; // original patch
// ndofEventHandler = setNdofEventHandler;
if (ndofLibraryInit && ndofDeviceOpen) if (ndofLibraryInit && ndofDeviceOpen)
{ {
printf("%i client \n", ndofLibraryInit()); printf("%i client \n", ndofLibraryInit());
m_DeviceHandle = ndofDeviceOpen((void *)&currentNdofValues);
} }
/* /*
if (ndofDeviceOpen) if (ndofDeviceOpen)
{ {
@@ -87,7 +94,8 @@ GHOST_NDOFManager::deviceOpen(GHOST_IWindow* window,
} }
/** original patch only */
/*
GHOST_TEventNDOFData* GHOST_TEventNDOFData*
GHOST_NDOFManager::handle(unsigned int message, unsigned int* wParam, unsigned long* lParam) 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); printf("handled %i\n", handled);
return handled ? &sbdata : 0; return handled ? &sbdata : 0;
} }
*/
bool bool
GHOST_NDOFManager::available() GHOST_NDOFManager::available()
@@ -108,3 +116,40 @@ GHOST_NDOFManager::available()
return m_DeviceHandle != 0; 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)
{
}
*/

View File

@@ -1,3 +1,24 @@
/*
* ***** 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_ #ifndef _GHOST_NDOFMANAGER_H_
#define _GHOST_NDOFMANAGER_H_ #define _GHOST_NDOFMANAGER_H_
@@ -23,13 +44,18 @@ public:
void deviceOpen(GHOST_IWindow* window, void deviceOpen(GHOST_IWindow* window,
GHOST_NDOFLibraryInit_fp setNdofLibraryInit, GHOST_NDOFLibraryInit_fp setNdofLibraryInit,
GHOST_NDOFLibraryShutdown_fp setNdofLibraryShutdown, GHOST_NDOFLibraryShutdown_fp setNdofLibraryShutdown,
GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen, GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen);
GHOST_NDOFEventHandler_fp setNdofEventHandler);
void GHOST_NDOFGetDatas(GHOST_TEventNDOFData &datas);
// GHOST_NDOFEventHandler_fp setNdofEventHandler);
bool available(); bool available();
bool event_present();
/* original patch. unused now */
/* to do: abstract for Linux, MacOS, etc. */ /* 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: protected:
void* m_DeviceHandle; void* m_DeviceHandle;

View File

@@ -243,14 +243,15 @@ GHOST_TSuccess GHOST_System::pushEvent(GHOST_IEvent* event)
void GHOST_System::openNDOF(GHOST_IWindow* w, void GHOST_System::openNDOF(GHOST_IWindow* w,
GHOST_NDOFLibraryInit_fp setNdofLibraryInit, GHOST_NDOFLibraryInit_fp setNdofLibraryInit,
GHOST_NDOFLibraryShutdown_fp setNdofLibraryShutdown, GHOST_NDOFLibraryShutdown_fp setNdofLibraryShutdown,
GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen, GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen)
GHOST_NDOFEventHandler_fp setNdofEventHandler) // original patch only
// GHOST_NDOFEventHandler_fp setNdofEventHandler)
{ {
m_ndofManager->deviceOpen(w, m_ndofManager->deviceOpen(w,
setNdofLibraryInit, setNdofLibraryInit,
setNdofLibraryShutdown, setNdofLibraryShutdown,
setNdofDeviceOpen, setNdofDeviceOpen);
setNdofEventHandler); // setNdofEventHandler);
} }

View File

@@ -197,8 +197,10 @@ public:
virtual void openNDOF(GHOST_IWindow* w, virtual void openNDOF(GHOST_IWindow* w,
GHOST_NDOFLibraryInit_fp setNdofLibraryInit, GHOST_NDOFLibraryInit_fp setNdofLibraryInit,
GHOST_NDOFLibraryShutdown_fp setNdofLibraryShutdown, GHOST_NDOFLibraryShutdown_fp setNdofLibraryShutdown,
GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen, GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen);
GHOST_NDOFEventHandler_fp setNdofEventHandler);
// original patch only
// GHOST_NDOFEventHandler_fp setNdofEventHandler);

View File

@@ -48,22 +48,33 @@
#include "GHOST_EventButton.h" #include "GHOST_EventButton.h"
#include "GHOST_EventCursor.h" #include "GHOST_EventCursor.h"
#include "GHOST_EventWheel.h" #include "GHOST_EventWheel.h"
#include "GHOST_EventNDOF.h"
#include "GHOST_TimerManager.h" #include "GHOST_TimerManager.h"
#include "GHOST_TimerTask.h" #include "GHOST_TimerTask.h"
#include "GHOST_WindowManager.h" #include "GHOST_WindowManager.h"
#include "GHOST_WindowCarbon.h" #include "GHOST_WindowCarbon.h"
#include "GHOST_NDOFManager.h"
#define GHOST_KEY_SWITCH(mac, ghost) { case (mac): ghostKey = (ghost); break; } #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[] = const EventTypeSpec kEvents[] =
{ {
{ kEventClassAppleEvent, kEventAppleEvent }, { kEventClassAppleEvent, kEventAppleEvent },
/* /*
{ kEventClassApplication, kEventAppActivated }, { kEventClassApplication, kEventAppActivated },
{ kEventClassApplication, kEventAppDeactivated }, { kEventClassApplication, kEventAppDeactivated },
*/ */
{ kEventClassKeyboard, kEventRawKeyDown }, { kEventClassKeyboard, kEventRawKeyDown },
{ kEventClassKeyboard, kEventRawKeyRepeat }, { kEventClassKeyboard, kEventRawKeyRepeat },
{ kEventClassKeyboard, kEventRawKeyUp }, { kEventClassKeyboard, kEventRawKeyUp },
@@ -84,7 +95,12 @@ const EventTypeSpec kEvents[] =
{ kEventClassWindow, kEventWindowActivated }, { kEventClassWindow, kEventWindowActivated },
{ kEventClassWindow, kEventWindowDeactivated }, { kEventClassWindow, kEventWindowDeactivated },
{ kEventClassWindow, kEventWindowUpdate }, { kEventClassWindow, kEventWindowUpdate },
{ kEventClassWindow, kEventWindowBoundsChanged } { kEventClassWindow, kEventWindowBoundsChanged },
{ kEventClassBlender, kEventBlenderNdofAxis },
{ kEventClassBlender, kEventBlenderNdofButtons }
}; };
@@ -416,7 +432,9 @@ GHOST_IWindow* GHOST_SystemCarbon::createWindow(
return window; 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 GHOST_SystemCarbon::processEvents(bool waitForEvent)
{ {
bool anyProcessed = false; bool anyProcessed = false;
@@ -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) { while (::ReceiveNextEvent(0, NULL, 0, true, &event)==noErr) {
OSStatus status= ::SendEventToEventTarget(event, ::GetEventDispatcherTarget()); OSStatus status= ::SendEventToEventTarget(event, ::GetEventDispatcherTarget());
if (status==noErr) { if (status==noErr) {
@@ -466,7 +486,7 @@ bool GHOST_SystemCarbon::processEvents(bool waitForEvent)
* are, but we get a lot of them * are, but we get a lot of them
*/ */
if (i!='cgs ') { 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); ::ReleaseEvent(event);
@@ -610,6 +630,7 @@ OSErr GHOST_SystemCarbon::sAEHandlerQuit(const AppleEvent *event, AppleEvent *re
GHOST_TSuccess GHOST_SystemCarbon::init() GHOST_TSuccess GHOST_SystemCarbon::init()
{ {
GHOST_TSuccess success = GHOST_System::init(); GHOST_TSuccess success = GHOST_System::init();
if (success) { if (success) {
/* /*
@@ -629,6 +650,7 @@ GHOST_TSuccess GHOST_SystemCarbon::init()
::AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, sAEHandlerOpenDocs, (SInt32) this, false); ::AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, sAEHandlerOpenDocs, (SInt32) this, false);
::AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, sAEHandlerPrintDocs, (SInt32) this, false); ::AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, sAEHandlerPrintDocs, (SInt32) this, false);
::AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, sAEHandlerQuit, (SInt32) this, false); ::AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, sAEHandlerQuit, (SInt32) this, false);
} }
return success; return success;
} }
@@ -765,6 +787,7 @@ OSStatus GHOST_SystemCarbon::handleTabletEvent(EventRef event)
} }
err = noErr; err = noErr;
} }
} }
OSStatus GHOST_SystemCarbon::handleMouseEvent(EventRef event) OSStatus GHOST_SystemCarbon::handleMouseEvent(EventRef event)
@@ -1039,10 +1062,13 @@ bool GHOST_SystemCarbon::handleMenuCommand(GHOST_TInt32 menuResult)
return handled; return handled;
} }
OSStatus GHOST_SystemCarbon::sEventHandlerProc(EventHandlerCallRef handler, EventRef event, void* userData) OSStatus GHOST_SystemCarbon::sEventHandlerProc(EventHandlerCallRef handler, EventRef event, void* userData)
{ {
GHOST_SystemCarbon* sys = (GHOST_SystemCarbon*) userData; GHOST_SystemCarbon* sys = (GHOST_SystemCarbon*) userData;
OSStatus err = eventNotHandledErr; OSStatus err = eventNotHandledErr;
GHOST_IWindow* window;
GHOST_TEventNDOFData data;
switch (::GetEventClass(event)) switch (::GetEventClass(event))
{ {
@@ -1061,6 +1087,15 @@ OSStatus GHOST_SystemCarbon::sEventHandlerProc(EventHandlerCallRef handler, Even
case kEventClassKeyboard: case kEventClassKeyboard:
err = sys->handleKeyEvent(event); err = sys->handleKeyEvent(event);
break; 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; return err;

View File

@@ -224,6 +224,10 @@ protected:
*/ */
bool handleMenuCommand(GHOST_TInt32 menuResult); 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. * Callback for Carbon when it has events.
*/ */

View File

@@ -556,25 +556,35 @@ static int event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr private)
case GHOST_kEventNDOFMotion: { case GHOST_kEventNDOFMotion: {
// update ndof device data, and dispatch motion event // update ndof device data, and dispatch motion event
GHOST_TEventNDOFData *sb= data; GHOST_TEventNDOFData *sb= data;
win->ndof[0] = sb->tx; // the multipliers are arbitrary values
win->ndof[1] = sb->ty; // they could be ajustable in the future
win->ndof[2] = sb->tz; win->ndof[0] = sb->tx * (1.0f/1024.0f);
win->ndof[3] = sb->rx; win->ndof[1] = sb->ty * (1.0f/1024.0f);
win->ndof[4] = sb->ry; win->ndof[2] = sb->tz * (1.0f/1024.0f);
win->ndof[5] = sb->rz; win->ndof[3] = sb->rx * 0.00003f;
win->ndof[6] = sb->dt; 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 // start interaction for larger than teeny-tiny motions
if ((fabsf(sb->tx) > 0.03f) || // if (fabs(win->ndof[0] > 0.003f) ||
(fabsf(sb->ty) > 0.03f) || // fabs(win->ndof[1] > 0.003f) ||
(fabsf(sb->tz) > 0.03f) || // fabs(win->ndof[2] > 0.003f) ||
(fabsf(sb->rx) > 0.03f) || // fabs(win->ndof[3] > 0.003f) ||
(fabsf(sb->ry) > 0.03f) || // fabs(win->ndof[4] > 0.003f) ||
(fabsf(sb->rz) > 0.03f)) { // fabs(win->ndof[5] > 0.003f)) {
window_handle(win, NDOFMOTION, sb->dt * 255); window_handle(win, NDOFMOTION, 1);
} // printf("ok\n");
// }
;
break; break;
} }
@@ -881,16 +891,19 @@ Window *winlay_get_active_window(void) {
void window_open_ndof(Window* win) 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) { if (ndofLib) {
GHOST_OpenNDOF(g_system, win->ghostwin, GHOST_OpenNDOF(g_system, win->ghostwin,
PIL_dynlib_find_symbol(ndofLib, "ndofInit"), PIL_dynlib_find_symbol(ndofLib, "ndofInit"),
PIL_dynlib_find_symbol(ndofLib, "ndofShutdown"), PIL_dynlib_find_symbol(ndofLib, "ndofShutdown"),
PIL_dynlib_find_symbol(ndofLib, "ndofOpen"), PIL_dynlib_find_symbol(ndofLib, "ndofOpen"));
PIL_dynlib_find_symbol(ndofLib, "ndofEventHandler"));
// original patch only
// PIL_dynlib_find_symbol(ndofLib, "ndofEventHandler"));
} }
else { 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);
} }
} }

View File

@@ -1568,7 +1568,7 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
break; break;
case NDOFMOTION: case NDOFMOTION:
viewmoveNDOF(0); viewmoveNDOF(1);
break; break;
case ONEKEY: case ONEKEY:

View File

@@ -827,6 +827,8 @@ void viewmoveNDOF(int mode)
float diff[4]; float diff[4];
float d, curareaX, curareaY; float d, curareaX, curareaY;
//printf("passing here \n");
/* Sensitivity will control how fast the view rotates. The value was /* Sensitivity will control how fast the view rotates. The value was
* obtained experimentally by tweaking until the author didn't get dizzy watching. * obtained experimentally by tweaking until the author didn't get dizzy watching.
* Perhaps this should be a configurable user parameter. * 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 * record how much time has passed. clamp at 10 Hz
* pretend the previous frame occured at the clamped time * pretend the previous frame occured at the clamped time
*/ */
now = PIL_check_seconds_timer(); // now = PIL_check_seconds_timer();
frametime = (now - prevTime); // frametime = (now - prevTime);
if (frametime > 0.1f){ /* if more than 1/10s */ // 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 */ // frametime = 1.0f/60.0; /* clamp at 1/60s so no jumps when starting to move */
} // }
prevTime = now; // prevTime = now;
sbadjust *= 60 * frametime; /* normalize ndof device adjustments to 100Hz for framerate independence */ // sbadjust *= 60 * frametime; /* normalize ndof device adjustments to 100Hz for framerate independence */
/* fetch the current state of the ndof device */ /* fetch the current state of the ndof device */
getndof(fval); 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 */ /* set object offset */
if (ob) { if (ob) {