;;; First the lisp code (not likely that you will be able to get it to compile ;;; since it depends on interface db defintions for the Chipmunk library to be ;;; defined. (defmacro cpv.x (cpv) `(pref ,cpv :cpect.x)) (defmacro cpv.y (cpv) `(pref ,cpv :cpect.y)) (defun cpv (x y) (let ((a (make-record (:struct :cpect (x :double-float) (y :double-float))))) (setf (cpv.x a) (coerce x 'double-float) (cpv.y a) (coerce y 'double-float)) a)) (defun cpv- (v1 v2) (cpv (- (cpv.x v1) (cpv.x v2)) (- (cpv.y v1) (cpv.y v2)))) (defun cpvcross (v1 v2) (- (* (cpv.x v1) (cpv.y v2)) (* (cpv.y v1) (cpv.x v2)))) (defun make-cpv-array (verts) (let ((a (#_calloc (length verts) *cpv-size*))) (iterate (for i upfrom 0) (for v in verts) (after-each (setf (ccl:%get-ptr a (* i *cpv-size*)) (cpv (first v) (second v))))) a)) (defun test-poly-validate (verts) (format t "cpPolyValidate says... ~A~%" (#_cpPolyValidate (make-cpv-array verts) (length verts))) (dotimes (i (length verts) t) (let* ((a (cpv (car (nth i verts)) (cadr (nth i verts)))) (i2 (mod (+ i 1) (length verts))) (i3 (mod (+ i 2) (length verts))) (b (cpv (car (nth i2 verts)) (cadr (nth i2 verts)))) (c (cpv (car (nth i3 verts)) (cadr (nth i3 verts))))) (format t "~A " (cpvcross (cpv- b a) (cpv- c b))) (when (> (cpvcross (cpv- b a) (cpv- c b)) 0.0d0) (return nil))))) ;;; And know the C code int cpPolyValidate(cpVect *verts, int numVerts) { for(int i=0; i= 0.0f) return 0; } return 1; } ;;; Then if we define the following (setq verts '((-15 -15) (-15 15) (15 15) (15 -15))) (setq rverts '((-15 -15) (15 -15) (15 15) (-15 15))) ;; I get the following output in the listener: ? (TEST-POLY-VALIDATE verts) cpPolyValidate says... 0 ; It should return 1!!! -900.0D0 -900.0D0 -900.0D0 -900.0D0 T ? (TEST-POLY-VALIDATE other-verts) cpPolyValidate says... 0 ; Yeah, but I don't trust you now... 900.0D0 NIL