NDOF support added to trunk from ndof branch.

The latter is now obsolete and will be soon 
removed.

Some tiny build tweaks for darwin committed
in preparation of bigger changes for proper
SDK suport both on intel and ppc
This commit is contained in:
Jean-Luc Peurière 2008-03-22 01:39:11 +00:00
commit 126ab7974d
42 changed files with 3732 additions and 2156 deletions

@ -350,33 +350,36 @@ else:
blenderinstall = env.Install(dir=env['BF_INSTALLDIR'], source=B.program_list)
#-- .blender
#- dont do .blender and scripts for darwin, it is already in the bundle
dotblendlist = []
dottargetlist = []
for dp, dn, df in os.walk('bin/.blender'):
if 'CVS' in dn:
dn.remove('CVS')
if '.svn' in dn:
dn.remove('.svn')
for f in df:
dotblendlist.append(dp+os.sep+f)
dottargetlist.append(env['BF_INSTALLDIR']+dp[3:]+os.sep+f)
dotblenderinstall = []
for targetdir,srcfile in zip(dottargetlist, dotblendlist):
td, tf = os.path.split(targetdir)
dotblenderinstall.append(env.Install(dir=td, source=srcfile))
#-- .blender/scripts
scriptinstall = []
scriptpath='release/scripts'
for dp, dn, df in os.walk(scriptpath):
if 'CVS' in dn:
dn.remove('CVS')
if '.svn' in dn:
dn.remove('.svn')
dir=env['BF_INSTALLDIR']+'/.blender/scripts'+dp[len(scriptpath):]
source=[dp+os.sep+f for f in df]
scriptinstall.append(env.Install(dir=dir,source=source))
if env['OURPLATFORM']!='darwin':
for dp, dn, df in os.walk('bin/.blender'):
if 'CVS' in dn:
dn.remove('CVS')
if '.svn' in dn:
dn.remove('.svn')
for f in df:
dotblendlist.append(dp+os.sep+f)
dottargetlist.append(env['BF_INSTALLDIR']+dp[3:]+os.sep+f)
dotblenderinstall = []
for targetdir,srcfile in zip(dottargetlist, dotblendlist):
td, tf = os.path.split(targetdir)
dotblenderinstall.append(env.Install(dir=td, source=srcfile))
#-- .blender/scripts
scriptpath='release/scripts'
for dp, dn, df in os.walk(scriptpath):
if 'CVS' in dn:
dn.remove('CVS')
if '.svn' in dn:
dn.remove('.svn')
dir=env['BF_INSTALLDIR']+'/.blender/scripts'+dp[len(scriptpath):]
source=[dp+os.sep+f for f in df]
scriptinstall.append(env.Install(dir=dir,source=source))
#-- plugins
pluglist = []
@ -407,7 +410,10 @@ for tp, tn, tf in os.walk('release/text'):
textinstall = env.Install(dir=env['BF_INSTALLDIR'], source=textlist)
allinstall = [blenderinstall, dotblenderinstall, scriptinstall, plugininstall, textinstall]
if env['OURPLATFORM']=='darwin':
allinstall = [blenderinstall, plugininstall, textinstall]
else:
allinstall = [blenderinstall, dotblenderinstall, scriptinstall, plugininstall, textinstall]
if env['OURPLATFORM'] in ('win32-vc', 'win32-mingw'):
dllsources = ['${LCGDIR}/gettext/lib/gnu_gettext.dll',

@ -3,10 +3,10 @@ LIBDIR = '${LCGDIR}'
# enable ffmpeg support
WITH_BF_FFMPEG = 'true' # -DWITH_FFMPEG
BF_FFMPEG = LIBDIR +'/ffmpeg'
BF_FFMPEG = "#extern/ffmpeg"
BF_FFMPEG_INC = '${BF_FFMPEG}/include'
BF_FFMPEG_LIBPATH='${BF_FFMPEG}/lib'
BF_FFMPEG_LIB = 'avformat.a avcodec.a avutil.a'
#BF_FFMPEG_LIBPATH='${BF_FFMPEG}/lib'
#BF_FFMPEG_LIB = 'avformat.a avcodec.a avutil.a'
WITH_BF_VERSE = 'false'
BF_VERSE = "#extern/verse/dist"
@ -15,7 +15,7 @@ BF_VERSE_INCLUDE = BF_VERSE
BF_VERSE_LIBS = "libverse"
# python.org libs install in /library
BF_PYTHON_VERSION = '2.3'
BF_PYTHON_VERSION = '2.5'
if BF_PYTHON_VERSION=='2.3':
BF_PYTHON = '/System/Library/Frameworks/Python.framework/Versions/'
else:
@ -131,11 +131,11 @@ BF_FREETYPE_LIBPATH = '${BF_FREETYPE}/lib'
WITH_BF_QUICKTIME = 'true' # -DWITH_QUICKTIME
WITH_BF_ICONV = 'false'
WITH_BF_ICONV = 'true'
BF_ICONV = LIBDIR + "/iconv"
BF_ICONV_INC = '${BF_ICONV}/include'
BF_ICONV_LIB = 'iconv'
BF_ICONV_LIBPATH = '${BF_ICONV}/lib'
#BF_ICONV_LIBPATH = '${BF_ICONV}/lib'
# Mesa Libs should go here if your using them as well....
WITH_BF_STATICOPENGL = 'true'

@ -265,6 +265,19 @@ extern GHOST_TSuccess GHOST_AddEventConsumer(GHOST_SystemHandle systemhandle,
GHOST_EventConsumerHandle consumerhandle);
/***************************************************************************************
** N-degree of freedom device management functionality
***************************************************************************************/
/**
* Open N-degree of freedom devices
*/
extern int GHOST_OpenNDOF(GHOST_SystemHandle systemhandle,
GHOST_WindowHandle windowhandle,
GHOST_NDOFLibraryInit_fp setNdofLibraryInit,
GHOST_NDOFLibraryShutdown_fp setNdofLibraryShutdown,
GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen
);
/***************************************************************************************
** Cursor management functionality

@ -295,6 +295,22 @@ public:
*/
virtual GHOST_TSuccess addEventConsumer(GHOST_IEventConsumer* consumer) = 0;
/***************************************************************************************
** N-degree of freedom device management functionality
***************************************************************************************/
/**
* Starts the N-degree of freedom device manager
*/
virtual int openNDOF(GHOST_IWindow*,
GHOST_NDOFLibraryInit_fp setNdofLibraryInit,
GHOST_NDOFLibraryShutdown_fp setNdofLibraryShutdown,
GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen
// original patch only
// GHOST_NDOFEventHandler_fp setNdofEventHandler
) = 0;
/***************************************************************************************
** Cursor management functionality
***************************************************************************************/

@ -39,6 +39,11 @@ typedef unsigned short GHOST_TUns16;
typedef int GHOST_TInt32;
typedef unsigned int GHOST_TUns32;
#ifdef WIN32
#define WM_BLND_NDOF_AXIS WM_USER + 1
#define WM_BLND_NDOF_BTN WM_USER + 2
#endif
#if defined(WIN32) && !defined(FREE_WINDOWS)
typedef __int64 GHOST_TInt64;
typedef unsigned __int64 GHOST_TUns64;
@ -133,6 +138,9 @@ typedef enum {
GHOST_kEventButtonUp, /// Mouse button event
GHOST_kEventWheel, /// Mouse wheel event
GHOST_kEventNDOFMotion, /// N degree of freedom device motion event
GHOST_kEventNDOFButton, /// N degree of freedom device button event
GHOST_kEventKeyDown,
GHOST_kEventKeyUp,
// GHOST_kEventKeyAuto,
@ -336,6 +344,38 @@ typedef struct {
GHOST_TInt32 z;
} 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 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;

@ -259,6 +259,21 @@ GHOST_TSuccess GHOST_AddEventConsumer(GHOST_SystemHandle systemhandle, GHOST_Eve
return system->addEventConsumer((GHOST_CallbackEventConsumer*)consumerhandle);
}
int GHOST_OpenNDOF(GHOST_SystemHandle systemhandle, GHOST_WindowHandle windowhandle,
GHOST_NDOFLibraryInit_fp setNdofLibraryInit,
GHOST_NDOFLibraryShutdown_fp setNdofLibraryShutdown,
GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen)
//original patch only
/* GHOST_NDOFEventHandler_fp setNdofEventHandler)*/
{
GHOST_ISystem* system = (GHOST_ISystem*) systemhandle;
return system->openNDOF((GHOST_IWindow*) windowhandle,
setNdofLibraryInit, setNdofLibraryShutdown, setNdofDeviceOpen);
// original patch
// setNdofLibraryInit, setNdofLibraryShutdown, setNdofDeviceOpen, setNdofEventHandler);
}
GHOST_TStandardCursor GHOST_GetCursorShape(GHOST_WindowHandle windowhandle)

@ -0,0 +1,57 @@
/*
* ***** 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_EVENT_NDOF_H_
#define _GHOST_EVENT_NDOF_H_
#include "GHOST_Event.h"
/**
* N-degree of freedom device event.
*/
class GHOST_EventNDOF : public GHOST_Event
{
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;
}
protected:
/** translation & rotation from the device. */
GHOST_TEventNDOFData m_ndofEventData;
};
#endif // _GHOST_EVENT_NDOF_H_

@ -0,0 +1,124 @@
/*
* ***** 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_NDOFManager.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};
#if !defined(_WIN32) && !defined(__APPLE__)
#include "GHOST_SystemX11.h"
#endif
namespace
{
GHOST_NDOFLibraryInit_fp ndofLibraryInit = 0;
GHOST_NDOFLibraryShutdown_fp ndofLibraryShutdown = 0;
GHOST_NDOFDeviceOpen_fp ndofDeviceOpen = 0;
}
GHOST_NDOFManager::GHOST_NDOFManager()
{
m_DeviceHandle = 0;
// discover the API from the plugin
ndofLibraryInit = 0;
ndofLibraryShutdown = 0;
ndofDeviceOpen = 0;
}
GHOST_NDOFManager::~GHOST_NDOFManager()
{
if (ndofLibraryShutdown)
ndofLibraryShutdown(m_DeviceHandle);
m_DeviceHandle = 0;
}
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;
if (ndofLibraryInit && ndofDeviceOpen)
{
Pid= ndofLibraryInit();
printf("%i client \n", Pid);
#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
return (Pid > 0) ? 0 : 1;
} else
return 1;
}
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;
}

@ -0,0 +1,52 @@
/*
* ***** 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_
#include "GHOST_System.h"
#include "GHOST_IWindow.h"
class GHOST_NDOFManager
{
public:
GHOST_NDOFManager();
virtual ~GHOST_NDOFManager();
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;
protected:
void* m_DeviceHandle;
};
#endif

@ -47,13 +47,14 @@
#include "GHOST_DisplayManager.h"
#include "GHOST_EventManager.h"
#include "GHOST_NDOFManager.h"
#include "GHOST_TimerTask.h"
#include "GHOST_TimerManager.h"
#include "GHOST_WindowManager.h"
GHOST_System::GHOST_System()
: m_displayManager(0), m_timerManager(0), m_windowManager(0), m_eventManager(0)
: m_displayManager(0), m_timerManager(0), m_windowManager(0), m_eventManager(0), m_ndofManager(0)
{
}
@ -239,6 +240,17 @@ GHOST_TSuccess GHOST_System::pushEvent(GHOST_IEvent* event)
return success;
}
int GHOST_System::openNDOF(GHOST_IWindow* w,
GHOST_NDOFLibraryInit_fp setNdofLibraryInit,
GHOST_NDOFLibraryShutdown_fp setNdofLibraryShutdown,
GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen)
{
return m_ndofManager->deviceOpen(w,
setNdofLibraryInit,
setNdofLibraryShutdown,
setNdofDeviceOpen);
}
GHOST_TSuccess GHOST_System::getModifierKeyState(GHOST_TModifierKeyMask mask, bool& isDown) const
{
@ -271,6 +283,11 @@ GHOST_TSuccess GHOST_System::init()
m_timerManager = new GHOST_TimerManager ();
m_windowManager = new GHOST_WindowManager ();
m_eventManager = new GHOST_EventManager ();
m_ndofManager = new GHOST_NDOFManager();
if(m_ndofManager)
printf("ndof manager \n");
#ifdef GHOST_DEBUG
if (m_eventManager) {
m_eventManager->addConsumer(&m_eventPrinter);
@ -306,6 +323,10 @@ GHOST_TSuccess GHOST_System::exit()
delete m_eventManager;
m_eventManager = 0;
}
if (m_ndofManager) {
delete m_ndofManager;
m_ndofManager = 0;
}
return GHOST_kSuccess;
}

@ -51,6 +51,7 @@ class GHOST_Event;
class GHOST_TimerManager;
class GHOST_Window;
class GHOST_WindowManager;
class GHOST_NDOFManager;
/**
* Implementation of platform independent functionality of the GHOST_ISystem
@ -184,6 +185,27 @@ public:
*/
virtual GHOST_TSuccess addEventConsumer(GHOST_IEventConsumer* consumer);
/***************************************************************************************
** N-degree of freedom devcice management functionality
***************************************************************************************/
/** Inherited from GHOST_ISystem
* Opens the N-degree of freedom device manager
* return 0 if device found, 1 otherwise
*/
virtual int openNDOF(GHOST_IWindow* w,
GHOST_NDOFLibraryInit_fp setNdofLibraryInit,
GHOST_NDOFLibraryShutdown_fp setNdofLibraryShutdown,
GHOST_NDOFDeviceOpen_fp setNdofDeviceOpen);
// original patch only
// GHOST_NDOFEventHandler_fp setNdofEventHandler);
/***************************************************************************************
** Cursor management functionality
***************************************************************************************/
@ -243,6 +265,12 @@ public:
*/
virtual inline GHOST_WindowManager* getWindowManager() const;
/**
* Returns a pointer to our n-degree of freedeom manager.
* @return A pointer to our n-degree of freedeom manager.
*/
virtual inline GHOST_NDOFManager* getNDOFManager() const;
/**
* Returns the state of all modifier keys.
* @param keys The state of all modifier keys (true == pressed).
@ -305,6 +333,9 @@ protected:
/** The event manager. */
GHOST_EventManager* m_eventManager;
/** The N-degree of freedom device manager */
GHOST_NDOFManager* m_ndofManager;
/** Prints all the events. */
#ifdef GHOST_DEBUG
GHOST_EventPrinter m_eventPrinter;
@ -329,5 +360,10 @@ inline GHOST_WindowManager* GHOST_System::getWindowManager() const
return m_windowManager;
}
inline GHOST_NDOFManager* GHOST_System::getNDOFManager() const
{
return m_ndofManager;
}
#endif // _GHOST_SYSTEM_H_

