From 32fa1cd3e0e78184dafa0f2c07b5b7937fc9f9ef Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Sun, 7 Aug 2011 10:06:20 -0700 Subject: [PATCH] finally show engine --- engine.lisp | 6 +++--- flight-sim.lisp | 27 +++++++++++++++------------ model.lisp | 1 + 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/engine.lisp b/engine.lisp index fb538fc..c171d81 100644 --- a/engine.lisp +++ b/engine.lisp @@ -13,6 +13,7 @@ ((template-vertices :initarg :template-vertices :accessor template-vertices :initform nil) (template-colors :initarg :template-colors :accessor template-colors :initform nil))) + (defun generate-step-2d-array (2darr time) (let ((len-arr (length 2darr)) (len-row (length (first 2darr)))) @@ -26,7 +27,6 @@ ; take 2 seconds to fully fire (defmethod regen-model ((model engine-model) time) - (format t "REGNE MODEL~%") (setf (vertices model) (generate-step-2d-array (template-vertices model) time)) (setf (colors model) (generate-step-2d-array (template-colors model) time))) @@ -44,8 +44,8 @@ (defmethod draw ((object engine-object) time) - (if (< (- time (start-time object)) (activation-time object)) - (regen-model (model object) time)) + (if (< (- time (start-time object)) (activation-time object)) ;; hack since times are in templates!!! + (regen-model (model object) (- time (start-time object)))) (call-next-method)) diff --git a/flight-sim.lisp b/flight-sim.lisp index f624aa6..948ad09 100644 --- a/flight-sim.lisp +++ b/flight-sim.lisp @@ -112,14 +112,14 @@ ; (object-draw (engine object))))) -(defun draw-world (time) +(defun draw-world (start-time) ;; clear the buffer (gl:clear :color-buffer-bit :depth-buffer-bit) ;; move to eye position ;;draw (make-instance 'powered-object :motion (make-instance 'motion :coords (vector 0 0 -3)) :model *ship-model* :engine (engine *self*))) (let ((orig-coords (coords (body *self*)))) (setf (coords (body *self*)) (vector 0 0 -3)) - (draw *self* time) + (draw *self* start-time) (setf (coords (body *self*)) orig-coords)) (gl:translate (- (aref (coords (body *self*)) 0)) (- (aref (coords (body *self*)) 1)) (- (aref (coords (body *self*)) 2))) ;; eye @@ -127,12 +127,12 @@ (loop for entity across *world* do ; only draw if its infront of me (if (< (aref (coords (body entity)) 2) (+ 10 (aref (coords (body *self*)) 2))) - (draw entity time))) + (draw entity start-time))) (gl:matrix-mode :modelview) (gl:load-identity) - (glu:look-at 0 6 10 ;; pos + (glu:look-at 0 6 10 ;; 0 6 10 pos 0 0 0 ;; center 0 1 0 ;; up in y pos ) @@ -198,13 +198,13 @@ (incf *num-frames*) - (if (not (eql (floor *last-time*) (floor time))) - (let* ((short-interval time) - (long-interval (- start-time *start-time*) ) - (short-fps (floor (if (zerop short-interval) 0 (/ 1 short-interval)))) - (long-fps (floor (if (zerop long-interval) 0 (/ *num-frames* long-interval))))) + ; (if (not (eql (floor *last-time*) (floor time))) +; (let* ((short-interval time) +; (long-interval (- start-time *start-time*) ) +; (short-fps (floor (if (zerop short-interval) 0 (/ 1 short-interval)))) +; (long-fps (floor (if (zerop long-interval) 0 (/ *num-frames* long-interval))))) - (format t "FPS since last:~a since start:~a (~a frames in ~a seconds)~%" short-fps long-fps *num-frames* long-interval))) +; (format t "FPS since last:~a since start:~a (~a frames in ~a seconds)~%" short-fps long-fps *num-frames* long-interval))) (setf *last-time* start-time))) @@ -261,9 +261,12 @@ :activation-time 2 :model (make-instance 'engine-model :template-vertices *thruster-vertices* - :template-colors *thruster-colors*) + :template-colors *thruster-colors* + :faces (make-2d-array 4 3 '((0 1 3) (0 2 1) (0 3 2) (1 2 3))) + :face-colors (make-2d-array 4 3 '((0 1 3) (0 2 1) (0 3 2) (1 2 3)))) + :body (make-instance 'body - :coords (vector 0 0 3)))))) + :coords (vector 0 0.5 3)))))) ;:engines (list :engines (list :thrust ; (make-instance 'engine-object ; :motion (make-instance 'motion :coords (vector 0 0.5 3.0)) diff --git a/model.lisp b/model.lisp index a4e2248..6bdd9cf 100644 --- a/model.lisp +++ b/model.lisp @@ -54,6 +54,7 @@ :faces (make-2d-array 8 3 '((0 3 1) (0 2 4) (0 1 2) (0 4 3) (3 5 1) (2 5 4) (1 5 2) (4 5 3))))) +;; returns a model of a 3 pyramid (defun make-model-3pyramid (points &key (face-colors nil) (point-colors nil)) (make-instance 'model :vertices points