Add contact listener for 3D physics

This commit is contained in:
oakes
2014-04-19 01:10:06 -04:00
parent 41ee2b947c
commit c8ffc51de7
8 changed files with 113 additions and 62 deletions

View File

@@ -14,7 +14,8 @@
[com.badlogic.gdx.physics.bullet.linearmath btMotionState]
[com.badlogic.gdx.physics.bullet.softbody btSoftBody
btSoftBodyRigidBodyCollisionConfiguration btSoftBodyWorldInfo
btSoftRigidDynamicsWorld]))
btSoftRigidDynamicsWorld]
[play_clj.g3d_physics ContactListener]))
(def ^:private init (delay (Bullet/init)))
@@ -123,6 +124,16 @@
[]
(btSoftBodyWorldInfo.))
(defmethod c/add-body!
World3D
[screen body]
(cond
(isa? (type (:object body)) btRigidBody)
(bullet-3d! screen :add-rigid-body (:object body))
(isa? (type (:object body)) btSoftBody)
(bullet-3d! screen :add-soft-body (:object body)))
body)
(defn ^:private body-x
[entity]
(let [^btCollisionObject object (:object (u/get-obj entity :body))]
@@ -161,6 +172,22 @@
[entity z]
(c/body-position! entity (body-x entity) (body-y entity) z))
(defn ^:private find-body
[body entities]
(some #(if (= body (:object (u/get-obj % :body))) %) entities))
(defmethod c/first-entity
World3D
[screen entities]
(-> (u/get-obj screen :first-body)
(find-body entities)))
(defmethod c/second-entity
World3D
[screen entities]
(-> (u/get-obj screen :second-body)
(find-body entities)))
; shapes
(defn box-shape*
@@ -235,15 +262,16 @@
; misc
(defmethod c/add-body!
(defmethod c/contact-listener
World3D
[screen body]
(cond
(isa? (type (:object body)) btRigidBody)
(bullet-3d! screen :add-rigid-body (:object body))
(isa? (type (:object body)) btSoftBody)
(bullet-3d! screen :add-soft-body (:object body)))
body)
[screen
{:keys [on-begin-contact on-end-contact]}
execute-fn!]
(ContactListener.
(fn [a b]
(execute-fn! on-begin-contact :first-body a :second-body b))
(fn [a b]
(execute-fn! on-end-contact :first-body a :second-body b))))
(defn ^:private get-bodies
[screen]