@ -48,22 +48,33 @@
#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,9 @@ 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));
if (i!='tblt') { // tablet event. we use the one packaged in the mouse event
; //printf("Missed - Class: '%.4s', Kind: %d\n", &i, ::GetEventKind(event));
}
}
}
::ReleaseEvent(event);
@ -610,6 +632,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 +652,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 +789,7 @@ OSStatus GHOST_SystemCarbon::handleTabletEvent(EventRef event)
}
err = noErr;
}
}
OSStatus GHOST_SystemCarbon::handleMouseEvent(EventRef event)
@ -961,7 +986,7 @@ bool GHOST_SystemCarbon::handleMouseDown(EventRef event)
GHOST_ASSERT(ghostWindow, "GHOST_SystemCarbon::handleMouseEvent: ghostWindow==0");
if (::TrackGoAway(window, mousePos))
{
// todo: add option-close, because itØs in the HIG
// todo: add option-close, because itÿs in the HIG
// if (event.modifiers & optionKey) {
// Close the clean documents, others will be confirmed one by one.
//}
@ -1039,11 +1064,15 @@ 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;
UInt32 kind;
switch (::GetEventClass(event))
{
case kEventClassAppleEvent:
@ -1061,7 +1090,28 @@ 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);
kind = ::GetEventKind(event);
switch (kind)
{
case 1:
sys->m_eventManager->pushEvent(new GHOST_EventNDOF(sys->getMilliSeconds(), GHOST_kEventNDOFMotion, window, data));
// printf("motion\n");
break;
case 2:
sys->m_eventManager->pushEvent(new GHOST_EventNDOF(sys->getMilliSeconds(), GHOST_kEventNDOFButton, window, data));
// printf("button\n");
break;
}
err = noErr;
break;
default :
;
break;
}
return err;
}

