<?xml version="1.0"?>
<paste-with-annotations>
  <paste>
    <number>
      <integer>71287</integer>
    </number>
    <user>
      <string>topo</string>
    </user>
    <title>
      <string>selfgeneration of opengl nested structures</string>
    </title>
    <contents>
      <string>(asdf:oos 'asdf:load-op :cl-opengl)
(asdf:oos 'asdf:load-op :cl-glu)
(load &quot;glut.lisp&quot;)

(load &quot;/Users/topo/slime-2.0/swank-loader.lisp&quot;)

(defparameter *window-width* 640)
(defparameter *window-height* 480)

(defvar a nil)



(defvar *object3* nil)

(defparameter *time* 0)


(defun time-in-seconds ()
  (float (/ (get-internal-real-time) internal-time-units-per-second)))

(defmacro safe-cffi-callback (lisp-function &amp;rest parameter-list &amp;aux (callback-tmpname (gensym)))
  `(prog2
       (cffi:defcallback ,callback-tmpname :void ,parameter-list
	 (handler-case (,lisp-function ,@(mapcar #'car parameter-list))

	   (error (condition)
	     (setf (symbol-function ',lisp-function) (constantly nil))
	     (format t &quot;Error in ~a: ~a~%&quot; ',lisp-function condition))))
       (cffi:callback ,callback-tmpname)))




;;(defun make-object4 ()
;;  (let ((list (GL:gen-lists 1))
;;	(qobj (glu:new-quadric)))
 ;;   (glu:Quadric-Draw-Style qobj GLU_FILL)
 ;;   (gl:New-List list GL_COMPILE)
 ;;   (glu:Sphere qobj 0.7d0 20 20)		; qobj, radius, slices, stacks
 ;;   (gl:End-List)
 ;;   list))


(defun random-elt2 (list)
  ;;esta funcion evalua el cons escojido
  (eval (elt list (random (length list)))))


(defun hola( )
  (random-elt2
   '((cons 'CL-OPENGL:ROTATE (cons 122 (cons 1233 (cons 15  (cons 15 nil) ))))
     (cons 'CL-OPENGL:TRANSLATE (cons 1 (cons 2 (cons 1.3  nil) )))  
     (cons 'CL-OPENGL:TRANSLATE (cons 0 (cons 6 (cons 0  nil) )))
     
  )))
 

 
(defun creapush-pop( )
  
  (cons (random-elt2
	 '(
	   (cons 'CL-OPENGL:ROTATE (cons 122 (cons 1233 (cons 15  (cons 15 nil) ))))
	   (cons 'CL-OPENGL:TRANSLATE (cons 1 (cons 2 (cons 1.3  nil) )))  
	   (cons 'CL-OPENGL:TRANSLATE (cons 0 (cons 6 (cons 0  nil) )))
	   (cons 'glut:solid-sphere (cons 6.529d0 (cons 4 (cons 5 nil))))
	   ;;(glut:solid-sphere 6.529d0 13 3)
	   ))
	(cons '(gl:pop-matrix) nil )  
	)
  )




(defun random-elt (list)
(elt list (random (length list))))


(defun make-structure ()
  (case (random-elt '(transformation iterations geo push-pop))
    (transformation 
     (let ((trans+geo (copy-seq (random-elt '((gl:scale 0.1 0.1 0) 
					      (gl:translate -1 -3 -1.5)
					      (gl:translate (* (sin (* *time* 0.3)) 59) -3 -1.5)
					      (glut:solid-sphere 3.529d0 13 3) 
					      (glut:solid-torus 3.2d0 14.2d0 20 32)
					      (gl:color 0.2 0.1 0)
					      (gl:color 0.2 0.1 1)
					      (gl:rotate 119 997 27 1))))))
       (concatenate 'list (list trans+geo) (make-structure))))
    (iterations (list (cons 'dotimes 
			    (cons 
			     (cons 'i (cons '10  nil) ) 
			     (cons (hola ) (make-structure))))))
    
    (push-pop (let ((cpp (creapush-pop))) (list (list 'gl:push-matrix) (first cpp) (second cpp))))
  ;;  (push-pop (list (cons 'gl:push-matrix nil) (creapush-pop)))
    (geo (list (random-elt '((glut:solid-sphere 6.529d0 13 3) 
			     (glut:solid-cube 9.d0)
			     (glut:wire-cube 12.2d0)
			     
			     ;;(glut:solid-teapot 50.2d0)
			     (glut:solid-cone 20.2d0 80.2d0 6 6)
			     (glut:solid-dodecahedron )
			     (glut:solid-octahedron)
			     (glut:wire-sphere 14.2d0 20 32)
			     (glut:wire-torus 13.2d0 50.2d0 30 42)
			     (glut:solid-torus 8.2d0 14.2d0 20 32)))))))


;;nuevas cosas:
;;(gl:push-matrix)
;;(gl:pop-matrix)
;;(gl:color 0.2 0.1 0)

;;si sale push matrix , debe escojer luego entre cualquier objeto que incluya todos has que salga popmatrix 
;;y acaba la funcion.

( setf a (make-structure))



;;(sin (* *time* ;;(* *time* 40)
(defun draw ()
  (gl:clear-color 1 1 0 1)
  (gl:clear :color-buffer-bit :depth-buffer-bit)
  (gl:matrix-mode :projection)
  (gl:load-identity)
  (glu:perspective 60 (/ 800 600) 1 2700)
  (gl:matrix-mode :modelview)
  (gl:load-identity)
  (gl:enable :lighting)
  (gl:enable :light0)
  (gl:enable :depth-test)
  (gl:enable :color-material)
  (gl:enable :auto-normal)
  (gl:enable :normalize)
  
  (gl:translate -90 -19 -790)
  

  (gl:rotate -14 -77 88 1)
    
 
    
    (dolist (primitive a)
      ;; PRIMITIVE is now a value such as: (GLUT:SOLID-SPHERE 3d0 13 3)
      ;; But it's still just data, until we ask Lisp to treat it as code:
      (eval primitive))
    ;; (funcall a)
    
    ;; )
    
    
  (glut:swap-buffers))

(defun animate (dt))

(defun init ()
  (glut:init-posix-argv sb-ext:*posix-argv*)
  (glut:init-window-size *window-width* *window-height*)
  (glut:init-display-string &quot;rgb double depth&gt;=16 samples=8&quot;)
  (glut:create-window &quot;GLUT - &lt;Untitled&gt;&quot;)

;;  (setf *object3* (make-object4))
  
  (glut:display-func (safe-cffi-callback draw))
  (let ((last-time))
    (flet ((aux-animate (&amp;aux (current-time (time-in-seconds))
                              (dt (- current-time
                                     (if last-time last-time current-time))))
             (setq *time* (+ *time* dt)
                   last-time current-time)
             (animate dt)
             (sb-sys:serve-all-events 0.01)
             (glut:post-redisplay)))
      (glut:idle-func (safe-cffi-callback aux-animate))))
  
  (flet ((window-resize (width height)
           (setq *window-width* width
                 *window-height* height)
           (gl:viewport 0 0 *window-width* *window-height*)))
    (glut:reshape-func (safe-cffi-callback window-resize (width :int) (height :int))))
  
  (swank:create-server)
  (glut:main-loop))

(unless (boundp 'inited)
  (defparameter inited nil)
  (init))

</string>
    </contents>
    <universal-time>
      <integer>3437085115</integer>
    </universal-time>
    <channel>
      <string>#lispcafe</string>
    </channel>
    <colorization-mode>
      <string>Common Lisp</string>
    </colorization-mode>
    <maybe-spam>
      <null/>
    </maybe-spam>
    <is-unicode>
      <keyword>TRUE</keyword>
    </is-unicode>
    <deletion-requested>
      <null/>
    </deletion-requested>
    <deletion-requested-email>
      <null/>
    </deletion-requested-email>
    <expiration-time>
      <null/>
    </expiration-time>
  </paste>
</paste-with-annotations>
