added translation, added all 4 top faces of the diamond, and got the rotation working more properly

This commit is contained in:
Dan Ballard 2011-07-05 13:20:18 -07:00
parent 5b62211682
commit 30663610d4
1 changed files with 45 additions and 12 deletions

View File

@ -14,9 +14,14 @@
arr))
(defparameter *n* (make-array 3 :initial-contents '(0 0 1)))
(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 *v* (make-2d-array 12 3 '((0.0 1 0) (0.5 0 0.5) (-0.5 0 0.5)
(0.0 1 0) (0.5 0 -0.5) (-0.5 0 -0.5)
(0.0 1 0) (0.5 0 0.5) (0.5 0 -0.5)
(0.0 1 0) (-0.5 0 0.5) (-0.5 0 -0.5)
)))
(defparameter *faces* (make-2d-array 2 3 '((0 1 2) (3 4 5) (6 7 8) (9 10 11))))
(defparameter *position* (make-array 3 :initial-contents '(0 0 1)))
(defparameter *start-time* (wall-time))
@ -26,7 +31,8 @@
;;(defparameter *t1* '( (-0.5 -0.5 0) (0 0.5 0) (0.5 -0.5 0)))
(defun get-vertecies (faces)
(loop for i from 0 to (1- (length faces)) collecting (aref *v* (aref faces i))))
(make-array (length faces) :initial-contents
(loop for i across faces collecting (aref *v* i))))
(let ((time-units (/ 1.0 internal-time-units-per-second)))
(defun wall-time (&key (offset 0))
@ -62,6 +68,16 @@
(incf (aref result x) (* (aref v y) (aref m x y)))))
result))
(defun translate-point (v1 v2)
(let ((result (make-array 3)))
(dotimes (i 3)
(setf (aref result i) (+ (aref v1 i) (aref v2 i))))
result))
(defun translate-triangle (tri position)
(make-array (length tri) :initial-contents
(loop for v across tri collecting (translate-point position v))))
;(defun rotate-vertex-2d (v rM)
; v)
@ -76,10 +92,9 @@
; (list (+ (first v) (/ (sin time) 2)) (+ (second v) (/ (cos time) 2)) (third v)))
(defun rotate-triangle (tri time)
(list
(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))))
(make-array (length tri) :initial-contents
(loop for v across tri collecting (rotate* (make-rotation-matrix 0 time 0) v))))
; (let* ((angle (/ time 1000))
; (cos-a (cos angle))
; (sin-a (sin angle))
@ -95,17 +110,17 @@
(gl:with-primitive :triangles
(multiple-value-bind (red green blue) (shift-color time)
(gl:color red green blue))
(let ((v (first tri)))
(let ((v (aref tri 0)))
(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)))
(let ((v (aref tri 1)))
(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)))
(let ((v (aref tri 2)))
(gl:vertex (aref v 0) (aref v 1) (aref v 2)))))
@ -118,7 +133,7 @@
(gl:clear :color-buffer-bit)
;;; draw a triangle
(loop for face-list across *faces* do
(let ((rt (rotate-triangle (get-vertecies face-list) time)))
(let ((rt (translate-triangle (rotate-triangle (get-vertecies face-list) time) *position*)))
(draw-triangle rt time)))
;; finish the frame
(gl:flush)
@ -135,11 +150,29 @@
(setf *last-time* time)))
(defun reshape ()
(gl:matrix-mode :projection)
(gl:load-identity)
(glu:perspective 45 ;; FOV
1.0 ;; aspect ratio(/ width (max height 1))
1/10 ;; z near
100 ;; z far
)
(gl:matrix-mode :modelview)
;(gl:load-identity)
(glu:look-at 0 0 0 ;; eye
0 0 0 ;; center
0 1 0 ;; up in y pos
)
)
(defun init ()
(setf *start-time* (wall-time))
(setf *num-frames* 0)
(setf *last-time* 0)
(reshape)
)
(defun main-loop ()