@ -238,6 +238,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.
*/

@ -64,10 +64,12 @@
#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"
#include "GHOST_WindowWin32.h"
#include "GHOST_NDOFManager.h"
// Key code values not found in winuser.h
#ifndef VK_MINUS
@ -845,6 +847,28 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam,
* In GHOST, we let DefWindowProc call the timer callback.
*/
break;
case WM_BLND_NDOF_AXIS:
{
GHOST_TEventNDOFData ndofdata;
system->m_ndofManager->GHOST_NDOFGetDatas(ndofdata);
system->m_eventManager->
pushEvent(new GHOST_EventNDOF(
system->getMilliSeconds(),
GHOST_kEventNDOFMotion,
window, ndofdata));
}
break;
case WM_BLND_NDOF_BTN:
{
GHOST_TEventNDOFData ndofdata;
system->m_ndofManager->GHOST_NDOFGetDatas(ndofdata);
system->m_eventManager->
pushEvent(new GHOST_EventNDOF(
system->getMilliSeconds(),
GHOST_kEventNDOFButton,
window, ndofdata));
}
break;
}
}
else {

@ -29,37 +29,6 @@
* ***** 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"
@ -95,9 +66,21 @@
#include <unistd.h>
#include <vector>
#include <stdio.h> // for fprintf only
typedef struct NDOFPlatformInfo {
Display *display;
Window window;
volatile GHOST_TEventNDOFData *currValues;
Atom cmdAtom;
Atom motionAtom;
Atom btnPressAtom;
Atom btnRelAtom;
} NDOFPlatformInfo;
static NDOFPlatformInfo sNdofInfo = {NULL, 0, NULL, 0, 0, 0, 0};
//these are for copy and select copy
static char *txt_cut_buffer= NULL;
static char *txt_select_buffer= NULL;
@ -151,8 +134,6 @@ init(
return GHOST_kFailure;
}
GHOST_TUns64
GHOST_SystemX11::
@ -241,7 +222,6 @@ createWindow(
}
}
return window;
}
GHOST_WindowX11 *
@ -489,10 +469,36 @@ GHOST_SystemX11::processEvent(XEvent *xe)
GHOST_kEventWindowClose,
window
);
} else
#endif
if (sNdofInfo.currValues) {
static GHOST_TEventNDOFData data = {0,0,0,0,0,0,0,0,0,0,0};
if (xcme.message_type == sNdofInfo.motionAtom)
{
data.changed = 1;
data.delta = xcme.data.s[8] - data.time;
data.time = xcme.data.s[8];
data.tx = xcme.data.s[2];
data.ty = xcme.data.s[3];
data.tz = xcme.data.s[4];
data.rx = xcme.data.s[5];
data.ry = xcme.data.s[6];
data.rz = xcme.data.s[7];
g_event = new GHOST_EventNDOF(getMilliSeconds(),
GHOST_kEventNDOFMotion,
window, data);
} else if (xcme.message_type == sNdofInfo.btnPressAtom) {
data.changed = 2;
data.delta = xcme.data.s[8] - data.time;
data.time = xcme.data.s[8];
data.buttons = xcme.data.s[2];
g_event = new GHOST_EventNDOF(getMilliSeconds(),
GHOST_kEventNDOFButton,
window, data);
}
} else {
/* Unknown client message, ignore */
}
#endif
break;
}
@ -594,6 +600,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::

@ -196,6 +196,11 @@ public:
return m_display;
}
void *
prepareNdofInfo(
volatile GHOST_TEventNDOFData *current_values
);
/**
* Returns unsinged char from CUT_BUFFER0
* @param flag Flag indicates which buffer to return 0 for clipboard 1 for selection

@ -39,6 +39,7 @@ CCSRCS += GHOST_EventManager.cpp GHOST_EventPrinter.cpp GHOST_WindowManager.cpp
CCSRCS += GHOST_ISystem.cpp GHOST_ModifierKeys.cpp GHOST_TimerManager.cpp
CCSRCS += GHOST_Rect.cpp GHOST_DisplayManager.cpp GHOST_C-api.cpp
CCSRCS += GHOST_CallbackEventConsumer.cpp
CCSRCS += GHOST_NDOFManager.cpp
include nan_definitions.mk

@ -280,6 +280,9 @@ ECHO Done
<File
RelativePath="..\..\intern\GHOST_EventManager.h">
</File>
<File
RelativePath="..\..\intern\GHOST_EventNDOF.h">
</File>
<File
RelativePath="..\..\intern\GHOST_EventPrinter.h">
</File>
@ -292,6 +295,9 @@ ECHO Done
<File
RelativePath="..\..\intern\GHOST_ModifierKeys.h">
</File>
<File
RelativePath="..\..\intern\GHOST_NDOFManager.cpp">
</File>
<File
RelativePath="..\..\intern\GHOST_System.h">
</File>
@ -373,6 +379,9 @@ ECHO Done
<File
RelativePath="..\..\intern\GHOST_ModifierKeys.cpp">
</File>
<File
RelativePath="..\..\intern\GHOST_NDOFManager.cpp">
</File>
<File
RelativePath="..\..\intern\GHOST_Rect.cpp">
</File>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 64 KiB

After

Width:  |  Height:  |  Size: 68 KiB

@ -149,6 +149,9 @@ typedef struct Global {
int compat; /* toggle compatibility mode for edge rendering */
int notonlysolid;/* T-> also edge-render transparent faces */
/* ndof device found ? */
int ndofdevice;
/* confusing... G.f and G.flags */
int flags;

@ -258,6 +258,7 @@ void BLI_free_file_lines(struct LinkNode *lines);
*/
void BLI_where_am_i(char *fullname, const char *name);
char *get_install_dir(void);
/**
* Gets the temp directory when blender first runs.
* If the default path is not found, use try $TEMP

@ -2129,7 +2129,7 @@ int BLO_write_file_mem(MemFile *compare, MemFile *current, int write_flags, char
#define PATHSEPERATOR "/"
#endif
static char *get_install_dir(void) {
char *get_install_dir(void) {
extern char bprogname[];
char *tmpname = BLI_strdup(bprogname);
char *cut;

@ -123,6 +123,9 @@ short get_mbut(void);
short get_qual(void);
void getmouse(short *mval);
void getndof(float *sbval);
void filterNDOFvalues(float *sbval);
float get_pressure(void);
void get_tilt(float *xtilt, float *ytilt);
#define DEV_MOUSE 0

@ -84,10 +84,10 @@ typedef enum {
ICON_SHORTDISPLAY,
ICON_TRIA_DOWN,
ICON_TRIA_RIGHT,
ICON_BLANK7,
ICON_BLANK8,
ICON_BLANK9,
ICON_BLANK10,
ICON_NDOF_TURN,
ICON_NDOF_FLY,
ICON_NDOF_TRANS,
ICON_NDOF_DOM,
ICON_VIEW_AXIS_ALL,
ICON_VIEW_AXIS_NONE,

@ -73,9 +73,11 @@
#define CTX_NO_MIRROR 16
#define CTX_AUTOCONFIRM 32
#define CTX_BMESH 64
#define CTX_NDOF 128
void initTransform(int mode, int context);
void Transform(void);
void NDofTransform();
/* Standalone call to get the transformation center corresponding to the current situation
* returns 1 if successful, 0 otherwise (usually means there's no selection)

@ -76,6 +76,8 @@ void sdrawbox(short x1, short y1, short x2, short y2);
void calctrackballvecfirst(struct rcti *area, short *mval, float *vec);
void calctrackballvec(struct rcti *area, short *mval, float *vec);
void viewmove(int mode);
void viewmoveNDOFfly(int mode);
void viewmoveNDOF(int mode);
void view_zoom_mouseloc(float dfac, short *mouseloc);
int get_view3d_viewplane(int winxi, int winyi, rctf *viewplane, float *clipsta, float *clipend, float *pixsize);

@ -238,6 +238,7 @@
#define B_SEL_POINT 167
#define B_SEL_END 168
#define B_MAN_MODE 169
#define B_NDOF 170
/* IPO: 200 */
#define B_IPOHOME 201

