forward motion just needs debugging

This commit is contained in:
Dan Ballard 2011-08-13 12:09:25 -07:00
parent 5ec1bdf8ba
commit ecece3590d
3 changed files with 20 additions and 18 deletions

View File

@ -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))))))

View File

@ -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 ()

View File

@ -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))