-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathode.lisp
60 lines (34 loc) · 1.34 KB
/
ode.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
;;;; cl-ode.lisp
(in-package #:cl-ode)
(declaim (optimize (speed 3)))
(defvar *default-max-contacts* 25)
(cffi:defcallback near-callback :void ((data :pointer)
(o1 :pointer)
(o2 :pointer))
(declare (ignore data))
(unless (pointer-eq o1 o2)
(close-callback (gethash (cffi:pointer-address o1) *object-hash*)
(gethash (cffi:pointer-address o2) *object-hash*))))
(cffi:defcallback moved-callback :void ((body :pointer))
(let ((body (gethash (cffi:pointer-address body) *object-hash*)))
(when (and body (move-handler body))
(body-moved-callback body))))
(defcfun-rename-function ("dBodySetMovedCallback") :void
(body dBodyID)
(callback :pointer))
(defun near-handler (data o1 o2)
(unless (cffi:pointer-eq o1 o2)
(let* ((lisp-object1 (gethash (pointer-address o1) *object-hash*))
(lisp-object2 (gethash (pointer-address o2) *object-hash*)))
(when (and lisp-object1 lisp-object2)
(close-callback lisp-object1 lisp-object2)))))
(defun init ()
(init-ode)
(setf *object-hash* (make-hash-table :test 'equal)))
(defun physics-step (world space)
(space-collide space (null-pointer) (callback near-callback))
(world-quick-step world (time-step world))
(joint-group-empty (contact-group world)))
(defun uninit ()
(close-ode)
(setf *object-hash* nil))