コード例 #1
0
 CDynamics2DStretchableObjectModel::~CDynamics2DStretchableObjectModel() {
    if(m_pcGrippable != NULL) delete m_pcGrippable;
    if(m_ptLinearFriction != NULL) {
       cpSpaceRemoveConstraint(GetDynamics2DEngine().GetPhysicsSpace(), m_ptLinearFriction);
       cpConstraintFree(m_ptLinearFriction);
    }
    if(m_ptAngularFriction != NULL) {
       cpSpaceRemoveConstraint(GetDynamics2DEngine().GetPhysicsSpace(), m_ptAngularFriction);
       cpConstraintFree(m_ptAngularFriction);
    }
 }
コード例 #2
0
 void CDynamics2DVelocityControl::Detach() {
    if(m_ptControlledBody != NULL) {
       /* Remove constraints */
       cpSpaceRemoveConstraint(m_cDyn2DEngine.GetPhysicsSpace(), m_ptLinearConstraint);
       cpSpaceRemoveConstraint(m_cDyn2DEngine.GetPhysicsSpace(), m_ptAngularConstraint);
       /* Free memory up */
       cpConstraintFree(m_ptLinearConstraint);
       cpConstraintFree(m_ptAngularConstraint);
       /* Erase pointer to controlled body */
       m_ptControlledBody = NULL;
    }
 }
コード例 #3
0
ファイル: cbchipmunk.c プロジェクト: Latexi95/cbChipmunk
void freeDll(void)
{
	
	int i;
	Variable *var;


	//Poistettaan kaikki muuttujat
	for (i = 1; i != mVariableHandler.mSize;i++)
	{
		var = mVariableHandler.mPtrArray[i];
		if (var != NULL)
		{
			switch(var->mType)
			{
			case VarTypeBody:
				cpBodyFree((cpBody*)var->mPtr);break;
			case VarTypeShape:
				cpShapeFree((cpShape*)var->mPtr);break;
			case VarTypeConstraint:
				cpConstraintFree((cpConstraint*)var->mPtr);break;
			case VarTypeDataArray:
				daFree((DataArray*)var->mPtr);break;
			}
		}
	}

	//Tuhotaan ne kaikki...
	vhDestroy(&mVariableHandler);
	cpSpaceDestroy(&mSpace);
	mState = Unloaded;
}
コード例 #4
0
ファイル: world.c プロジェクト: fjolnir/Dynamo
static void world_destroyJoint(WorldConstraint_t *aJoint)
{
    worldConstr_invalidate(aJoint);
    cpConstraintFree(aJoint->cpConstraint);
    obj_release(aJoint->a);
    obj_release(aJoint->b);
}
コード例 #5
0
PhysicsJointInfo::~PhysicsJointInfo()
{
    for (cpConstraint* joint : m_aJoints)
    {
        cpConstraintFree(joint);
    }
}
コード例 #6
0
CDynamics2DCylinderEntity::~CDynamics2DCylinderEntity() {
    if(m_ptBody != NULL) {
        cpSpaceRemoveConstraint(m_cEngine.GetPhysicsSpace(), m_ptLinearFriction);
        cpSpaceRemoveConstraint(m_cEngine.GetPhysicsSpace(), m_ptAngularFriction);
        cpConstraintFree(m_ptLinearFriction);
        cpConstraintFree(m_ptAngularFriction);
        cpSpaceRemoveBody(m_cEngine.GetPhysicsSpace(), m_ptBody);
        cpBodyFree(m_ptBody);
        cpSpaceRemoveShape(m_cEngine.GetPhysicsSpace(), m_ptShape);
    }
    else {
        cpSpaceRemoveStaticShape(m_cEngine.GetPhysicsSpace(), m_ptShape);
        cpSpaceRehashStatic(m_cEngine.GetPhysicsSpace());
    }
    cpShapeFree(m_ptShape);
}
コード例 #7
0
ファイル: constraint.c プロジェクト: SIEGE/siege
void SG_CALL sgPhysicsConstraintDestroy(SGPhysicsConstraint* constr)
{
    if(!constr) return;

    _sgPhysicsSpaceRemoveConstraint(constr->body1->space, constr);
    cpConstraintFree(constr->handle);
    free(constr);
}
コード例 #8
0
 void SDynamics2DEngineGripperData::ClearConstraints() {
    if(GripConstraint != NULL) {
       cpSpaceRemoveConstraint(Space, GripConstraint);
       cpConstraintFree(GripConstraint);
       GripConstraint = NULL;
       GripperEntity.ClearGrippedEntity();
    }
 }
