Refactored some model generation code

This commit is contained in:
Dan Ballard 2012-06-03 21:13:14 -07:00
parent e6bd3e819f
commit 741baafc2b
2 changed files with 44 additions and 10 deletions

View File

@ -1,5 +1,6 @@
(in-package #:flight-sim)
(defclass engine-object (game-object)
((start-time :initarg :start-time :accessor start-time :initform 0)
;; time till fully active
@ -10,6 +11,17 @@
(defmethod activate ((object engine-object) start-time)
(setf (start-time object) start-time))
;; Engine Vertices &
;; Engine colors
;; array of color transforms for engine vertices
;; Each cell if an RGB array of transforms for the vertex
;; Each subcell is (Start-color Final-color Transform-time)
;; 4 vertices
;; each of 3 coords/colors
;; each either:
;; Value
;; (start end time)
(defclass engine-model (model)
((template-vertices :initarg :template-vertices :accessor template-vertices :initform nil)
(template-colors :initarg :template-colors :accessor template-colors :initform nil)))
@ -31,21 +43,40 @@
(setf (vertices model) (generate-step-2d-array (template-vertices model) time))
(setf (colors model) (generate-step-2d-array (template-colors model) time)))
(defun make-thruster-vertices (start-model final-model duration)
(loop for i from 0 to (1- (length start-model)) collect
(let ((start (elt start-model i))
(final (elt final-model i)))
(loop for x from 0 to 2 collect
;(if (eql (elt start x) (elt final x))
; x
(list (elt start x) (elt final x) duration)))));)
(defparameter *thruster-vertices*
'((0.0 0.5 0.0) (-2.0 -0.5 0.0) (2.0 -0.5 0.0)
; z goes from 0 to 1 in 2 seconds
(0.0 0.0 (0 1.5 2))))
(make-thruster-vertices
'( (0.0 0.5 0.0) (-2.0 -0.5 0.0) (2.0 -0.5 0.0) (0.0 0.0 0.0))
'( (0.0 0.5 0.0) (-2.0 -0.5 0.0) (2.0 -0.5 0.0) (0.0 1.5 0.0))
2))
; '((0.0 0.5 0.0) (-2.0 -0.5 0.0) (2.0 -0.5 0.0)
; ; z goes from 0 to 1 in 2 seconds
; (0.0 0.0 (0 1.5 2))))
(defun make-thruster-colors (base-color-start base-color-final tip-color-start tip-color-final duration)
(append (loop for i from 1 to 3 collect
(loop for x from 0 to 2 collect
(list (elt base-color-start x) (elt base-color-final x) duration)))
(loop for x from 0 to 2 collect
(list (elt tip-color-start x) (elt tip-color-final x) duration))))
(defparameter *thruster-colors*
'(((32 64 2) (32 132 2) (32 164 2))
((32 64 2) (32 132 2) (32 164 2))
((32 64 2) (32 132 2) (32 164 2))
((0 255 2) (0 255 2) (64 255 2))))
(make-thruster-colors '(32 32 32) '(64 132 164) '(0 0 64) '(255 255 255) 2))
; '(((32 64 2) (32 132 2) (32 164 2)) ;; vertex1 : Red (32 -> 62 in 2 sec) Green (32 -> 132 in 2 sec) Blue (32 -> 164 in 2 sec
; ((32 64 2) (32 132 2) (32 164 2))
; ((32 64 2) (32 132 2) (32 164 2))
; ((0 255 2) (0 255 2) (64 255 2))))
;; jet shooting up
(defparameter *jet-vertices*
'((0 0 -0.2) (-0.2 0 0.2) (0.2 0 0.2) (0 (0 0.4 1) 0)))
;(defparameter *jet-vertices*
; '((0 0 -0.2) (-0.2 0 0.2) (0.2 0 0.2) (0 (0 0.4 1) 0)))
(defmethod draw ((object engine-object) time)
(if (< (- time (start-time object)) (activation-time object)) ;; hack since times are in templates!!!

View File

@ -78,9 +78,12 @@
(setf (gethash "lime" *colors*) '(0 255 0))
(setf (gethash "orange" *colors*) '(255 165 0))
(setf (gethash "yellow" *colors*) '(255 255 0))
(setf (gethash "purple" *colors*) '(128 0 128))
(setf (gethash "black" *colors*) '(0 0 0))
(setf (gethash "white" *colors*) '(255 255 255))
(setf (gethash "grey" *colors*) '(128 128 128))
;; returns a model of a 3 pyramid from points and colors