most of the engine drawing code
This commit is contained in:
parent
9fac5b54a0
commit
86b3849ee3
|
@ -0,0 +1,46 @@
|
||||||
|
(in-package #:flight-sim)
|
||||||
|
|
||||||
|
(defclass engine-object (game-object)
|
||||||
|
((start-time :initarg :start-time :accessor start-time :initform 0)
|
||||||
|
(activation-time :initarg :activation-time :accessor activation-time :initform 0)))
|
||||||
|
|
||||||
|
|
||||||
|
(defclass engine-model (model)
|
||||||
|
((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 (aref 2darr 0))))
|
||||||
|
(make-2d-array len-arr len-row
|
||||||
|
(loop for i from 0 to len-arr collecting
|
||||||
|
(loop for j from 0 to len-row collecting
|
||||||
|
(let ((item (aref (aref 2darr i) j)))
|
||||||
|
(if (listp item)
|
||||||
|
(converge (first item) (second item) (third item) time)
|
||||||
|
item)))))))
|
||||||
|
|
||||||
|
; take 2 seconds to fully fire
|
||||||
|
(defmethod regen-model ((model engine-model) time)
|
||||||
|
(setf (vertices model) (generate-step-2d-array *thruster-vertices* time))
|
||||||
|
(setf (colors model) (generate-step-2d-array *thruster-colors* time)))
|
||||||
|
|
||||||
|
|
||||||
|
(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 2))))
|
||||||
|
|
||||||
|
(defparameter *thruster-colors*
|
||||||
|
'(((16 64 2) (0 132 2) (32 164 2))
|
||||||
|
((16 64 2) (0 132 2) (32 164 2))
|
||||||
|
((16 64 2) (0 132 2) (32 164 2))
|
||||||
|
((0 255 2) (0 255 2) (64 255 2))))
|
||||||
|
|
||||||
|
|
||||||
|
(defmethod draw ((model engine-model) time)
|
||||||
|
(if (and (generated-model model) (< (- time (start-time model)) (activation-time model)))
|
||||||
|
(regen-model model time))
|
||||||
|
(call-next-method))
|
||||||
|
|
||||||
|
|
|
@ -112,14 +112,14 @@
|
||||||
; (object-draw (engine object)))))
|
; (object-draw (engine object)))))
|
||||||
|
|
||||||
|
|
||||||
(defun draw-world ()
|
(defun draw-world (time)
|
||||||
;; clear the buffer
|
;; clear the buffer
|
||||||
(gl:clear :color-buffer-bit :depth-buffer-bit)
|
(gl:clear :color-buffer-bit :depth-buffer-bit)
|
||||||
;; move to eye position
|
;; move to eye position
|
||||||
;;draw (make-instance 'powered-object :motion (make-instance 'motion :coords (vector 0 0 -3)) :model *ship-model* :engine (engine *self*)))
|
;;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*))))
|
(let ((orig-coords (coords (body *self*))))
|
||||||
(setf (coords (body *self*)) (vector 0 0 -3))
|
(setf (coords (body *self*)) (vector 0 0 -3))
|
||||||
(draw *self*)
|
(draw *self* time)
|
||||||
(setf (coords (body *self*)) orig-coords))
|
(setf (coords (body *self*)) orig-coords))
|
||||||
|
|
||||||
(gl:translate (- (aref (coords (body *self*)) 0)) (- (aref (coords (body *self*)) 1)) (- (aref (coords (body *self*)) 2))) ;; eye
|
(gl:translate (- (aref (coords (body *self*)) 0)) (- (aref (coords (body *self*)) 1)) (- (aref (coords (body *self*)) 2))) ;; eye
|
||||||
|
@ -127,7 +127,7 @@
|
||||||
(loop for entity across *world* do
|
(loop for entity across *world* do
|
||||||
; only draw if its infront of me
|
; only draw if its infront of me
|
||||||
(if (< (aref (coords (body entity)) 2) (+ 10 (aref (coords (body *self*)) 2)))
|
(if (< (aref (coords (body entity)) 2) (+ 10 (aref (coords (body *self*)) 2)))
|
||||||
(draw entity)))
|
(draw entity time)))
|
||||||
|
|
||||||
(gl:matrix-mode :modelview)
|
(gl:matrix-mode :modelview)
|
||||||
(gl:load-identity)
|
(gl:load-identity)
|
||||||
|
@ -192,7 +192,7 @@
|
||||||
|
|
||||||
|
|
||||||
; (phys-step time)
|
; (phys-step time)
|
||||||
(draw-world)
|
(draw-world start-time)
|
||||||
|
|
||||||
|
|
||||||
(incf *num-frames*)
|
(incf *num-frames*)
|
||||||
|
|
|
@ -22,4 +22,4 @@
|
||||||
;(defun draw-entity (entity)
|
;(defun draw-entity (entity)
|
||||||
|
|
||||||
|
|
||||||
(defgeneric draw (object))
|
(defgeneric draw (object time))
|
|
@ -6,7 +6,7 @@
|
||||||
(colors :initarg :colors :reader colors :initform (vector) :type shape-vector)
|
(colors :initarg :colors :reader colors :initform (vector) :type shape-vector)
|
||||||
(face-colors :initarg :face-colors :accessor face-colors :initform (vector) :type shape-ref-vector)))
|
(face-colors :initarg :face-colors :accessor face-colors :initform (vector) :type shape-ref-vector)))
|
||||||
|
|
||||||
(defmethod draw ((model model))
|
(defmethod draw ((model model) time)
|
||||||
(loop for i from 0 to (1- (length (faces model))) do
|
(loop for i from 0 to (1- (length (faces model))) do
|
||||||
(draw-triangle (get-vertecies (aref (faces model) i) (vertices model))
|
(draw-triangle (get-vertecies (aref (faces model) i) (vertices model))
|
||||||
(get-vertecies (aref (face-colors model) i) (colors model)))))
|
(get-vertecies (aref (face-colors model) i) (colors model)))))
|
||||||
|
|
13
objects.lisp
13
objects.lisp
|
@ -11,17 +11,20 @@
|
||||||
|
|
||||||
;(defmethod coords ((object game-object))
|
;(defmethod coords ((object game-object))
|
||||||
; (coords (body object)))
|
; (coords (body object)))
|
||||||
|
|
||||||
|
|
||||||
(defmethod draw :before ((object game-object))
|
(defmethod activate ((object game-object) sym start-time)
|
||||||
|
(push sym (active-attachments object))
|
||||||
|
(activate (getf (attachments object) sym)))
|
||||||
|
|
||||||
|
(defmethod draw :before ((object game-object) time)
|
||||||
(gl:push-matrix)
|
(gl:push-matrix)
|
||||||
(gl:translate (aref (coords (body object)) 0) (aref (coords (body object)) 1) (aref (coords (body object)) 2))
|
(gl:translate (aref (coords (body object)) 0) (aref (coords (body object)) 1) (aref (coords (body object)) 2))
|
||||||
(gl:rotate (aref (angles (body object)) 0) 1 0 0)
|
(gl:rotate (aref (angles (body object)) 0) 1 0 0)
|
||||||
(gl:rotate (aref (angles (body object)) 1) 0 1 0)
|
(gl:rotate (aref (angles (body object)) 1) 0 1 0)
|
||||||
(gl:rotate (aref (angles (body object)) 2) 0 0 1))
|
(gl:rotate (aref (angles (body object)) 2) 0 0 1))
|
||||||
|
|
||||||
(defmethod draw :after ((object game-object))
|
(defmethod draw :after ((object game-object) time)
|
||||||
(gl:pop-matrix))
|
(gl:pop-matrix))
|
||||||
|
|
||||||
(defmethod draw ((object game-object))
|
(defmethod draw ((object game-object) time)
|
||||||
(draw (model object)))
|
(draw (model object) time))
|
||||||
|
|
Loading…
Reference in New Issue