コード例 #9
0
void GeometrySpringDynamic::clearJoints()
{
	if( 0 != m_ConstraintGear && true == cpSpaceContainsConstraint( m_Space, m_ConstraintGear ) )
	{
		cpSpaceRemoveConstraint( m_Space, m_ConstraintGear );
		cpConstraintFree( m_ConstraintGear );
		m_ConstraintGear = 0;
	}
}
コード例 #10
0
ファイル: Sticky.c プロジェクト: Adefy/AdefyiOS
static void
PostStepRemoveJoint(cpSpace *space, void *key, void *data)
{
//	printf("Removing joint for %p\n", data);
	
	cpConstraint *joint = (cpConstraint *)key;
	cpSpaceRemoveConstraint(space, joint);
	cpConstraintFree(joint);
}
コード例 #11
0
PhysicsJoint::~PhysicsJoint()
{
    // reset the shapes collision group
    setCollisionEnable(true);
    
    for (auto constraint : _cpConstraints)
    {
        cpConstraintFree(constraint);
    }
}
コード例 #12
0
PhysicsJoint::~PhysicsJoint()
{
    // reset the shapes collision group
    setCollisionEnable(true);

    for (cpConstraint* joint : _cpConstraints)
    {
        cpConstraintFree(joint);
    }
    _cpConstraints.clear();
}
コード例 #13
0
void PhysicsJointInfo::removeAll()
{
    for (cpConstraint* joint : m_aJoints)
    {
        auto mit = m_aMap.find(joint);
        if (mit != m_aMap.end()) m_aMap.erase(mit);
        cpConstraintFree(joint);
    }
    
    m_aJoints.clear();
}
コード例 #14
0
void
mrb_cp_constraint_free(mrb_state *mrb, void *ptr)
{
  cpConstraint *constraint = ptr;
  mrb_cp_constraint_user_data *user_data;

  if (constraint) {
    user_data = cpConstraintGetUserData(constraint);
    if (user_data) {
      mrb_cp_constraint_user_data_free(mrb, user_data);
    }
    cpConstraintFree(constraint);
  }
}
コード例 #15
0
void PhysicsJointInfo::remove(cpConstraint* joint)
{
    if (joint == nullptr) return;
    
    auto it = std::find(m_aJoints.begin(), m_aJoints.end(), joint);
    if (it != m_aJoints.end())
    {
        m_aJoints.erase(it);
        
        auto mit = m_aMap.find(joint);
        if (mit != m_aMap.end()) m_aMap.erase(mit);
        
        cpConstraintFree(joint);
    }
}
コード例 #16
0
static void
update(cpSpace *space, double dt)
{
	// Set the first anchor point (the one attached to the static body) of the dolly servo to the mouse's x position.
	cpPivotJointSetAnchorA(dollyServo, cpv(ChipmunkDemoMouse.x, 100));
	
	// Set the max length of the winch servo to match the mouse's height.
	cpSlideJointSetMax(winchServo, cpfmax(100 - ChipmunkDemoMouse.y, 50));
	
	if(hookJoint && ChipmunkDemoRightClick){
		cpSpaceRemoveConstraint(space, hookJoint);
		cpConstraintFree(hookJoint);
		hookJoint = NULL;
	}
	
	cpSpaceStep(space, dt);
}
コード例 #17
0
cpConstraint *cpSpaceSerializer::createConstraint(TiXmlElement *elm)
{
	cpConstraint *constraint = NULL;
	
	const char* type = elm->Attribute("type");
	
	if (stringEquals(type, "pin"))
		constraint = createPinJoint(elm);
	else if (stringEquals(type, "slide"))
		constraint = createSlideJoint(elm);
	else if (stringEquals(type, "pivot"))
		constraint = createPivotJoint(elm);
	else if (stringEquals(type, "groove"))
		constraint = createGrooveJoint(elm);
	else if (stringEquals(type, "motor"))
		constraint = createMotorJoint(elm);
	else if (stringEquals(type, "gear"))
		constraint = createGearJoint(elm);
	else if (stringEquals(type, "spring"))
		constraint = createSpringJoint(elm);
	else if (stringEquals(type, "rotaryLimit"))
		constraint = createRotaryLimitJoint(elm);
	else if (stringEquals(type, "ratchet"))
		constraint = createRatchetJoint(elm);
	else if (stringEquals(type, "rotarySpring"))
		constraint = createRotarySpringJoint(elm);
	else
		return NULL;
	
	CPSS_ID id = createValue<CPSS_ID>("id", elm);
	constraint->maxForce = createValue<cpFloat>("maxForce", elm);
	constraint->errorBias = createValue<cpFloat>("errorBias", elm);
	constraint->maxBias = createValue<cpFloat>("maxBias", elm);
	
	if (delegate)
	{
		if (!delegate->reading(constraint, id))
		{
			cpConstraintFree(constraint);
			constraint = NULL;
		}
	}
	
	return constraint;
}
コード例 #18
0
ファイル: Crane.c プロジェクト: galexcode/SuperAngryBall
static void
update(int ticks)
{
	int steps = 1;
	cpFloat dt = 1.0f/60.0f/(cpFloat)steps;
	
	for(int i=0; i<steps; i++){
		// Set the first anchor point (the one attached to the static body) of the dolly servo to the mouse's x position.
		cpPivotJointSetAnchr1(dollyServo, cpv(ChipmunkDemoMouse.x, 100));
		
		// Set the max length of the winch servo to match the mouse's height.
		cpSlideJointSetMax(winchServo, cpfmax(100 - ChipmunkDemoMouse.y, 50));
		
		if(hookJoint && ChipmunkDemoKeyboard.y < 0){
			cpSpaceRemoveConstraint(space, hookJoint);
			cpConstraintFree(hookJoint);
			hookJoint = NULL;
		}
		
		cpSpaceStep(space, dt);
	}
}
コード例 #19
0
static void
click(int button, int state, int x, int y)
{
	if(button == GLUT_LEFT_BUTTON){
		if(state == GLUT_DOWN){
			cpVect point = mouseToSpace(x, y);
		
			cpShape *shape = cpSpacePointQueryFirst(space, point, GRABABLE_MASK_BIT, CP_NO_GROUP);
			if(shape){
				cpBody *body = shape->body;
				mouseJoint = cpPivotJointNew2(mouseBody, body, cpvzero, cpBodyWorld2Local(body, point));
				mouseJoint->maxForce = 50000.0f;
				mouseJoint->errorBias = cpfpow(1.0f - 0.15f, 60.0f);
				cpSpaceAddConstraint(space, mouseJoint);
			}
		} else if(mouseJoint){
			cpSpaceRemoveConstraint(space, mouseJoint);
			cpConstraintFree(mouseJoint);
			mouseJoint = NULL;
		}
	}
}
コード例 #20
0
ファイル: chipmunk.c プロジェクト: rlofc/cage
/* Mouse handling is a bit tricky. We want the user to move
 * tiles using the mouse but because tiles are dynamic bodies
 * managed by Chipmunk2D, we cannot directly control them.
 * This is resolved by creating a pivot joint between an
 * invisible mouse body that we can control and the tile body
 * that we cannot directly control.
 */
