Prims - Implement die
[clnl] / src / main / interface.lisp
index 27d5eed3ebec4e1b33a25fc5c2e9c2cc4e41850a..ba3efc5fdc4961e3da75ed3a77ac4faab272fe47 100644 (file)
@@ -1,12 +1,12 @@
 (in-package #:clnl-interface)
 
 (defvar *patch-size* 13d0)
-(defvar *world-dims* '(:xmin -5 :xmax 5 :ymin -5 :ymax 5))
 
 (defvar *turtle-list* nil)
 
 ; It may be useful to keep windows around
 (defvar *glut-window-opened* nil)
+(defvar *dimensions* nil)
 
 (defvar *colors*
  '((140 140 140) ; gray       (5)
    (let
     ((color (nl-color->rgb (getf turtle :color))))
     (gl:color (car color) (cadr color) (caddr color)))
-   (gl:with-pushed-matrix
-    (gl:translate (* (getf turtle :xcor) *patch-size*) (* (getf turtle :ycor) *patch-size*) 0)
-    (gl:rotate (getf turtle :heading) 0 0 -1)
-    (gl:call-list *turtle-list*)))
+   (mapcar
+    (lambda (x-modification y-modification)
+     (gl:with-pushed-matrix
+      (gl:translate (* (getf turtle :xcor) *patch-size*) (* (getf turtle :ycor) *patch-size*) 0)
+      (gl:translate x-modification y-modification 0)
+      (gl:rotate (getf turtle :heading) 0 0 -1)
+      (gl:call-list *turtle-list*)))
+    (list 0 (1- (world-width-in-pixels)) (- (1- (world-width-in-pixels))) 0 0)
+    (list 0 0 0 (1- (world-height-in-pixels)) (- (1- (world-height-in-pixels))))))
   (clnl-nvm:current-state))
  (gl:flush))
 
   (gl:vertex 260 250 0)
   (gl:end)))
 
+(defun initialize (&key dims)
+ "INITIALIZE &key DIMS => RESULT
+
+  DIMS: (:xmin XMIN :xmax XMAX :ymin YMIN :ymax YMAX)
+
+ARGUMENTS AND VALUES:
+
+  RESULT: undefined
+  XMIN: An integer representing the minimum patch coord in X
+  XMAX: An integer representing the maximum patch coord in X
+  YMIN: An integer representing the minimum patch coord in Y
+  YMAX: An integer representing the maximum patch coord in Y
+
+DESCRIPTION:
+
+  This is where the initialization of the interface that sits behind
+  the interface lives.  From here, one can go into headless or running
+  mode, but for certain things this interface will still need to act,
+  and also allows for bringing up and taking down of visual elements."
+ (setf *dimensions* dims))
+
 (defun run ()
  "RUN => RESULT
 
@@ -103,8 +129,8 @@ DESCRIPTION:
  (sb-int:with-float-traps-masked (:invalid)
   (cl-glut:init)
   (cl-glut:init-window-size
-   (floor (* *patch-size* (1+ (- (getf *world-dims* :xmax) (getf *world-dims* :xmin)))))
-   (floor (* *patch-size* (1+ (- (getf *world-dims* :ymax) (getf *world-dims* :ymin))))))
+   (world-width-in-pixels)
+   (world-height-in-pixels))
   (cl-glut:init-display-mode :double :rgba)
   (cl-glut:create-window "CLNL Test Window")
   (setf *glut-window-opened* t)
@@ -116,6 +142,12 @@ DESCRIPTION:
   (set-turtle-list)
   (cl-glut:main-loop)))
 
+(defun world-width-in-pixels ()
+ (floor (* *patch-size* (1+ (- (getf *dimensions* :xmax) (getf *dimensions* :xmin))))))
+
+(defun world-height-in-pixels ()
+ (floor (* *patch-size* (1+ (- (getf *dimensions* :ymax) (getf *dimensions* :ymin))))))
+
 (defun export-view ()
  "EXPORT-VIEW => IMAGE-DATA
 
@@ -144,10 +176,17 @@ DESCRIPTION:
   (let
    ((fbo (first (gl:gen-framebuffers 1)))
     (render-buf (first (gl:gen-renderbuffers 1)))
-   ;(width (floor (* *patch-size* (1+ (- (getf *world-dims* :xmax) (getf *world-dims* :xmin))))))
-   ;(height (floor (* *patch-size* (1+ (- (getf *world-dims* :ymax) (getf *world-dims* :ymin))))))
-    (width 143)  ; Hard coded for now, yay v1 (if you see this comment in a year, please cry for me)
-    (height 143))
+   ;(width
+   ; (floor (* *patch-size* (1+ (-
+   ;                             (getf *dimensions* :ymax)
+   ;                             (getf *dimensions* :ymin))))))
+   ;(height
+   ; (floor (* *patch-size* (1+ (- (getf *world-dims* :xmax) (getf *world-dims* :xmin))))))
+   ; (floor (* *patch-size* (1+ (-
+   ;                            (getf *dimensions* :xmax)
+   ;                            (getf *dimensions* :xmin)))))
+    (width (world-width-in-pixels))  ; Hard coded for now, yay v1 (if you see this comment in a year, please cry for me)
+    (height (world-height-in-pixels)))
    (gl:bind-framebuffer :framebuffer fbo)
    (gl:bind-renderbuffer :renderbuffer render-buf)
    (gl:renderbuffer-storage :renderbuffer :rgba8 width height)