From 132446d0c38e30003223c977772e97bf94009b29 Mon Sep 17 00:00:00 2001 From: malc Date: Sat, 1 Nov 2008 14:17:01 +0300 Subject: [PATCH] Mouse support --- rend.ml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/rend.ml b/rend.ml index 4131824..709e582 100644 --- a/rend.ml +++ b/rend.ml @@ -24,6 +24,9 @@ type view = ; mutable roteye: bool ; mutable sphere : bool ; mutable help : bool + ; mutable x : int + ; mutable y : int + ; mutable track_mouse : bool } let view = @@ -42,6 +45,9 @@ let view = ; roteye = true ; sphere = false ; help = true + ; x = 0 + ; y = 0 + ; track_mouse = false } ;; @@ -276,6 +282,31 @@ let special ~key ~x ~y = Glut.postRedisplay (); ;; +let motion ~x ~y = + if view.track_mouse + then + let dx = (x - view.x) in + let dy = (y - view.y) in + view.x <- x; + view.y <- y; + view.rotx <- view.rotx +. float dy; + view.roty <- view.roty -. float dx; + setup view.w view.h; + Glut.postRedisplay (); +;; + +let mouse ~button ~state ~x ~y = + if button = Glut.LEFT_BUTTON + then + if state = Glut.DOWN + then ( + view.x <- x; + view.y <- y; + view.track_mouse <- true; + ) + else view.track_mouse <- false +;; + let main () = let w = 704 and h = 576 in @@ -290,6 +321,8 @@ let main () = let () = Glut.reshapeFunc reshape in let () = Glut.keyboardFunc keyboard in let () = Glut.specialFunc special in + let () = Glut.mouseFunc mouse in + let () = Glut.motionFunc motion in let () = Glut.mainLoop () in () ;; -- 2.11.4.GIT