Skip to content

Commit

Permalink
Update space objects after collision step ended
Browse files Browse the repository at this point in the history
  • Loading branch information
borodust committed Apr 19, 2020
1 parent 2a1b571 commit c726a1b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
25 changes: 15 additions & 10 deletions physics/2d/body.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,10 @@

(defmethod (setf simulation-engine-body-mass) ((value mass) (engine chipmunk-engine)
(body rigid-body))
(let ((handle (handle-value-of body)))
(%cp:body-set-mass handle (cp-float (mass-value value)))
(%cp:body-set-moment handle (cp-float (mass-inertia value))))
(between-observations
(let ((handle (handle-value-of body)))
(%cp:body-set-mass handle (cp-float (mass-value value)))
(%cp:body-set-moment handle (cp-float (mass-inertia value)))))
value)


Expand All @@ -106,8 +107,9 @@

(defmethod (setf simulation-engine-body-position) ((value vec2) (engine chipmunk-engine)
(body rigid-body))
(with-cp-vect (vect value)
(%cp:body-set-position (handle-value-of body) vect))
(between-observations
(with-cp-vect (vect value)
(%cp:body-set-position (handle-value-of body) vect)))
value)


Expand All @@ -119,8 +121,9 @@

(defmethod (setf simulation-engine-body-linear-velocity) ((value vec2) (engine chipmunk-engine)
(body rigid-body))
(with-cp-vect (vect value)
(%cp:body-set-velocity (handle-value-of body) vect))
(between-observations
(with-cp-vect (vect value)
(%cp:body-set-velocity (handle-value-of body) vect)))
value)


Expand All @@ -131,8 +134,9 @@
(defmethod (setf simulation-engine-body-rotation) ((value mat2)
(engine chipmunk-engine)
(body rigid-body))
(%cp:body-set-angle (handle-value-of body) (cp-float (atan (mref value 1 0)
(mref value 0 0))))
(between-observations
(%cp:body-set-angle (handle-value-of body) (cp-float (atan (mref value 1 0)
(mref value 0 0)))))
value)


Expand All @@ -142,7 +146,8 @@

(defmethod (setf simulation-engine-body-angular-velocity) ((value number) (engine chipmunk-engine)
(body rigid-body))
(%cp:body-set-angular-velocity (handle-value-of body) (cp-float value)))
(between-observations
(%cp:body-set-angular-velocity (handle-value-of body) (cp-float value))))


(defmethod simulation-engine-destroy-rigid-body ((engine chipmunk-engine) (body rigid-body))
Expand Down
4 changes: 4 additions & 0 deletions physics/2d/chipmunk.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@
(if *observing-p*
(push hook *post-observation-hooks*)
(funcall hook)))


(defmacro between-observations (&body body)
`(invoke-between-observations (lambda () ,@body)))

0 comments on commit c726a1b

Please sign in to comment.