Copyright | (c) 2015 Brian W Bush |
---|---|
License | MIT |
Maintainer | Brian W Bush <consult@brianwbush.info> |
Stability | Stable |
Portability | Portable |
Safe Haskell | None |
Language | Haskell2010 |
Functions for managing input from a SpaceNavigator <http://www.3dconnexion.com/products/spacemouse/spacenavigator.html>, or a 3D mouse compatible with its protocols. OpenGL callbacks are provided, along with utilities for quantizing the input from the mouse or tracking its six degrees of freedom.
Here is a simple example illustating the use of this module:
main :: IO () main = do _ <- getArgsAndInitialize initialDisplayMode $= [WithDepthBuffer, DoubleBuffered] _ <- createWindow "SpaceNavigator OpenGL Example" depthFunc $= Just Less -- Create the tracker. tracking <- newIORef $ def {spaceNavigatorPosition = Vector3 0 0 0} -- Register a callback which quantizes and tracks the 3D mouse input. spaceNavigatorCallback $=! Just ( quantizeSpaceNavigator defaultQuantization $ trackSpaceNavigator defaultTracking tracking) -- The display callback needs the tracker. displayCallback $= display tracking idleCallback $= Just (postRedisplay Nothing) mainLoop display :: IORef SpaceNavigatorTrack -> DisplayCallback display tracking = do clear [ColorBuffer, DepthBuffer] loadIdentity -- Get the tracking state. tracking' <- get tracking -- Update the matrix based on the tracking doTracking tracking' -- All of the rendering actions go here. renderPrimitive . . . swapBuffers
This code has been validated with the following configuration of hardware and software:
- SpaceNavigator <http://www.3dconnexion.com/products/spacemouse/spacenavigator.html>
- spacenavd <http://spacenav.sourceforge.net/>, 0.5
- Ubuntu 15.04, 64-bit
- GHC 7.6.3
- OpenGL == 2.8.0.0
- GLUT == 2.4.0.0
- data SpaceNavigatorInput
- data Button
- data ButtonAction
- type SpaceNavigatorCallback = SpaceNavigatorInput -> IO ()
- spaceNavigatorCallback :: SettableStateVar (Maybe SpaceNavigatorCallback)
- quantize :: (GLfloat, GLfloat) -> SpaceNavigatorCallback -> SpaceNavigatorCallback
- defaultQuantization :: (GLfloat, GLfloat)
- data Track = Track {}
- data TrackMode = TrackPlatform
- defaultTracking :: (Vector3 GLfloat, Vector3 GLfloat)
- track :: (Vector3 GLfloat, Vector3 GLfloat) -> IORef Track -> SpaceNavigatorCallback
- doTracking :: Track -> IO ()
- doTracking' :: IORef Track -> IO ()
- doPilotView :: Track -> IO ()
- doPilotView' :: IORef Track -> IO ()
- doPolarView :: Track -> IO ()
- doPolarView' :: IORef Track -> IO ()
Input
data SpaceNavigatorInput Source #
Input received from a SpaceNavigator 3D mouse.
Push | The mouse has been pushed. |
| |
Tilt | The mouse has been tilted. |
| |
Button | A mouse button has been pressed. |
|
Buttons on a SpaceNavigator 3D mouse.
ButtonLeft | The left button. |
ButtonRight | The right button. |
ButtonOther Int | Neither the left nor the right button. |
data ButtonAction Source #
Pressing and releasing actions on a SpaceNavigator 3D mouse.
ButtonPress | The button has been pressed. |
ButtonRelease | The button has been released. |
type SpaceNavigatorCallback = SpaceNavigatorInput -> IO () Source #
A callback for input from the SpaceNavigator 3D mouse.
spaceNavigatorCallback :: SettableStateVar (Maybe SpaceNavigatorCallback) Source #
Register the callback for input from the SpaceNavigator 3D mouse.
Quantization
:: (GLfloat, GLfloat) | The thresholds for pushing and titling, respectively, between 0 and +1. |
-> SpaceNavigatorCallback | The callback for the mouse. |
-> SpaceNavigatorCallback | A callback that receives quantized input {-1, 0, +1}. |
Quantize the input from a SpaceNavigator 3D mouse according to whether the input exceeds a threshold. The quantized input is -1, +1, or 0, depending on whether a threshold is exceeded.
defaultQuantization :: (GLfloat, GLfloat) Source #
A default quantization for the SpaceNavigator 3D mouse.
Tracking
Tracking information for a SpaceNavigator 3D mouse.
Track | |
|
The mode for tracking a SpaceNavigator 3D mouse.
Currently only one mode is available, but other modes, such as flying and examining, will be implemented in the future.
TrackPlatform | Track the mouse as a "platform" in 3D space:
|
defaultTracking :: (Vector3 GLfloat, Vector3 GLfloat) Source #
Default tracking rates for the SpaceNavigator 3D mouse.
:: (Vector3 GLfloat, Vector3 GLfloat) | The rates at which to push or tilt, respectively, based on the mouse input. |
-> IORef Track | A reference to the tracking information. |
-> SpaceNavigatorCallback | A callback for doing the tracking. |
Track the movement of a SpaceNavigator 3D mouse.
Return an action to track a SpaceNavigator 3D mouse via OpenGL matrices.
This simply calls glTranslate
on the position, followed by calls to glRotate
for the third Euler angle (roll/bank) around the x-axis, the second (pitch/elevation) around the y-axis, and then the first (yaw/heading) around the z-axis, relative to an initial orientation where the -z axis is forward.
Return an action to track a SpaceNavigator 3D mouse via OpenGL matrices.
This simply calls glTranslate
on the position, followed by calls to glRotate
for the third Euler angle (roll/bank) around the x-axis, the second (pitch/elevation) around the y-axis, and then the first (yaw/heading) around the z-axis, relative to an initial orientation where the -z axis is forward.
Viewing
Return an action to create a "pilot-eye" view from tracking a SpaceNavigator 3D mouse via OpenGL matrices.
This simply calls glRotate
for the third Euler angle (roll/bank) around the x-axis, then the second (pitch/elevation) around the y-axis, and then the first (yaw/heading) around the z-axis, relative to an initial orientation where the -z axis is forward, finalling calling glTranslate
on the negated position.
Return an action to create a "pilot-eye" view from tracking a SpaceNavigator 3D mouse via OpenGL matrices.
This simply calls glRotate
for the third Euler angle (roll/bank) around the x-axis, then the second (pitch/elevation) around the y-axis, and then the first (yaw/heading) around the z-axis, relative to an initial orientation where the -z axis is forward, finalling calling glTranslate
on the negated position.
Return an action to create a "polar" view from tracking a SpaceNavigator 3D mouse via OpenGL matrices.
This simply calls glTranslate
on along the z-axis negative norm of the position, followed by calls to glRotate
for the negated third Euler angle (roll/bank) around the x-axis, the negate second (pitch/elevation) around the y-axis, and then the first (yaw/heading) around the z-axis, relative to an initial orientation where the -z axis is forward.
Return an action to create a "polar" view from tracking a SpaceNavigator 3D mouse via OpenGL matrices.
This simply calls glTranslate
on along the z-axis negative norm of the position, followed by calls to glRotate
for the negated third Euler angle (roll/bank) around the x-axis, the negate second (pitch/elevation) around the y-axis, and then the first (yaw/heading) around the z-axis, relative to an initial orientation where the -z axis is forward.