Browse Source

Chipmunk fixes.

Mark Sibly 8 years ago
parent
commit
d8abf1c74e

+ 44 - 3
bananas/hellochipmunk/hellochimpmunk.monkey2

@@ -13,8 +13,15 @@ Class HelloChipmunk Extends Window
 
 	Field space:cpSpace
 	Field ground:cpShape
+	
 	Field ballBody:cpBody
 	Field ballShape:cpShape
+
+	Field ballBody2:cpBody
+	Field ballShape2:cpShape
+
+	Field polyBody:cpBody
+	Field polyShape:cpShape
 	
 	Field debugger:=New ChipmunkDebugger
 	
@@ -36,13 +43,21 @@ Class HelloChipmunk Extends Window
 		ground.CollisionType=1
 		space.AddShape( ground )
 		
+		Local tshape:=space.AddShape( cpSegmentShapeNew( space.StaticBody,cpv(-Width/2,Height/2-64),cpv(0,Height/2),0 ) )
+		tshape.Friction=1
+		tshape.CollisionType=1
+
+		tshape=space.AddShape( cpSegmentShapeNew( space.StaticBody,cpv(0,Height/2),cpv(Width/2,Height/2-64),0 ) )
+		tshape.Friction=1
+		tshape.CollisionType=1
+		
 		'Now let's make a ball that falls onto the line and rolls off.
 		'First we need to make a cpBody to hold the physical properties of the object.
 		'These include the mass, position, velocity, angle, etc. of the object.
 		'Then we attach collision shapes to the cpBody to give it a size and shape.
 		
-		Local radius:=10
-		Local mass:=1
+		Local mass:=1.0
+		Local radius:=10.0
   
 		'The moment of inertia is like mass for rotation
 		'Use the cpMomentFor*() functions to help you approximate it.
@@ -52,13 +67,39 @@ Class HelloChipmunk Extends Window
 		'It's convenient to create and add an object in one line.
 		ballBody=space.AddBody( cpBodyNew( mass,moment ) )
 		ballBody.Position=cpv( 0,-100 )
-		
+
 		'Now we create the collision shape for the ball.
 		'You can create multiple collision shapes that point to the same body.
 		'They will all be attached to the body and move around to follow it.
 		ballShape=space.AddShape( cpCircleShapeNew( ballBody,radius,cpvzero ) )
 		ballShape.Friction=0.7
 		ballShape.CollisionType=2
+
+		ballBody2=space.AddBody( cpBodyNew( mass,moment ) )
+		ballBody2.Position=cpv( 50,-100 )
+		
+		ballShape2=space.AddShape( cpCircleShapeNew( ballBody2,radius,cpvzero ) )
+		ballShape2.Friction=0.7
+		ballShape2.CollisionType=2
+		
+		'Now a pentagon...
+		mass=0.3
+		radius=30.0
+
+		Local NUM_VERTS:=5
+		Local verts:=New cpVect[NUM_VERTS]
+		For Local it:=0 Until NUM_VERTS
+			Local angle:=TwoPi * it / NUM_VERTS
+			verts[it]=cpv( radius*Cos( angle ),radius*Sin( angle ) )
+		Next
+
+		moment=cpMomentForPoly( mass,NUM_VERTS,verts.Data,cpvzero,0.0 )
+
+		polyBody=space.AddBody( cpBodyNew( mass,moment ) )
+		polyBody.Position=cpv( 50.0,-190.0 )
+				
+		polyShape=space.AddShape( cpPolyShapeNew( polyBody,NUM_VERTS,verts.Data,cpTransformIdentity,0.0 ) )
+		polyShape.Friction=0.03
 		
 		Local handler:=space.AddDefaultCollisionHandler()
 		

+ 10 - 10
modules/chipmunk/arbiter.monkey2

@@ -23,8 +23,8 @@ Function cpArbiterSetUserData:Void( arb:cpArbiter, userData:cpDataPointer )
 Function cpArbiterTotalImpulse:cpVect( arb:cpArbiter )
 Function cpArbiterTotalKE:cpFloat( arb:cpArbiter )
 Function cpArbiterIgnore:cpBool( arb:cpArbiter )
