Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 65 lines (46 sloc) 2.313 kb
86b3849 Dan Ballard most of the engine drawing code
authored
1 (in-package #:flight-sim)
2
3 (defclass engine-object (game-object)
4 ((start-time :initarg :start-time :accessor start-time :initform 0)
bfda5bc Dan Ballard almost drawing engine. at least no syntax errors...
authored
5 ;; time till fully active
5ec1bdf Dan Ballard most of physics for moving
authored
6 (activation-time :initarg :activation-time :accessor activation-time :initform 0)
7 (force :initarg :force :accessor force :initform (make-instance 'force))))
86b3849 Dan Ballard most of the engine drawing code
authored
8
9
bfda5bc Dan Ballard almost drawing engine. at least no syntax errors...
authored
10 (defmethod activate ((object engine-object) start-time)
11 (setf (start-time object) start-time))
12
86b3849 Dan Ballard most of the engine drawing code
authored
13 (defclass engine-model (model)
14 ((template-vertices :initarg :template-vertices :accessor template-vertices :initform nil)
15 (template-colors :initarg :template-colors :accessor template-colors :initform nil)))
16
32fa1cd Dan Ballard finally show engine
authored
17
86b3849 Dan Ballard most of the engine drawing code
authored
18 (defun generate-step-2d-array (2darr time)
19 (let ((len-arr (length 2darr))
bfda5bc Dan Ballard almost drawing engine. at least no syntax errors...
authored
20 (len-row (length (first 2darr))))
86b3849 Dan Ballard most of the engine drawing code
authored
21 (make-2d-array len-arr len-row
bfda5bc Dan Ballard almost drawing engine. at least no syntax errors...
authored
22 (loop for row in 2darr collecting
23 (loop for item in row collecting
24 ;(let ((item (aref (aref 2darr i) j)))
25 (if (listp item)
26 (converge (first item) (second item) (third item) time)
27 item))))))
86b3849 Dan Ballard most of the engine drawing code
authored
28
29 ; take 2 seconds to fully fire
30 (defmethod regen-model ((model engine-model) time)
3a3c66b Dan Ballard getting ready to activate engine on key
authored
31 (setf (vertices model) (generate-step-2d-array (template-vertices model) time))
32 (setf (colors model) (generate-step-2d-array (template-colors model) time)))
86b3849 Dan Ballard most of the engine drawing code
authored
33
34
35 (defparameter *thruster-vertices*
36 '((0.0 0.5 0.0) (-2.0 -0.5 0.0) (2.0 -0.5 0.0)
37 ; z goes from 0 to 1 in 2 seconds
a2879d4 Dan Ballard forward motion!
authored
38 (0.0 0.0 (0 1.5 2))))
86b3849 Dan Ballard most of the engine drawing code
authored
39
40 (defparameter *thruster-colors*
5ec1bdf Dan Ballard most of physics for moving
authored
41 '(((32 64 2) (32 132 2) (32 164 2))
42 ((32 64 2) (32 132 2) (32 164 2))
43 ((32 64 2) (32 132 2) (32 164 2))
86b3849 Dan Ballard most of the engine drawing code
authored
44 ((0 255 2) (0 255 2) (64 255 2))))
45
bbfd06b Dan Ballard jet model
authored
46 ;; jet shooting up
47 (defparameter *jet-vertices*
48 '((0 0 -0.2) (-0.2 0 0.2) (0.2 0 0.2) (0 (0 0.4 1) 0)))
86b3849 Dan Ballard most of the engine drawing code
authored
49
bfda5bc Dan Ballard almost drawing engine. at least no syntax errors...
authored
50 (defmethod draw ((object engine-object) time)
32fa1cd Dan Ballard finally show engine
authored
51 (if (< (- time (start-time object)) (activation-time object)) ;; hack since times are in templates!!!
52 (regen-model (model object) (- time (start-time object))))
86b3849 Dan Ballard most of the engine drawing code
authored
53 (call-next-method))
54
55
ecece35 Dan Ballard forward motion just needs debugging
authored
56 (defmethod get-accel ((src engine-object) (target game-object))
a2879d4 Dan Ballard forward motion!
authored
57 (let* ((force-used (scalar-proj (scale-vector-1 (direction (force src))) (scale-vector-1 (coords (body src)))))
58 (accel (/ (* (newtons (force src)) force-used) (mass (body target))))
59 (accel-vec (scale-vector (scale-vector-1 (direction (force src))) (- accel))))
ecece35 Dan Ballard forward motion just needs debugging
authored
60 accel-vec))
5ec1bdf Dan Ballard most of physics for moving
authored
61
62
63
64
Something went wrong with that request. Please try again.