forward motion!

This commit is contained in:
Dan Ballard 2011-08-20 10:16:46 -07:00
parent f2eb4cea36
commit a2879d45ed
4 changed files with 14 additions and 11 deletions

View File

@ -35,7 +35,7 @@
(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))))
(0.0 0.0 (0 1.5 2))))
(defparameter *thruster-colors*
'(((32 64 2) (32 132 2) (32 164 2))
@ -51,9 +51,9 @@
(defmethod get-accel ((src engine-object) (target game-object))
(let* ((scalar-proj (scalar-proj (scale-vector-1 (direction (force src))) (scale-vector-1 (coords (body src)))))
(accel (/ (newtons (force src)) (mass (body target))))
(accel-vec (scale-vector scalar-proj accel)))
(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))))
accel-vec))

View File

@ -175,7 +175,7 @@
(setf *self*
(make-instance
'game-object
:body (make-instance 'body :coords (vector 0 0 11))
:body (make-instance 'body :coords (vector 0 0 11) :mass 1000)
:model *ship-model*
:attachments
(list :thruster
@ -186,10 +186,10 @@
: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))))
:force (make-instance 'force :newtons 10 :direction (vector 0 0 1))
:force (make-instance 'force :newtons 10000 :direction (vector 0 0 1))
:body (make-instance 'body
:coords (vector 0 0.5 1.5))))))
:coords (vector 0 0 1.5))))))
;:engines (list :engines (list :thrust
; (make-instance 'engine-object
; :motion (make-instance 'motion :coords (vector 0 0.5 3.0))

View File

@ -60,7 +60,7 @@
; returns a vector with all elemts scaled to biggest 1 which is scaled to 1
; e.x. (scale-vector (8 4 2)) -> (1 .5 .25)
(defun scale-vector-1 (v)
(let ((max (loop for i across v maximize i into result finally (return result))))
(let ((max (loop for i across v maximize (abs i) into result finally (return result))))
(make-array (length v) :initial-contents (loop for i across v collecting (float (/ i max))))))
(defun dot (v1 v2)
@ -76,4 +76,7 @@
(/ (dot vector direction) length))))
(defun vector- (v1 v2)
(make-array (length v1) :initial-contents (loop for i from 0 to (1- (length v1)) collecting (- (aref v1 i) (aref v2 i)))))
(make-array (length v1) :initial-contents (loop for i from 0 to (1- (length v1)) collecting (- (aref v1 i) (aref v2 i)))))
(defun vector+ (v1 v2)
(make-array (length v1) :initial-contents (loop for i from 0 to (1- (length v1)) collecting (+ (aref v1 i) (aref v2 i)))))

View File

@ -50,7 +50,7 @@
; x = x +v*t + 1/2 * a * t^2
(dotimes (i 3) (progn
(incf (aref (coords (body object)) i)
(+ (* (aref (velocity (body object)) i) time) (* .5 (aref accel i) (expt time 2))))
(incf (aref (velocity (body object)) i)
(+ (* (aref (velocity (motion (body object))) i) time) (* .5 (aref accel i) (expt time 2))))
(incf (aref (velocity (motion (body object))) i)
(* time (aref accel i))))))