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 a
- = Push {
- pushRightward :: a
- pushUpward :: a
- pushBackward :: a
- | Tilt {
- tiltForward :: a
- tiltClockwise :: a
- tiltRightward :: a
- | Button { }
- = Push {
- data Button
- data ButtonAction
- type SpaceNavigatorCallback a = SpaceNavigatorInput a -> IO ()
- spaceNavigatorCallback :: forall a. Fractional a => SettableStateVar (Maybe (SpaceNavigatorCallback a))
- quantize :: RealFloat a => (a, a) -> SpaceNavigatorCallback a -> SpaceNavigatorCallback a
- defaultQuantization :: RealFloat a => (a, a)
- data Track a = Track {}
- data TrackMode = TrackPlatform
- defaultTracking :: RealFloat a => (Vector3 a, Vector3 a)
- track :: Num a => (Vector3 a, Vector3 a) -> IORef (Track a) -> SpaceNavigatorCallback a
- doTracking :: (MatrixComponent a, Num a) => Track a -> IO ()
- doTracking' :: (MatrixComponent a, Num a) => IORef (Track a) -> IO ()
- doPilotView :: (MatrixComponent a, Num a) => Track a -> IO ()
- doPilotView' :: (MatrixComponent a, Num a) => IORef (Track a) -> IO ()
- doPolarView :: (MatrixComponent a, RealFloat a) => Track a -> IO ()
- doPolarView' :: (MatrixComponent a, RealFloat a) => IORef (Track a) -> IO ()
Input
data SpaceNavigatorInput a 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 a = SpaceNavigatorInput a -> IO () Source
A callback for input from the SpaceNavigator 3D mouse.
spaceNavigatorCallback :: forall a. Fractional a => SettableStateVar (Maybe (SpaceNavigatorCallback a)) Source
Register the callback for input from the SpaceNavigator 3D mouse.
Quantization
:: RealFloat a | |
=> (a, a) | The thresholds for pushing and titling, respectively, between 0 and +1. |
-> SpaceNavigatorCallback a | The callback for the mouse. |
-> SpaceNavigatorCallback a | 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 :: RealFloat a => (a, a) 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 :: RealFloat a => (Vector3 a, Vector3 a) Source
Default tracking rates for the SpaceNavigator 3D mouse.
:: Num a | |
=> (Vector3 a, Vector3 a) | The rates at which to push or tilt, respectively, based on the mouse input. |
-> IORef (Track a) | A reference to the tracking information. |
-> SpaceNavigatorCallback a | A callback for doing the tracking. |
Track the movement of a SpaceNavigator 3D mouse.
:: (MatrixComponent a, Num a) | |
=> Track a | The tracking information. |
-> IO () | An action to track the 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.
:: (MatrixComponent a, Num a) | |
=> IORef (Track a) | A reference to the tracking information. |
-> IO () | An action to track the 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.
Viewing
:: (MatrixComponent a, Num a) | |
=> Track a | The tracking information. |
-> IO () | An action to set the view. |
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.
:: (MatrixComponent a, Num a) | |
=> IORef (Track a) | A reference to the tracking information. |
-> IO () | An action to set the view. |
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.
:: (MatrixComponent a, RealFloat a) | |
=> Track a | The tracking information. |
-> IO () | An action to set the view. |
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.
:: (MatrixComponent a, RealFloat a) | |
=> IORef (Track a) | A reference to the tracking information. |
-> IO () | An action to set the view. |
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.