static void apply_mouse_motion(struct state* state)
{
    struct mouse m;
    update_mouse(&m);
    int w, h;
    get_screen_size(&w, &h);
    int x = m.x_position * w;
    int y = m.y_position * h;
    cpVect mouse_pos = cpv(x, y);
    cpVect new_point =
        cpvlerp(cpBodyGetPosition(state->mouse_body), mouse_pos, 0.25f);
    cpBodySetVelocity(
        state->mouse_body,
        cpvmult(cpvsub(new_point, cpBodyGetPosition(state->mouse_body)),
                60.0f));
    cpBodySetPosition(state->mouse_body, new_point);
    if (m.left_click && state->mouse_joint == NULL) {
        cpFloat radius = 5.0;
        cpPointQueryInfo info = { 0 };
        cpShape* shape = cpSpacePointQueryNearest(state->space, mouse_pos,
                                                  radius, GRAB_FILTER, &info);
        if (shape && cpBodyGetMass(cpShapeGetBody(shape)) < INFINITY) {
            cpVect nearest = (info.distance > 0.0f ? info.point : mouse_pos);
            cpBody* body = cpShapeGetBody(shape);
            state->mouse_joint =
                cpPivotJointNew2(state->mouse_body, body, cpvzero,
                                 cpBodyWorldToLocal(body, nearest));
            cpConstraintSetMaxForce(state->mouse_joint, 5000000.0f);
            cpConstraintSetErrorBias(state->mouse_joint,
                                     cpfpow(1.0f - 0.15f, 60.0f));
            cpSpaceAddConstraint(state->space, state->mouse_joint);
        }
    }
    if (m.left_click == false && state->mouse_joint != NULL) {
        cpSpaceRemoveConstraint(state->space, state->mouse_joint);                                                 
        cpConstraintFree(state->mouse_joint);                                                               
        state->mouse_joint = NULL;  
    }
}
コード例 #21
0
CCJoint::~CCJoint()
{
	cpSpaceRemoveConstraint(this->world->getSpace(), this->m_constraint);
	cpConstraintFree(this->m_constraint);
}
コード例 #22
0
ファイル: Constraint.cpp プロジェクト: dichodaemon/flatland
Flatland::Constraint::~Constraint()
{
  cpConstraintFree( _constraint );
}
コード例 #23
0
ファイル: cpSpace.c プロジェクト: rickystone/TwilightGolf
static void   constraintFreeWrap(cpConstraint *ptr, void *unused){cpConstraintFree(ptr);}
コード例 #24
0
ファイル: ChipmunkDemo.c プロジェクト: 50Cubes/ClusterFear
static void constraintFreeWrap(cpSpace *space, cpConstraint *constraint, void *unused){
	cpSpaceRemoveConstraint(space, constraint);
	cpConstraintFree(constraint);
}
コード例 #25
0
ファイル: Constraint.cpp プロジェクト: eVillain/CppMunk
 Constraint::~Constraint()
 {
     if (_constraint != NULL)
         cpConstraintFree(_constraint);
 }
