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