opengl-spacenavigator-0.1.4.2: Library and example for using a SpaceNavigator-compatible 3-D mouse with OpenGL

Copyright(c) 2015 Brian W Bush
LicenseMIT
MaintainerBrian W Bush <consult@brianwbush.info>
StabilityStable
PortabilityPortable
Safe HaskellNone
LanguageHaskell2010

Graphics.UI.SpaceNavigator

Contents

Description

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:

Synopsis

Input

data SpaceNavigatorInput Source #

Input received from a SpaceNavigator 3D mouse.

Constructors

Push

The mouse has been pushed.

Fields

Tilt

The mouse has been tilted.

Fields

Button

A mouse button has been pressed.

Fields

data Button Source #

Buttons on a SpaceNavigator 3D mouse.

Constructors

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.

Constructors

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

quantize Source #

Arguments

:: (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

data Track Source #

Tracking information for a SpaceNavigator 3D mouse.

Constructors

Track 

Fields

data TrackMode Source #

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.

Constructors

TrackPlatform

Track the mouse as a "platform" in 3D space:

push rightward
increment x position
push leftward
decrement x position
pull upward
increment z position
push downward
decrement z position
pull backward
increment z position
push forward
decrement z position
tilt leftward
increment first Euler angle, yaw/heading
tilt rightward
decrement first Euler angle, yaw/heading
twist counterclockwise
increment second Euler angle, pitch/elevation
twist clockwise
decrement second Euler angle, pitch/elevation
tilt backward
increment third Euler angle, roll/bank
tilt forward
decrement third Euler angle, roll/bank

defaultTracking :: (Vector3 GLfloat, Vector3 GLfloat) Source #

Default tracking rates for the SpaceNavigator 3D mouse.

track Source #

Arguments

:: (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.

doTracking Source #

Arguments

:: Track

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.

doTracking' Source #

Arguments

:: IORef Track

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

doPilotView Source #

Arguments

:: Track

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.

doPilotView' Source #

Arguments

:: IORef Track

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.

doPolarView Source #

Arguments

:: Track

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.

doPolarView' Source #

Arguments

:: IORef Track

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.