-Function cpArbiterGetShapes:Void( arb:cpArbiter, a:cpShape Ptr Ptr, b:cpShape Ptr Ptr )
-Function cpArbiterGetBodies:Void( arb:cpArbiter, a:cpBody Ptr Ptr, b:cpBody Ptr Ptr )
+Function cpArbiterGetShapes:Void( arb:cpArbiter, a:cpShape Ptr, b:cpShape Ptr )
+Function cpArbiterGetBodies:Void( arb:cpArbiter, a:cpBody Ptr, b:cpBody Ptr )
 Function cpArbiterGetContactPointSet:cpContactPointSet( arb:cpArbiter )
 Function cpArbiterSetContactPointSet:Void( arb:cpArbiter, set:cpContactPointSet Ptr )
 Function cpArbiterIsFirstContact:cpBool( arb:cpArbiter )
@@ -34,14 +34,14 @@ Function cpArbiterGetNormal:cpVect( arb:cpArbiter )
 Function cpArbiterGetPointA:cpVect( arb:cpArbiter, i:Int )
 Function cpArbiterGetPointB:cpVect( arb:cpArbiter, i:Int )
 Function cpArbiterGetDepth:cpFloat( arb:cpArbiter, i:Int )
-Function cpArbiterCallWildcardBeginA:cpBool( arb:cpArbiter, space:cpSpace Ptr )
-Function cpArbiterCallWildcardBeginB:cpBool( arb:cpArbiter, space:cpSpace Ptr )
-Function cpArbiterCallWildcardPreSolveA:cpBool( arb:cpArbiter, space:cpSpace Ptr )
-Function cpArbiterCallWildcardPreSolveB:cpBool( arb:cpArbiter, space:cpSpace Ptr )
-Function cpArbiterCallWildcardPostSolveA:Void( arb:cpArbiter, space:cpSpace Ptr )
-Function cpArbiterCallWildcardPostSolveB:Void( arb:cpArbiter, space:cpSpace Ptr )
-Function cpArbiterCallWildcardSeparateA:Void( arb:cpArbiter, space:cpSpace Ptr )
-Function cpArbiterCallWildcardSeparateB:Void( arb:cpArbiter, space:cpSpace Ptr )
+Function cpArbiterCallWildcardBeginA:cpBool( arb:cpArbiter, space:cpSpace )
+Function cpArbiterCallWildcardBeginB:cpBool( arb:cpArbiter, space:cpSpace )
+Function cpArbiterCallWildcardPreSolveA:cpBool( arb:cpArbiter, space:cpSpace )
+Function cpArbiterCallWildcardPreSolveB:cpBool( arb:cpArbiter, space:cpSpace )
+Function cpArbiterCallWildcardPostSolveA:Void( arb:cpArbiter, space:cpSpace )
+Function cpArbiterCallWildcardPostSolveB:Void( arb:cpArbiter, space:cpSpace )
+Function cpArbiterCallWildcardSeparateA:Void( arb:cpArbiter, space:cpSpace )
+Function cpArbiterCallWildcardSeparateB:Void( arb:cpArbiter, space:cpSpace )
 
 Class cpArbiter Extends Void
 

+ 2 - 2
modules/chipmunk/body.monkey2

@@ -17,8 +17,8 @@ Alias cpBodyVelocityFunc:Void( cpBody, cpVect, cpFloat, cpFloat )
 Alias cpBodyPositionFunc:Void( cpBody, cpFloat )
 
 Alias cpBodyShapeIteratorFunc:Void( cpBody, cpShape, Void Ptr )
-Alias cpBodyConstraintIteratorFunc:Void( cpBody, cpConstraint Ptr, Void Ptr )
-Alias cpBodyArbiterIteratorFunc:Void( cpBody, cpArbiter Ptr, Void Ptr )
+Alias cpBodyConstraintIteratorFunc:Void( cpBody, cpConstraint, Void Ptr )
+Alias cpBodyArbiterIteratorFunc:Void( cpBody, cpArbiter, Void Ptr )
 
 Function cpBodyAlloc:cpBody(  )
 Function cpBodyInit:cpBody( body:cpBody, mass:cpFloat, moment:cpFloat )

+ 6 - 6
modules/chipmunk/constraint.monkey2

@@ -88,8 +88,8 @@ Function cpGrooveJointSetAnchorB:Void( constraint:cpConstraint, anchorB:cpVect )
 
 Function cpConstraintIsDampedSpring:cpBool( constraint:cpConstraint )
 Alias cpDampedSpringForceFunc:cpFloat( cpConstraint, cpFloat )
