Page Menu
Home
Search
Configure Global Search
Log In
Files
F2474
GHOST_SpaceballManager.cpp
Public
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Authored By
Stealth Apprentice (sapprentice)
Nov 13 2013, 1:04 PM
Size
3 KB
Subscribers
None
GHOST_SpaceballManager.cpp
View Options
// note: an implementation is currently only provided for Windows, but designed to be easy to move to Linux, etc.
/**
To use this implemenation, you must specify the #define WITH_SPACEBALL for the ghost library.
Only this cpp file is affected by the macro, the header file and everything else are independent
of the spaceball libraries.
The 3dXWare SDK is available from the tab on the left side of -
http://www.3dconnexion.com/support/4a.php
The SDK is necessary to build this file with WITH_SPACEBALL defined.
*/
#include
"GHOST_SpaceballManager.h"
#ifdef WITH_SPACEBALL
#include
"spwmacro.h"
#include
"si.h"
#include
"spwmath.h"
#include
"siapp.h"
#include
"GHOST_WindowWin32.h"
#endif
GHOST_SpaceballManager
::
GHOST_SpaceballManager
()
{
#ifdef WITH_SPACEBALL
SiInitialize
();
m_DeviceHandle
=
SI_NO_HANDLE
;
#endif
}
void
GHOST_SpaceballManager
::
spaceballOpen
(
GHOST_IWindow
*
window
)
{
#ifdef WITH_SPACEBALL
GHOST_WindowWin32
*
win32
=
(
GHOST_WindowWin32
*
)
window
;
// GHOST_IWindow doesn't have RTTI...
if
(
win32
!=
0
)
{
SiOpenData
oData
;
SiOpenWinInit
(
&
oData
,
win32
->
getHWND
());
m_DeviceHandle
=
(
void
*
)
SiOpen
(
"Blender"
,
SI_ANY_DEVICE
,
SI_NO_MASK
,
SI_EVENT
,
&
oData
);
if
(
m_DeviceHandle
==
SI_NO_HANDLE
)
{
SiTerminate
();
}
else
{
SiSetUiMode
((
SiHdl
)
m_DeviceHandle
,
SI_UI_NO_CONTROLS
);
}
}
#endif
}
GHOST_SpaceballManager
::~
GHOST_SpaceballManager
()
{
#ifdef WITH_SPACEBALL
if
((
SiHdl
)
m_DeviceHandle
!=
SI_NO_HANDLE
)
{
SiClose
((
SiHdl
)
m_DeviceHandle
);
SiTerminate
();
m_DeviceHandle
=
(
void
*
)
SI_NO_HANDLE
;
}
#endif
}
GHOST_TEventSpaceballData
*
GHOST_SpaceballManager
::
handle
(
unsigned
int
message
,
unsigned
int
*
wParam
,
unsigned
long
*
lParam
)
{
#ifdef WITH_SPACEBALL
SpwReturnValue
ret
;
SiGetEventData
EData
;
SiSpwEvent
event
;
static
GHOST_TEventSpaceballData
sbdata
;
bool
handledSpaceball
=
false
;
if
(
m_DeviceHandle
!=
SI_NO_HANDLE
)
{
SiGetEventWinInit
(
&
EData
,
message
,
(
WPARAM
)
wParam
,
(
LPARAM
)
lParam
);
if
((
ret
=
SiGetEvent
(
m_DeviceHandle
,
0
,
&
EData
,
&
event
))
==
SI_IS_EVENT
)
{
if
(
event
.
type
==
SI_MOTION_EVENT
)
{
sbdata
.
tx
=
(
float
)(
event
.
u
.
spwData
.
mData
[
SI_TX
])
*
(
1.0f
/
256.0f
);
// -X left
sbdata
.
ty
=
(
float
)(
event
.
u
.
spwData
.
mData
[
SI_TY
])
*
(
1.0f
/
256.0f
);
// +y up
sbdata
.
tz
=
(
float
)(
event
.
u
.
spwData
.
mData
[
SI_TZ
])
*
(
1.0f
/
256.0f
);
// +z forward
sbdata
.
rx
=
(
float
)(
event
.
u
.
spwData
.
mData
[
SI_RX
])
*
0.001f
;
sbdata
.
ry
=
(
float
)(
event
.
u
.
spwData
.
mData
[
SI_RY
])
*
0.001f
;
sbdata
.
rz
=
(
float
)(
event
.
u
.
spwData
.
mData
[
SI_RZ
])
*
0.001f
;
sbdata
.
dt
=
(
float
)(
event
.
u
.
spwData
.
period
);
}
if
(
event
.
type
==
SI_BUTTON_EVENT
)
{
printf
(
"Button event
\n
"
);
//SbButtonEvent (&event);
}
handledSpaceball
=
true
;
}
else
if
(
ret
!=
SI_NOT_EVENT
)
{
//ShowEventError (ret);
handledSpaceball
=
true
;
}
}
return
handledSpaceball
?
&
sbdata
:
0
;
#else
return
0
;
#endif
}
File Metadata
Details
Mime Type
text/x-c
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
61/12/fb02de558a4d4f40ef3134e11c89
Event Timeline
Log In to Comment