From ecece3590dc1bf91e10c13facccbd283c58fc535 Mon Sep 17 00:00:00 2001 From: Dan Ballard Date: Sat, 13 Aug 2011 12:09:25 -0700 Subject: [PATCH] forward motion just needs debugging --- engine.lisp | 18 +++--------------- flight-sim.lisp | 6 ++++-- objects.lisp | 14 +++++++++++++- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/engine.lisp b/engine.lisp index 44b244f..4a2a01e 100644 --- a/engine.lisp +++ b/engine.lisp @@ -50,24 +50,12 @@ (call-next-method)) -(defmethod phys-act ((src engine-object) (target game-object) time) - (let* ((scalar-proj (scalar-proj (vector-scale-1 (direction (force (src)))) (vector-scale-1 (position src)))) +(defmethod get-accel ((src engine-object) (target game-object)) + (let* ((scalar-proj (scalar-proj (scale-vector-1 (direction (force (body src)))) (scale-vector-1 (coords (body src))))) (accel (/ (newtons (force src)) (mass (body target)))) (accel-vec (scale-vector scalar-proj accel))) + accel-vec)) - - -; time is time elapsed in seconds (with decimal for sub seconds) -;(defmethod time-step ((engine engine) object time) -; ; f = ma -; (let ((accel (/ (force engine) (mass object)))) -; ; x = x +v*t + 1/2 * a * t^2 -; (dotimes (i 3) (progn -; (incf (aref (coords motion) i) -; (+ (* (aref (velocity motion) i) time) (* .5 (aref (acceleration motion) i) (expt time 2)))) -; (incf (aref (velocity motion) i) -; (* time (aref (acceleration motion) i)))))) - diff --git a/flight-sim.lisp b/flight-sim.lisp index c64e56a..bd688b8 100644 --- a/flight-sim.lisp +++ b/flight-sim.lisp @@ -103,8 +103,10 @@ (otherwise (format t "~a~%" key)))) (defun phys-step (time) - (loop for sym in (active-attachments *self*) do - (phys-act (getf (attachments *self*) sym) *self* time))) + (let ((accel (vector 0 0 0))) + (loop for sym in (active-attachments *self*) do + (setf accel (vector+ accel (get-accel (getf (attachments *self*) sym) *self*)))) + (apply-accel *self* accel time))) (defun sim-step () diff --git a/objects.lisp b/objects.lisp index bc9f8b6..7117f4b 100644 --- a/objects.lisp +++ b/objects.lisp @@ -40,5 +40,17 @@ (loop for a in (active-attachments object) do (draw (getf (attachments object) a) time))) +;; get the vector of accel src object exerts on target object +(defgeneric get-accel (src target)) + +(defgeneric apply-accel (object accel time)) + +; time is time elapsed in seconds (with decimal for sub seconds) +(defmethod apply-accel ((object game-object) accel time) + ; 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) + (* time (aref accel i)))))) -(defgeneric phys-act (src target time)) \ No newline at end of file