-Function cpDampedSpringAlloc:cpDampedSpring Ptr(  )
-Function cpDampedSpringInit:cpDampedSpring Ptr( joint:cpDampedSpring Ptr, a:cpBody, b:cpBody, anchorA:cpVect, anchorB:cpVect, restLength:cpFloat, stiffness:cpFloat, damping:cpFloat )
+Function cpDampedSpringAlloc:cpDampedSpring(  )
+Function cpDampedSpringInit:cpDampedSpring( joint:cpDampedSpring, a:cpBody, b:cpBody, anchorA:cpVect, anchorB:cpVect, restLength:cpFloat, stiffness:cpFloat, damping:cpFloat )
 Function cpDampedSpringNew:cpConstraint( a:cpBody, b:cpBody, anchorA:cpVect, anchorB:cpVect, restLength:cpFloat, stiffness:cpFloat, damping:cpFloat )
 Function cpDampedSpringGetAnchorA:cpVect( constraint:cpConstraint )
 Function cpDampedSpringSetAnchorA:Void( constraint:cpConstraint, anchorA:cpVect )
@@ -108,8 +108,8 @@ Function cpDampedSpringSetSpringForceFunc:Void( constraint:cpConstraint, springF
 
 Function cpConstraintIsDampedRotarySpring:cpBool( constraint:cpConstraint )
 Alias cpDampedRotarySpringTorqueFunc:cpFloat( cpConstraint, cpFloat )
-Function cpDampedRotarySpringAlloc:cpDampedRotarySpring Ptr(  )
-Function cpDampedRotarySpringInit:cpDampedRotarySpring Ptr( joint:cpDampedRotarySpring Ptr, a:cpBody, b:cpBody, restAngle:cpFloat, stiffness:cpFloat, damping:cpFloat )
+Function cpDampedRotarySpringAlloc:cpDampedRotarySpring(  )
+Function cpDampedRotarySpringInit:cpDampedRotarySpring( joint:cpDampedRotarySpring, a:cpBody, b:cpBody, restAngle:cpFloat, stiffness:cpFloat, damping:cpFloat )
 Function cpDampedRotarySpringNew:cpConstraint( a:cpBody, b:cpBody, restAngle:cpFloat, stiffness:cpFloat, damping:cpFloat )
 Function cpDampedRotarySpringGetRestAngle:cpFloat( constraint:cpConstraint )
 Function cpDampedRotarySpringSetRestAngle:Void( constraint:cpConstraint, restAngle:cpFloat )
@@ -158,8 +158,8 @@ Function cpGearJointSetRatio:Void( constraint:cpConstraint, ratio:cpFloat )
 '***** File: Chipmunk7/include/chipmunk/cpSimpleMotor.h *****
 
 Function cpConstraintIsSimpleMotor:cpBool( constraint:cpConstraint )
-Function cpSimpleMotorAlloc:cpSimpleMotor Ptr(  )
-Function cpSimpleMotorInit:cpSimpleMotor Ptr( joint:cpSimpleMotor Ptr, a:cpBody, b:cpBody, rate:cpFloat )
+Function cpSimpleMotorAlloc:cpSimpleMotor(  )
+Function cpSimpleMotorInit:cpSimpleMotor( joint:cpSimpleMotor, a:cpBody, b:cpBody, rate:cpFloat )
 Function cpSimpleMotorNew:cpConstraint( a:cpBody, b:cpBody, rate:cpFloat )
 Function cpSimpleMotorGetRate:cpFloat( constraint:cpConstraint )
 Function cpSimpleMotorSetRate:Void( constraint:cpConstraint, rate:cpFloat )

+ 13 - 13
modules/chipmunk/shape.monkey2

@@ -38,7 +38,7 @@ Function cpShapeUpdate:cpBB( shape:cpShape, transform:cpTransform )
 Function cpShapePointQuery:cpFloat( shape:cpShape, p:cpVect, out:cpPointQueryInfo Ptr )
 Function cpShapeSegmentQuery:cpBool( shape:cpShape, a:cpVect, b:cpVect, radius:cpFloat, info:cpSegmentQueryInfo Ptr )
 Function cpShapesCollide:cpContactPointSet( a:cpShape, b:cpShape )
-Function cpShapeGetSpace:cpSpace Ptr( shape:cpShape )
+Function cpShapeGetSpace:cpSpace( shape:cpShape )
 Function cpShapeGetBody:cpBody( shape:cpShape )
 Function cpShapeSetBody:Void( shape:cpShape, body:cpBody )
 Function cpShapeGetMass:cpFloat( shape:cpShape )
@@ -63,13 +63,13 @@ Function cpShapeGetCollisionType:cpCollisionType( shape:cpShape )
 Function cpShapeSetCollisionType:Void( shape:cpShape, collisionType:cpCollisionType )
 Function cpShapeGetFilter:cpShapeFilter( shape:cpShape )
 Function cpShapeSetFilter:Void( shape:cpShape, filter:cpShapeFilter )
-Function cpCircleShapeAlloc:cpCircleShape Ptr(  )
-Function cpCircleShapeInit:cpCircleShape Ptr( circle:cpCircleShape Ptr, body:cpBody, radius:cpFloat, offset:cpVect )
+Function cpCircleShapeAlloc:cpCircleShape(  )
+Function cpCircleShapeInit:cpCircleShape( circle:cpCircleShape, body:cpBody, radius:cpFloat, offset:cpVect )
 Function cpCircleShapeNew:cpShape( body:cpBody, radius:cpFloat, offset:cpVect )
 Function cpCircleShapeGetOffset:cpVect( shape:cpShape )
 Function cpCircleShapeGetRadius:cpFloat( shape:cpShape )
-Function cpSegmentShapeAlloc:cpSegmentShape Ptr(  )
-Function cpSegmentShapeInit:cpSegmentShape Ptr( seg:cpSegmentShape Ptr, body:cpBody, a:cpVect, b:cpVect, radius:cpFloat )
+Function cpSegmentShapeAlloc:cpSegmentShape(  )
+Function cpSegmentShapeInit:cpSegmentShape( seg:cpSegmentShape, body:cpBody, a:cpVect, b:cpVect, radius:cpFloat )
 Function cpSegmentShapeNew:cpShape( body:cpBody, a:cpVect, b:cpVect, radius:cpFloat )
 Function cpSegmentShapeSetNeighbors:Void( shape:cpShape, prev:cpVect, next_:cpVect )
 Function cpSegmentShapeGetA:cpVect( shape:cpShape )
@@ -80,14 +80,14 @@ Function cpSegmentShapeGetRadius:cpFloat( shape:cpShape )
 '***** File: Chipmunk7/include/chipmunk/cpPolyShape.h *****
 
 Function cpPolyShapeAlloc:cpPolyShape(  )
-Function cpPolyShapeInit:cpPolyShape( poly:cpPolyShape, body:cpBody Ptr, count:Int, verts:cpVect Ptr, transform:cpTransform, radius:cpFloat )
-Function cpPolyShapeInitRaw:cpPolyShape( poly:cpPolyShape, body:cpBody Ptr, count:Int, verts:cpVect Ptr, radius:cpFloat )
-Function cpPolyShapeNew:cpShape( body:cpBody Ptr, count:Int, verts:cpVect Ptr, transform:cpTransform, radius:cpFloat )
-Function cpPolyShapeNewRaw:cpShape( body:cpBody Ptr, count:Int, verts:cpVect Ptr, radius:cpFloat )
-Function cpBoxShapeInit:cpPolyShape( poly:cpPolyShape, body:cpBody Ptr, width:cpFloat, height:cpFloat, radius:cpFloat )
-Function cpBoxShapeInit2:cpPolyShape( poly:cpPolyShape, body:cpBody Ptr, box:cpBB, radius:cpFloat )
-Function cpBoxShapeNew:cpShape( body:cpBody Ptr, width:cpFloat, height:cpFloat, radius:cpFloat )
-Function cpBoxShapeNew2:cpShape( body:cpBody Ptr, box:cpBB, radius:cpFloat )
+Function cpPolyShapeInit:cpPolyShape( poly:cpPolyShape, body:cpBody, count:Int, verts:cpVect Ptr, transform:cpTransform, radius:cpFloat )
+Function cpPolyShapeInitRaw:cpPolyShape( poly:cpPolyShape, body:cpBody, count:Int, verts:cpVect Ptr, radius:cpFloat )
+Function cpPolyShapeNew:cpShape( body:cpBody, count:Int, verts:cpVect Ptr, transform:cpTransform, radius:cpFloat )
+Function cpPolyShapeNewRaw:cpShape( body:cpBody, count:Int, verts:cpVect Ptr, radius:cpFloat )
+Function cpBoxShapeInit:cpPolyShape( poly:cpPolyShape, body:cpBody, width:cpFloat, height:cpFloat, radius:cpFloat )
+Function cpBoxShapeInit2:cpPolyShape( poly:cpPolyShape, body:cpBody, box:cpBB, radius:cpFloat )
+Function cpBoxShapeNew:cpShape( body:cpBody, width:cpFloat, height:cpFloat, radius:cpFloat )
+Function cpBoxShapeNew2:cpShape( body:cpBody, box:cpBB, radius:cpFloat )
 Function cpPolyShapeGetCount:Int( shape:cpShape )
 Function cpPolyShapeGetVert:cpVect( shape:cpShape, index:Int )
 Function cpPolyShapeGetRadius:cpFloat( shape:cpShape )

+ 8 - 4
modules/chipmunk/space.monkey2

@@ -64,7 +64,7 @@ Alias cpSpaceBBQueryFunc:Void( cpShape, Void Ptr )
 Alias cpSpaceShapeQueryFunc:Void( cpShape, cpContactPointSet Ptr, Void Ptr )
 Alias cpSpaceBodyIteratorFunc:Void( cpBody, Void Ptr )
 Alias cpSpaceShapeIteratorFunc:Void( cpShape, Void Ptr )
-Alias cpSpaceConstraintIteratorFunc:Void( cpConstraint Ptr, Void Ptr )
+Alias cpSpaceConstraintIteratorFunc:Void( cpConstraint, Void Ptr )
 
 Function cpSpaceAlloc:cpSpace(  )
 Function cpSpaceInit:cpSpace( space:cpSpace )
@@ -97,13 +97,13 @@ Function cpSpaceAddCollisionHandler:cpCollisionHandler( space:cpSpace, a:cpColli
 Function cpSpaceAddWildcardHandler:cpCollisionHandler( space:cpSpace, type:cpCollisionType )="bb_cpSpaceAddWildcardHandler"
 Function cpSpaceAddShape:cpShape( space:cpSpace, shape:cpShape )
 Function cpSpaceAddBody:cpBody( space:cpSpace, body:cpBody )
-Function cpSpaceAddConstraint:cpConstraint Ptr( space:cpSpace, constraint:cpConstraint Ptr )
+Function cpSpaceAddConstraint:cpConstraint( space:cpSpace, constraint:cpConstraint )
 Function cpSpaceRemoveShape:Void( space:cpSpace, shape:cpShape )
 Function cpSpaceRemoveBody:Void( space:cpSpace, body:cpBody )
-Function cpSpaceRemoveConstraint:Void( space:cpSpace, constraint:cpConstraint Ptr )
+Function cpSpaceRemoveConstraint:Void( space:cpSpace, constraint:cpConstraint )
 Function cpSpaceContainsShape:cpBool( space:cpSpace, shape:cpShape )
 Function cpSpaceContainsBody:cpBool( space:cpSpace, body:cpBody )
-Function cpSpaceContainsConstraint:cpBool( space:cpSpace, constraint:cpConstraint Ptr )
+Function cpSpaceContainsConstraint:cpBool( space:cpSpace, constraint:cpConstraint )
 Function cpSpaceAddPostStepCallback:cpBool( space:cpSpace, func:cpPostStepFunc, key:Void Ptr, data:Void Ptr )
 Function cpSpacePointQuery:Void( space:cpSpace, point:cpVect, maxDistance:cpFloat, filter:cpShapeFilter, func:cpSpacePointQueryFunc, data:Void Ptr )
 Function cpSpacePointQueryNearest:cpShape( space:cpSpace, point:cpVect, maxDistance:cpFloat, filter:cpShapeFilter, out:cpPointQueryInfo Ptr )
@@ -162,10 +162,14 @@ Class cpSpace Extends Void
 	
 	Method AddBody:cpBody( body:cpBody ) Extension="cpSpaceAddBody"
 
+	Method AddConstraint:cpConstraint( constraint:cpConstraint ) Extension="cpSpaceAddConstraint"
+	
 	Method RemoveShape( shape:cpShape ) Extension="cpSpaceRemoveShape"
 	
 	Method RemoveBody( body:cpBody ) Extension="cpSpaceRemoveBody"
 
+	Method RemoveConstraint( constraint:cpConstraint ) Extension="cpSpaceRemoveConstraint"
+
 	Method AddDefaultCollisionHandler:cpCollisionHandler() Extension="bb_cpSpaceAddDefaultCollisionHandler"
 	
 	Method DebugDraw( options:cpSpaceDebugDrawOptions ) Extension="bb_cpSpaceDebugDraw"