1 ! Copyright (C) 2010 Erik Charlebois
2 ! See http:// factorcode.org/license.txt for BSD license.
3 USING: accessors alien.c-types alien.syntax classes.struct combinators
4 combinators.short-circuit kernel math math.order sequences
5 typed specialized-arrays locals system alien.libraries ;
6 SPECIALIZED-ARRAY: void*
11 { [ os windows? ] [ "chipmunk.dll" ] }
12 { [ os macosx? ] [ "libchipmunk.dylib" ] }
13 { [ os unix? ] [ "libchipmunk.so" ] }
14 } cond "cdecl" add-library
16 "chipmunk" deploy-library
21 TYPEDEF: double cpFloat
25 SPECIALIZED-ARRAY: cpVect
27 TYPEDEF: uint cpHashValue
28 TYPEDEF: void* cpDataPointer
29 TYPEDEF: uint cpCollisionType
30 TYPEDEF: uint cpLayers
33 CONSTANT: CP_NO_GROUP 0
34 CONSTANT: CP_ALL_LAYERS HEX: ffffffff
37 TYPED: cpv ( x y -- v: cpVect )
38 cpVect <struct-boa> ; inline
40 TYPED: cpvzero ( -- v: cpVect )
43 FUNCTION: cpFloat cpvlength ( cpVect v ) ;
44 FUNCTION: cpVect cpvslerp ( cpVect v1, cpVect v2, cpFloat t ) ;
45 FUNCTION: cpVect cpvslerpconst ( cpVect v1, cpVect v2, cpFloat a ) ;
46 FUNCTION: cpVect cpvforangle ( cpFloat a ) ;
47 FUNCTION: cpFloat cpvtoangle ( cpVect v ) ;
48 FUNCTION: c-string cpvstr ( cpVect v ) ;
50 TYPED: cpvadd ( v1: cpVect v2: cpVect -- v3: cpVect )
52 [ [ y>> ] bi@ + ] 2bi cpv ; inline
54 TYPED: cpvneg ( v1: cpVect -- v2: cpVect )
55 [ x>> ] [ y>> ] bi [ neg ] bi@ cpv ; inline
57 TYPED: cpvsub ( v1: cpVect v2: cpVect -- v3: cpVect )
59 [ [ y>> ] bi@ - ] 2bi cpv ; inline
61 TYPED: cpvmult ( v1: cpVect s -- v2: cpVect )
63 [ swap y>> * ] 2bi cpv ; inline
65 TYPED: cpvdot ( v1: cpVect v2: cpVect -- s )
67 [ [ y>> ] bi@ * ] 2bi + ; inline
69 TYPED: cpvcross ( v1: cpVect v2: cpVect -- s )
70 [ [ x>> ] [ y>> ] bi* * ]
71 [ [ y>> ] [ x>> ] bi* * ] 2bi - ; inline
73 TYPED: cpvperp ( v1: cpVect -- v2: cpVect )
74 [ y>> neg ] [ x>> ] bi cpv ; inline
76 TYPED: cpvrperp ( v1: cpVect -- v2: cpVect )
77 [ y>> ] [ x>> neg ] bi cpv ; inline
79 TYPED: cpvproject ( v1: cpVect v2: cpVect -- v3: cpVect )
83 2tri / cpvmult ; inline
85 TYPED: cpvrotate ( v1: cpVect v2: cpVect -- v3: cpVect )
88 [ [ y>> ] bi@ * ] 2bi -
91 [ [ x>> ] [ y>> ] bi* * ]
92 [ [ y>> ] [ x>> ] bi* * ] 2bi +
95 TYPED: cpvunrotate ( v1: cpVect v2: cpVect -- v3: cpVect )
98 [ [ y>> ] bi@ * ] 2bi +
101 [ [ y>> ] [ x>> ] bi* * ]
102 [ [ x>> ] [ y>> ] bi* * ] 2bi -
105 TYPED: cpvlengthsq ( v: cpVect -- s )
108 TYPED: cpvlerp ( v1: cpVect v2: cpVect s -- v3: cpVect )
109 [ nip 1.0 swap - cpvmult ]
110 [ cpvmult nip ] 3bi cpvadd ; inline
112 TYPED: cpvnormalize ( v1: cpVect -- v2: cpVect )
113 dup cpvlength 1.0 swap / cpvmult ; inline
115 TYPED: cpvnormalize_safe ( v1: cpVect -- v2: cpVect )
116 dup [ x>> 0.0 = ] [ y>> 0.0 = ] bi and
118 [ cpvnormalize ] if ; inline
120 TYPED: cpvclamp ( v1: cpVect len -- v2: cpVect )
124 [ [ cpvnormalize ] dip cpvmult ]
127 TYPED: cpvlerpconst ( v1: cpVect v2: cpVect d -- v3: cpVect )
129 [ [ swap cpvsub ] dip cpvclamp ] 3bi cpvadd ; inline
131 TYPED: cpvdist ( v1: cpVect v2: cpVect -- dist )
132 cpvsub cpvlength ; inline
134 TYPED: cpvdistsq ( v1: cpVect v2: cpVect -- distsq )
135 cpvsub cpvlengthsq ; inline
137 TYPED: cpvnear ( v1: cpVect v2: cpVect dist -- ? )
138 [ cpvdistsq ] dip sq < ; inline
147 TYPED: cpBBNew ( l b r t -- cpbb: cpBB )
148 cpBB <struct-boa> ; inline
150 TYPED: cpBBintersects ( a: cpBB b: cpBB -- ? )
152 [ [ l>> ] [ r>> ] bi* <= ]
153 [ [ r>> ] [ l>> ] bi* > ]
154 [ [ b>> ] [ t>> ] bi* <= ]
155 [ [ t>> ] [ b>> ] bi* > ]
158 TYPED: cpBBcontainsBB ( bb: cpBB other: cpBB -- ? )
166 TYPED: cpBBcontainsVect ( bb: cpBB v: cpVect -- ? )
168 [ [ l>> ] [ x>> ] bi* < ]
169 [ [ r>> ] [ x>> ] bi* > ]
170 [ [ b>> ] [ y>> ] bi* < ]
171 [ [ t>> ] [ y>> ] bi* > ]
174 TYPED: cpBBmerge ( a: cpBB b: cpBB -- c: cpBB )
180 } 2cleave cpBBNew ; inline
182 TYPED: cpBBexpand ( bb: cpBB v: cpVect -- b: cpBB )
184 [ [ l>> ] [ x>> ] bi* min ]
185 [ [ b>> ] [ y>> ] bi* min ]
186 [ [ r>> ] [ x>> ] bi* max ]
187 [ [ t>> ] [ y>> ] bi* max ]
188 } 2cleave cpBBNew ; inline
190 FUNCTION: cpVect cpBBClampVect ( cpBB bb, cpVect v ) ;
191 FUNCTION: cpVect cpBBWrapVect ( cpBB bb, cpVect v ) ;
195 CALLBACK: void cpBodyVelocityFunc ( cpBody* body, cpVect gravity, cpFloat damping, cpFloat dt ) ;
196 CALLBACK: void cpBodyPositionFunc ( cpBody* body, cpFloat dt ) ;
199 { velocity_func cpBodyVelocityFunc }
200 { position_func cpBodyPositionFunc }
212 { data cpDataPointer }
218 FUNCTION: cpBody* cpBodyAlloc ( ) ;
219 FUNCTION: cpBody* cpBodyInit ( cpBody* body, cpFloat m, cpFloat i ) ;
220 FUNCTION: cpBody* cpBodyNew ( cpFloat m, cpFloat i ) ;
221 FUNCTION: void cpBodyDestroy ( cpBody* body ) ;
222 FUNCTION: void cpBodyFree ( cpBody* body ) ;
223 FUNCTION: void cpBodySetMass ( cpBody* body, cpFloat m ) ;
224 FUNCTION: void cpBodySetMoment ( cpBody* body, cpFloat i ) ;
225 FUNCTION: void cpBodySetAngle ( cpBody* body, cpFloat a ) ;
226 FUNCTION: void cpBodySlew ( cpBody* body, cpVect pos, cpFloat dt ) ;
227 FUNCTION: void cpBodyUpdateVelocity ( cpBody* body, cpVect gravity, cpFloat damping, cpFloat dt ) ;
228 FUNCTION: void cpBodyUpdatePosition ( cpBody* body, cpFloat dt ) ;
230 TYPED: cpBodyLocal2World ( body: cpBody v: cpVect -- v2: cpVect )
232 [ swap rot>> cpvrotate ] 2bi cpvadd ; inline
234 TYPED: cpBodyWorld2Local ( body: cpBody v: cpVect -- v2: cpVect )
236 [ drop rot>> ] 2bi cpvunrotate ; inline
238 TYPED: cpBodyApplyImpulse ( body: cpBody j: cpVect r: cpVect -- )
242 [ swap m_inv>> cpvmult ] 2bi cpvadd >>v drop
245 [ 2drop dup w_bias>> ]
246 [ swap cpvcross [ i_inv>> ] dip * ] 3bi + >>w_bias drop
249 FUNCTION: void cpBodyResetForces ( cpBody* body ) ;
250 FUNCTION: void cpBodyApplyForce ( cpBody* body, cpVect f, cpVect r ) ;
251 FUNCTION: void cpApplyDampedSpring ( cpBody* a, cpBody* b, cpVect anchr1, cpVect anchr2, cpFloat rlen, cpFloat k, cpFloat dmp, cpFloat dt ) ;
259 CALLBACK: void cpArrayIter ( void* ptr, void* data ) ;
261 FUNCTION: cpArray* cpArrayAlloc ( ) ;
262 FUNCTION: cpArray* cpArrayInit ( cpArray* arr, int size ) ;
263 FUNCTION: cpArray* cpArrayNew ( int size ) ;
264 FUNCTION: void cpArrayDestroy ( cpArray* arr ) ;
265 FUNCTION: void cpArrayFree ( cpArray* arr ) ;
266 FUNCTION: void cpArrayPush ( cpArray* arr, void* object ) ;
267 FUNCTION: void cpArrayDeleteIndex ( cpArray* arr, int idx ) ;
268 FUNCTION: void cpArrayDeleteObj ( cpArray* arr, void* obj ) ;
269 FUNCTION: void cpArrayEach ( cpArray* arr, cpArrayIter iterFunc, void* data ) ;
270 FUNCTION: int cpArrayContains ( cpArray* arr, void* ptr ) ;
276 { next cpHashSetBin* } ;
278 CALLBACK: int cpHashSetEqlFunc ( void* ptr, void* elt ) ;
279 CALLBACK: void* cpHashSetTransFunc ( void* ptr, void* data ) ;
280 CALLBACK: void cpHashSetIterFunc ( void* elt, void* data ) ;
281 CALLBACK: int cpHashSetFilterFunc ( void* elt, void* data ) ;
286 { eql cpHashSetEqlFunc }
287 { trans cpHashSetTransFunc }
288 { default_value void* }
289 { table cpHashSetBin** } ;
291 FUNCTION: void cpHashSetDestroy ( cpHashSet* set ) ;
292 FUNCTION: void cpHashSetFree ( cpHashSet* set ) ;
293 FUNCTION: cpHashSet* cpHashSetAlloc ( ) ;
294 FUNCTION: cpHashSet* cpHashSetInit ( cpHashSet* set, int size, cpHashSetEqlFunc eqlFunc, cpHashSetTransFunc trans ) ;
295 FUNCTION: cpHashSet* cpHashSetNew ( int size, cpHashSetEqlFunc eqlFunc, cpHashSetTransFunc trans ) ;
296 FUNCTION: void* cpHashSetInsert ( cpHashSet* set, cpHashValue hash, void* ptr, void* data ) ;
297 FUNCTION: void* cpHashSetRemove ( cpHashSet* set, cpHashValue hash, void* ptr ) ;
298 FUNCTION: void* cpHashSetFind ( cpHashSet* set, cpHashValue hash, void* ptr ) ;
299 FUNCTION: void cpHashSetEach ( cpHashSet* set, cpHashSetIterFunc func, void* data ) ;
300 FUNCTION: void cpHashSetFilter ( cpHashSet* set, cpHashSetFilterFunc func, void* data ) ;
308 STRUCT: cpSpaceHashBin
310 { next cpSpaceHashBin* } ;
312 CALLBACK: cpBB cpSpaceHashBBFunc ( void* obj ) ;
317 { bbfunc cpSpaceHashBBFunc }
318 { handleSet cpHashSet* }
319 { table cpSpaceHashBin** }
320 { bins cpSpaceHashBin* }
323 FUNCTION: cpSpaceHash* cpSpaceHashAlloc ( ) ;
324 FUNCTION: cpSpaceHash* cpSpaceHashInit ( cpSpaceHash* hash, cpFloat celldim, int cells, cpSpaceHashBBFunc bbfunc ) ;
325 FUNCTION: cpSpaceHash* cpSpaceHashNew ( cpFloat celldim, int cells, cpSpaceHashBBFunc bbfunc ) ;
326 FUNCTION: void cpSpaceHashDestroy ( cpSpaceHash* hash ) ;
327 FUNCTION: void cpSpaceHashFree ( cpSpaceHash* hash ) ;
328 FUNCTION: void cpSpaceHashResize ( cpSpaceHash* hash, cpFloat celldim, int numcells ) ;
329 FUNCTION: void cpSpaceHashInsert ( cpSpaceHash* hash, void* obj, cpHashValue id, cpBB bb ) ;
330 FUNCTION: void cpSpaceHashRemove ( cpSpaceHash* hash, void* obj, cpHashValue id ) ;
331 CALLBACK: void cpSpaceHashIterator ( void* obj, void* data ) ;
332 FUNCTION: void cpSpaceHashEach ( cpSpaceHash* hash, cpSpaceHashIterator func, void* data ) ;
333 FUNCTION: void cpSpaceHashRehash ( cpSpaceHash* hash ) ;
334 FUNCTION: void cpSpaceHashRehashObject ( cpSpaceHash* hash, void* obj, cpHashValue id ) ;
335 CALLBACK: void cpSpaceHashQueryFunc ( void* obj1, void* obj2, void* data ) ;
336 FUNCTION: void cpSpaceHashPointQuery ( cpSpaceHash* hash, cpVect point, cpSpaceHashQueryFunc func, void* data ) ;
337 FUNCTION: void cpSpaceHashQuery ( cpSpaceHash* hash, void* obj, cpBB bb, cpSpaceHashQueryFunc func, void* data ) ;
338 FUNCTION: void cpSpaceHashQueryRehash ( cpSpaceHash* hash, cpSpaceHashQueryFunc func, void* data ) ;
339 CALLBACK: cpFloat cpSpaceHashSegmentQueryFunc ( void* obj1, void* obj2, void* data ) ;
340 FUNCTION: void cpSpaceHashSegmentQuery ( cpSpaceHash* hash, void* obj, cpVect a, cpVect b, cpFloat t_exit, cpSpaceHashSegmentQueryFunc func, void* data ) ;
346 STRUCT: cpSegmentQueryInfo
357 CALLBACK: cpBB cacheData_cb ( cpShape* shape, cpVect p, cpVect rot ) ;
358 CALLBACK: void destroy_cb ( cpShape* shape ) ;
359 CALLBACK: int pointQuery_cb ( cpShape* shape, cpVect p ) ;
360 CALLBACK: void segmentQuery_cb ( cpShape* shape, cpVect a, cpVect b, cpSegmentQueryInfo* info ) ;
364 { cacheData cacheData_cb }
365 { destroy destroy_cb }
366 { pointQuery pointQuery_cb }
367 { segmentQuery segmentQuery_cb } ;
370 { klass cpShapeClass* }
377 { data cpDataPointer }
378 { collision_type cpCollisionType }
381 { hashid cpHashValue } ;
383 FUNCTION: cpShape* cpShapeInit ( cpShape* shape, cpShapeClass* klass, cpBody* body ) ;
384 FUNCTION: void cpShapeDestroy ( cpShape* shape ) ;
385 FUNCTION: void cpShapeFree ( cpShape* shape ) ;
386 FUNCTION: cpBB cpShapeCacheBB ( cpShape* shape ) ;
387 FUNCTION: int cpShapePointQuery ( cpShape* shape, cpVect p ) ;
389 STRUCT: cpCircleShape
395 FUNCTION: cpCircleShape* cpCircleShapeAlloc ( ) ;
396 FUNCTION: cpCircleShape* cpCircleShapeInit ( cpCircleShape* circle, cpBody* body, cpFloat radius, cpVect offset ) ;
397 FUNCTION: cpShape* cpCircleShapeNew ( cpBody* body, cpFloat radius, cpVect offset ) ;
399 STRUCT: cpSegmentShape
409 FUNCTION: cpSegmentShape* cpSegmentShapeAlloc ( ) ;
410 FUNCTION: cpSegmentShape* cpSegmentShapeInit ( cpSegmentShape* seg, cpBody* body, cpVect a, cpVect b, cpFloat radius ) ;
411 FUNCTION: cpShape* cpSegmentShapeNew ( cpBody* body, cpVect a, cpVect b, cpFloat radius ) ;
412 FUNCTION: void cpResetShapeIdCounter ( ) ;
413 FUNCTION: void cpSegmentQueryInfoPrint ( cpSegmentQueryInfo* info ) ;
414 FUNCTION: int cpShapeSegmentQuery ( cpShape* shape, cpVect a, cpVect b, cpSegmentQueryInfo* info ) ;
416 TYPED: cpSegmentQueryHitPoint ( start: cpVect end: cpVect info: cpSegmentQueryInfo -- hit-point: cpVect )
419 TYPED: cpSegmentQueryHitDist ( start: cpVect end: cpVect info: cpSegmentQueryInfo -- hit-dist )
420 t>> [ cpvdist ] dip * ; inline
423 STRUCT: cpPolyShapeAxis
426 SPECIALIZED-ARRAY: cpPolyShapeAxis
432 { axes cpPolyShapeAxis* }
434 { tAxes cpPolyShapeAxis* } ;
436 FUNCTION: cpPolyShape* cpPolyShapeAlloc ( ) ;
437 FUNCTION: cpPolyShape* cpPolyShapeInit ( cpPolyShape* poly, cpBody* body, int numVerts, cpVect* verts, cpVect offset ) ;
438 FUNCTION: cpShape* cpPolyShapeNew ( cpBody* body, int numVerts, cpVect* verts, cpVect offset ) ;
439 FUNCTION: int cpPolyValidate ( cpVect* verts, int numVerts ) ;
440 FUNCTION: int cpPolyShapeGetNumVerts ( cpShape* shape ) ;
441 FUNCTION: cpVect cpPolyShapeGetVert ( cpShape* shape, int idx ) ;
443 TYPED: cpPolyShapeValueOnAxis ( poly: cpPolyShape n: cpVect d -- min-dist )
444 swap rot [ numVerts>> ] [ tVerts>> swap <direct-cpVect-array> ] bi swap
445 [ cpvdot ] curry [ min ] reduce swap - ; inline
447 TYPED: cpPolyShapeContainsVert ( poly: cpPolyShape v: cpVect -- ? )
448 swap [ numVerts>> ] [ tAxes>> swap <direct-cpPolyShapeAxis-array> ] bi swap
450 [ [ n>> ] dip cpvdot ] [ drop d>> ] 2bi -
451 ] curry [ max ] reduce 0.0 <= ; inline
453 TYPED: cpPolyShapeContainsVertPartial ( poly: cpPolyShape v: cpVect n: cpVect -- ? )
454 rot [ numVerts>> ] [ tAxes>> swap <direct-cpPolyShapeAxis-array> ] bi -rot
456 axis n>> n cpvdot 0.0 < 0
458 [ axis n>> v cpvdot axis d>> - ]
460 ] 2curry [ max ] reduce 0.0 <= ; inline
465 C-TYPE: cpCollisionHandler
480 { hash cpHashValue } ;
482 FUNCTION: cpContact* cpContactInit ( cpContact* con, cpVect p, cpVect n, cpFloat dist, cpHashValue hash ) ;
484 C-ENUM: cpArbiterState
486 cpArbiterStateFirstColl
487 cpArbiterStateIgnore ;
491 { contacts cpContact* }
496 { surface_vr cpVect }
498 { handler cpCollisionHandler* }
502 FUNCTION: cpArbiter* cpArbiterAlloc ( ) ;
503 FUNCTION: cpArbiter* cpArbiterInit ( cpArbiter* arb, cpShape* a, cpShape* b ) ;
504 FUNCTION: cpArbiter* cpArbiterNew ( cpShape* a, cpShape* b ) ;
505 FUNCTION: void cpArbiterDestroy ( cpArbiter* arb ) ;
506 FUNCTION: void cpArbiterFree ( cpArbiter* arb ) ;
507 FUNCTION: void cpArbiterUpdate ( cpArbiter* arb, cpContact* contacts, int numContacts, cpCollisionHandler* handler, cpShape* a, cpShape* b ) ;
508 FUNCTION: void cpArbiterPreStep ( cpArbiter* arb, cpFloat dt_inv ) ;
509 FUNCTION: void cpArbiterApplyCachedImpulse ( cpArbiter* arb ) ;
510 FUNCTION: void cpArbiterApplyImpulse ( cpArbiter* arb, cpFloat eCoef ) ;
511 FUNCTION: cpVect cpArbiterTotalImpulse ( cpArbiter* arb ) ;
512 FUNCTION: cpVect cpArbiterTotalImpulseWithFriction ( cpArbiter* arb ) ;
513 FUNCTION: void cpArbiterIgnore ( cpArbiter* arb ) ;
515 TYPED: cpArbiterGetShapes ( arb: cpArbiter -- a: cpShape b: cpShape )
516 dup swappedColl>> 0 = [
522 TYPED: cpArbiterIsFirstContact ( arb: cpArbiter -- ? )
523 state>> cpArbiterStateFirstColl = ; inline
525 TYPED: cpArbiterGetNormal ( arb: cpArbiter i -- n: cpVect )
529 [ contacts>> swap <direct-void*-array> ] bi nth cpContact memory>struct n>>
532 drop swappedColl>> 0 = [ ] [ cpvneg ] if
535 TYPED: cpArbiterGetPoint ( arb: cpArbiter i -- p: cpVect )
538 [ contacts>> swap <direct-void*-array> ] bi
539 nth cpContact memory>struct p>> ; inline
542 FUNCTION: int cpCollideShapes ( cpShape* a, cpShape* b, cpContact** arr ) ;
546 C-TYPE: cpConstraintClass
549 CALLBACK: void cpConstraintPreStepFunction ( cpConstraint* constraint, cpFloat dt, cpFloat dt_inv ) ;
550 CALLBACK: void cpConstraintApplyImpulseFunction ( cpConstraint* constraint ) ;
551 CALLBACK: cpFloat cpConstraintGetImpulseFunction ( cpConstraint* constraint ) ;
553 STRUCT: cpConstraintClass
554 { preStep cpConstraintPreStepFunction }
555 { applyImpulse cpConstraintApplyImpulseFunction }
556 { getImpulse cpConstraintGetImpulseFunction } ;
559 { klass cpConstraintClass* }
565 { data cpDataPointer } ;
567 FUNCTION: void cpConstraintDestroy ( cpConstraint* constraint ) ;
568 FUNCTION: void cpConstraintFree ( cpConstraint* constraint ) ;
569 FUNCTION: void cpConstraintCheckCast ( cpConstraint* constraint, cpConstraintClass* klass ) ;
572 FUNCTION: cpConstraintClass* cpPinJointGetClass ( ) ;
575 { constraint cpConstraint }
587 FUNCTION: cpPinJoint* cpPinJointAlloc ( ) ;
588 FUNCTION: cpPinJoint* cpPinJointInit ( cpPinJoint* joint, cpBody* a, cpBody* b, cpVect anchr1, cpVect anchr2 ) ;
589 FUNCTION: cpConstraint* cpPinJointNew ( cpBody* a, cpBody* b, cpVect anchr1, cpVect anchr2 ) ;
592 FUNCTION: cpConstraintClass* cpSlideJointGetClass ( ) ;
595 { constraint cpConstraint }
608 FUNCTION: cpSlideJoint* cpSlideJointAlloc ( ) ;
609 FUNCTION: cpSlideJoint* cpSlideJointInit ( cpSlideJoint* joint, cpBody* a, cpBody* b, cpVect anchr1, cpVect anchr2, cpFloat min, cpFloat max ) ;
610 FUNCTION: cpConstraint* cpSlideJointNew ( cpBody* a, cpBody* b, cpVect anchr1, cpVect anchr2, cpFloat min, cpFloat max ) ;
613 FUNCTION: cpConstraintClass* cpPivotJointGetClass ( ) ;
616 { constraint cpConstraint }
627 FUNCTION: cpPivotJoint* cpPivotJointAlloc ( ) ;
628 FUNCTION: cpPivotJoint* cpPivotJointInit ( cpPivotJoint* joint, cpBody* a, cpBody* b, cpVect anchr1, cpVect anchr2 ) ;
629 FUNCTION: cpConstraint* cpPivotJointNew ( cpBody* a, cpBody* b, cpVect pivot ) ;
630 FUNCTION: cpConstraint* cpPivotJointNew2 ( cpBody* a, cpBody* b, cpVect anchr1, cpVect anchr2 ) ;
633 FUNCTION: cpConstraintClass* cpGrooveJointGetClass ( ) ;
635 STRUCT: cpGrooveJoint
636 { constraint cpConstraint }
651 FUNCTION: cpGrooveJoint* cpGrooveJointAlloc ( ) ;
652 FUNCTION: cpGrooveJoint* cpGrooveJointInit ( cpGrooveJoint* joint, cpBody* a, cpBody* b, cpVect groove_a, cpVect groove_b, cpVect anchr2 ) ;
653 FUNCTION: cpConstraint* cpGrooveJointNew ( cpBody* a, cpBody* b, cpVect groove_a, cpVect groove_b, cpVect anchr2 ) ;
656 CALLBACK: cpFloat cpDampedSpringForceFunc ( cpConstraint* spring, cpFloat dist ) ;
657 FUNCTION: cpConstraintClass* cpDampedSpringGetClass ( ) ;
659 STRUCT: cpDampedSpring
660 { constraint cpConstraint }
663 { restLength cpFloat }
664 { stiffness cpFloat }
666 { springForceFunc cpDampedSpringForceFunc }
668 { target_vrn cpFloat }
674 FUNCTION: cpDampedSpring* cpDampedSpringAlloc ( ) ;
675 FUNCTION: cpDampedSpring* cpDampedSpringInit ( cpDampedSpring* joint, cpBody* a, cpBody* b, cpVect anchr1, cpVect anchr2, cpFloat restLength, cpFloat stiffness, cpFloat damping ) ;
676 FUNCTION: cpConstraint* cpDampedSpringNew ( cpBody* a, cpBody* b, cpVect anchr1, cpVect anchr2, cpFloat restLength, cpFloat stiffness, cpFloat damping ) ;
678 ! cpDampedRotarySpring.h
679 CALLBACK: cpFloat cpDampedRotarySpringTorqueFunc ( cpConstraint* spring, cpFloat relativeAngle ) ;
680 FUNCTION: cpConstraintClass* cpDampedRotarySpringGetClass ( ) ;
682 STRUCT: cpDampedRotarySpring
683 { constraint cpConstraint }
684 { restAngle cpFloat }
685 { stiffness cpFloat }
687 { springTorqueFunc cpDampedRotarySpringTorqueFunc }
689 { target_wrn cpFloat }
692 FUNCTION: cpDampedRotarySpring* cpDampedRotarySpringAlloc ( ) ;
693 FUNCTION: cpDampedRotarySpring* cpDampedRotarySpringInit ( cpDampedRotarySpring* joint, cpBody* a, cpBody* b, cpFloat restAngle, cpFloat stiffness, cpFloat damping ) ;
694 FUNCTION: cpConstraint* cpDampedRotarySpringNew ( cpBody* a, cpBody* b, cpFloat restAngle, cpFloat stiffness, cpFloat damping ) ;
696 ! cpRotaryLimitJoint.h
697 FUNCTION: cpConstraintClass* cpRotaryLimitJointGetClass ( ) ;
699 STRUCT: cpRotaryLimitJoint
700 { constraint cpConstraint }
708 FUNCTION: cpRotaryLimitJoint* cpRotaryLimitJointAlloc ( ) ;
709 FUNCTION: cpRotaryLimitJoint* cpRotaryLimitJointInit ( cpRotaryLimitJoint* joint, cpBody* a, cpBody* b, cpFloat min, cpFloat max ) ;
710 FUNCTION: cpConstraint* cpRotaryLimitJointNew ( cpBody* a, cpBody* b, cpFloat min, cpFloat max ) ;
713 FUNCTION: cpConstraintClass* cpRatchetJointGetClass ( ) ;
715 STRUCT: cpRatchetJoint
716 { constraint cpConstraint }
725 FUNCTION: cpRatchetJoint* cpRatchetJointAlloc ( ) ;
726 FUNCTION: cpRatchetJoint* cpRatchetJointInit ( cpRatchetJoint* joint, cpBody* a, cpBody* b, cpFloat phase, cpFloat ratchet ) ;
727 FUNCTION: cpConstraint* cpRatchetJointNew ( cpBody* a, cpBody* b, cpFloat phase, cpFloat ratchet ) ;
730 FUNCTION: cpConstraintClass* cpGearJointGetClass ( ) ;
733 { constraint cpConstraint }
736 { ratio_inv cpFloat }
742 FUNCTION: cpGearJoint* cpGearJointAlloc ( ) ;
743 FUNCTION: cpGearJoint* cpGearJointInit ( cpGearJoint* joint, cpBody* a, cpBody* b, cpFloat phase, cpFloat ratio ) ;
744 FUNCTION: cpConstraint* cpGearJointNew ( cpBody* a, cpBody* b, cpFloat phase, cpFloat ratio ) ;
745 FUNCTION: void cpGearJointSetRatio ( cpConstraint* constraint, cpFloat value ) ;
748 FUNCTION: cpConstraintClass* cpSimpleMotorGetClass ( ) ;
750 STRUCT: cpSimpleMotor
751 { constraint cpConstraint }
757 FUNCTION: cpSimpleMotor* cpSimpleMotorAlloc ( ) ;
758 FUNCTION: cpSimpleMotor* cpSimpleMotorInit ( cpSimpleMotor* joint, cpBody* a, cpBody* b, cpFloat rate ) ;
759 FUNCTION: cpConstraint* cpSimpleMotorNew ( cpBody* a, cpBody* b, cpFloat rate ) ;
764 CALLBACK: int cpCollisionBeginFunc ( cpArbiter* arb, cpSpace* space, void* data ) ;
765 CALLBACK: int cpCollisionPreSolveFunc ( cpArbiter* arb, cpSpace* space, void* data ) ;
766 CALLBACK: void cpCollisionPostSolveFunc ( cpArbiter* arb, cpSpace* space, void* data ) ;
767 CALLBACK: void cpCollisionSeparateFunc ( cpArbiter* arb, cpSpace* space, void* data ) ;
769 STRUCT: cpCollisionHandler
770 { a cpCollisionType }
771 { b cpCollisionType }
772 { begin cpCollisionBeginFunc }
773 { preSolve cpCollisionPreSolveFunc }
774 { postSolve cpCollisionPostSolveFunc }
775 { separate cpCollisionSeparateFunc }
780 { elasticIterations int }
784 { staticShapes cpSpaceHash* }
785 { activeShapes cpSpaceHash* }
787 { arbiters cpArray* }
788 { contactSet cpHashSet* }
789 { constraints cpArray* }
790 { collFuncSet cpHashSet* }
791 { defaultHandler cpCollisionHandler }
792 { postStepCallbacks cpHashSet* } ;
794 FUNCTION: cpSpace* cpSpaceAlloc ( ) ;
795 FUNCTION: cpSpace* cpSpaceInit ( cpSpace* space ) ;
796 FUNCTION: cpSpace* cpSpaceNew ( ) ;
797 FUNCTION: void cpSpaceDestroy ( cpSpace* space ) ;
798 FUNCTION: void cpSpaceFree ( cpSpace* space ) ;
799 FUNCTION: void cpSpaceFreeChildren ( cpSpace* space ) ;
800 FUNCTION: void cpSpaceSetDefaultCollisionHandler (
802 cpCollisionBeginFunc begin,
803 cpCollisionPreSolveFunc preSolve,
804 cpCollisionPostSolveFunc postSolve,
805 cpCollisionSeparateFunc separate,
807 FUNCTION: void cpSpaceAddCollisionHandler (
811 cpCollisionBeginFunc begin,
812 cpCollisionPreSolveFunc preSolve,
813 cpCollisionPostSolveFunc postSolve,
814 cpCollisionSeparateFunc separate,
816 FUNCTION: void cpSpaceRemoveCollisionHandler ( cpSpace* space, cpCollisionType a, cpCollisionType b ) ;
817 FUNCTION: cpShape* cpSpaceAddShape ( cpSpace* space, cpShape* shape ) ;
818 FUNCTION: cpShape* cpSpaceAddStaticShape ( cpSpace* space, cpShape* shape ) ;
819 FUNCTION: cpBody* cpSpaceAddBody ( cpSpace* space, cpBody* body ) ;
820 FUNCTION: cpConstraint* cpSpaceAddConstraint ( cpSpace* space, cpConstraint* constraint ) ;
821 FUNCTION: void cpSpaceRemoveShape ( cpSpace* space, cpShape* shape ) ;
822 FUNCTION: void cpSpaceRemoveStaticShape ( cpSpace* space, cpShape* shape ) ;
823 FUNCTION: void cpSpaceRemoveBody ( cpSpace* space, cpBody* body ) ;
824 FUNCTION: void cpSpaceRemoveConstraint ( cpSpace* space, cpConstraint* constraint ) ;
825 CALLBACK: void cpPostStepFunc ( cpSpace* space, void* obj, void* data ) ;
826 FUNCTION: void cpSpaceAddPostStepCallback ( cpSpace* space, cpPostStepFunc func, void* obj, void* data ) ;
827 CALLBACK: void cpSpacePointQueryFunc ( cpShape* shape, void* data ) ;
828 FUNCTION: void cpSpacePointQuery ( cpSpace* space, cpVect point, cpLayers layers, cpGroup group, cpSpacePointQueryFunc func, void* data ) ;
829 FUNCTION: cpShape* cpSpacePointQueryFirst ( cpSpace* space, cpVect point, cpLayers layers, cpGroup group ) ;
830 CALLBACK: void cpSpaceSegmentQueryFunc ( cpShape* shape, cpFloat t, cpVect n, void* data ) ;
831 FUNCTION: int cpSpaceSegmentQuery ( cpSpace* space, cpVect start, cpVect end, cpLayers layers, cpGroup group, cpSpaceSegmentQueryFunc func, void* data ) ;
832 FUNCTION: cpShape* cpSpaceSegmentQueryFirst ( cpSpace* space, cpVect start, cpVect end, cpLayers layers, cpGroup group, cpSegmentQueryInfo* out ) ;
833 CALLBACK: void cpSpaceBBQueryFunc ( cpShape* shape, void* data ) ;
834 FUNCTION: void cpSpaceBBQuery ( cpSpace* space, cpBB bb, cpLayers layers, cpGroup group, cpSpaceBBQueryFunc func, void* data ) ;
835 CALLBACK: void cpSpaceBodyIterator ( cpBody* body, void* data ) ;
836 FUNCTION: void cpSpaceEachBody ( cpSpace* space, cpSpaceBodyIterator func, void* data ) ;
837 FUNCTION: void cpSpaceResizeStaticHash ( cpSpace* space, cpFloat dim, int count ) ;
838 FUNCTION: void cpSpaceResizeActiveHash ( cpSpace* space, cpFloat dim, int count ) ;
839 FUNCTION: void cpSpaceRehashStatic ( cpSpace* space ) ;
840 FUNCTION: void cpSpaceStep ( cpSpace* space, cpFloat dt ) ;
843 FUNCTION: void cpInitChipmunk ( ) ;
844 FUNCTION: cpFloat cpMomentForCircle ( cpFloat m, cpFloat r1, cpFloat r2, cpVect offset ) ;
845 FUNCTION: cpFloat cpMomentForSegment ( cpFloat m, cpVect a, cpVect b ) ;
846 FUNCTION: cpFloat cpMomentForPoly ( cpFloat m, int numVerts, cpVect* verts, cpVect offset ) ;