示例#1
0
Physics::Physics(uint32 timeStep) {
    // Create an empty space.
    mSpace = cpSpaceNew();
    cpSpaceSetGravity(mSpace, cpv(0, 0));
    cpSpaceSetDamping(mSpace, 0.5);
    mTimeStep = timeStep;
    mAccumulator = 0;
}
示例#2
0
文件: physics.c 项目: dns/CLove
static int l_physics_setSpaceDamping(lua_State* state)
{
    l_tools_checkUserDataPlusErrMsg(state, 1, "You must provide a space");
    l_physics_PhysicsData* physics = (l_physics_PhysicsData*)lua_touserdata(state, 1);

	float damping = l_tools_toNumberOrError(state, 2);

    cpSpaceSetDamping(physics->physics->space, damping);

	return 0;
}
示例#3
0
void Phys::init()
{
	// Create physics space;
	space = cpSpaceNew();

	cpSpaceSetDamping( space, 0.0 );

	cpSpaceAddCollisionHandler( space, utAll, utPlant,
			DynamiUint_begin, NULL, NULL, DynamiUint_separate, NULL );
	cpSpaceAddCollisionHandler( space, utAll, utEntity,
		DynamiUint_begin, NULL, NULL, DynamiUint_separate, NULL );
	cpSpaceAddCollisionHandler( space, utAll, utPlayer,
			DynamiUint_begin, NULL, NULL, DynamiUint_separate, NULL );
	cpSpaceAddCollisionHandler( space, utAll, utCorpse,
				DynamiUint_begin, NULL, NULL, DynamiUint_separate, NULL );
}
示例#4
0
static cpSpace *
init(void)
{
	ChipmunkDemoMessageString = "Control the crane by moving the mouse. Press the down arrow to release.";
	
	space = cpSpaceNew();
	cpSpaceSetIterations(space, 30);
	cpSpaceSetGravity(space, cpv(0, -100));
	cpSpaceSetDamping(space, 0.8);
	
	cpBody *staticBody = cpSpaceGetStaticBody(space);
	cpShape *shape;
	
	shape = cpSpaceAddShape(space, cpSegmentShapeNew(staticBody, cpv(-320,-240), cpv(320,-240), 0.0f));
	cpShapeSetElasticity(shape, 1.0f);
	cpShapeSetFriction(shape, 1.0f);
	cpShapeSetLayers(shape, NOT_GRABABLE_MASK);
	
	// Add a body for the dolly.
	dollyBody = cpSpaceAddBody(space, cpBodyNew(10, INFINITY));
	cpBodySetPos(dollyBody, cpv(0, 100));
	
	// Add a block so you can see it.
	cpSpaceAddShape(space, cpBoxShapeNew(dollyBody, 30, 30));
	
	// Add a groove joint for it to move back and forth on.
	cpSpaceAddConstraint(space, cpGrooveJointNew(staticBody, dollyBody, cpv(-250, 100), cpv(250, 100), cpvzero));
	
	// Add a pivot joint to act as a servo motor controlling it's position
	// By updating the anchor points of the pivot joint, you can move the dolly.
	dollyServo = cpSpaceAddConstraint(space, cpPivotJointNew(staticBody, dollyBody, cpBodyGetPos(dollyBody)));
	// Max force the dolly servo can generate.
	cpConstraintSetMaxForce(dollyServo, 10000);
	// Max speed of the dolly servo
	cpConstraintSetMaxBias(dollyServo, 100);
	// You can also change the error bias to control how it slows down.
	//cpConstraintSetErrorBias(dollyServo, 0.2);
	
	
	// Add the crane hook.
	cpBody *hookBody = cpSpaceAddBody(space, cpBodyNew(1, INFINITY));
	cpBodySetPos(hookBody, cpv(0, 50));
	
	// Add a sensor shape for it. This will be used to figure out when the hook touches a box.
	shape = cpSpaceAddShape(space, cpCircleShapeNew(hookBody, 10, cpvzero));
	cpShapeSetSensor(shape, cpTrue);
	cpShapeSetCollisionType(shape, HOOK_SENSOR);
	
	// Add a slide joint to act as a winch motor
	// By updating the max length of the joint you can make it pull up the load.
	winchServo = cpSpaceAddConstraint(space, cpSlideJointNew(dollyBody, hookBody, cpvzero, cpvzero, 0, INFINITY));
	// Max force the dolly servo can generate.
	cpConstraintSetMaxForce(winchServo, 30000);
	// Max speed of the dolly servo
	cpConstraintSetMaxBias(winchServo, 60);
	
	// TODO cleanup
	// Finally a box to play with
	cpBody *boxBody = cpSpaceAddBody(space, cpBodyNew(30, cpMomentForBox(30, 50, 50)));
	cpBodySetPos(boxBody, cpv(200, -200));
	
	// Add a block so you can see it.
	shape = cpSpaceAddShape(space, cpBoxShapeNew(boxBody, 50, 50));
	cpShapeSetFriction(shape, 0.7);
	cpShapeSetCollisionType(shape, CRATE);
	
	cpSpaceAddCollisionHandler(space, HOOK_SENSOR, CRATE, (cpCollisionBeginFunc)HookCrate, NULL, NULL, NULL, NULL);
	
	return space;
}
示例#5
0
__declspec( dllexport ) void setdamping( const void * _in, int in_size, void * _out, int out_sz )
{
	cpSpaceSetDamping(&mSpace,PEEKFLOAT(INPUT_MEMBLOCK,0));
}
示例#6
0
void Space::setDamping(cpFloat value)
{
		cpSpaceSetDamping(space,value);
}