]> git.jsancho.org Git - gacela.git/blobdiff - src/views.scm
New procedure-header procedure.
[gacela.git] / src / views.scm
index 63c162a9d954e4b2a9238b7a7aaefbb721a74539..32a7c3c30b35eecca5829a461c32f183f906ebfb 100644 (file)
   (let ((x 0) (y 0) (z 0)
        (ax 0) (ay 0) (az 0)
        (rx 0) (ry 0) (rz 0)
-       (id (gensym)))
-    (let ((get-properties
+       (id (gensym))
+       (properties '()))
+    (let ((inner-properties
           (lambda ()
             `((id . ,id) (x . ,x) (y . ,y) (z . ,z) (ax . ,ax) (ay . ,ay) (az . ,az) (rx . ,rx) (ry . ,ry) (rz . ,rz)))))
       (lambda (option . params)
        (case option
          ((draw)
           (video:glmatrix-block
-           (video:rotate rx ry rz)
-           (video:translate x y z)
            (video:rotate ax ay az)
+           (video:translate x y z)
+           (video:rotate rx ry rz)
            (primitive)))
          ((translate)
           (set! x (+ x (car params)))
           (set! y (+ y (cadr params)))
           (set! z (+ z (caddr params))))
-         ((get-properties)
-          (get-properties))
-         ((get-property)
-          (assoc-ref (get-properties) (car params))))))))
+         ((turn)
+          (set! ax (+ ax (car params)))
+          (set! ay (+ ay (cadr params)))
+          (set! az (+ az (caddr params))))
+         ((rotate)
+          (set! rx (+ rx (car params)))
+          (set! ry (+ ry (cadr params)))
+          (set! rz (+ rz (caddr params))))
+         ((inner-properties)
+          (inner-properties))
+         ((inner-property)
+          (assoc-ref (inner-properties) (car params)))
+         ((properties)
+          properties)
+         ((property)
+          (assoc-ref properties (car params)))
+         ((property-set!)
+          (set! properties (assoc-set! properties (car params) (cadr params)))))))))
 
-(define* (show-mesh mesh #:optional (view default-view))
-  (let ((id (mesh 'get-property 'id)))
+(define* (show mesh #:optional (view default-view))
+  (let ((id (mesh 'inner-property 'id)))
     (if (not (hash-ref view id))
        (hash-set! view id mesh))))
 
-(define* (hide-mesh mesh #:optional (view default-view))
-  (hash-remove! view (mesh 'get-property 'id)))
+(define* (hide mesh #:optional (view default-view))
+  (hash-remove! view (mesh 'inner-property 'id)))
 
 (define* (translate mesh x y #:optional (z 0))
   (mesh 'translate x y z)
   mesh)
 
+(define (turn mesh . params)
+  (if (>= (length params) 3)
+      (apply mesh (cons 'turn params))
+      (mesh 'turn 0 0 (car params)))
+  mesh)
+
+(define (rotate mesh . params)
+  (if (>= (length params) 3)
+      (apply mesh (cons 'rotate params))
+      (mesh 'rotate 0 0 (car params)))
+  mesh)
+
 (define-macro (define-primitives . symbols)
   (cond ((null? symbols)
         `#t)
        (else
-        `(begin
-           (define (,(caar symbols) . params) (mesh (lambda () (apply ,(cadar symbols) params))))
-           (define-primitives ,@(cdr symbols))))))
+        (let ((origin (caar symbols))
+              (dest (cadar symbols)))
+          `(begin
+             ,(if (and (list? origin) (list? dest))
+                  `(define* ,origin #f)
+                  `(define (,origin . params) (mesh (lambda () (apply ,dest params)))))
+             (define-primitives ,@(cdr symbols)))))))
 
 (define-primitives
   (rectangle video:draw-rectangle)