2011-08-03 05:55:24 +00:00
|
|
|
(in-package #:flight-sim)
|
|
|
|
|
|
|
|
(defclass engine-object (game-object)
|
|
|
|
((start-time :initarg :start-time :accessor start-time :initform 0)
|
2011-08-07 00:20:23 +00:00
|
|
|
;; time till fully active
|
2011-08-13 15:10:01 +00:00
|
|
|
(activation-time :initarg :activation-time :accessor activation-time :initform 0)
|
|
|
|
(force :initarg :force :accessor force :initform (make-instance 'force))))
|
2011-08-03 05:55:24 +00:00
|
|
|
|
|
|
|
|
2011-08-07 00:20:23 +00:00
|
|
|
(defmethod activate ((object engine-object) start-time)
|
|
|
|
(setf (start-time object) start-time))
|
|
|
|
|
2011-08-03 05:55:24 +00:00
|
|
|
(defclass engine-model (model)
|
|
|
|
((template-vertices :initarg :template-vertices :accessor template-vertices :initform nil)
|
|
|
|
(template-colors :initarg :template-colors :accessor template-colors :initform nil)))
|
|
|
|
|
2011-08-07 17:06:20 +00:00
|
|
|
|
2011-08-03 05:55:24 +00:00
|
|
|
(defun generate-step-2d-array (2darr time)
|
|
|
|
(let ((len-arr (length 2darr))
|
2011-08-07 00:20:23 +00:00
|
|
|
(len-row (length (first 2darr))))
|
2011-08-03 05:55:24 +00:00
|
|
|
(make-2d-array len-arr len-row
|
2011-08-07 00:20:23 +00:00
|
|
|
(loop for row in 2darr collecting
|
|
|
|
(loop for item in row collecting
|
|
|
|
;(let ((item (aref (aref 2darr i) j)))
|
|
|
|
(if (listp item)
|
|
|
|
(converge (first item) (second item) (third item) time)
|
|
|
|
item))))))
|
2011-08-03 05:55:24 +00:00
|
|
|
|
|
|
|
; take 2 seconds to fully fire
|
|
|
|
(defmethod regen-model ((model engine-model) time)
|
2011-08-04 06:13:25 +00:00
|
|
|
(setf (vertices model) (generate-step-2d-array (template-vertices model) time))
|
|
|
|
(setf (colors model) (generate-step-2d-array (template-colors model) time)))
|
2011-08-03 05:55:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
(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
|
2011-08-20 17:16:46 +00:00
|
|
|
(0.0 0.0 (0 1.5 2))))
|
2011-08-03 05:55:24 +00:00
|
|
|
|
|
|
|
(defparameter *thruster-colors*
|
2011-08-13 15:10:01 +00:00
|
|
|
'(((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))
|
2011-08-03 05:55:24 +00:00
|
|
|
((0 255 2) (0 255 2) (64 255 2))))
|
|
|
|
|
2011-08-20 22:50:49 +00:00
|
|
|
;; 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)))
|
2011-08-03 05:55:24 +00:00
|
|
|
|
2011-08-07 00:20:23 +00:00
|
|
|
(defmethod draw ((object engine-object) time)
|
2011-08-07 17:06:20 +00:00
|
|
|
(if (< (- time (start-time object)) (activation-time object)) ;; hack since times are in templates!!!
|
|
|
|
(regen-model (model object) (- time (start-time object))))
|
2011-08-03 05:55:24 +00:00
|
|
|
(call-next-method))
|
|
|
|
|
|
|
|
|
2011-08-13 19:09:25 +00:00
|
|
|
(defmethod get-accel ((src engine-object) (target game-object))
|
2011-08-20 17:16:46 +00:00
|
|
|
(let* ((force-used (scalar-proj (scale-vector-1 (direction (force src))) (scale-vector-1 (coords (body src)))))
|
|
|
|
(accel (/ (* (newtons (force src)) force-used) (mass (body target))))
|
|
|
|
(accel-vec (scale-vector (scale-vector-1 (direction (force src))) (- accel))))
|
2011-08-13 19:09:25 +00:00
|
|
|
accel-vec))
|
2011-08-13 15:10:01 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|