コード例 #26
0
ファイル: body.cpp プロジェクト: dumganhar/sugs_spiderMonkey
static void
removeConstraintFromBodyIterator(cpBody* body, cpConstraint* constraint, void* data)
{
  cpConstraintFree(constraint);
}
コード例 #27
0
ファイル: Chains.cpp プロジェクト: damucz/chipmunk2d
void Chains::BreakablejointPostStepRemove(cpSpace *space, cpConstraint *joint, void *unused)
{
	cpSpaceRemoveConstraint(space, joint);
	cpConstraintFree(joint);
}
コード例 #28
0
ファイル: cbchipmunk.c プロジェクト: Latexi95/cbChipmunk
__declspec( dllexport ) void deletevar( const void * _in, int in_size, void * _out, int out_sz )
{
	cpBody *body;
	int i;
	int index;
	Variable *var;
	Variable *mainVar = vhRemoveVariable(&mVariableHandler,PEEKINT(INPUT_MEMBLOCK,0));
	
	if (mainVar->mType == VarTypeBody)
	{
		body = (cpBody*)mainVar->mPtr;
		resetVariableList();
		cpBodyEachShape(body,listShape,0);
		index = 0;
		for (i = 0;i != mVariableListIterator;i++)
		{
			var = mVariableList[i];
			
			POKEINT(OUTPUT_MEMBLOCK,index,var->mCBPtr);index += 4;
			
			cpSpaceRemoveShape(&mSpace,(cpShape*)var->mPtr);
			cpShapeFree((cpShape*)var->mPtr);
			//MessageBoxA(NULL,"ShapeRemoved2","Error",MB_OK);

			vhRemoveVariable(&mVariableHandler,var->mLocalHandle);
			varFree(var);
		}

		resetVariableList();
		cpBodyEachConstraint(body,listConstraint,0);
		for (i = 0;i != mVariableListIterator;i++)
		{
			var = mVariableList[i];
			POKEINT(OUTPUT_MEMBLOCK,index,var->mCBPtr);index+=4;
			//MessageBoxA(NULL,"Constraint removed2","Error",MB_OK);
			cpSpaceRemoveConstraint(&mSpace,(cpConstraint*)var->mPtr);
			cpConstraintFree((cpConstraint*)var->mPtr);
			vhRemoveVariable(&mVariableHandler,var->mLocalHandle);
			varFree(var);
		}
		POKEINT(OUTPUT_MEMBLOCK,index,0);//End point
		//MessageBoxA(NULL,"BodyRemoved","Error",MB_OK);
		cpSpaceRemoveBody(&mSpace,body);
		cpBodyFree(body);
		varFree(mainVar);
	}
	else if (mainVar->mType == VarTypeShape)
	{
		cpSpaceRemoveShape(&mSpace,(cpShape*)mainVar->mPtr);
		cpShapeFree((cpShape*)mainVar->mPtr);
		//MessageBoxA(NULL,"ShapeRemoved","Error",MB_OK);
		varFree(mainVar);
		POKEINT(OUTPUT_MEMBLOCK,0,0);
	}
	else if (mainVar->mType == VarTypeConstraint)
	{
		cpSpaceRemoveConstraint(&mSpace,(cpConstraint*)mainVar->mPtr);
		cpConstraintFree((cpConstraint*)mainVar->mPtr);
		varFree(mainVar);

		POKEINT(OUTPUT_MEMBLOCK,0,0);
	}
	else if (mainVar->mType == VarTypeDataArray)
	{
		daFree((DataArray*)mainVar->mPtr);
		varFree(mainVar);
		POKEINT(OUTPUT_MEMBLOCK,0,0);
	}
	else
	{
		//Failure...
		MessageBoxA(NULL,"Unknown cpChipmunk error 11","Error",MB_OK);
		varFree(mainVar);
		POKEINT(OUTPUT_MEMBLOCK,0,0);
		
	}
	
}
コード例 #29
0
JNIEXPORT void JNICALL Java_com_wiyun_engine_chipmunk_Constraint_destroy
  (JNIEnv * env, jobject thiz) {
	cpConstraint* constraint = (cpConstraint*)env->GetIntField(thiz, g_fid_Constraint_mPointer);
	cpConstraintFree(constraint);
}