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 system ;
6 SPECIALIZED-ARRAY: void*
9 LIBRARY-WINDOWS: chipmunk cdecl "chipmunk.dll"
10 LIBRARY-UNIX: chipmunk cdecl "libchipmunk.so"
11 LIBRARY-MACOSX: chipmunk cdecl "libchipmunk.dylib"
13 DEPLOY-LIBRARY: chipmunk
18 TYPEDEF: double cpFloat
22 SPECIALIZED-ARRAY: cpVect
24 TYPEDEF: uint cpHashValue
25 TYPEDEF: void* cpDataPointer
26 TYPEDEF: uint cpCollisionType
27 TYPEDEF: uint cpLayers
30 CONSTANT: CP_NO_GROUP 0
31 CONSTANT: CP_ALL_LAYERS 0xffffffff
34 TYPED: cpv ( x y -- v: cpVect )
37 TYPED: cpvzero ( -- v: cpVect )
40 FUNCTION: cpFloat cpvlength ( cpVect v )
41 FUNCTION: cpVect cpvslerp ( cpVect v1, cpVect v2, cpFloat t )
42 FUNCTION: cpVect cpvslerpconst ( cpVect v1, cpVect v2, cpFloat a )
43 FUNCTION: cpVect cpvforangle ( cpFloat a )
44 FUNCTION: cpFloat cpvtoangle ( cpVect v )
45 FUNCTION: c-string cpvstr ( cpVect v )
47 TYPED: cpvadd ( v1: cpVect v2: cpVect -- v3: cpVect )
49 [ [ y>> ] bi@ + ] 2bi cpv ; inline
51 TYPED: cpvneg ( v1: cpVect -- v2: cpVect )
52 [ x>> ] [ y>> ] bi [ neg ] bi@ cpv ; inline
54 TYPED: cpvsub ( v1: cpVect v2: cpVect -- v3: cpVect )
56 [ [ y>> ] bi@ - ] 2bi cpv ; inline
58 TYPED: cpvmult ( v1: cpVect s -- v2: cpVect )
60 [ swap y>> * ] 2bi cpv ; inline
62 TYPED: cpvdot ( v1: cpVect v2: cpVect -- s )
64 [ [ y>> ] bi@ * ] 2bi + ; inline
66 TYPED: cpvcross ( v1: cpVect v2: cpVect -- s )
67 [ [ x>> ] [ y>> ] bi* * ]
68 [ [ y>> ] [ x>> ] bi* * ] 2bi - ; inline
70 TYPED: cpvperp ( v1: cpVect -- v2: cpVect )
71 [ y>> neg ] [ x>> ] bi cpv ; inline
73 TYPED: cpvrperp ( v1: cpVect -- v2: cpVect )
74 [ y>> ] [ x>> neg ] bi cpv ; inline
76 TYPED: cpvproject ( v1: cpVect v2: cpVect -- v3: cpVect )
80 2tri / cpvmult ; inline
82 TYPED: cpvrotate ( v1: cpVect v2: cpVect -- v3: cpVect )
85 [ [ y>> ] bi@ * ] 2bi -
88 [ [ x>> ] [ y>> ] bi* * ]
89 [ [ y>> ] [ x>> ] bi* * ] 2bi +
92 TYPED: cpvunrotate ( v1: cpVect v2: cpVect -- v3: cpVect )
95 [ [ y>> ] bi@ * ] 2bi +
98 [ [ y>> ] [ x>> ] bi* * ]
99 [ [ x>> ] [ y>> ] bi* * ] 2bi -
102 TYPED: cpvlengthsq ( v: cpVect -- s )
105 TYPED: cpvlerp ( v1: cpVect v2: cpVect s -- v3: cpVect )
106 [ nip 1.0 swap - cpvmult ]
107 [ cpvmult nip ] 3bi cpvadd ; inline
109 TYPED: cpvnormalize ( v1: cpVect -- v2: cpVect )
110 dup cpvlength 1.0 swap / cpvmult ; inline
112 TYPED: cpvnormalize_safe ( v1: cpVect -- v2: cpVect )
113 dup [ x>> 0.0 = ] [ y>> 0.0 = ] bi and
115 [ cpvnormalize ] if ; inline
117 TYPED: cpvclamp ( v1: cpVect len -- v2: cpVect )
121 [ [ cpvnormalize ] dip cpvmult ]
124 TYPED: cpvlerpconst ( v1: cpVect v2: cpVect d -- v3: cpVect )
126 [ [ swap cpvsub ] dip cpvclamp ] 3bi cpvadd ; inline
128 TYPED: cpvdist ( v1: cpVect v2: cpVect -- dist )
129 cpvsub cpvlength ; inline
131 TYPED: cpvdistsq ( v1: cpVect v2: cpVect -- distsq )
132 cpvsub cpvlengthsq ; inline
134 TYPED: cpvnear ( v1: cpVect v2: cpVect dist -- ? )
135 [ cpvdistsq ] dip sq < ; inline
144 TYPED: cpBBNew ( l b r t -- cpbb: cpBB )
147 TYPED: cpBBintersects ( a: cpBB b: cpBB -- ? )
149 [ [ l>> ] [ r>> ] bi* <= ]
150 [ [ r>> ] [ l>> ] bi* > ]
151 [ [ b>> ] [ t>> ] bi* <= ]
152 [ [ t>> ] [ b>> ] bi* > ]
155 TYPED: cpBBcontainsBB ( bb: cpBB other: cpBB -- ? )
163 TYPED: cpBBcontainsVect ( bb: cpBB v: cpVect -- ? )
165 [ [ l>> ] [ x>> ] bi* < ]
166 [ [ r>> ] [ x>> ] bi* > ]
167 [ [ b>> ] [ y>> ] bi* < ]
168 [ [ t>> ] [ y>> ] bi* > ]
171 TYPED: cpBBmerge ( a: cpBB b: cpBB -- c: cpBB )
177 } 2cleave cpBBNew ; inline
179 TYPED: cpBBexpand ( bb: cpBB v: cpVect -- b: cpBB )
181 [ [ l>> ] [ x>> ] bi* min ]
182 [ [ b>> ] [ y>> ] bi* min ]
183 [ [ r>> ] [ x>> ] bi* max ]
184 [ [ t>> ] [ y>> ] bi* max ]
185 } 2cleave cpBBNew ; inline
187 FUNCTION: cpVect cpBBClampVect ( cpBB bb, cpVect v )
188 FUNCTION: cpVect cpBBWrapVect ( cpBB bb, cpVect v )
192 CALLBACK: void cpBodyVelocityFunc ( cpBody* body, cpVect gravity, cpFloat damping, cpFloat dt )
193 CALLBACK: void cpBodyPositionFunc ( cpBody* body, cpFloat dt )
196 { velocity_func cpBodyVelocityFunc }
197 { position_func cpBodyPositionFunc }
209 { data cpDataPointer }
215 FUNCTION: cpBody* cpBodyAlloc ( )
216 FUNCTION: cpBody* cpBodyInit ( cpBody* body, cpFloat m, cpFloat i )
217 FUNCTION: cpBody* cpBodyNew ( cpFloat m, cpFloat i )
218 FUNCTION: void cpBodyDestroy ( cpBody* body )
219 FUNCTION: void cpBodyFree ( cpBody* body )
220 FUNCTION: void cpBodySetMass ( cpBody* body, cpFloat m )
221 FUNCTION: void cpBodySetMoment ( cpBody* body, cpFloat i )
222 FUNCTION: void cpBodySetAngle ( cpBody* body, cpFloat a )
223 FUNCTION: void cpBodySlew ( cpBody* body, cpVect pos, cpFloat dt )
224 FUNCTION: void cpBodyUpdateVelocity ( cpBody* body, cpVect gravity, cpFloat damping, cpFloat dt )
225 FUNCTION: void cpBodyUpdatePosition ( cpBody* body, cpFloat dt )
227 TYPED: cpBodyLocal2World ( body: cpBody v: cpVect -- v2: cpVect )
229 [ swap rot>> cpvrotate ] 2bi cpvadd ; inline
231 TYPED: cpBodyWorld2Local ( body: cpBody v: cpVect -- v2: cpVect )
233 [ drop rot>> ] 2bi cpvunrotate ; inline
235 TYPED: cpBodyApplyImpulse ( body: cpBody j: cpVect r: cpVect -- )
239 [ swap m_inv>> cpvmult ] 2bi cpvadd >>v drop
242 [ 2drop dup w_bias>> ]
243 [ swap cpvcross [ i_inv>> ] dip * ] 3bi + >>w_bias drop
246 FUNCTION: void cpBodyResetForces ( cpBody* body )
247 FUNCTION: void cpBodyApplyForce ( cpBody* body, cpVect f, cpVect r )
248 FUNCTION: void cpApplyDampedSpring ( cpBody* a, cpBody* b, cpVect anchr1, cpVect anchr2, cpFloat rlen, cpFloat k, cpFloat dmp, cpFloat dt )
256 CALLBACK: void cpArrayIter ( void* ptr, void* data )
258 FUNCTION: cpArray* cpArrayAlloc ( )
259 FUNCTION: cpArray* cpArrayInit ( cpArray* arr, int size )
260 FUNCTION: cpArray* cpArrayNew ( int size )
261 FUNCTION: void cpArrayDestroy ( cpArray* arr )
262 FUNCTION: void cpArrayFree ( cpArray* arr )
263 FUNCTION: void cpArrayPush ( cpArray* arr, void* object )
264 FUNCTION: void cpArrayDeleteIndex ( cpArray* arr, int idx )
265 FUNCTION: void cpArrayDeleteObj ( cpArray* arr, void* obj )
266 FUNCTION: void cpArrayEach ( cpArray* arr, cpArrayIter iterFunc, void* data )
267 FUNCTION: int cpArrayContains ( cpArray* arr, void* ptr )
273 { next cpHashSetBin* } ;
275 CALLBACK: int cpHashSetEqlFunc ( void* ptr, void* elt )
276 CALLBACK: void* cpHashSetTransFunc ( void* ptr, void* data )
277 CALLBACK: void cpHashSetIterFunc ( void* elt, void* data )
278 CALLBACK: int cpHashSetFilterFunc ( void* elt, void* data )
283 { eql cpHashSetEqlFunc }
284 { trans cpHashSetTransFunc }
285 { default_value void* }
286 { table cpHashSetBin** } ;
288 FUNCTION: void cpHashSetDestroy ( cpHashSet* set )
289 FUNCTION: void cpHashSetFree ( cpHashSet* set )
290 FUNCTION: cpHashSet* cpHashSetAlloc ( )
291 FUNCTION: cpHashSet* cpHashSetInit ( cpHashSet* set, int size, cpHashSetEqlFunc eqlFunc, cpHashSetTransFunc trans )
292 FUNCTION: cpHashSet* cpHashSetNew ( int size, cpHashSetEqlFunc eqlFunc, cpHashSetTransFunc trans )
293 FUNCTION: void* cpHashSetInsert ( cpHashSet* set, cpHashValue hash, void* ptr, void* data )
294 FUNCTION: void* cpHashSetRemove ( cpHashSet* set, cpHashValue hash, void* ptr )
295 FUNCTION: void* cpHashSetFind ( cpHashSet* set, cpHashValue hash, void* ptr )
296 FUNCTION: void cpHashSetEach ( cpHashSet* set, cpHashSetIterFunc func, void* data )
297 FUNCTION: void cpHashSetFilter ( cpHashSet* set, cpHashSetFilterFunc func, void* data )
305 STRUCT: cpSpaceHashBin
307 { next cpSpaceHashBin* } ;
309 CALLBACK: cpBB cpSpaceHashBBFunc ( void* obj )
314 { bbfunc cpSpaceHashBBFunc }
315 { handleSet cpHashSet* }
316 { table cpSpaceHashBin** }
317 { bins cpSpaceHashBin* }
320 FUNCTION: cpSpaceHash* cpSpaceHashAlloc ( )
321 FUNCTION: cpSpaceHash* cpSpaceHashInit ( cpSpaceHash* hash, cpFloat celldim, int cells, cpSpaceHashBBFunc bbfunc )
322 FUNCTION: cpSpaceHash* cpSpaceHashNew ( cpFloat celldim, int cells, cpSpaceHashBBFunc bbfunc )
323 FUNCTION: void cpSpaceHashDestroy ( cpSpaceHash* hash )
324 FUNCTION: void cpSpaceHashFree ( cpSpaceHash* hash )
325 FUNCTION: void cpSpaceHashResize ( cpSpaceHash* hash, cpFloat celldim, int numcells )
326 FUNCTION: void cpSpaceHashInsert ( cpSpaceHash* hash, void* obj, cpHashValue id, cpBB bb )
327 FUNCTION: void cpSpaceHashRemove ( cpSpaceHash* hash, void* obj, cpHashValue id )
328 CALLBACK: void cpSpaceHashIterator ( void* obj, void* data )
329 FUNCTION: void cpSpaceHashEach ( cpSpaceHash* hash, cpSpaceHashIterator func, void* data )
330 FUNCTION: void cpSpaceHashRehash ( cpSpaceHash* hash )
331 FUNCTION: void cpSpaceHashRehashObject ( cpSpaceHash* hash, void* obj, cpHashValue id )
332 CALLBACK: void cpSpaceHashQueryFunc ( void* obj1, void* obj2, void* data )
333 FUNCTION: void cpSpaceHashPointQuery ( cpSpaceHash* hash, cpVect point, cpSpaceHashQueryFunc func, void* data )
334 FUNCTION: void cpSpaceHashQuery ( cpSpaceHash* hash, void* obj, cpBB bb, cpSpaceHashQueryFunc func, void* data )
335 FUNCTION: void cpSpaceHashQueryRehash ( cpSpaceHash* hash, cpSpaceHashQueryFunc func, void* data )
336 CALLBACK: cpFloat cpSpaceHashSegmentQueryFunc ( void* obj1, void* obj2, void* data )
337 FUNCTION: void cpSpaceHashSegmentQuery ( cpSpaceHash* hash, void* obj, cpVect a, cpVect b, cpFloat t_exit, cpSpaceHashSegmentQueryFunc func, void* data )
343 STRUCT: cpSegmentQueryInfo
354 CALLBACK: cpBB cacheData_cb ( cpShape* shape, cpVect p, cpVect rot )
355 CALLBACK: void destroy_cb ( cpShape* shape )
356 CALLBACK: int pointQuery_cb ( cpShape* shape, cpVect p )
357 CALLBACK: void segmentQuery_cb ( cpShape* shape, cpVect a, cpVect b, cpSegmentQueryInfo* info )
361 { cacheData cacheData_cb }
362 { destroy destroy_cb }
363 { pointQuery pointQuery_cb }
364 { segmentQuery segmentQuery_cb } ;
367 { klass cpShapeClass* }
374 { data cpDataPointer }
375 { collision_type cpCollisionType }
378 { hashid cpHashValue } ;
380 FUNCTION: cpShape* cpShapeInit ( cpShape* shape, cpShapeClass* klass, cpBody* body )
381 FUNCTION: void cpShapeDestroy ( cpShape* shape )
382 FUNCTION: void cpShapeFree ( cpShape* shape )
383 FUNCTION: cpBB cpShapeCacheBB ( cpShape* shape )
384 FUNCTION: int cpShapePointQuery ( cpShape* shape, cpVect p )
386 STRUCT: cpCircleShape
392 FUNCTION: cpCircleShape* cpCircleShapeAlloc ( )
393 FUNCTION: cpCircleShape* cpCircleShapeInit ( cpCircleShape* circle, cpBody* body, cpFloat radius, cpVect offset )
394 FUNCTION: cpShape* cpCircleShapeNew ( cpBody* body, cpFloat radius, cpVect offset )
396 STRUCT: cpSegmentShape
406 FUNCTION: cpSegmentShape* cpSegmentShapeAlloc ( )
407 FUNCTION: cpSegmentShape* cpSegmentShapeInit ( cpSegmentShape* seg, cpBody* body, cpVect a, cpVect b, cpFloat radius )
408 FUNCTION: cpShape* cpSegmentShapeNew ( cpBody* body, cpVect a, cpVect b, cpFloat radius )
409 FUNCTION: void cpResetShapeIdCounter ( )
410 FUNCTION: void cpSegmentQueryInfoPrint ( cpSegmentQueryInfo* info )
411 FUNCTION: int cpShapeSegmentQuery ( cpShape* shape, cpVect a, cpVect b, cpSegmentQueryInfo* info )
413 TYPED: cpSegmentQueryHitPoint ( start: cpVect end: cpVect info: cpSegmentQueryInfo -- hit-point: cpVect )
416 TYPED: cpSegmentQueryHitDist ( start: cpVect end: cpVect info: cpSegmentQueryInfo -- hit-dist )
417 t>> [ cpvdist ] dip * ; inline
420 STRUCT: cpPolyShapeAxis
423 SPECIALIZED-ARRAY: cpPolyShapeAxis
429 { axes cpPolyShapeAxis* }
431 { tAxes cpPolyShapeAxis* } ;
433 FUNCTION: cpPolyShape* cpPolyShapeAlloc ( )
434 FUNCTION: cpPolyShape* cpPolyShapeInit ( cpPolyShape* poly, cpBody* body, int numVerts, cpVect* verts, cpVect offset )
435 FUNCTION: cpShape* cpPolyShapeNew ( cpBody* body, int numVerts, cpVect* verts, cpVect offset )
436 FUNCTION: int cpPolyValidate ( cpVect* verts, int numVerts )
437 FUNCTION: int cpPolyShapeGetNumVerts ( cpShape* shape )
438 FUNCTION: cpVect cpPolyShapeGetVert ( cpShape* shape, int idx )
440 TYPED: cpPolyShapeValueOnAxis ( poly: cpPolyShape n: cpVect d -- min-dist )
441 swap rot [ numVerts>> ] [ tVerts>> swap cpVect <c-direct-array> ] bi swap
442 [ cpvdot ] curry [ min ] reduce swap - ; inline
444 TYPED: cpPolyShapeContainsVert ( poly: cpPolyShape v: cpVect -- ? )
445 swap [ numVerts>> ] [ tAxes>> swap cpPolyShapeAxis <c-direct-array> ] bi swap
447 [ [ n>> ] dip cpvdot ] [ drop d>> ] 2bi -
448 ] curry [ max ] reduce 0.0 <= ; inline
450 TYPED: cpPolyShapeContainsVertPartial ( poly: cpPolyShape v: cpVect n: cpVect -- ? )
451 rot [ numVerts>> ] [ tAxes>> swap cpPolyShapeAxis <c-direct-array> ] bi -rot
453 axis n>> n cpvdot 0.0 < 0
455 [ axis n>> v cpvdot axis d>> - ]
457 ] 2curry [ max ] reduce 0.0 <= ; inline
462 C-TYPE: cpCollisionHandler
477 { hash cpHashValue } ;
479 FUNCTION: cpContact* cpContactInit ( cpContact* con, cpVect p, cpVect n, cpFloat dist, cpHashValue hash )
483 cpArbiterStateFirstColl
484 cpArbiterStateIgnore ;
488 { contacts cpContact* }
493 { surface_vr cpVect }
495 { handler cpCollisionHandler* }
499 FUNCTION: cpArbiter* cpArbiterAlloc ( )
500 FUNCTION: cpArbiter* cpArbiterInit ( cpArbiter* arb, cpShape* a, cpShape* b )
501 FUNCTION: cpArbiter* cpArbiterNew ( cpShape* a, cpShape* b )
502 FUNCTION: void cpArbiterDestroy ( cpArbiter* arb )
503 FUNCTION: void cpArbiterFree ( cpArbiter* arb )
504 FUNCTION: void cpArbiterUpdate ( cpArbiter* arb, cpContact* contacts, int numContacts, cpCollisionHandler* handler, cpShape* a, cpShape* b )
505 FUNCTION: void cpArbiterPreStep ( cpArbiter* arb, cpFloat dt_inv )
506 FUNCTION: void cpArbiterApplyCachedImpulse ( cpArbiter* arb )
507 FUNCTION: void cpArbiterApplyImpulse ( cpArbiter* arb, cpFloat eCoef )
508 FUNCTION: cpVect cpArbiterTotalImpulse ( cpArbiter* arb )
509 FUNCTION: cpVect cpArbiterTotalImpulseWithFriction ( cpArbiter* arb )
510 FUNCTION: void cpArbiterIgnore ( cpArbiter* arb )
512 TYPED: cpArbiterGetShapes ( arb: cpArbiter -- a: cpShape b: cpShape )
513 dup swappedColl>> 0 = [
519 TYPED: cpArbiterIsFirstContact ( arb: cpArbiter -- ? )
520 state>> cpArbiterStateFirstColl = ; inline
522 TYPED: cpArbiterGetNormal ( arb: cpArbiter i -- n: cpVect )
526 [ contacts>> swap void* <c-direct-array> ] bi nth cpContact memory>struct n>>
529 drop swappedColl>> 0 = [ cpvneg ] unless
532 TYPED: cpArbiterGetPoint ( arb: cpArbiter i -- p: cpVect )
535 [ contacts>> swap void* <c-direct-array> ] bi
536 nth cpContact memory>struct p>> ; inline
539 FUNCTION: int cpCollideShapes ( cpShape* a, cpShape* b, cpContact** arr )
543 C-TYPE: cpConstraintClass
546 CALLBACK: void cpConstraintPreStepFunction ( cpConstraint* constraint, cpFloat dt, cpFloat dt_inv )
547 CALLBACK: void cpConstraintApplyImpulseFunction ( cpConstraint* constraint )
548 CALLBACK: cpFloat cpConstraintGetImpulseFunction ( cpConstraint* constraint )
550 STRUCT: cpConstraintClass
551 { preStep cpConstraintPreStepFunction }
552 { applyImpulse cpConstraintApplyImpulseFunction }
553 { getImpulse cpConstraintGetImpulseFunction } ;
556 { klass cpConstraintClass* }
562 { data cpDataPointer } ;
564 FUNCTION: void cpConstraintDestroy ( cpConstraint* constraint )
565 FUNCTION: void cpConstraintFree ( cpConstraint* constraint )
566 FUNCTION: void cpConstraintCheckCast ( cpConstraint* constraint, cpConstraintClass* klass )
569 FUNCTION: cpConstraintClass* cpPinJointGetClass ( )
572 { constraint cpConstraint }
584 FUNCTION: cpPinJoint* cpPinJointAlloc ( )
585 FUNCTION: cpPinJoint* cpPinJointInit ( cpPinJoint* joint, cpBody* a, cpBody* b, cpVect anchr1, cpVect anchr2 )
586 FUNCTION: cpConstraint* cpPinJointNew ( cpBody* a, cpBody* b, cpVect anchr1, cpVect anchr2 )
589 FUNCTION: cpConstraintClass* cpSlideJointGetClass ( )
592 { constraint cpConstraint }
605 FUNCTION: cpSlideJoint* cpSlideJointAlloc ( )
606 FUNCTION: cpSlideJoint* cpSlideJointInit ( cpSlideJoint* joint, cpBody* a, cpBody* b, cpVect anchr1, cpVect anchr2, cpFloat min, cpFloat max )
607 FUNCTION: cpConstraint* cpSlideJointNew ( cpBody* a, cpBody* b, cpVect anchr1, cpVect anchr2, cpFloat min, cpFloat max )
610 FUNCTION: cpConstraintClass* cpPivotJointGetClass ( )
613 { constraint cpConstraint }
624 FUNCTION: cpPivotJoint* cpPivotJointAlloc ( )
625 FUNCTION: cpPivotJoint* cpPivotJointInit ( cpPivotJoint* joint, cpBody* a, cpBody* b, cpVect anchr1, cpVect anchr2 )
626 FUNCTION: cpConstraint* cpPivotJointNew ( cpBody* a, cpBody* b, cpVect pivot )
627 FUNCTION: cpConstraint* cpPivotJointNew2 ( cpBody* a, cpBody* b, cpVect anchr1, cpVect anchr2 )
630 FUNCTION: cpConstraintClass* cpGrooveJointGetClass ( )
632 STRUCT: cpGrooveJoint
633 { constraint cpConstraint }
648 FUNCTION: cpGrooveJoint* cpGrooveJointAlloc ( )
649 FUNCTION: cpGrooveJoint* cpGrooveJointInit ( cpGrooveJoint* joint, cpBody* a, cpBody* b, cpVect groove_a, cpVect groove_b, cpVect anchr2 )
650 FUNCTION: cpConstraint* cpGrooveJointNew ( cpBody* a, cpBody* b, cpVect groove_a, cpVect groove_b, cpVect anchr2 )
653 CALLBACK: cpFloat cpDampedSpringForceFunc ( cpConstraint* spring, cpFloat dist )
654 FUNCTION: cpConstraintClass* cpDampedSpringGetClass ( )
656 STRUCT: cpDampedSpring
657 { constraint cpConstraint }
660 { restLength cpFloat }
661 { stiffness cpFloat }
663 { springForceFunc cpDampedSpringForceFunc }
665 { target_vrn cpFloat }
671 FUNCTION: cpDampedSpring* cpDampedSpringAlloc ( )
672 FUNCTION: cpDampedSpring* cpDampedSpringInit ( cpDampedSpring* joint, cpBody* a, cpBody* b, cpVect anchr1, cpVect anchr2, cpFloat restLength, cpFloat stiffness, cpFloat damping )
673 FUNCTION: cpConstraint* cpDampedSpringNew ( cpBody* a, cpBody* b, cpVect anchr1, cpVect anchr2, cpFloat restLength, cpFloat stiffness, cpFloat damping )
675 ! cpDampedRotarySpring.h
676 CALLBACK: cpFloat cpDampedRotarySpringTorqueFunc ( cpConstraint* spring, cpFloat relativeAngle )
677 FUNCTION: cpConstraintClass* cpDampedRotarySpringGetClass ( )
679 STRUCT: cpDampedRotarySpring
680 { constraint cpConstraint }
681 { restAngle cpFloat }
682 { stiffness cpFloat }
684 { springTorqueFunc cpDampedRotarySpringTorqueFunc }
686 { target_wrn cpFloat }
689 FUNCTION: cpDampedRotarySpring* cpDampedRotarySpringAlloc ( )
690 FUNCTION: cpDampedRotarySpring* cpDampedRotarySpringInit ( cpDampedRotarySpring* joint, cpBody* a, cpBody* b, cpFloat restAngle, cpFloat stiffness, cpFloat damping )
691 FUNCTION: cpConstraint* cpDampedRotarySpringNew ( cpBody* a, cpBody* b, cpFloat restAngle, cpFloat stiffness, cpFloat damping )
693 ! cpRotaryLimitJoint.h
694 FUNCTION: cpConstraintClass* cpRotaryLimitJointGetClass ( )
696 STRUCT: cpRotaryLimitJoint
697 { constraint cpConstraint }
705 FUNCTION: cpRotaryLimitJoint* cpRotaryLimitJointAlloc ( )
706 FUNCTION: cpRotaryLimitJoint* cpRotaryLimitJointInit ( cpRotaryLimitJoint* joint, cpBody* a, cpBody* b, cpFloat min, cpFloat max )
707 FUNCTION: cpConstraint* cpRotaryLimitJointNew ( cpBody* a, cpBody* b, cpFloat min, cpFloat max )
710 FUNCTION: cpConstraintClass* cpRatchetJointGetClass ( )
712 STRUCT: cpRatchetJoint
713 { constraint cpConstraint }
722 FUNCTION: cpRatchetJoint* cpRatchetJointAlloc ( )
723 FUNCTION: cpRatchetJoint* cpRatchetJointInit ( cpRatchetJoint* joint, cpBody* a, cpBody* b, cpFloat phase, cpFloat ratchet )
724 FUNCTION: cpConstraint* cpRatchetJointNew ( cpBody* a, cpBody* b, cpFloat phase, cpFloat ratchet )
727 FUNCTION: cpConstraintClass* cpGearJointGetClass ( )
730 { constraint cpConstraint }
733 { ratio_inv cpFloat }
739 FUNCTION: cpGearJoint* cpGearJointAlloc ( )
740 FUNCTION: cpGearJoint* cpGearJointInit ( cpGearJoint* joint, cpBody* a, cpBody* b, cpFloat phase, cpFloat ratio )
741 FUNCTION: cpConstraint* cpGearJointNew ( cpBody* a, cpBody* b, cpFloat phase, cpFloat ratio )
742 FUNCTION: void cpGearJointSetRatio ( cpConstraint* constraint, cpFloat value )
745 FUNCTION: cpConstraintClass* cpSimpleMotorGetClass ( )
747 STRUCT: cpSimpleMotor
748 { constraint cpConstraint }
754 FUNCTION: cpSimpleMotor* cpSimpleMotorAlloc ( )
755 FUNCTION: cpSimpleMotor* cpSimpleMotorInit ( cpSimpleMotor* joint, cpBody* a, cpBody* b, cpFloat rate )
756 FUNCTION: cpConstraint* cpSimpleMotorNew ( cpBody* a, cpBody* b, cpFloat rate )
761 CALLBACK: int cpCollisionBeginFunc ( cpArbiter* arb, cpSpace* space, void* data )
762 CALLBACK: int cpCollisionPreSolveFunc ( cpArbiter* arb, cpSpace* space, void* data )
763 CALLBACK: void cpCollisionPostSolveFunc ( cpArbiter* arb, cpSpace* space, void* data )
764 CALLBACK: void cpCollisionSeparateFunc ( cpArbiter* arb, cpSpace* space, void* data )
766 STRUCT: cpCollisionHandler
767 { a cpCollisionType }
768 { b cpCollisionType }
769 { begin cpCollisionBeginFunc }
770 { preSolve cpCollisionPreSolveFunc }
771 { postSolve cpCollisionPostSolveFunc }
772 { separate cpCollisionSeparateFunc }
777 { elasticIterations int }
781 { staticShapes cpSpaceHash* }
782 { activeShapes cpSpaceHash* }
784 { arbiters cpArray* }
785 { contactSet cpHashSet* }
786 { constraints cpArray* }
787 { collFuncSet cpHashSet* }
788 { defaultHandler cpCollisionHandler }
789 { postStepCallbacks cpHashSet* } ;
791 FUNCTION: cpSpace* cpSpaceAlloc ( )
792 FUNCTION: cpSpace* cpSpaceInit ( cpSpace* space )
793 FUNCTION: cpSpace* cpSpaceNew ( )
794 FUNCTION: void cpSpaceDestroy ( cpSpace* space )
795 FUNCTION: void cpSpaceFree ( cpSpace* space )
796 FUNCTION: void cpSpaceFreeChildren ( cpSpace* space )
797 FUNCTION: void cpSpaceSetDefaultCollisionHandler (
799 cpCollisionBeginFunc begin,
800 cpCollisionPreSolveFunc preSolve,
801 cpCollisionPostSolveFunc postSolve,
802 cpCollisionSeparateFunc separate,
804 FUNCTION: void cpSpaceAddCollisionHandler (
808 cpCollisionBeginFunc begin,
809 cpCollisionPreSolveFunc preSolve,
810 cpCollisionPostSolveFunc postSolve,
811 cpCollisionSeparateFunc separate,
813 FUNCTION: void cpSpaceRemoveCollisionHandler ( cpSpace* space, cpCollisionType a, cpCollisionType b )
814 FUNCTION: cpShape* cpSpaceAddShape ( cpSpace* space, cpShape* shape )
815 FUNCTION: cpShape* cpSpaceAddStaticShape ( cpSpace* space, cpShape* shape )
816 FUNCTION: cpBody* cpSpaceAddBody ( cpSpace* space, cpBody* body )
817 FUNCTION: cpConstraint* cpSpaceAddConstraint ( cpSpace* space, cpConstraint* constraint )
818 FUNCTION: void cpSpaceRemoveShape ( cpSpace* space, cpShape* shape )
819 FUNCTION: void cpSpaceRemoveStaticShape ( cpSpace* space, cpShape* shape )
820 FUNCTION: void cpSpaceRemoveBody ( cpSpace* space, cpBody* body )
821 FUNCTION: void cpSpaceRemoveConstraint ( cpSpace* space, cpConstraint* constraint )
822 CALLBACK: void cpPostStepFunc ( cpSpace* space, void* obj, void* data )
823 FUNCTION: void cpSpaceAddPostStepCallback ( cpSpace* space, cpPostStepFunc func, void* obj, void* data )
824 CALLBACK: void cpSpacePointQueryFunc ( cpShape* shape, void* data )
825 FUNCTION: void cpSpacePointQuery ( cpSpace* space, cpVect point, cpLayers layers, cpGroup group, cpSpacePointQueryFunc func, void* data )
826 FUNCTION: cpShape* cpSpacePointQueryFirst ( cpSpace* space, cpVect point, cpLayers layers, cpGroup group )
827 CALLBACK: void cpSpaceSegmentQueryFunc ( cpShape* shape, cpFloat t, cpVect n, void* data )
828 FUNCTION: int cpSpaceSegmentQuery ( cpSpace* space, cpVect start, cpVect end, cpLayers layers, cpGroup group, cpSpaceSegmentQueryFunc func, void* data )
829 FUNCTION: cpShape* cpSpaceSegmentQueryFirst ( cpSpace* space, cpVect start, cpVect end, cpLayers layers, cpGroup group, cpSegmentQueryInfo* out )
830 CALLBACK: void cpSpaceBBQueryFunc ( cpShape* shape, void* data )
831 FUNCTION: void cpSpaceBBQuery ( cpSpace* space, cpBB bb, cpLayers layers, cpGroup group, cpSpaceBBQueryFunc func, void* data )
832 CALLBACK: void cpSpaceBodyIterator ( cpBody* body, void* data )
833 FUNCTION: void cpSpaceEachBody ( cpSpace* space, cpSpaceBodyIterator func, void* data )
834 FUNCTION: void cpSpaceResizeStaticHash ( cpSpace* space, cpFloat dim, int count )
835 FUNCTION: void cpSpaceResizeActiveHash ( cpSpace* space, cpFloat dim, int count )
836 FUNCTION: void cpSpaceRehashStatic ( cpSpace* space )
837 FUNCTION: void cpSpaceStep ( cpSpace* space, cpFloat dt )
840 FUNCTION: void cpInitChipmunk ( )
841 FUNCTION: cpFloat cpMomentForCircle ( cpFloat m, cpFloat r1, cpFloat r2, cpVect offset )
842 FUNCTION: cpFloat cpMomentForSegment ( cpFloat m, cpVect a, cpVect b )
843 FUNCTION: cpFloat cpMomentForPoly ( cpFloat m, int numVerts, cpVect* verts, cpVect offset )