Пример #1
0
/*
 * Chipmunk2d::Constraint#max_bias=(max_bias)
 * @param [Float] max_bias
 */
static mrb_value
constraint_set_max_bias(mrb_state *mrb, mrb_value self)
{
  cpConstraint *constraint;
  mrb_float max_bias;
  mrb_get_args(mrb, "f", &max_bias);

  constraint = mrb_data_get_ptr(mrb, self, &mrb_cp_constraint_type);

  cpConstraintSetMaxBias(constraint, (cpFloat)max_bias);

  return mrb_nil_value();
}
Пример #2
0
void physics_add_top_down_friction(cpBody *body, cpBody *control, float friction, cpConstraint **out_pivot, cpConstraint **out_gear) {
    //emulates linear friction
    cpConstraint *pivot = cpSpaceAddConstraint(game.space, cpPivotJointNew2(
        control,
        body,
        cpvzero,
        cpvzero
    ));
    cpConstraintSetErrorBias(pivot, cpBodyGetMass(body) * friction);
    cpConstraintSetMaxForce(pivot, cpBodyGetMass(body) * friction);

    //emulates angular friction
    cpConstraint *gear = cpSpaceAddConstraint(game.space, cpGearJointNew(
        control,
        body,
        0, 1
    ));
    cpConstraintSetMaxBias(gear, 0);
    cpConstraintSetMaxForce(gear, friction / cpBodyGetMass(body) / 10);

    if (out_pivot) *out_pivot = pivot;
    if (out_gear) *out_gear = gear;
}
Пример #3
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;
}
Пример #4
0
// float SG_CALL sgPhysicsConstraintGetErrorBias(SGPhysicsConstraint* constr);
void SG_CALL sgPhysicsConstraintSetMaxBias(SGPhysicsConstraint* constr, float max)
{
    cpConstraintSetMaxBias(constr->handle, max);
}
Пример #5
0
void CCJoint::setMaxBias(cpFloat maxBias)
{
	cpConstraintSetMaxBias(this->m_constraint, maxBias);
}