--lightGray = color3 0.7 0.7 0.7

orign :: IO ()
orign = do
  lineWidth $= 1
  renderPrimitive Lines $ do
    color3  0.7 0 0
    vertex3 0 0 0
    vertex3 inf 0 0
    color3  0 0.7 0
    vertex3 0 0 0
    vertex3 0 inf 0
    color3  0 0 0.7
    vertex3 0 0 0
    vertex3 0 0 inf
    darkGray
    vertex3 0 0 0
    vertex3 (-inf) 0 0
    vertex3 0 0 0
    vertex3 0 (-inf) 0
    vertex3 0 0 0
    vertex3 0 0 (-inf)
  where
  inf = 1e6
    
{-
plane :: Float -> Int -> Int -> IO ()
plane delta linesPerMajor totalMajors = do
  lineWidth $= 1
  renderPrimitive Lines $ line 1 (linesPerMajor - 1) delta
  where
  y = delta * fromIntegral (linesPerMajor * totalMajors)
  line :: Int -> Int -> Float -> IO ()
  line majorCount _ _ | majorCount > totalMajors = return ()
  line majorCount minorCount x | minorCount == 0 = do
    darkGray
    line' x
    line (majorCount + 1) (linesPerMajor - 1) (x + delta)
  line majorCount minorCount x = do
    lightGray
    line' x
    line majorCount (minorCount - 1) (x + delta)
  line' x = do
    vertex3   x    y  0
    vertex3   x  (-y) 0
    vertex3 (-x)   y  0
    vertex3 (-x) (-y) 0
    vertex3   y    x  0
    vertex3 (-y)   x  0
    vertex3   y  (-x) 0
    vertex3 (-y) (-x) 0
-}
{-
posZ0 :: Int -> Int -> IO (Maybe (Float,Float))
posZ0 x y = do
  ((x1,y1,z1),(x2,y2,z2)) <- unProject x y
  if z1 > 0 && z2 > 0 || z1 < 0 && z2 < 0 then return Nothing else do
    let r = abs z1 / abs (z2 - z1)
        x' = r * (x2 - x1) + x1
        y' = r * (y2 - y1) + y1
    return $ Just (x',y')
-}
orign :: IO ()
orign = do
  lineWidth $= 1
  renderPrimitive Lines $ do
    color3  0.7 0 0
    vertex3 0 0 0
    vertex3 inf 0 0
    color3  0 0.7 0
    vertex3 0 0 0
    vertex3 0 inf 0
    color3  0 0 0.7
    vertex3 0 0 0
    vertex3 0 0 inf
    darkGray
    vertex3 0 0 0
    vertex3 (-inf) 0 0
    vertex3 0 0 0
    vertex3 0 (-inf) 0
    vertex3 0 0 0
    vertex3 0 0 (-inf)
  where
  inf = 1e6
    
{-
plane :: Float -> Int -> Int -> IO ()
plane delta linesPerMajor totalMajors = do
  lineWidth $= 1
  renderPrimitive Lines $ line 1 (linesPerMajor - 1) delta
  where
  y = delta * fromIntegral (linesPerMajor * totalMajors)
  line :: Int -> Int -> Float -> IO ()
  line majorCount _ _ | majorCount > totalMajors = return ()
  line majorCount minorCount x | minorCount == 0 = do
    darkGray
    line' x
    line (majorCount + 1) (linesPerMajor - 1) (x + delta)
  line majorCount minorCount x = do
    lightGray
    line' x
    line majorCount (minorCount - 1) (x + delta)
  line' x = do
    vertex3   x    y  0
    vertex3   x  (-y) 0
    vertex3 (-x)   y  0
    vertex3 (-x) (-y) 0
    vertex3   y    x  0
    vertex3 (-y)   x  0
    vertex3   y  (-x) 0
    vertex3 (-y) (-x) 0
-}
{-
posZ0 :: Int -> Int -> IO (Maybe (Float,Float))
posZ0 x y = do
  ((x1,y1,z1),(x2,y2,z2)) <- unProject x y
  if z1 > 0 && z2 > 0 || z1 < 0 && z2 < 0 then return Nothing else do
    let r = abs z1 / abs (z2 - z1)
        x' = r * (x2 - x1) + x1
        y' = r * (y2 - y1) + y1
    return $ Just (x',y')
-}
orign = do
  lineWidth $= 1
  renderPrimitive Lines $ do
    color3  0.7 0 0
    vertex3 0 0 0
    vertex3 inf 0 0
    color3  0 0.7 0
    vertex3 0 0 0
    vertex3 0 inf 0
    color3  0 0 0.7
    vertex3 0 0 0
    vertex3 0 0 inf
    darkGray
    vertex3 0 0 0
    vertex3 (-inf) 0 0
    vertex3 0 0 0
    vertex3 0 (-inf) 0
    vertex3 0 0 0
    vertex3 0 0 (-inf)
  where
  inf = 1e6
    
{-
plane :: Float -> Int -> Int -> IO ()
plane delta linesPerMajor totalMajors = do
  lineWidth $= 1
  renderPrimitive Lines $ line 1 (linesPerMajor - 1) delta
  where
  y = delta * fromIntegral (linesPerMajor * totalMajors)
  line :: Int -> Int -> Float -> IO ()
  line majorCount _ _ | majorCount > totalMajors = return ()
  line majorCount minorCount x | minorCount == 0 = do
    darkGray
    line' x
    line (majorCount + 1) (linesPerMajor - 1) (x + delta)
  line majorCount minorCount x = do
    lightGray
    line' x
    line majorCount (minorCount - 1) (x + delta)
  line' x = do
    vertex3   x    y  0
    vertex3   x  (-y) 0
    vertex3 (-x)   y  0
    vertex3 (-x) (-y) 0
    vertex3   y    x  0
    vertex3 (-y)   x  0
    vertex3   y  (-x) 0
    vertex3 (-y) (-x) 0
-}
{-
posZ0 :: Int -> Int -> IO (Maybe (Float,Float))
posZ0 x y = do
  ((x1,y1,z1),(x2,y2,z2)) <- unProject x y
  if z1 > 0 && z2 > 0 || z1 < 0 && z2 < 0 then return Nothing else do
    let r = abs z1 / abs (z2 - z1)
        x' = r * (x2 - x1) + x1
        y' = r * (y2 - y1) + y1
    return $ Just (x',y')
-}