]> git.jsancho.org Git - gacela.git/commitdiff
Primitives definition (for meshes)
authorJavier Sancho <jsf@jsancho.org>
Thu, 27 Sep 2012 22:52:27 +0000 (00:52 +0200)
committerJavier Sancho <jsf@jsancho.org>
Thu, 27 Sep 2012 22:52:27 +0000 (00:52 +0200)
src/video.scm

index 0e6a51345dfd9a6337a27a79bb7f83ad69e12f26..87ba9e0e43e78a42e9cb07784e7bd3f9560806fd 100644 (file)
                    '(draw translate turn rotate inner-properties inner-property properties properties-set! property property-set!)
                    (lambda (record port)
                      (format port "#<mesh: ~a" (mesh-inner-property record 'type))
-                     (for-each (lambda (x)
-                                 (cond (((@ (gacela utils) bound?) (cdr x))
-                                        (format port " ~a" x))))
+                     (for-each (lambda (x) (format port " ~a" x))
                                (mesh-properties record))
                      (display ">" port))))
 
   mesh)
 
 
+;;; Advanced meshes
+
+(define (mesh-join . meshes)
+  (make-mesh
+   'joined-meshes
+   (lambda (props)
+     (for-each (lambda (m) (glmatrix-block (mesh-draw m))) meshes))))
+
+
 ;;; Primitives
 
 (define-macro (define-mesh header . body)
         (mesh-properties-set! m (list ,@(map (lambda (a) `(cons ',a ,a)) (names-arguments args))))
         m))))
 
-(define-mesh (square size #:key texture color)
+(define-macro (primitive header . body)
+  (let* ((type (car header))
+        (args (cdr header))
+        (list-args (names-arguments args)))
+    `(lambda* ,args
+       (let ((m (make-mesh
+                ',type
+                (lambda (props)
+                  (apply (lambda* ,(cons #:key list-args) ,@body)
+                         (list
+                          ,@(let get-params ((l list-args))
+                              (cond ((null? l) '())
+                                    (else
+                                     (cons (symbol->keyword (car l))
+                                           (cons `(assoc-ref props ',(car l))
+                                                 (get-params (cdr l)))))))))))))
+        (mesh-properties-set! m (list ,@(map (lambda (a) `(cons ',a ,a)) list-args)))
+        m))))
+
+(define-macro (define-primitive header . body)
+  `(define ,(car header) (primitive ,header ,@body)))
+
+
+;;; Primitives definition
+
+(define-primitive (square size #:key texture color)
   (draw-square size #:texture texture #:color color))
 
+(define-primitive (rectangle width height #:key texture color texture-coord)
+  (draw-rectangle width height #:texture texture #:color color #:texture-coord texture-coord))
+
 
 (module-map (lambda (sym var)
              (if (not (eq? sym '%module-public-interface))