X-Git-Url: https://git.jsancho.org/?a=blobdiff_plain;f=gacela_draw.lisp;h=a23c735d98947e58c1a6660030708adf420a7959;hb=90b112bd017851a29a00bcba04eb23216c642214;hp=fd2a7174d8ed7eabf7c5fd591565251e9cd25381;hpb=ee0ee8aa7b6140f964ef3b04828f4144f831fcd4;p=gacela.git diff --git a/gacela_draw.lisp b/gacela_draw.lisp index fd2a717..a23c735 100644 --- a/gacela_draw.lisp +++ b/gacela_draw.lisp @@ -14,13 +14,21 @@ ;;; You should have received a copy of the GNU General Public License ;;; along with this program. If not, see . -(in-package :gacela) + +(eval-when (compile load eval) + (when (not (find-package 'gacela)) (make-package 'gacela :nicknames '(gg) :use '(lisp))) + (in-package 'gacela :nicknames '(gg) :use '(lisp))) + (defmacro with-color (color &body code) - `(let ((original-color (get-current-color))) - (apply #'set-current-color ,color) - ,@code - (apply #'set-current-color original-color))) + (cond (color + `(let ((original-color (get-current-color))) + (apply #'set-current-color ,color) + ,@code + (apply #'set-current-color original-color))) + (t + `(progn + ,@code)))) (defmacro progn-textures (&body code) `(let (values) @@ -105,7 +113,8 @@ (draw-rectangle (* f width) (* f height) :texture texture))))))) (defun draw-quad (v1 v2 v3 v4 &key texture) - (cond (texture + (cond ((consp texture) (with-color texture (draw v1 v2 v3 v4))) + (texture (progn-textures (glBindTexture GL_TEXTURE_2D (getf (get-resource texture) :id-texture)) (begin-draw 4) @@ -123,7 +132,7 @@ (defun draw-square (&key (size 1) texture) (draw-rectangle size size :texture texture)) -(defun draw-cube (&key size texture texture-1 texture-2 texture-3 texture-4 texture-5 texture-6) +(defun draw-cube (&key (size 1) texture texture-1 texture-2 texture-3 texture-4 texture-5 texture-6) (let ((-size (neg size))) (progn-textures (glNormal3f 0 0 1) @@ -150,10 +159,27 @@ (defun translate (x y &optional (z 0)) (glTranslatef x y z)) -(defun rotate (xrot yrot zrot) +(defun rotate (&rest rot) + (cond ((3d-mode?) (apply #'3d-rotate rot)) + (t (apply #'2d-rotate rot)))) + +(defun 3d-rotate (xrot yrot zrot) (glRotatef xrot 1 0 0) (glRotatef yrot 0 1 0) (glRotatef zrot 0 0 1)) (defun 2d-rotate (rot) - (rotate 0 0 rot)) \ No newline at end of file + (glRotatef rot 0 0 1)) + +(defun to-origin () + (glLoadIdentity) + (cond ((3d-mode?) (camera-look)))) + +(let ((camera-eye '(0 0 0)) (camera-center '(0 0 -100)) (camera-up '(0 1 0))) + (defun set-camera (&key eye center up) + (cond (eye (setq camera-eye eye))) + (cond (center (setq camera-center center))) + (cond (up (setq camera-up up)))) + + (defun camera-look () + (apply #'gluLookAt (concatenate 'list camera-eye camera-center camera-up))))