dded cycling rainbow and start of transform code
This commit is contained in:
parent
0afbe7502b
commit
4e25d91ce5
54
3bb-1.lisp
54
3bb-1.lisp
|
@ -5,20 +5,60 @@
|
|||
(progn ,@body)
|
||||
(continue () :report "Continue")))
|
||||
|
||||
(let ((time-units (/ 1.0 internal-time-units-per-second)))
|
||||
(defun wall-time (&key (offset 0))
|
||||
(+ (* (get-internal-real-time) time-units)
|
||||
offset)))
|
||||
|
||||
(defvar *start-time* (wall-time))
|
||||
|
||||
(defun shift-color (time)
|
||||
(values
|
||||
;;; red
|
||||
(/ (+ (* (sin (+ (* 0.3 time) 0)) 127) 128) 255)
|
||||
;;; green
|
||||
(/ (+ (* (sin (+ (* 0.3 time) (* 2/3 PI))) 127 ) 128) 255)
|
||||
;;; blue
|
||||
(/ (+ (* (sin (+ (* 0.3 time) (* 4/3 PI))) 127) 128) 255)))
|
||||
|
||||
(defparameter *t1* '( (-0.5 -0.5 0) (0 0.5 0) (0.5 -0.5 0)))
|
||||
|
||||
(defun rotate-vertex (v time)
|
||||
(list (+ (first v) (/ (sin time) 2)) (+ (second v) (/ (cos time) 2)) (third v)))
|
||||
|
||||
(defun rotate-triangle (tri time)
|
||||
(list (rotate-vertex (first tri) time)
|
||||
(rotate-vertex (second tri) time)
|
||||
(rotate-vertex (third tri) time)))
|
||||
|
||||
(defun draw ()
|
||||
"draw a frame"
|
||||
(let* ((time (- (wall-time) *start-time*))
|
||||
(t1 (rotate-triangle *t1* time)))
|
||||
;;;(setf *last-time* (wall-time))
|
||||
|
||||
; (format t "~a ~a: ~a ~a ~a~%" *start-time* time red green blue)
|
||||
(gl:clear :color-buffer-bit)
|
||||
;;; draw a triangle
|
||||
(gl:with-primitive :triangles
|
||||
(gl:color 1 0 0)
|
||||
(gl:vertex 0 0 0)
|
||||
(gl:color 0 1 0)
|
||||
(gl:vertex 0.5 1 0)
|
||||
(gl:color 0 0 1)
|
||||
(gl:vertex 1 0 0))
|
||||
(multiple-value-bind (red green blue) (shift-color time)
|
||||
(gl:color red green blue))
|
||||
(multiple-value-bind (v1 v2 v3) (values-list (first t1))
|
||||
(gl:vertex v1 v2 v3))
|
||||
(multiple-value-bind (green blue red) (shift-color time)
|
||||
(gl:color red green blue))
|
||||
(multiple-value-bind (v1 v2 v3) (values-list (second t1))
|
||||
(gl:vertex v1 v2 v3))
|
||||
(multiple-value-bind (blue green red) (shift-color time)
|
||||
(gl:color red green blue))
|
||||
(multiple-value-bind (v1 v2 v3) (values-list (third t1))
|
||||
(gl:vertex v1 v2 v3)))
|
||||
|
||||
;; finish the frame
|
||||
(gl:flush)
|
||||
(sdl:update-display))
|
||||
(sdl:update-display)))
|
||||
|
||||
|
||||
|
||||
(defun main-loop ()
|
||||
(sdl:with-init ()
|
||||
|
|
Loading…
Reference in New Issue