@ -70,6 +70,10 @@
#define WINQUIT 0x018 /* signal from user that app is to go away */
#define Q_FIRSTTIME 0x019 /* on startup */
/* N-degre of freedom device : 500 */
#define NDOFMOTION 500
#define NDOFBUTTON 501
/* standard keyboard */
#define AKEY 'a'

@ -48,6 +48,13 @@ struct bPose;
struct bConstraint;
typedef struct NDofInput {
int flag;
int axis;
float fval[7];
float factor[3];
} NDofInput;
typedef struct NumInput {
short idx;
short idx_max;
@ -172,6 +179,7 @@ typedef struct TransInfo {
TransCon con; /* transformed constraint */
TransSnap tsnap;
NumInput num; /* numerical input */
NDofInput ndof; /* ndof input */
char redraw; /* redraw flag */
float propsize; /* proportional circle radius */
char proptext[20]; /* proportional falloff text */
@ -212,6 +220,9 @@ typedef struct TransInfo {
#define NUM_NO_FRACTION 16
#define NUM_AFFECT_ALL 32
/* NDOFINPUT FLAGS */
#define NDOF_INIT 1
/* transinfo->state */
#define TRANS_RUNNING 0
#define TRANS_CONFIRM 1
@ -478,6 +489,20 @@ short hasNumInput(NumInput *n);
void applyNumInput(NumInput *n, float *vec);
char handleNumInput(NumInput *n, unsigned short event);
/*********************** NDofInput ********************************/
void initNDofInput(NDofInput *n);
int hasNDofInput(NDofInput *n);
void applyNDofInput(NDofInput *n, float *vec);
int handleNDofInput(NDofInput *n, unsigned short event, short val);
/* handleNDofInput return values */
#define NDOF_REFRESH 1
#define NDOF_NOMOVE 2
#define NDOF_CONFIRM 3
#define NDOF_CANCEL 4
/*********************** TransSpace ******************************/
int manageObjectSpace(int confirm, int set);

@ -200,6 +200,9 @@ typedef struct UserDef {
short recent_files; /* maximum number of recently used files to remember */
short smooth_viewtx; /* miliseconds to spend spinning the view */
short glreslimit;
short ndof_pan, ndof_rotate;
short pads[2];
// char pad[8];
char versemaster[160];
char verseuser[160];
float glalphaclip;

@ -139,7 +139,8 @@ typedef struct View3D {
short pad3;
short pad2;
char ndofmode; /* mode of transform for 6DOF devices -1 not found, 0 normal, 1 fly, 2 ob transform */
char ndoffilter; /*filter for 6DOF devices 0 normal, 1 dominant */
void *properties_storage; /* Nkey panel stores stuff here, not in file */

File diff suppressed because it is too large Load Diff

@ -2178,6 +2178,25 @@ short get_activedevice(void)
return window_get_activedevice(mainwin);
}
void getndof(float *sbval)
{
winlay_process_events(0);
window_get_ndof(mainwin, sbval);
}
void filterNDOFvalues(float *sbval)
{
int i=0;
float max = 0.0;
for (i =0; i<6;i++)
if (fabs(sbval[i]) > max)
max = fabs(sbval[i]);
for (i =0; i<6;i++)
if (fabs(sbval[i]) != max )
sbval[i]=0.0;
}
void add_to_mainqueue(Window *win, void *user_data, short evt, short val, char ascii)
{
@ -2242,6 +2261,7 @@ static bScreen *addscreen(char *name) /* use setprefsize() if you want somethin
}
window_set_handler(mainwin, add_to_mainqueue, NULL);
window_open_ndof(mainwin); /* needs to occur once the mainwin handler is set */
init_mainwin();
mywinset(1);

@ -55,11 +55,16 @@
#include "BIF_usiblender.h"
#include "BIF_cursors.h"
#include "PIL_dynlib.h"
#include "mydevice.h"
#include "blendef.h"
#include "winlay.h"
#include <math.h>
#ifdef __APPLE__
#include <OpenGL/OpenGL.h>
#define __CARBONSOUND__
@ -109,6 +114,12 @@ struct _Window {
*/
int faked_mbut;
/* Last known ndof device state
* note that the ghost device manager
* can handle any number of devices, but ghostwinlay can't
*/
float ndof[7]; /* tx, ty, tz, rx, ry, rz, dt */
GHOST_TimerTaskHandle timer;
int timer_event;
};
@ -336,6 +347,7 @@ Window *window_open(char *title, int posx, int posy, int sizex, int sizey, int s
GHOST_WindowHandle ghostwin;
GHOST_TWindowState inital_state;
int scr_w, scr_h;
int i;
winlay_get_screensize(&scr_w, &scr_h);
posy= (scr_h-posy-sizey);
@ -368,7 +380,10 @@ Window *window_open(char *title, int posx, int posy, int sizex, int sizey, int s
win->lmouse[0]= win->size[0]/2;
win->lmouse[1]= win->size[1]/2;
for (i = 0; i < 7; ++i)
win->ndof[i] = 0;
} else {
GHOST_DisposeWindow(g_system, ghostwin);
@ -540,6 +555,46 @@ static int event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr private)
}
switch (type) {
case GHOST_kEventNDOFMotion: {
// update ndof device data, and dispatch motion event
GHOST_TEventNDOFData *sb= data;
// no scaling per sfgoros patch
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->delta;
// 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;
}
case GHOST_kEventNDOFButton: {
GHOST_TEventNDOFData *sb= data;
// printf("this is a button %i\n", sb->buttons);
window_handle(win, NDOFBUTTON, sb->buttons);
break;
}
case GHOST_kEventCursorMove: {
if(win->active == 1) {
GHOST_TEventCursorData *cd= data;
@ -707,6 +762,13 @@ static int event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr private)
return 1;
}
void window_get_ndof(Window* win, float* sbval) {
int i;
for (i = 0; i < 7; ++i) {
*sbval++ = win->ndof[i];
}
}
char *window_get_title(Window *win) {
char *title= GHOST_GetTitle(win->ghostwin);
char *mem_title= BLI_strdup(title);
@ -834,6 +896,59 @@ Window *winlay_get_active_window(void) {
return active_gl_window;
}
#ifdef _WIN32
#define PATH_SEP "\\"
#else
#define PATH_SEP "/"
#endif
void window_open_ndof(Window* win)
{
char *inst_path, *plug_path;
const char *plug_dir = "plugins";
const char *plug_name = "3DxNdofBlender.plug";
PILdynlib *ndofLib;
// build the plugin path
plug_path = NULL;
inst_path = get_install_dir(); // path to main blender exec/bundle
if (inst_path) {
// assume the ndof plugin is located in the plug-in dir
size_t len = strlen(inst_path) + strlen(plug_dir) + strlen(PATH_SEP)*2
+ strlen(plug_name) + 1;
plug_path = MEM_mallocN(len, "ndofpluginpath");
if (plug_path) {
strncpy(plug_path, inst_path, len);
strcat(plug_path, PATH_SEP);
strcat(plug_path, plug_dir);
strcat(plug_path, PATH_SEP);
strcat(plug_path, plug_name);
}
MEM_freeN(inst_path);
}
ndofLib = PIL_dynlib_open(plug_path);
#if 0
fprintf(stderr, "plugin path=%s; ndofLib=%p\n", plug_path, (void*)ndofLib);
#endif
if (plug_path)
MEM_freeN(plug_path);
if (ndofLib) {
G.ndofdevice = 0 - GHOST_OpenNDOF(g_system, win->ghostwin,
PIL_dynlib_find_symbol(ndofLib, "ndofInit"),
PIL_dynlib_find_symbol(ndofLib, "ndofShutdown"),
PIL_dynlib_find_symbol(ndofLib, "ndofOpen"));
}
else {
GHOST_OpenNDOF(g_system, win->ghostwin, 0, 0, 0);
G.ndofdevice = -1;
}
}
char *getClipboard(int flag) {
return (char*)GHOST_getClipboard(flag);
}

@ -5057,6 +5057,19 @@ static char *around_pup(void)
return string;
}
static char *ndof_pup(void)
{
static char string[512];
char *str = string;
str += sprintf(str, "%s", "ndof mode: %t");
str += sprintf(str, "%s", "|turntable %x0");
str += sprintf(str, "%s", "|fly %x1");
str += sprintf(str, "%s", "|transform %x2");
return string;
}
static char *propfalloff_pup(void)
{
static char string[512];
@ -5287,9 +5300,13 @@ void do_view3d_buttons(short event)
G.vd->twtype= V3D_MANIP_SCALE;
allqueue(REDRAWVIEW3D, 1);
break;
case B_NDOF:
allqueue(REDRAWVIEW3D, 1);
break;
case B_MAN_MODE:
allqueue(REDRAWVIEW3D, 1);
break;
default:
if(event>=B_LAY && event<B_LAY+31) {
@ -5588,10 +5605,28 @@ void view3d_buttons(void)
xco+= XIC+8;
uiBlockBeginAlign(block);
/* NDOF */
if (G.ndofdevice ==0 ) {
uiDefIconTextButC(block, ICONTEXTROW,B_NDOF, ICON_NDOF_TURN, ndof_pup(), xco,0,XIC+10,YIC, &(G.vd->ndofmode), 0, 3.0, 0, 0, "Ndof mode");
xco+= XIC+10;
uiDefIconButC(block, TOG, B_NDOF, ICON_NDOF_DOM,
xco,0,XIC,YIC,
&G.vd->ndoffilter, 0, 1, 0, 0, "dominant axis");
uiBlockEndAlign(block);
xco+= XIC+8;
}
uiBlockEndAlign(block);
/* Transform widget / manipulators */
uiBlockBeginAlign(block);
uiDefIconButBitS(block, TOG, V3D_USE_MANIPULATOR, B_REDR, ICON_MANIPUL,xco,0,XIC,YIC, &G.vd->twflag, 0, 0, 0, 0, "Use 3d transform manipulator (Ctrl Space)");
xco+= XIC;
if(G.vd->twflag & V3D_USE_MANIPULATOR) {
uiDefIconButBitS(block, TOG, V3D_MANIP_TRANSLATE, B_MAN_TRANS, ICON_MAN_TRANS, xco,0,XIC,YIC, &G.vd->twtype, 1.0, 0.0, 0, 0, "Translate manipulator mode (Ctrl Alt G)");
@ -5701,7 +5736,8 @@ void view3d_buttons(void)
}
uiDefIconBut(block, BUT, B_VIEWRENDER, ICON_SCENE_DEHLT, xco,0,XIC,YIC, NULL, 0, 1.0, 0, 0, "Render this window (hold CTRL for anim)");
if (ob && (ob->flag & OB_POSEMODE)) {
xco+= XIC/2;
uiBlockBeginAlign(block);

@ -1560,6 +1560,31 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
do_layer_buttons(11); break;
case ACCENTGRAVEKEY:
do_layer_buttons(-1); break;
case NDOFMOTION:
if (G.vd->ndofmode == 0) {
viewmoveNDOF(1);
} else if (G.vd->ndofmode == 1) {
viewmoveNDOFfly(1);
} else {
if (OBACT) {
NDofTransform();
}
}
break;
case NDOFBUTTON:
if (val == 1) {
G.vd->ndofmode +=1;
if (G.vd->ndofmode > 2) /* we have currently 3 modes : 0 original, 1 fly, 2 transform */
G.vd->ndofmode = 0;
}
if (val == 2) {
G.vd->ndoffilter =(G.vd->ndoffilter == 1 ? 0 : 1);
}
allqueue(REDRAWHEADERS, 0);
break;
}
/* Redraw buttons window as well as view 3d (for floating panel) */
@ -1659,6 +1684,30 @@ static void winqreadview3dspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
doredraw= 1;
break;
case NDOFMOTION:
if (G.vd->ndofmode == 0) {
viewmoveNDOF(1);
} else if (G.vd->ndofmode == 1) {
viewmoveNDOFfly(1);
} else {
if (OBACT) {
NDofTransform();
}
}
break;
case NDOFBUTTON:
if (val == 1) {
G.vd->ndofmode +=1;
if (G.vd->ndofmode > 2) /* we have currently 3 modes : 0 original, 1 fly, 2 transform */
G.vd->ndofmode = 0;
}
if (val == 2) {
G.vd->ndoffilter =(G.vd->ndoffilter == 1 ? 0 : 1);
}
allqueue(REDRAWHEADERS, 0);
break;
case ONEKEY:
if(G.qual==LR_CTRLKEY) {
flip_subdivison(1);
@ -2809,6 +2858,7 @@ static void initview3d(ScrArea *sa)
vd->gridflag &= ~V3D_SHOW_Z;
vd->depths= NULL;
vd->ndofmode=0;
}
@ -3654,7 +3704,9 @@ void drawinfospace(ScrArea *sa, void *spacedata)
(xpos+edgsp+mpref+(2*spref)+(3*midsp)+(mpref/2)),y1,(mpref/2),buth,
&(U.uiflag), 0, 0, 0, 0,
"Use selection as the orbiting center");
uiBlockEndAlign(block);
uiBlockEndAlign(block);
uiDefBut(block, LABEL,0,"Select with:",
(xpos+(2*edgsp)+(3*mpref)+(3*midsp)),y6label,mpref,buth,
@ -3772,6 +3824,18 @@ void drawinfospace(ScrArea *sa, void *spacedata)
&(U.obcenter_dia), 4, 10, 0, 0,
"Diameter in Pixels for Object/Lamp center display");
uiDefBut(block, LABEL,0,"6DOF devices speeds :",
(xpos+edgsp+(5*mpref)+(6*midsp)),y2label,mpref,buth,
0, 0, 0, 0, 0, "");
//FIXME NDOF BAD ETIQUETTES
uiDefButS(block, NUM, USER_AUTOPERSP, "ndPan",
(xpos+edgsp+(5*mpref)+(6*midsp)),y1,(mpref/2),buth,
&(U.ndof_pan), 0, 200, 0, 0,
"The overall panning speed of an NDOF device, as percent of standard");
uiDefButS(block, NUM, USER_ORBIT_SELECTION, "ndRot",
(xpos+edgsp+(5*mpref)+(6*midsp)+(mpref/2)),y1,(mpref/2),buth,
&(U.ndof_rotate), 0, 200, 0, 0,
"The overall rotation speed of an NDOF device, as percent of standard");
} else if (U.userpref == 1) { /* edit methods */

@ -852,11 +852,49 @@ static void transformEvent(unsigned short event, short val) {
else view_editmove(event);
Trans.redraw= 1;
break;
// case NDOFMOTION:
// viewmoveNDOF(1);
// break;
}
// Numerical input events
Trans.redraw |= handleNumInput(&(Trans.num), event);
// NDof input events
switch(handleNDofInput(&(Trans.ndof), event, val))
{
case NDOF_CONFIRM:
if ((Trans.context & CTX_NDOF) == 0)
{
/* Confirm on normal transform only */
Trans.state = TRANS_CONFIRM;
}
break;
case NDOF_CANCEL:
if (Trans.context & CTX_NDOF)
{
/* Cancel on pure NDOF transform */
Trans.state = TRANS_CANCEL;
}
else
{
/* Otherwise, just redraw, NDof input was cancelled */
Trans.redraw = 1;
}
break;
case NDOF_NOMOVE:
if (Trans.context & CTX_NDOF)
{
/* Confirm on pure NDOF transform */
Trans.state = TRANS_CONFIRM;
}
break;
case NDOF_REFRESH:
Trans.redraw = 1;
break;
}
// Snapping events
Trans.redraw |= handleSnapping(&Trans, event);
@ -1244,6 +1282,9 @@ void ManipulatorTransform()
case RETKEY:
Trans.state = TRANS_CONFIRM;
break;
// case NDOFMOTION:
// viewmoveNDOF(1);
// break;
}
if(val) {
switch(event) {
@ -2295,6 +2336,10 @@ void initRotation(TransInfo *t)
t->mode = TFM_ROTATION;
t->transform = Rotation;
t->ndof.axis = 16;
/* Scale down and flip input for rotation */
t->ndof.factor[0] = -0.2f;
t->idx_max = 0;
t->num.idx_max = 0;
t->snap[0] = 0.0f;
@ -2576,6 +2621,8 @@ int Rotation(TransInfo *t, short mval[2])
final = t->fac;
applyNDofInput(&t->ndof, &final);
snapGrid(t, &final);
t->imval[0] = mval[0];
@ -2634,6 +2681,11 @@ void initTrackball(TransInfo *t)
{
t->mode = TFM_TRACKBALL;
t->transform = Trackball;
t->ndof.axis = 40;
/* Scale down input for rotation */
t->ndof.factor[0] = 0.2f;
t->ndof.factor[1] = 0.2f;
t->idx_max = 1;
t->num.idx_max = 1;
@ -2707,6 +2759,8 @@ int Trackball(TransInfo *t, short mval[2])
phi[0]= 0.01f*(float)( t->imval[1] - mval[1] );
phi[1]= 0.01f*(float)( mval[0] - t->imval[0] );
applyNDofInput(&t->ndof, phi);
snapGrid(t, phi);
if (hasNumInput(&t->num)) {
@ -2761,6 +2815,7 @@ void initTranslation(TransInfo *t)
t->num.flag = 0;
t->num.idx_max = t->idx_max;
t->ndof.axis = 7;
if(t->spacetype == SPACE_VIEW3D) {
/* initgrabz() defines a factor for perspective depth correction, used in window_to_3d() */
@ -2909,6 +2964,7 @@ int Translation(TransInfo *t, short mval[2])
headerTranslation(t, pvec, str);
}
else {
applyNDofInput(&t->ndof, t->vec);
snapGrid(t, t->vec);
applyNumInput(&t->num, t->vec);
applySnapping(t, t->vec);
@ -3014,6 +3070,10 @@ void initTilt(TransInfo *t)
t->mode = TFM_TILT;
t->transform = Tilt;
t->ndof.axis = 16;
/* Scale down and flip input for rotation */
t->ndof.factor[0] = -0.2f;
t->idx_max = 0;
t->num.idx_max = 0;
t->snap[0] = 0.0f;
@ -3057,6 +3117,8 @@ int Tilt(TransInfo *t, short mval[2])
else t->fac += dphi;
final = t->fac;
applyNDofInput(&t->ndof, &final);
snapGrid(t, &final);
@ -3195,6 +3257,10 @@ void initPushPull(TransInfo *t)
t->mode = TFM_PUSHPULL;
t->transform = PushPull;
t->ndof.axis = 4;
/* Flip direction */
t->ndof.factor[0] = -1.0f;
t->idx_max = 0;
t->num.idx_max = 0;
t->snap[0] = 0.0f;
@ -3212,6 +3278,8 @@ int PushPull(TransInfo *t, short mval[2])
TransData *td = t->data;
distance = InputVerticalAbsolute(t, mval);
applyNDofInput(&t->ndof, &distance);
snapGrid(t, &distance);
@ -4624,4 +4692,50 @@ void BIF_TransformSetUndo(char *str)
}
void NDofTransform()
{
float fval[7];
float maxval = 50.0f; // also serves as threshold
int axis = -1;
int mode = 0;
int i;
getndof(fval);
for(i = 0; i < 6; i++)
{
float val = fabs(fval[i]);
if (val > maxval)
{
axis = i;
maxval = val;
}
}
switch(axis)
{
case -1:
/* No proper axis found */
break;
case 0:
case 1:
case 2:
mode = TFM_TRANSLATION;
break;
case 4:
mode = TFM_ROTATION;
break;
case 3:
case 5:
mode = TFM_TRACKBALL;
break;
default:
printf("ndof: what we are doing here ?");
}
if (mode != 0)
{
initTransform(mode, CTX_NDOF);
Transform();
}
}

@ -550,6 +550,39 @@ void recalcData(TransInfo *t)
}
void initTransModeFlags(TransInfo *t, int mode)
{
t->mode = mode;
t->num.flag = 0;
/* REMOVING RESTRICTIONS FLAGS */
t->flag &= ~T_ALL_RESTRICTIONS;
switch (mode) {
case TFM_RESIZE:
t->flag |= T_NULL_ONE;
t->num.flag |= NUM_NULL_ONE;
t->num.flag |= NUM_AFFECT_ALL;
if (!G.obedit) {
t->flag |= T_NO_ZERO;
t->num.flag |= NUM_NO_ZERO;
}
break;
case TFM_TOSPHERE:
t->num.flag |= NUM_NULL_ONE;
t->num.flag |= NUM_NO_NEGATIVE;
t->flag |= T_NO_CONSTRAINT;
break;
case TFM_SHEAR:
case TFM_CREASE:
case TFM_BONE_ENVELOPE:
case TFM_CURVE_SHRINKFATTEN:
case TFM_BONE_ROLL:
t->flag |= T_NO_CONSTRAINT;
break;
}
}
void drawLine(float *center, float *dir, char axis, short options)
{
extern void make_axis_color(char *col, char *col2, char axis); // drawview.c
@ -584,6 +617,7 @@ void drawLine(float *center, float *dir, char axis, short options)
void initTrans (TransInfo *t)
{
/* moving: is shown in drawobject() (transform color) */
if(G.obedit || (t->flag & T_POSE) ) G.moving= G_TRANSFORM_EDIT;
else if(G.f & G_PARTICLEEDIT) G.moving= G_TRANSFORM_PARTICLE;
@ -593,8 +627,6 @@ void initTrans (TransInfo *t)
t->ext = NULL;
t->flag = 0;
t->num.flag = 0;
/* setting PET flag */
if ((t->context & CTX_NO_PET) == 0 && (G.scene->proportional)) {
@ -607,8 +639,6 @@ void initTrans (TransInfo *t)
t->con.imval[1] = t->imval[1];
t->transform = NULL;
t->handleEvent = NULL;
t->customData = NULL;
t->total =
t->num.idx =
@ -644,6 +674,7 @@ void initTrans (TransInfo *t)
t->around = V3D_CENTER;
setTransformViewMatrices(t);
initNDofInput(&(t->ndof));
}
/* Here I would suggest only TransInfo related issues, like free data & reset vars. Not redraws */
@ -689,10 +720,6 @@ void postTrans (TransInfo *t)
MEM_freeN(t->data2d);
t->data2d= NULL;
}
if ((t->flag & T_FREE_CUSTOMDATA) && t->customData != NULL) {
MEM_freeN(t->customData);
}
if(t->spacetype==SPACE_IMAGE) {
if (G.sima->flag & SI_LIVE_UNWRAP)

@ -0,0 +1,156 @@
/**
* $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: all of this file.
*
* Contributor(s): Martin Poirier
*
* ***** END GPL/BL DUAL LICENSE BLOCK *****
*/
#include <math.h> /* fabs */
#include <stdio.h> /* for sprintf */
#include "BKE_global.h" /* for G */
#include "BKE_utildefines.h" /* ABS */
#include "DNA_view3d_types.h" /* for G.vd (view3d) */
#include "BIF_mywindow.h"
#include "mydevice.h" /* for KEY defines */
#include "transform.h"
int updateNDofMotion(NDofInput *n); // return 0 when motion is null
void resetNDofInput(NDofInput *n);
void initNDofInput(NDofInput *n)
{
int i;
n->flag = 0;
n->axis = 0;
resetNDofInput(n);
for(i = 0; i < 3; i++)
{
n->factor[i] = 1.0f;
}
}
void resetNDofInput(NDofInput *n)
{
int i;
for(i = 0; i < 6; i++)
{
n->fval[i] = 0.0f;
}
}
int handleNDofInput(NDofInput *n, unsigned short event, short val)
{
int retval = 0;
switch(event)
{
case NDOFMOTION:
if (updateNDofMotion(n) == 0)
{
retval = NDOF_NOMOVE;
}
else
{
retval = NDOF_REFRESH;
}
break;
case NDOFBUTTON:
if (val == 1)
{
retval = NDOF_CONFIRM;
}
else if (val == 2)
{
retval = NDOF_CANCEL;
resetNDofInput(n);
n->flag &= ~NDOF_INIT;
}
break;
}
return retval;
}
int hasNDofInput(NDofInput *n)
{
return (n->flag & NDOF_INIT) == NDOF_INIT;
}
void applyNDofInput(NDofInput *n, float *vec)
{
if (hasNDofInput(n))
{
int i, j;
for (i = 0, j = 0; i < 6; i++)
{
if (n->axis & (1 << i))
{
vec[j] = n->fval[i] * n->factor[j];
j++;
}
}
}
}
int updateNDofMotion(NDofInput *n)
{
float fval[7];
int i;
int retval = 0;
getndof(fval);
if (G.vd->ndoffilter)
filterNDOFvalues(fval);
for(i = 0; i < 6; i++)
{
if (!retval && fval[i] != 0.0f)
{
retval = 1;
}
n->fval[i] += fval[i] / 1024.0f;
}
n->flag |= NDOF_INIT;
return retval;
}

@ -193,6 +193,13 @@ static void init_userdef_file(void)
if(U.pad_rot_angle==0)
U.pad_rot_angle= 15;
if (U.ndof_pan==0) {
U.ndof_pan = 100;
}
if (U.ndof_rotate==0) {
U.ndof_rotate = 100;
}
if(U.flag & USER_CUSTOM_RANGE)
vDM_ColorBand_store(&U.coba_weight); /* signal for derivedmesh to use colorband */

@ -92,6 +92,7 @@
#include "transform.h"
#include "PIL_time.h" /* smoothview */
#include <float.h>
#define TRACKBALLSIZE (1.1)
#define BL_NEAR_CLIP 0.001
@ -540,6 +541,185 @@ void calctrackballvec(rcti *area, short *mval, float *vec)
}
// ndof scaling will be moved to user setting.
// In the mean time this is just a place holder.
// Note: scaling in the plugin and ghostwinlay.c
// should be removed. With driver default setting,
// each axis returns approx. +-200 max deflection.
// The values I selected are based on the older
// polling i/f. With event i/f, the sensistivity
// can be increased for improved response from
// small deflections of the device input.
// lukep notes : i disagree on the range.
// the normal 3Dconnection driver give +/-400
// on defaut range in other applications
// and up to +/- 1000 if set to maximum
// because i remove the scaling by delta,
// which was a bad idea as it depend of the system
// speed and os, i changed the scaling values, but
// those are still not ok
float ndof_axis_scale[6] = {
+0.01, // Tx
+0.01, // Tz
+0.01, // Ty
+0.0015, // Rx
+0.0015, // Rz
+0.0015 // Ry
};
// statics for controlling G.vd->dist corrections.
// viewmoveNDOF zeros and adjusts G.vd->ofs.
// viewmove restores based on dz_flag state.
int dz_flag = 0;
float m_dist;
void viewmoveNDOFfly(int mode)
{
int i;
float phi;
float dval[7];
// static fval[6] for low pass filter; device input vector is dval[6]
static float fval[6];
float tvec[3],rvec[3];
float q1[4];
float mat[3][3];
float upvec[3];
/*----------------------------------------------------
* sometimes this routine is called from headerbuttons
* viewmove needs to refresh the screen
*/
areawinset(curarea->win);
// fetch the current state of the ndof device
getndof(dval);
if (G.vd->ndoffilter)
filterNDOFvalues(fval);
// for(i=0;i<7;i++) printf("%f ",dval[i]);
// printf("\n");
// Scale input values
// if(dval[6] == 0) return; // guard against divide by zero
for(i=0;i<6;i++) {
// user scaling
dval[i] = dval[i] * ndof_axis_scale[i];
// non-linear scaling
if(dval[i]<0.0f)
dval[i] = -1.0f * dval[i] * dval[i];
else
dval[i] = dval[i] * dval[i];
}
// low pass filter with zero crossing reset
for(i=0;i<6;i++) {
if((dval[i] * fval[i]) >= 0)
dval[i] = (fval[i] * 15 + dval[i]) / 16;
else
fval[i] = 0;
}
// force perspective mode. This is a hack and is
// incomplete. It doesn't actually effect the view
// until the first draw and doesn't update the menu
// to reflect persp mode.
G.vd->persp = 1;
// Correct the distance jump if G.vd->dist != 0
// This is due to a side effect of the original
// mouse view rotation code. The rotation point is
// set a distance in front of the viewport to
// make rotating with the mouse look better.
// The distance effect is written at a low level
// in the view management instead of the mouse
// view function. This means that all other view
// movement devices must subtract this from their
// view transformations.
if(G.vd->dist != 0.0) {
dz_flag = 1;
m_dist = G.vd->dist;
upvec[0] = upvec[1] = 0;
upvec[2] = G.vd->dist;
Mat3CpyMat4(mat, G.vd->viewinv);
Mat3MulVecfl(mat, upvec);
VecSubf(G.vd->ofs, G.vd->ofs, upvec);
G.vd->dist = 0.0;
}
// Apply rotation
rvec[0] = -dval[3];
rvec[1] = -dval[4];
rvec[2] = dval[5];
// rotate device x and y by view z
Mat3CpyMat4(mat, G.vd->viewinv);
mat[2][2] = 0.0f;
Mat3MulVecfl(mat, rvec);
// rotate the view
phi = Normalize(rvec);
if(phi != 0) {
VecRotToQuat(rvec,phi,q1);
QuatMul(G.vd->viewquat, G.vd->viewquat, q1);
}
// Apply translation
tvec[0] = dval[0];
tvec[1] = dval[1];
tvec[2] = -dval[2];
// the next three lines rotate the x and y translation coordinates
// by the current z axis angle
Mat3CpyMat4(mat, G.vd->viewinv);
mat[2][2] = 0.0f;
Mat3MulVecfl(mat, tvec);
// translate the view
VecSubf(G.vd->ofs, G.vd->ofs, tvec);
/*----------------------------------------------------
* refresh the screen
*/
scrarea_do_windraw(curarea);
screen_swapbuffers();
// update render preview window
BIF_view3d_previewrender_signal(curarea, PR_DBASE|PR_DISPRECT);
}
void viewmove(int mode)
{
Object *ob = OBACT;
@ -551,12 +731,30 @@ void viewmove(int mode)
short use_sel = 0;
short preview3d_event= 1;
/* 3D window may not be defined */
// locals for dist correction
float mat[3][3];
float upvec[3];
/* 3D window may not be defined */
if( !G.vd ) {
fprintf( stderr, "G.vd == NULL in viewmove()\n" );
return;
}
// dist correction from other movement devices
if(dz_flag) {
dz_flag = 0;
G.vd->dist = m_dist;
upvec[0] = upvec[1] = 0;
upvec[2] = G.vd->dist;
Mat3CpyMat4(mat, G.vd->viewinv);
Mat3MulVecfl(mat, upvec);
VecAddf(G.vd->ofs, G.vd->ofs, upvec);
}
/* sometimes this routine is called from headerbuttons */
areawinset(curarea->win);
@ -857,6 +1055,208 @@ void view_zoom_mouseloc(float dfac, short *mouseloc)
}
}
void viewmoveNDOF(int mode)
{
static double prevTime = 0.0;
int i;
float fval[7];
float dvec[3];
float sbadjust = 1.0f;
float len;
double now, frametime;
short use_sel = 0;
Object *ob = OBACT;
float m[3][3];
float m_inv[3][3];
float xvec[3] = {1,0,0};
float yvec[3] = {0,-1,0};
float zvec[3] = {0,0,1};
float phi, si;
float q1[4];
float obofs[3];
float reverse;
float diff[4];
float d, curareaX, curareaY;
/* 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.
*/
float psens = 0.005f * (float) U.ndof_pan; /* pan sensitivity */
float rsens = 0.005f * (float) U.ndof_rotate; /* rotate sensitivity */
float zsens = 0.3f; /* zoom sensitivity */
const float minZoom = -30.0f;
const float maxZoom = 300.0f;
//reset view type
G.vd->view = 0;
//printf("passing here \n");
//
if (G.obedit==NULL && ob && !(ob->flag & OB_POSEMODE)) {
use_sel = 1;
}
/*----------------------------------------------------
* sometimes this routine is called from headerbuttons
* viewmove needs to refresh the screen
*/
areawinset(curarea->win);
/*----------------------------------------------------
* 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 */
/* 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]);
if (G.vd->ndoffilter)
filterNDOFvalues(fval);
// put scaling back here, was previously in ghostwinlay
fval[0] = fval[0] * (1.0f/800.0f);
fval[1] = fval[1] * (1.0f/800.0f);
fval[2] = fval[2] * (1.0f/800.0f);
fval[3] = fval[3] * 0.00005f;
fval[4] = fval[4] * 0.00005f;
fval[5] = fval[5] * 0.00005f;
fval[6] = fval[6] / 1000000.0f;
// scale more if not in perspective mode
if (G.vd->persp == 0) {
fval[0] = fval[0] * 0.05f;
fval[1] = fval[1] * 0.05f;
fval[2] = fval[2] * 0.05f;
fval[3] = fval[3] * 0.9f;
fval[4] = fval[4] * 0.9f;
fval[5] = fval[5] * 0.9f;
zsens *= 8;
}
/* set object offset */
if (ob) {
obofs[0] = -ob->obmat[3][0];
obofs[1] = -ob->obmat[3][1];
obofs[2] = -ob->obmat[3][2];
}
else {
VECCOPY(obofs, G.vd->ofs);
}
/* calc an adjustment based on distance from camera */
if (ob) {
VecSubf(diff, obofs, G.vd->ofs);
d = VecLength(diff);
}
else {
d = 1.0f;
}
reverse = (G.vd->persmat[2][1] < 0.0f) ? -1.0f : 1.0f;
/*----------------------------------------------------
* ndof device pan
*/
psens *= 1.0f + d;
curareaX = sbadjust * psens * fval[0];
curareaY = sbadjust * psens * fval[1];
dvec[0] = curareaX * G.vd->persinv[0][0] + curareaY * G.vd->persinv[1][0];
dvec[1] = curareaX * G.vd->persinv[0][1] + curareaY * G.vd->persinv[1][1];
dvec[2] = curareaX * G.vd->persinv[0][2] + curareaY * G.vd->persinv[1][2];
VecAddf(G.vd->ofs, G.vd->ofs, dvec);
/*----------------------------------------------------
* ndof device dolly
*/
len = zsens * sbadjust * fval[2];
if (G.vd->persp==2) {
if(G.vd->persp==2) {
G.vd->camzoom+= 10.0f * -len;
}
if (G.vd->camzoom < minZoom) G.vd->camzoom = minZoom;
else if (G.vd->camzoom > maxZoom) G.vd->camzoom = maxZoom;
}
else if ((G.vd->dist> 0.001*G.vd->grid) && (G.vd->dist<10.0*G.vd->far)) {
G.vd->dist*=(1.0 + len);
}
/*----------------------------------------------------
* ndof device turntable
* derived from the turntable code in viewmove
*/
/* Get the 3x3 matrix and its inverse from the quaternion */
QuatToMat3(G.vd->viewquat, m);
Mat3Inv(m_inv,m);
/* Determine the direction of the x vector (for rotating up and down) */
/* This can likely be compuated directly from the quaternion. */
Mat3MulVecfl(m_inv,xvec);
Mat3MulVecfl(m_inv,yvec);
Mat3MulVecfl(m_inv,zvec);
/* Perform the up/down rotation */
phi = sbadjust * rsens * /*0.5f * */ fval[3]; /* spin vertically half as fast as horizontally */
si = sin(phi);
q1[0] = cos(phi);
q1[1] = si * xvec[0];
q1[2] = si * xvec[1];
q1[3] = si * xvec[2];
QuatMul(G.vd->viewquat, G.vd->viewquat, q1);
if (use_sel) {
QuatConj(q1); /* conj == inv for unit quat */
VecSubf(G.vd->ofs, G.vd->ofs, obofs);
QuatMulVecf(q1, G.vd->ofs);
VecAddf(G.vd->ofs, G.vd->ofs, obofs);
}
/* Perform the orbital rotation */
/* Perform the orbital rotation
If the seen Up axis is parallel to the zoom axis, rotation should be
achieved with a pure Roll motion (no Spin) on the device. When you start
to tilt, moving from Top to Side view, Spinning will increasingly become
more relevant while the Roll component will decrease. When a full
Side view is reached, rotations around the world's Up axis are achieved
with a pure Spin-only motion. In other words the control of the spinning
around the world's Up axis should move from the device's Spin axis to the
device's Roll axis depending on the orientation of the world's Up axis
relative to the screen. */
//phi = sbadjust * rsens * reverse * fval[4]; /* spin the knob, y axis */
phi = sbadjust * rsens * (yvec[2] * fval[4] + zvec[2] * fval[5]);
q1[0] = cos(phi);
q1[1] = q1[2] = 0.0;
q1[3] = sin(phi);
QuatMul(G.vd->viewquat, G.vd->viewquat, q1);
if (use_sel) {
QuatConj(q1);
VecSubf(G.vd->ofs, G.vd->ofs, obofs);
QuatMulVecf(q1, G.vd->ofs);
VecAddf(G.vd->ofs, G.vd->ofs, obofs);
}
/*----------------------------------------------------
* refresh the screen
*/
scrarea_do_windraw(curarea);
screen_swapbuffers();
}
/* Gets the lens and clipping values from a camera of lamp type object */
void object_view_settings(Object *ob, float *lens, float *clipsta, float *clipend)
{

@ -57,6 +57,7 @@ void window_lower (Window *win);
short window_get_qual (Window *win);
short window_get_mbut (Window *win);
void window_get_mouse (Window *win, short *mval);
void window_get_ndof (Window* win, float* sbval);
float window_get_pressure(Window *win);
void window_get_tilt(Window *win, float *xtilt, float *ytilt);
@ -79,6 +80,8 @@ void window_warp_pointer (Window *win, int x, int y);
void window_queue_redraw (Window *win);
void window_open_ndof(Window* win);
/* Global windowing operations */
Window* winlay_get_active_window(void);