opengl-spacenavigator 0.1.2.0 → 0.1.4.2
raw patch · 4 files changed
+93/−22 lines, 4 filesdep ~GLUTdep ~OpenGLdep ~basePVP: major bump suggested
API removals or changes: PVP suggests a major version bump
Dependency ranges changed: GLUT, OpenGL, base, data-default
API changes (from Hackage documentation)
+ Graphics.UI.SpaceNavigator: [trackLastPressed] :: Track -> Maybe Button
+ Graphics.UI.SpaceNavigator: doPilotView :: Track -> IO ()
+ Graphics.UI.SpaceNavigator: doPilotView' :: IORef Track -> IO ()
+ Graphics.UI.SpaceNavigator: doPolarView :: Track -> IO ()
+ Graphics.UI.SpaceNavigator: doPolarView' :: IORef Track -> IO ()
+ Graphics.UI.SpaceNavigator: doTracking' :: IORef Track -> IO ()
- Graphics.UI.SpaceNavigator: Track :: TrackMode -> Vector3 GLfloat -> Vector3 GLfloat -> Bool -> Bool -> Track
+ Graphics.UI.SpaceNavigator: Track :: TrackMode -> Vector3 GLfloat -> Vector3 GLfloat -> Bool -> Bool -> Maybe Button -> Track
Files
- ReadMe.md +2/−0
- opengl-spacenavigator.cabal +10/−10
- src/Graphics/UI/SpaceNavigator.hs +79/−9
- src/Main.hs +2/−3
ReadMe.md view
@@ -3,6 +3,8 @@ This Haskell package contains 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. +Please report issues at <<https://bwbush.atlassian.net/projects/HOGLSPNV/issues/>>.+ Skeletal example illustrating the use of a SpaceNavigator with OpenGL ---------------------------------------------------------------------
@@ -1,5 +1,5 @@ name: opengl-spacenavigator-version: 0.1.2.0+version: 0.1.4.2 synopsis: Library and example for using a SpaceNavigator-compatible 3-D mouse with OpenGL description: This package contains 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. license: MIT@@ -9,11 +9,11 @@ copyright: (c) 2015 Brian W Bush category: Graphics build-type: Simple-cabal-version: >=1.10+cabal-version: >= 1.10 stability: Stable homepage: https://bitbucket.org/bwbush/opengl-spacenavigator bug-reports: https://bwbush.atlassian.net/projects/HOGLSPNV/issues/-package-url: https://bitbucket.org/bwbush/opengl-spacenavigator/downloads/opengl-spacenavigator-0.1.2.0.tar.gz+package-url: https://bitbucket.org/bwbush/opengl-spacenavigator/downloads/opengl-spacenavigator-0.1.4.2.tar.gz extra-source-files: ReadMe.md @@ -23,18 +23,18 @@ library exposed-modules: Graphics.UI.SpaceNavigator- build-depends: base >= 4.6 && < 5- , data-default- , GLUT >= 2.4- , OpenGL >= 2.8+ build-depends: base >= 4.6 && < 5+ , data-default >= 0.5.3+ , GLUT >= 2.4+ , OpenGL >= 2.8 hs-source-dirs: src default-language: Haskell2010 executable opengl-spacenavigator main-is: Main.hs- build-depends: base >= 4.6 && < 5+ build-depends: base , data-default- , GLUT >= 2.4- , OpenGL >= 2.8+ , GLUT+ , OpenGL hs-source-dirs: src default-language: Haskell2010
@@ -75,6 +75,12 @@ , defaultTracking , track , doTracking+, doTracking'+-- * Viewing+, doPilotView+, doPilotView'+, doPolarView+, doPolarView' ) where @@ -82,8 +88,8 @@ import Control.Monad (when) import Data.Default (Default(..)) import Data.IORef (IORef)-import Graphics.Rendering.OpenGL (GLfloat, Vector3(..), rotate, translate)-import Graphics.UI.GLUT (KeyState(..), SettableStateVar, SpaceballInput(..), ($=!), ($~!), makeSettableStateVar, spaceballCallback)+import Graphics.Rendering.OpenGL (GLfloat, SettableStateVar, Vector3(..), ($=!), ($~!), get, makeSettableStateVar, rotate, translate)+import Graphics.UI.GLUT (KeyState(..), SpaceballInput(..), spaceballCallback) -- | Input received from a SpaceNavigator 3D mouse.@@ -210,11 +216,12 @@ , trackOrientation :: Vector3 GLfloat -- ^ The Euler angles for the orientation: yaw\/heading, pitch\/elevation, and roll\/bank, relative an initial orientation where the /-z/ axis is forward: see \<<https://en.wikipedia.org/wiki/Euler_angles#Alternative_names>\>. , trackLeftPress :: Bool -- ^ Whether the left button is pressed. , trackRightPress :: Bool -- ^ Whether the right button is pressed.+ , trackLastPressed :: Maybe Button -- ^ The last button pressed, if any. } deriving (Eq, Read, Show) instance Default Track where- def = Track def (Vector3 0 0 0) (Vector3 0 0 0) False False+ def = Track def (Vector3 0 0 0) (Vector3 0 0 0) False False Nothing -- | The mode for tracking a SpaceNavigator 3D mouse.@@ -273,15 +280,22 @@ tracking $~! \t -> t {- trackLeftPress = action == ButtonPress+ trackLeftPress = action == ButtonPress+ , trackLastPressed = Just ButtonLeft } track _ tracking (Button ButtonRight action) = tracking $~! \t -> t { trackRightPress = action == ButtonPress+ , trackLastPressed = Just ButtonRight }-track _ _ (Button (ButtonOther _) _) = return ()+track _ tracking (Button b _) =+ tracking $~!+ \t ->+ t {+ trackLastPressed = Just b+ } -- | Translate a 3-vector.@@ -313,8 +327,64 @@ doTracking Track{..} = do let- Vector3 alpha beta gamma = trackOrientation+ Vector3 yaw pitch roll = trackOrientation translate trackPosition- rotate gamma $ Vector3 1 0 0- rotate beta $ Vector3 0 1 0- rotate alpha $ Vector3 0 0 1+ rotate roll $ Vector3 1 0 0+ rotate pitch $ Vector3 0 1 0+ rotate yaw $ Vector3 0 0 1+++-- | 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' :: IORef Track -- ^ A reference to the tracking information.+ -> IO () -- ^ An action to track the mouse.+doTracking' = (doTracking =<<) . get+++-- | 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 :: Track -- ^ The tracking information.+ -> IO () -- ^ An action to set the view.+doPilotView Track{..} =+ do+ let+ Vector3 x y z = trackPosition+ Vector3 heading elevation bank = trackOrientation+ rotate bank $ Vector3 1 0 0+ rotate elevation $ Vector3 0 1 0+ rotate heading $ Vector3 0 0 1+ translate $ Vector3 (-x) (-y) (-z)+++-- | 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' :: IORef Track -- ^ A reference to the tracking information.+ -> IO () -- ^ An action to set the view.+doPilotView' = (doPilotView =<<) . get+++-- | 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 :: Track -- ^ The tracking information.+ -> IO () -- ^ An action to set the view.+doPolarView Track{..} =+ do+ let+ Vector3 x y z = trackPosition+ Vector3 azimuth elevation twist = trackOrientation+ translate $ Vector3 0 0 (- sqrt (x^(2 :: Int) + y^(2 :: Int) + z^(2 :: Int)))+ rotate (-twist) $ Vector3 0 0 1+ rotate (-elevation) $ Vector3 1 0 0+ rotate azimuth $ Vector3 0 0 1+++-- | 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' :: IORef Track -- ^ A reference to the tracking information.+ -> IO () -- ^ An action to set the view.+doPolarView' = (doPolarView =<<) . get
src/Main.hs view
@@ -20,7 +20,7 @@ import Data.IORef (IORef, newIORef) import Graphics.Rendering.OpenGL (ClearBuffer(..), Color3(..), ComparisonFunction(Less), GLfloat, MatrixMode(Modelview, Projection), Position(..), PrimitiveMode(..), Size(..), Vector3(..), Vertex3(..), ($=), ($=!), clear, color, depthFunc, flush, frustum, get, loadIdentity, matrixMode, preservingMatrix, renderPrimitive, rotate, translate, vertex, viewport) import Graphics.UI.GLUT (DisplayCallback, DisplayMode(..), ReshapeCallback, createWindow, displayCallback, getArgsAndInitialize, idleCallback, initialDisplayMode, mainLoop, postRedisplay, reshapeCallback, swapBuffers)-import Graphics.UI.SpaceNavigator (Track(..), defaultQuantization, defaultTracking, doTracking, quantize, spaceNavigatorCallback, track)+import Graphics.UI.SpaceNavigator (Track(..), defaultQuantization, defaultTracking, doTracking', quantize, spaceNavigatorCallback, track) -- | The main action.@@ -107,13 +107,12 @@ p1 = (-u, -u, 0) p2 = ( u, -u, 0) p3 = ( 0, v, 0)- tracking' <- get tracking clear [ColorBuffer, DepthBuffer] loadIdentity rotate 10 $ Vector3 1 2 (0 :: GLfloat) translate $ Vector3 0.5 (-0.2) (-3.5 :: GLfloat) preservingMatrix $ do- doTracking tracking'+ doTracking' tracking color $ Color3 1.0 0.4 (0.5 :: GLfloat) renderPrimitive Triangles $ mapM_ vertex3f