1 ;;; Gacela, a GNU Guile extension for fast games development
2 ;;; Copyright (C) 2009 by Javier Sancho Fernandez <jsf at jsancho dot org>
4 ;;; This program is free software: you can redistribute it and/or modify
5 ;;; it under the terms of the GNU General Public License as published by
6 ;;; the Free Software Foundation, either version 3 of the License, or
7 ;;; (at your option) any later version.
9 ;;; This program is distributed in the hope that it will be useful,
10 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ;;; GNU General Public License for more details.
14 ;;; You should have received a copy of the GNU General Public License
15 ;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
18 (define-module (gacela views)
19 #:use-module (gacela gacela)
20 #:use-module ((gacela video) #:renamer (symbol-prefix-proc 'video:))
21 #:use-module ((gacela gl) #:select (glPushMatrix glPopMatrix))
22 #:use-module (ice-9 optargs))
24 (define-macro (define-view name content)
26 (hash-set! active-views ',name (lambda () (video:glmatrix-block ,content)))
29 (define (mesh primitive)
30 (let ((x 0) (y 0) (z 0)
36 `((id . ,id) (x . ,x) (y . ,y) (z . ,z) (ax . ,ax) (ay . ,ay) (az . ,az) (rx . ,rx) (ry . ,ry) (rz . ,rz)))))
37 (lambda (option . params)
41 (video:rotate rx ry rz)
42 (video:translate x y z)
43 (video:rotate ax ay az)
46 (set! x (+ x (car params)))
47 (set! y (+ y (cadr params)))
48 (set! z (+ z (caddr params))))
52 (assoc-ref (get-properties) (car params))))))))
54 (define* (show-mesh mesh #:optional (view default-view))
55 (let ((id (mesh 'get-property 'id)))
56 (if (not (hash-ref view id))
57 (hash-set! view id mesh))))
59 (define* (hide-mesh mesh #:optional (view default-view))
60 (hash-remove! view (mesh 'get-property 'id)))
62 (define* (translate mesh x y #:optional (z 0))
63 (mesh 'translate x y z)
66 (define-macro (define-primitives . symbols)
67 (cond ((null? symbols)
71 (define (,(caar symbols) . params) (mesh (lambda () (apply ,(cadar symbols) params))))
72 (define-primitives ,@(cdr symbols))))))
75 (rectangle video:draw-rectangle)
76 (square video:draw-square))
79 (module-map (lambda (sym var)
80 (if (not (eq? sym '%module-public-interface))
81 (module-export! (current-module) (list sym))))