Skip to content

Commit

Permalink
Add cancel-contact
Browse files Browse the repository at this point in the history
  • Loading branch information
Shinmera committed May 28, 2024
1 parent 7003a74 commit 75f17a1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@
#:contact-a-relative
#:contact-b-relative
#:make-contact
#:cancel-contact
#:rigidbody-system
#:collides-p
#:resolve-collision
Expand Down
14 changes: 12 additions & 2 deletions physics/resolution.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
(a-velocity-change (vec3 0 0 0) :type vec3)
(b-velocity-change (vec3 0 0 0) :type vec3))

(defun cancel-contact (contact)
(setf (contact-depth contact) 0.0)
(setf (contact-desired-delta contact) 0.0)
(v<- (contact-a-rotation-change contact) 0)
(v<- (contact-a-velocity-change contact) 0)
(v<- (contact-b-rotation-change contact) 0)
(v<- (contact-b-velocity-change contact) 0))

(defun hit-basis (hit &optional (basis (mat3)))
(declare (optimize speed (safety 1)))
(declare (type hit hit))
Expand Down Expand Up @@ -369,7 +377,8 @@
for worst = (the single-float (depth-eps system))
for contact = NIL
do (do-contacts (tentative)
(when (< worst (contact-depth tentative))
(when (and (< worst (contact-depth tentative))
(< 0.0 (contact-depth tentative)))
(setf contact tentative)
(setf worst (contact-depth contact))))
(unless contact (return))
Expand All @@ -390,7 +399,8 @@
for worst = (the single-float (velocity-eps system)) ;; Some kinda epsilon.
for contact = NIL
do (do-contacts (tentative)
(when (< worst (contact-desired-delta tentative))
(when (and (< worst (contact-desired-delta tentative))
(< 0.0 (contact-desired-delta tentative)))
(setf contact tentative)
(setf worst (contact-desired-delta contact))))
(unless contact (return))
Expand Down

0 comments on commit 75f17a1

Please sign in to comment.