added second triangle

This commit is contained in:
Dan Ballard 2011-07-04 23:45:09 -07:00
parent 1f44333fc0
commit 5b62211682
1 changed files with 36 additions and 27 deletions

View File

@ -14,8 +14,9 @@
arr))
(defparameter *n* (make-array 3 :initial-contents '(0 0 1)))
(defparameter *v* (make-2d-array 3 3 '((0 0.5 0) (0.5 -0.5 0.0) (-0.5 -0.5 0.0))))
(defparameter *faces* (make-2d-array 1 3 '((0 1 2))))
(defparameter *v* (make-2d-array 6 3 '((0.0 0.5 0.0) (0.5 -0.5 0.0) (-0.5 -0.5 0.0)
(0.0 0.5 1.0) (0.5 -0.5 1.0) (-0.5 -0.5 1.0))))
(defparameter *faces* (make-2d-array 2 3 '((0 1 2) (3 4 5))))
(defparameter *start-time* (wall-time))
@ -62,8 +63,8 @@
result))
(defun rotate-vertex-2d (v rM)
v)
;(defun rotate-vertex-2d (v rM)
; v)
;; (let ((result (lm:* rM (lm:vector (first v) (second v)))))
;; (list (lm:elt result 0) (lm:elt result 1))))
@ -76,9 +77,9 @@
(defun rotate-triangle (tri time)
(list
(rotate* (make-rotation-matrix 0 0 time) (first tri))
(rotate* (make-rotation-matrix 0 0 time) (second tri))
(rotate* (make-rotation-matrix 0 0 time) (third tri))))
(rotate* (make-rotation-matrix 0 time 0) (first tri))
(rotate* (make-rotation-matrix 0 time 0) (second tri))
(rotate* (make-rotation-matrix 0 time 0) (third tri))))
; (let* ((angle (/ time 1000))
; (cos-a (cos angle))
; (sin-a (sin angle))
@ -90,31 +91,39 @@
; (append (rotate-vertex-2d (third tri) rM) (third (third tri))))))
;
(defun draw-triangle (tri time)
(gl:with-primitive :triangles
(multiple-value-bind (red green blue) (shift-color time)
(gl:color red green blue))
(let ((v (first tri)))
(gl:vertex (aref v 0) (aref v 1) (aref v 2)))
(multiple-value-bind (green blue red) (shift-color time)
(gl:color red green blue))
(let ((v (second tri)))
(gl:vertex (aref v 0) (aref v 1) (aref v 2)))
(multiple-value-bind (blue green red) (shift-color time)
(gl:color red green blue))
(let ((v (third tri)))
(gl:vertex (aref v 0) (aref v 1) (aref v 2)))))
(defun draw ()
"draw a frame"
(let* ((time (- (wall-time) *start-time*))
(t1 (rotate-triangle (get-vertecies (aref *faces* 0)) time)))
(let* ((time (- (wall-time) *start-time*)))
(gl:clear :color-buffer-bit)
;;; draw a triangle
(gl:with-primitive :triangles
(multiple-value-bind (red green blue) (shift-color time)
(gl:color red green blue))
(let ((v (first t1)))
(gl:vertex (aref v 0) (aref v 1) (aref v 2)))
(multiple-value-bind (green blue red) (shift-color time)
(gl:color red green blue))
(let ((v (second t1)))
(gl:vertex (aref v 0) (aref v 1) (aref v 2)))
(multiple-value-bind (blue green red) (shift-color time)
(gl:color red green blue))
(let ((v (third t1)))
(gl:vertex (aref v 0) (aref v 1) (aref v 2))))
(loop for face-list across *faces* do
(let ((rt (rotate-triangle (get-vertecies face-list) time)))
(draw-triangle rt time)))
;; finish the frame
(gl:flush)
(sdl:update-display)
(gl:flush)
(sdl:update-display)
(incf *num-frames*)
(if (not (eql (floor *last-time*) (floor time)))
(let* ((short-interval (- time *last-time* ))