Permalink
Browse files

little things

  • Loading branch information...
Nik Nyby
Nik Nyby committed Feb 25, 2010
1 parent eef4079 commit d296f79eb0ac78820288f9595b74979520fa7100
Showing with 21 additions and 11 deletions.
  1. +14 −3 Bindings.hs
  2. +4 −4 Main.hs
  3. +0 −2 MetaGL.hs
  4. +2 −1 Render.hs
  5. +1 −1 makefile
View
@@ -17,23 +17,33 @@ keyboardMouse window _ (GL.Char '\ESC') GL.Down _ _ = do
exitWith ExitSuccess
keyboardMouse _ env key state modifiers position = do
e <- GL.get env
+ print $ clock $ vars $ e
env $= userAction e key state
motion env pos = do
e <- GL.get env
+ --pos $= oglToGlut pos
+ print $ sprites e
env $= mouseMotion e pos
passiveMotion env pos = do
e <- GL.get env
+ --pos $= oglToGlut pos
env $= passiveMouseMotion e pos
--__----__----__----__----__----__----__----__----__----__----__----__--
+-- OpenGL and GLUT don't use the same co-ordinates, lol
+--oglToGlut :: GL.Position -> GL.Position
+--oglToGlut (GL.Position x y) = GL.Position (x - (640/2)) (y - (480-2))
-- add a sprite
userAction (Env v sprites) (GL.Char 'a') GL.Down = Env v s
where
- s = (Square (GL.Position newPos newPos) [] False):sprites
- newPos = (fromIntegral $ length sprites * 2) :: GL.GLint
+ s = (Square (GL.Position x y) [] False):sprites
+ -- get random new position from clock
+ -- yeah...... doesn't really work :P
+ x = fromIntegral $ clock v `mod` 20 :: GL.GLint
+ y = fromIntegral $ (clock v + 8) `mod` 20 :: GL.GLint
--- drag a sprite
+-- start dragging a sprite
userAction (Env v sprites)
(GL.MouseButton GL.LeftButton) _ = Env v $
map toggleSticky (filter (isMouseOverSprite v) sprites)
@@ -44,6 +54,7 @@ userAction e _ _ = e
mouseMotion (Env v s) pos = Env (setMousePos pos v)
$ map updateSprite s
where
+ -- drag a sprite
updateSprite q =
if sticky q
then setSpritePos pos q
View
@@ -1,6 +1,5 @@
import Data.IORef
import qualified Graphics.UI.GLUT as GL
-import System.Exit
import Bindings
import MetaGL (render)
@@ -9,7 +8,7 @@ import State
main = do
-- make the GL window
- (progname,args) <- GL.getArgsAndInitialize
+ (_,_) <- GL.getArgsAndInitialize
wnd <- initGL
-- pointer to the program state
@@ -54,9 +53,9 @@ reshape s@(GL.Size x y) = do
tick :: Int -> Env -> Env
-tick tnew (Env v sprites) = Env (setClock (clock v+elapsed) v) s
+tick tnew (Env v sprs) = Env (setClock (clock v+elapsed) v) s
where
- s = map idleSprite sprites
+ s = map idleSprite sprs
elapsed = fromIntegral $ tnew - clock v
idleSprite z = z
@@ -73,5 +72,6 @@ initGL = do
return window
+
($=) :: (GL.HasSetter s) => s a -> a -> IO ()
($=) = (GL.$=)
View
@@ -20,8 +20,6 @@ module MetaGL (
import qualified Graphics.UI.GLUT as GL
-import State
-
class GLCommand a where
render :: a -> IO ()
View
@@ -1,5 +1,6 @@
module Render (
- world
+ world,
+ renderSprite,
) where
import qualified Graphics.UI.GLUT as GL
View
@@ -1,6 +1,6 @@
.PHONY: build clean
build:
- ghc --make -package GLUT -O2 Main.hs -o mma
+ ghc --make -package GLUT -Wall -O2 Main.hs -o mma
clean:
rm *.hi *.o mma

0 comments on commit d296f79

Please sign in to comment.