1 ! Copyright (C) 2010 Erik Charlebois
2 ! See http:// factorcode.org/license.txt for BSD license.
3 USING: accessors alien alien.c-types alien.data alien.libraries
4 alien.syntax classes.struct combinators combinators.short-circuit
5 kernel math math.order sequences typed specialized-arrays locals
7 SPECIALIZED-ARRAY: void*
12 { [ os windows? ] [ "chipmunk.dll" ] }
13 { [ os macosx? ] [ "libchipmunk.dylib" ] }
14 { [ os unix? ] [ "libchipmunk.so" ] }
15 } cond cdecl add-library
17 "chipmunk" deploy-library
22 TYPEDEF: double cpFloat
26 SPECIALIZED-ARRAY: cpVect
28 TYPEDEF: uint cpHashValue
29 TYPEDEF: void* cpDataPointer
30 TYPEDEF: uint cpCollisionType
31 TYPEDEF: uint cpLayers
34 CONSTANT: CP_NO_GROUP 0
35 CONSTANT: CP_ALL_LAYERS 0xffffffff
38 TYPED: cpv ( x y -- v: cpVect )
39 cpVect <struct-boa> ; inline
41 TYPED: cpvzero ( -- v: cpVect )
44 FUNCTION: cpFloat cpvlength ( cpVect v ) ;
45 FUNCTION: cpVect cpvslerp ( cpVect v1, cpVect v2, cpFloat t ) ;
46 FUNCTION: cpVect cpvslerpconst ( cpVect v1, cpVect v2, cpFloat a ) ;
47 FUNCTION: cpVect cpvforangle ( cpFloat a ) ;
48 FUNCTION: cpFloat cpvtoangle ( cpVect v ) ;
49 FUNCTION: c-string cpvstr ( cpVect v ) ;
51 TYPED: cpvadd ( v1: cpVect v2: cpVect -- v3: cpVect )
53 [ [ y>> ] bi@ + ] 2bi cpv ; inline
55 TYPED: cpvneg ( v1: cpVect -- v2: cpVect )
56 [ x>> ] [ y>> ] bi [ neg ] bi@ cpv ; inline
58 TYPED: cpvsub ( v1: cpVect v2: cpVect -- v3: cpVect )
60 [ [ y>> ] bi@ - ] 2bi cpv ; inline
62 TYPED: cpvmult ( v1: cpVect s -- v2: cpVect )
64 [ swap y>> * ] 2bi cpv ; inline
66 TYPED: cpvdot ( v1: cpVect v2: cpVect -- s )
68 [ [ y>> ] bi@ * ] 2bi + ; inline
70 TYPED: cpvcross ( v1: cpVect v2: cpVect -- s )
71 [ [ x>> ] [ y>> ] bi* * ]
72 [ [ y>> ] [ x>> ] bi* * ] 2bi - ; inline
74 TYPED: cpvperp ( v1: cpVect -- v2: cpVect )
75 [ y>> neg ] [ x>> ] bi cpv ; inline
77 TYPED: cpvrperp ( v1: cpVect -- v2: cpVect )
78 [ y>> ] [ x>> neg ] bi cpv ; inline
80 TYPED: cpvproject ( v1: cpVect v2: cpVect -- v3: cpVect )
84 2tri / cpvmult ; inline
86 TYPED: cpvrotate ( v1: cpVect v2: cpVect -- v3: cpVect )
89 [ [ y>> ] bi@ * ] 2bi -
92 [ [ x>> ] [ y>> ] bi* * ]
93 [ [ y>> ] [ x>> ] bi* * ] 2bi +
96 TYPED: cpvunrotate ( v1: cpVect v2: cpVect -- v3: cpVect )
99 [ [ y>> ] bi@ * ] 2bi +
102 [ [ y>> ] [ x>> ] bi* * ]
103 [ [ x>> ] [ y>> ] bi* * ] 2bi -
106 TYPED: cpvlengthsq ( v: cpVect -- s )
109 TYPED: cpvlerp ( v1: cpVect v2: cpVect s -- v3: cpVect )
110 [ nip 1.0 swap - cpvmult ]
111 [ cpvmult nip ] 3bi cpvadd ; inline
113 TYPED: cpvnormalize ( v1: cpVect -- v2: cpVect )
114 dup cpvlength 1.0 swap / cpvmult ; inline
116 TYPED: cpvnormalize_safe ( v1: cpVect -- v2: cpVect )
117 dup [ x>> 0.0 = ] [ y>> 0.0 = ] bi and
119 [ cpvnormalize ] if ; inline
121 TYPED: cpvclamp ( v1: cpVect len -- v2: cpVect )
125 [ [ cpvnormalize ] dip cpvmult ]
128 TYPED: cpvlerpconst ( v1: cpVect v2: cpVect d -- v3: cpVect )
130 [ [ swap cpvsub ] dip cpvclamp ] 3bi cpvadd ; inline
132 TYPED: cpvdist ( v1: cpVect v2: cpVect -- dist )
133 cpvsub cpvlength ; inline
135 TYPED: cpvdistsq ( v1: cpVect v2: cpVect -- distsq )
136 cpvsub cpvlengthsq ; inline
138 TYPED: cpvnear ( v1: cpVect v2: cpVect dist -- ? )
139 [ cpvdistsq ] dip sq < ; inline
148 TYPED: cpBBNew ( l b r t -- cpbb: cpBB )
149 cpBB <struct-boa> ; inline
151 TYPED: cpBBintersects ( a: cpBB b: cpBB -- ? )
153 [ [ l>> ] [ r>> ] bi* <= ]
154 [ [ r>> ] [ l>> ] bi* > ]
155 [ [ b>> ] [ t>> ] bi* <= ]
156 [ [ t>> ] [ b>> ] bi* > ]
159 TYPED: cpBBcontainsBB ( bb: cpBB other: cpBB -- ? )
167 TYPED: cpBBcontainsVect ( bb: cpBB v: cpVect -- ? )
169 [ [ l>> ] [ x>> ] bi* < ]
170 [ [ r>> ] [ x>> ] bi* > ]
171 [ [ b>> ] [ y>> ] bi* < ]
172 [ [ t>> ] [ y>> ] bi* > ]
175 TYPED: cpBBmerge ( a: cpBB b: cpBB -- c: cpBB )
181 } 2cleave cpBBNew ; inline
183 TYPED: cpBBexpand ( bb: cpBB v: cpVect -- b: cpBB )
185 [ [ l>> ] [ x>> ] bi* min ]
186 [ [ b>> ] [ y>> ] bi* min ]
187 [ [ r>> ] [ x>> ] bi* max ]
188 [ [ t>> ] [ y>> ] bi* max ]
189 } 2cleave cpBBNew ; inline
191 FUNCTION: cpVect cpBBClampVect ( cpBB bb, cpVect v ) ;
192 FUNCTION: cpVect cpBBWrapVect ( cpBB bb, cpVect v ) ;
196 CALLBACK: void cpBodyVelocityFunc ( cpBody* body, cpVect gravity, cpFloat damping, cpFloat dt ) ;
197 CALLBACK: void cpBodyPositionFunc ( cpBody* body, cpFloat dt ) ;
200 { velocity_func cpBodyVelocityFunc }
201 { position_func cpBodyPositionFunc }
213 { data cpDataPointer }
219 FUNCTION: cpBody* cpBodyAlloc ( ) ;
220 FUNCTION: cpBody* cpBodyInit ( cpBody* body, cpFloat m, cpFloat i ) ;
221 FUNCTION: cpBody* cpBodyNew ( cpFloat m, cpFloat i ) ;
222 FUNCTION: void cpBodyDestroy ( cpBody* body ) ;
223 FUNCTION: void cpBodyFree ( cpBody* body ) ;
224 FUNCTION: void cpBodySetMass ( cpBody* body, cpFloat m ) ;
225 FUNCTION: void cpBodySetMoment ( cpBody* body, cpFloat i ) ;
226 FUNCTION: void cpBodySetAngle ( cpBody* body, cpFloat a ) ;
227 FUNCTION: void cpBodySlew ( cpBody* body, cpVect pos, cpFloat dt ) ;
228 FUNCTION: void cpBodyUpdateVelocity ( cpBody* body, cpVect gravity, cpFloat damping, cpFloat dt ) ;
229 FUNCTION: void cpBodyUpdatePosition ( cpBody* body, cpFloat dt ) ;
231 TYPED: cpBodyLocal2World ( body: cpBody v: cpVect -- v2: cpVect )
233 [ swap rot>> cpvrotate ] 2bi cpvadd ; inline
235 TYPED: cpBodyWorld2Local ( body: cpBody v: cpVect -- v2: cpVect )
237 [ drop rot>> ] 2bi cpvunrotate ; inline
239 TYPED: cpBodyApplyImpulse ( body: cpBody j: cpVect r: cpVect -- )
243 [ swap m_inv>> cpvmult ] 2bi cpvadd >>v drop
246 [ 2drop dup w_bias>> ]
247 [ swap cpvcross [ i_inv>> ] dip * ] 3bi + >>w_bias drop
250 FUNCTION: void cpBodyResetForces ( cpBody* body ) ;
251 FUNCTION: void cpBodyApplyForce ( cpBody* body, cpVect f, cpVect r ) ;
252 FUNCTION: void cpApplyDampedSpring ( cpBody* a, cpBody* b, cpVect anchr1, cpVect anchr2, cpFloat rlen, cpFloat k, cpFloat dmp, cpFloat dt ) ;
260 CALLBACK: void cpArrayIter ( void* ptr, void* data ) ;
262 FUNCTION: cpArray* cpArrayAlloc ( ) ;
263 FUNCTION: cpArray* cpArrayInit ( cpArray* arr, int size ) ;
264 FUNCTION: cpArray* cpArrayNew ( int size ) ;
265 FUNCTION: void cpArrayDestroy ( cpArray* arr ) ;
266 FUNCTION: void cpArrayFree ( cpArray* arr ) ;
267 FUNCTION: void cpArrayPush ( cpArray* arr, void* object ) ;
268 FUNCTION: void cpArrayDeleteIndex ( cpArray* arr, int idx ) ;
269 FUNCTION: void cpArrayDeleteObj ( cpArray* arr, void* obj ) ;
270 FUNCTION: void cpArrayEach ( cpArray* arr, cpArrayIter iterFunc, void* data ) ;
271 FUNCTION: int cpArrayContains ( cpArray* arr, void* ptr ) ;
277 { next cpHashSetBin* } ;
279 CALLBACK: int cpHashSetEqlFunc ( void* ptr, void* elt ) ;
280 CALLBACK: void* cpHashSetTransFunc ( void* ptr, void* data ) ;
281 CALLBACK: void cpHashSetIterFunc ( void* elt, void* data ) ;
282 CALLBACK: int cpHashSetFilterFunc ( void* elt, void* data ) ;
287 { eql cpHashSetEqlFunc }
288 { trans cpHashSetTransFunc }
289 { default_value void* }
290 { table cpHashSetBin** } ;
292 FUNCTION: void cpHashSetDestroy ( cpHashSet* set ) ;
293 FUNCTION: void cpHashSetFree ( cpHashSet* set ) ;
294 FUNCTION: cpHashSet* cpHashSetAlloc ( ) ;
295 FUNCTION: cpHashSet* cpHashSetInit ( cpHashSet* set, int size, cpHashSetEqlFunc eqlFunc, cpHashSetTransFunc trans ) ;
296 FUNCTION: cpHashSet* cpHashSetNew ( int size, cpHashSetEqlFunc eqlFunc, cpHashSetTransFunc trans ) ;
297 FUNCTION: void* cpHashSetInsert ( cpHashSet* set, cpHashValue hash, void* ptr, void* data ) ;
298 FUNCTION: void* cpHashSetRemove ( cpHashSet* set, cpHashValue hash, void* ptr ) ;
299 FUNCTION: void* cpHashSetFind ( cpHashSet* set, cpHashValue hash, void* ptr ) ;
300 FUNCTION: void cpHashSetEach ( cpHashSet* set, cpHashSetIterFunc func, void* data ) ;
301 FUNCTION: void cpHashSetFilter ( cpHashSet* set, cpHashSetFilterFunc func, void* data ) ;
309 STRUCT: cpSpaceHashBin
311 { next cpSpaceHashBin* } ;
313 CALLBACK: cpBB cpSpaceHashBBFunc ( void* obj ) ;
318 { bbfunc cpSpaceHashBBFunc }
319 { handleSet cpHashSet* }
320 { table cpSpaceHashBin** }
321 { bins cpSpaceHashBin* }
324 FUNCTION: cpSpaceHash* cpSpaceHashAlloc ( ) ;
325 FUNCTION: cpSpaceHash* cpSpaceHashInit ( cpSpaceHash* hash, cpFloat celldim, int cells, cpSpaceHashBBFunc bbfunc ) ;
326 FUNCTION: cpSpaceHash* cpSpaceHashNew ( cpFloat celldim, int cells, cpSpaceHashBBFunc bbfunc ) ;
327 FUNCTION: void cpSpaceHashDestroy ( cpSpaceHash* hash ) ;
328 FUNCTION: void cpSpaceHashFree ( cpSpaceHash* hash ) ;
329 FUNCTION: void cpSpaceHashResize ( cpSpaceHash* hash, cpFloat celldim, int numcells ) ;
330 FUNCTION: void cpSpaceHashInsert ( cpSpaceHash* hash, void* obj, cpHashValue id, cpBB bb ) ;
331 FUNCTION: void cpSpaceHashRemove ( cpSpaceHash* hash, void* obj, cpHashValue id ) ;
332 CALLBACK: void cpSpaceHashIterator ( void* obj, void* data ) ;
333 FUNCTION: void cpSpaceHashEach ( cpSpaceHash* hash, cpSpaceHashIterator func, void* data ) ;
334 FUNCTION: void cpSpaceHashRehash ( cpSpaceHash* hash ) ;
335 FUNCTION: void cpSpaceHashRehashObject ( cpSpaceHash* hash, void* obj, cpHashValue id ) ;
336 CALLBACK: void cpSpaceHashQueryFunc ( void* obj1, void* obj2, void* data ) ;
337 FUNCTION: void cpSpaceHashPointQuery ( cpSpaceHash* hash, cpVect point, cpSpaceHashQueryFunc func, void* data ) ;
338 FUNCTION: void cpSpaceHashQuery ( cpSpaceHash* hash, void* obj, cpBB bb, cpSpaceHashQueryFunc func, void* data ) ;
339 FUNCTION: void cpSpaceHashQueryRehash ( cpSpaceHash* hash, cpSpaceHashQueryFunc func, void* data ) ;
340 CALLBACK: cpFloat cpSpaceHashSegmentQueryFunc ( void* obj1, void* obj2, void* data ) ;
341 FUNCTION: void cpSpaceHashSegmentQuery ( cpSpaceHash* hash, void* obj, cpVect a, cpVect b, cpFloat t_exit, cpSpaceHashSegmentQueryFunc func, void* data ) ;
347 STRUCT: cpSegmentQueryInfo
358 CALLBACK: cpBB cacheData_cb ( cpShape* shape, cpVect p, cpVect rot ) ;
359 CALLBACK: void destroy_cb ( cpShape* shape ) ;
360 CALLBACK: int pointQuery_cb ( cpShape* shape, cpVect p ) ;
361 CALLBACK: void segmentQuery_cb ( cpShape* shape, cpVect a, cpVect b, cpSegmentQueryInfo* info ) ;
365 { cacheData cacheData_cb }
366 { destroy destroy_cb }
367 { pointQuery pointQuery_cb }
368 { segmentQuery segmentQuery_cb } ;
371 { klass cpShapeClass* }
378 { data cpDataPointer }
379 { collision_type cpCollisionType }
382 { hashid cpHashValue } ;
384 FUNCTION: cpShape* cpShapeInit ( cpShape* shape, cpShapeClass* klass, cpBody* body ) ;
385 FUNCTION: void cpShapeDestroy ( cpShape* shape ) ;
386 FUNCTION: void cpShapeFree ( cpShape* shape ) ;
387 FUNCTION: cpBB cpShapeCacheBB ( cpShape* shape ) ;
388 FUNCTION: int cpShapePointQuery ( cpShape* shape, cpVect p ) ;
390 STRUCT: cpCircleShape
396 FUNCTION: cpCircleShape* cpCircleShapeAlloc ( ) ;
397 FUNCTION: cpCircleShape* cpCircleShapeInit ( cpCircleShape* circle, cpBody* body, cpFloat radius, cpVect offset ) ;
398 FUNCTION: cpShape* cpCircleShapeNew ( cpBody* body, cpFloat radius, cpVect offset ) ;
400 STRUCT: cpSegmentShape
410 FUNCTION: cpSegmentShape* cpSegmentShapeAlloc ( ) ;
411 FUNCTION: cpSegmentShape* cpSegmentShapeInit ( cpSegmentShape* seg, cpBody* body, cpVect a, cpVect b, cpFloat radius ) ;
412 FUNCTION: cpShape* cpSegmentShapeNew ( cpBody* body, cpVect a, cpVect b, cpFloat radius ) ;
413 FUNCTION: void cpResetShapeIdCounter ( ) ;
414 FUNCTION: void cpSegmentQueryInfoPrint ( cpSegmentQueryInfo* info ) ;
415 FUNCTION: int cpShapeSegmentQuery ( cpShape* shape, cpVect a, cpVect b, cpSegmentQueryInfo* info ) ;
417 TYPED: cpSegmentQueryHitPoint ( start: cpVect end: cpVect info: cpSegmentQueryInfo -- hit-point: cpVect )
420 TYPED: cpSegmentQueryHitDist ( start: cpVect end: cpVect info: cpSegmentQueryInfo -- hit-dist )
421 t>> [ cpvdist ] dip * ; inline
424 STRUCT: cpPolyShapeAxis
427 SPECIALIZED-ARRAY: cpPolyShapeAxis
433 { axes cpPolyShapeAxis* }
435 { tAxes cpPolyShapeAxis* } ;
437 FUNCTION: cpPolyShape* cpPolyShapeAlloc ( ) ;
438 FUNCTION: cpPolyShape* cpPolyShapeInit ( cpPolyShape* poly, cpBody* body, int numVerts, cpVect* verts, cpVect offset ) ;
439 FUNCTION: cpShape* cpPolyShapeNew ( cpBody* body, int numVerts, cpVect* verts, cpVect offset ) ;
440 FUNCTION: int cpPolyValidate ( cpVect* verts, int numVerts ) ;
441 FUNCTION: int cpPolyShapeGetNumVerts ( cpShape* shape ) ;
442 FUNCTION: cpVect cpPolyShapeGetVert ( cpShape* shape, int idx ) ;
444 TYPED: cpPolyShapeValueOnAxis ( poly: cpPolyShape n: cpVect d -- min-dist )
445 swap rot [ numVerts>> ] [ tVerts>> swap cpVect <c-direct-array> ] bi swap
446 [ cpvdot ] curry [ min ] reduce swap - ; inline
448 TYPED: cpPolyShapeContainsVert ( poly: cpPolyShape v: cpVect -- ? )
449 swap [ numVerts>> ] [ tAxes>> swap cpPolyShapeAxis <c-direct-array> ] bi swap
451 [ [ n>> ] dip cpvdot ] [ drop d>> ] 2bi -
452 ] curry [ max ] reduce 0.0 <= ; inline
454 TYPED: cpPolyShapeContainsVertPartial ( poly: cpPolyShape v: cpVect n: cpVect -- ? )
455 rot [ numVerts>> ] [ tAxes>> swap cpPolyShapeAxis <c-direct-array> ] bi -rot
457 axis n>> n cpvdot 0.0 < 0
459 [ axis n>> v cpvdot axis d>> - ]
461 ] 2curry [ max ] reduce 0.0 <= ; inline
466 C-TYPE: cpCollisionHandler
481 { hash cpHashValue } ;
483 FUNCTION: cpContact* cpContactInit ( cpContact* con, cpVect p, cpVect n, cpFloat dist, cpHashValue hash ) ;
487 cpArbiterStateFirstColl
488 cpArbiterStateIgnore ;
492 { contacts cpContact* }
497 { surface_vr cpVect }
499 { handler cpCollisionHandler* }
503 FUNCTION: cpArbiter* cpArbiterAlloc ( ) ;
504 FUNCTION: cpArbiter* cpArbiterInit ( cpArbiter* arb, cpShape* a, cpShape* b ) ;
505 FUNCTION: cpArbiter* cpArbiterNew ( cpShape* a, cpShape* b ) ;
506 FUNCTION: void cpArbiterDestroy ( cpArbiter* arb ) ;
507 FUNCTION: void cpArbiterFree ( cpArbiter* arb ) ;
508 FUNCTION: void cpArbiterUpdate ( cpArbiter* arb, cpContact* contacts, int numContacts, cpCollisionHandler* handler, cpShape* a, cpShape* b ) ;
509 FUNCTION: void cpArbiterPreStep ( cpArbiter* arb, cpFloat dt_inv ) ;
510 FUNCTION: void cpArbiterApplyCachedImpulse ( cpArbiter* arb ) ;
511 FUNCTION: void cpArbiterApplyImpulse ( cpArbiter* arb, cpFloat eCoef ) ;
512 FUNCTION: cpVect cpArbiterTotalImpulse ( cpArbiter* arb ) ;
513 FUNCTION: cpVect cpArbiterTotalImpulseWithFriction ( cpArbiter* arb ) ;
514 FUNCTION: void cpArbiterIgnore ( cpArbiter* arb ) ;
516 TYPED: cpArbiterGetShapes ( arb: cpArbiter -- a: cpShape b: cpShape )
517 dup swappedColl>> 0 = [
523 TYPED: cpArbiterIsFirstContact ( arb: cpArbiter -- ? )
524 state>> cpArbiterStateFirstColl = ; inline
526 TYPED: cpArbiterGetNormal ( arb: cpArbiter i -- n: cpVect )
530 [ contacts>> swap void* <c-direct-array> ] bi nth cpContact memory>struct n>>
533 drop swappedColl>> 0 = [ cpvneg ] unless
536 TYPED: cpArbiterGetPoint ( arb: cpArbiter i -- p: cpVect )
539 [ contacts>> swap void* <c-direct-array> ] bi
540 nth cpContact memory>struct p>> ; inline
543 FUNCTION: int cpCollideShapes ( cpShape* a, cpShape* b, cpContact** arr ) ;
547 C-TYPE: cpConstraintClass
550 CALLBACK: void cpConstraintPreStepFunction ( cpConstraint* constraint, cpFloat dt, cpFloat dt_inv ) ;
551 CALLBACK: void cpConstraintApplyImpulseFunction ( cpConstraint* constraint ) ;
552 CALLBACK: cpFloat cpConstraintGetImpulseFunction ( cpConstraint* constraint ) ;
554 STRUCT: cpConstraintClass
555 { preStep cpConstraintPreStepFunction }
556 { applyImpulse cpConstraintApplyImpulseFunction }
557 { getImpulse cpConstraintGetImpulseFunction } ;
560 { klass cpConstraintClass* }
566 { data cpDataPointer } ;
568 FUNCTION: void cpConstraintDestroy ( cpConstraint* constraint ) ;
569 FUNCTION: void cpConstraintFree ( cpConstraint* constraint ) ;
570 FUNCTION: void cpConstraintCheckCast ( cpConstraint* constraint, cpConstraintClass* klass ) ;
573 FUNCTION: cpConstraintClass* cpPinJointGetClass ( ) ;
576 { constraint cpConstraint }
588 FUNCTION: cpPinJoint* cpPinJointAlloc ( ) ;
589 FUNCTION: cpPinJoint* cpPinJointInit ( cpPinJoint* joint, cpBody* a, cpBody* b, cpVect anchr1, cpVect anchr2 ) ;
590 FUNCTION: cpConstraint* cpPinJointNew ( cpBody* a, cpBody* b, cpVect anchr1, cpVect anchr2 ) ;
593 FUNCTION: cpConstraintClass* cpSlideJointGetClass ( ) ;
596 { constraint cpConstraint }
609 FUNCTION: cpSlideJoint* cpSlideJointAlloc ( ) ;
610 FUNCTION: cpSlideJoint* cpSlideJointInit ( cpSlideJoint* joint, cpBody* a, cpBody* b, cpVect anchr1, cpVect anchr2, cpFloat min, cpFloat max ) ;
611 FUNCTION: cpConstraint* cpSlideJointNew ( cpBody* a, cpBody* b, cpVect anchr1, cpVect anchr2, cpFloat min, cpFloat max ) ;
614 FUNCTION: cpConstraintClass* cpPivotJointGetClass ( ) ;
617 { constraint cpConstraint }
628 FUNCTION: cpPivotJoint* cpPivotJointAlloc ( ) ;
629 FUNCTION: cpPivotJoint* cpPivotJointInit ( cpPivotJoint* joint, cpBody* a, cpBody* b, cpVect anchr1, cpVect anchr2 ) ;
630 FUNCTION: cpConstraint* cpPivotJointNew ( cpBody* a, cpBody* b, cpVect pivot ) ;
631 FUNCTION: cpConstraint* cpPivotJointNew2 ( cpBody* a, cpBody* b, cpVect anchr1, cpVect anchr2 ) ;
634 FUNCTION: cpConstraintClass* cpGrooveJointGetClass ( ) ;
636 STRUCT: cpGrooveJoint
637 { constraint cpConstraint }
652 FUNCTION: cpGrooveJoint* cpGrooveJointAlloc ( ) ;
653 FUNCTION: cpGrooveJoint* cpGrooveJointInit ( cpGrooveJoint* joint, cpBody* a, cpBody* b, cpVect groove_a, cpVect groove_b, cpVect anchr2 ) ;
654 FUNCTION: cpConstraint* cpGrooveJointNew ( cpBody* a, cpBody* b, cpVect groove_a, cpVect groove_b, cpVect anchr2 ) ;
657 CALLBACK: cpFloat cpDampedSpringForceFunc ( cpConstraint* spring, cpFloat dist ) ;
658 FUNCTION: cpConstraintClass* cpDampedSpringGetClass ( ) ;
660 STRUCT: cpDampedSpring
661 { constraint cpConstraint }
664 { restLength cpFloat }
665 { stiffness cpFloat }
667 { springForceFunc cpDampedSpringForceFunc }
669 { target_vrn cpFloat }
675 FUNCTION: cpDampedSpring* cpDampedSpringAlloc ( ) ;
676 FUNCTION: cpDampedSpring* cpDampedSpringInit ( cpDampedSpring* joint, cpBody* a, cpBody* b, cpVect anchr1, cpVect anchr2, cpFloat restLength, cpFloat stiffness, cpFloat damping ) ;
677 FUNCTION: cpConstraint* cpDampedSpringNew ( cpBody* a, cpBody* b, cpVect anchr1, cpVect anchr2, cpFloat restLength, cpFloat stiffness, cpFloat damping ) ;
679 ! cpDampedRotarySpring.h
680 CALLBACK: cpFloat cpDampedRotarySpringTorqueFunc ( cpConstraint* spring, cpFloat relativeAngle ) ;
681 FUNCTION: cpConstraintClass* cpDampedRotarySpringGetClass ( ) ;
683 STRUCT: cpDampedRotarySpring
684 { constraint cpConstraint }
685 { restAngle cpFloat }
686 { stiffness cpFloat }
688 { springTorqueFunc cpDampedRotarySpringTorqueFunc }
690 { target_wrn cpFloat }
693 FUNCTION: cpDampedRotarySpring* cpDampedRotarySpringAlloc ( ) ;
694 FUNCTION: cpDampedRotarySpring* cpDampedRotarySpringInit ( cpDampedRotarySpring* joint, cpBody* a, cpBody* b, cpFloat restAngle, cpFloat stiffness, cpFloat damping ) ;
695 FUNCTION: cpConstraint* cpDampedRotarySpringNew ( cpBody* a, cpBody* b, cpFloat restAngle, cpFloat stiffness, cpFloat damping ) ;
697 ! cpRotaryLimitJoint.h
698 FUNCTION: cpConstraintClass* cpRotaryLimitJointGetClass ( ) ;
700 STRUCT: cpRotaryLimitJoint
701 { constraint cpConstraint }
709 FUNCTION: cpRotaryLimitJoint* cpRotaryLimitJointAlloc ( ) ;
710 FUNCTION: cpRotaryLimitJoint* cpRotaryLimitJointInit ( cpRotaryLimitJoint* joint, cpBody* a, cpBody* b, cpFloat min, cpFloat max ) ;
711 FUNCTION: cpConstraint* cpRotaryLimitJointNew ( cpBody* a, cpBody* b, cpFloat min, cpFloat max ) ;
714 FUNCTION: cpConstraintClass* cpRatchetJointGetClass ( ) ;
716 STRUCT: cpRatchetJoint
717 { constraint cpConstraint }
726 FUNCTION: cpRatchetJoint* cpRatchetJointAlloc ( ) ;
727 FUNCTION: cpRatchetJoint* cpRatchetJointInit ( cpRatchetJoint* joint, cpBody* a, cpBody* b, cpFloat phase, cpFloat ratchet ) ;
728 FUNCTION: cpConstraint* cpRatchetJointNew ( cpBody* a, cpBody* b, cpFloat phase, cpFloat ratchet ) ;
731 FUNCTION: cpConstraintClass* cpGearJointGetClass ( ) ;
734 { constraint cpConstraint }
737 { ratio_inv cpFloat }
743 FUNCTION: cpGearJoint* cpGearJointAlloc ( ) ;
744 FUNCTION: cpGearJoint* cpGearJointInit ( cpGearJoint* joint, cpBody* a, cpBody* b, cpFloat phase, cpFloat ratio ) ;
745 FUNCTION: cpConstraint* cpGearJointNew ( cpBody* a, cpBody* b, cpFloat phase, cpFloat ratio ) ;
746 FUNCTION: void cpGearJointSetRatio ( cpConstraint* constraint, cpFloat value ) ;
749 FUNCTION: cpConstraintClass* cpSimpleMotorGetClass ( ) ;
751 STRUCT: cpSimpleMotor
752 { constraint cpConstraint }
758 FUNCTION: cpSimpleMotor* cpSimpleMotorAlloc ( ) ;
759 FUNCTION: cpSimpleMotor* cpSimpleMotorInit ( cpSimpleMotor* joint, cpBody* a, cpBody* b, cpFloat rate ) ;
760 FUNCTION: cpConstraint* cpSimpleMotorNew ( cpBody* a, cpBody* b, cpFloat rate ) ;
765 CALLBACK: int cpCollisionBeginFunc ( cpArbiter* arb, cpSpace* space, void* data ) ;
766 CALLBACK: int cpCollisionPreSolveFunc ( cpArbiter* arb, cpSpace* space, void* data ) ;
767 CALLBACK: void cpCollisionPostSolveFunc ( cpArbiter* arb, cpSpace* space, void* data ) ;
768 CALLBACK: void cpCollisionSeparateFunc ( cpArbiter* arb, cpSpace* space, void* data ) ;
770 STRUCT: cpCollisionHandler
771 { a cpCollisionType }
772 { b cpCollisionType }
773 { begin cpCollisionBeginFunc }
774 { preSolve cpCollisionPreSolveFunc }
775 { postSolve cpCollisionPostSolveFunc }
776 { separate cpCollisionSeparateFunc }
781 { elasticIterations int }
785 { staticShapes cpSpaceHash* }
786 { activeShapes cpSpaceHash* }
788 { arbiters cpArray* }
789 { contactSet cpHashSet* }
790 { constraints cpArray* }
791 { collFuncSet cpHashSet* }
792 { defaultHandler cpCollisionHandler }
793 { postStepCallbacks cpHashSet* } ;
795 FUNCTION: cpSpace* cpSpaceAlloc ( ) ;
796 FUNCTION: cpSpace* cpSpaceInit ( cpSpace* space ) ;
797 FUNCTION: cpSpace* cpSpaceNew ( ) ;
798 FUNCTION: void cpSpaceDestroy ( cpSpace* space ) ;
799 FUNCTION: void cpSpaceFree ( cpSpace* space ) ;
800 FUNCTION: void cpSpaceFreeChildren ( cpSpace* space ) ;
801 FUNCTION: void cpSpaceSetDefaultCollisionHandler (
803 cpCollisionBeginFunc begin,
804 cpCollisionPreSolveFunc preSolve,
805 cpCollisionPostSolveFunc postSolve,
806 cpCollisionSeparateFunc separate,
808 FUNCTION: void cpSpaceAddCollisionHandler (
812 cpCollisionBeginFunc begin,
813 cpCollisionPreSolveFunc preSolve,
814 cpCollisionPostSolveFunc postSolve,
815 cpCollisionSeparateFunc separate,
817 FUNCTION: void cpSpaceRemoveCollisionHandler ( cpSpace* space, cpCollisionType a, cpCollisionType b ) ;
818 FUNCTION: cpShape* cpSpaceAddShape ( cpSpace* space, cpShape* shape ) ;
819 FUNCTION: cpShape* cpSpaceAddStaticShape ( cpSpace* space, cpShape* shape ) ;
820 FUNCTION: cpBody* cpSpaceAddBody ( cpSpace* space, cpBody* body ) ;
821 FUNCTION: cpConstraint* cpSpaceAddConstraint ( cpSpace* space, cpConstraint* constraint ) ;
822 FUNCTION: void cpSpaceRemoveShape ( cpSpace* space, cpShape* shape ) ;
823 FUNCTION: void cpSpaceRemoveStaticShape ( cpSpace* space, cpShape* shape ) ;
824 FUNCTION: void cpSpaceRemoveBody ( cpSpace* space, cpBody* body ) ;
825 FUNCTION: void cpSpaceRemoveConstraint ( cpSpace* space, cpConstraint* constraint ) ;
826 CALLBACK: void cpPostStepFunc ( cpSpace* space, void* obj, void* data ) ;
827 FUNCTION: void cpSpaceAddPostStepCallback ( cpSpace* space, cpPostStepFunc func, void* obj, void* data ) ;
828 CALLBACK: void cpSpacePointQueryFunc ( cpShape* shape, void* data ) ;
829 FUNCTION: void cpSpacePointQuery ( cpSpace* space, cpVect point, cpLayers layers, cpGroup group, cpSpacePointQueryFunc func, void* data ) ;
830 FUNCTION: cpShape* cpSpacePointQueryFirst ( cpSpace* space, cpVect point, cpLayers layers, cpGroup group ) ;
831 CALLBACK: void cpSpaceSegmentQueryFunc ( cpShape* shape, cpFloat t, cpVect n, void* data ) ;
832 FUNCTION: int cpSpaceSegmentQuery ( cpSpace* space, cpVect start, cpVect end, cpLayers layers, cpGroup group, cpSpaceSegmentQueryFunc func, void* data ) ;
833 FUNCTION: cpShape* cpSpaceSegmentQueryFirst ( cpSpace* space, cpVect start, cpVect end, cpLayers layers, cpGroup group, cpSegmentQueryInfo* out ) ;
834 CALLBACK: void cpSpaceBBQueryFunc ( cpShape* shape, void* data ) ;
835 FUNCTION: void cpSpaceBBQuery ( cpSpace* space, cpBB bb, cpLayers layers, cpGroup group, cpSpaceBBQueryFunc func, void* data ) ;
836 CALLBACK: void cpSpaceBodyIterator ( cpBody* body, void* data ) ;
837 FUNCTION: void cpSpaceEachBody ( cpSpace* space, cpSpaceBodyIterator func, void* data ) ;
838 FUNCTION: void cpSpaceResizeStaticHash ( cpSpace* space, cpFloat dim, int count ) ;
839 FUNCTION: void cpSpaceResizeActiveHash ( cpSpace* space, cpFloat dim, int count ) ;
840 FUNCTION: void cpSpaceRehashStatic ( cpSpace* space ) ;
841 FUNCTION: void cpSpaceStep ( cpSpace* space, cpFloat dt ) ;
844 FUNCTION: void cpInitChipmunk ( ) ;
845 FUNCTION: cpFloat cpMomentForCircle ( cpFloat m, cpFloat r1, cpFloat r2, cpVect offset ) ;
846 FUNCTION: cpFloat cpMomentForSegment ( cpFloat m, cpVect a, cpVect b ) ;
847 FUNCTION: cpFloat cpMomentForPoly ( cpFloat m, int numVerts, cpVect* verts, cpVect offset ) ;