Page 1 of 1
Example dragging object and explosions for XCode
Posted: Tue May 31, 2011 9:14 am
by jpablo2003
I want to do an example abaut draggin objects and explosions, but I don't know how to do it.
I put you an example I want to do it.
http://www.emanueleferonato.com/2008/11 ... x2d-flash/
Under the source code there is an example of dragging a boxes.
Can anyone say to me how to do it?
Thank you.
Re: Example dragging object and explosions for XCode
Posted: Tue May 31, 2011 10:52 am
by slembcke
Yes. The Chipmunk demo application implements mouse dragging in a very similar fashion. It's even a bit simpler in Chipmunk because it has a point query feature.
Code: Select all
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->biasCoef = 0.15f;
cpSpaceAddConstraint(space, mouseJoint);
}
} else if(mouseJoint){
cpSpaceRemoveConstraint(space, mouseJoint);
cpConstraintFree(mouseJoint);
mouseJoint = NULL;
}
}
}
I smooth out the mouse position and update it like this once every frame.
Code: Select all
cpVect newPoint = cpvlerp(mousePoint_last, mousePoint, 0.25f);
mouseBody->p = newPoint;
mouseBody->v = cpvmult(cpvsub(newPoint, mousePoint_last), 60.0f);
mousePoint_last = newPoint;
You can see all of the code here:
http://code.google.com/p/chipmunk-physi ... munkDemo.c
Re: Example dragging object and explosions for XCode
Posted: Tue May 31, 2011 10:57 am
by jpablo2003
Thank you, bay I want it the example for XCode.
Re: Example dragging object and explosions for XCode
Posted: Tue May 31, 2011 10:59 am
by jpablo2003
would you can put to me two examples very simple, please.
Re: Example dragging object and explosions for XCode
Posted: Tue May 31, 2011 11:05 am
by slembcke
That file, ChipmunkDemo.c, is included with Chipmunk and there is an XCode project.
Re: Example dragging object and explosions for XCode
Posted: Tue May 31, 2011 11:20 am
by jpablo2003
Thank you but where find it?
I'm a bit lost.
Re: Example dragging object and explosions for XCode
Posted: Wed Jun 01, 2011 1:45 am
by jpablo2003
Good morning, can anydody help me, please?
Thank you
Re: Example dragging object and explosions for XCode
Posted: Wed Jun 01, 2011 8:37 am
by jpablo2003
I see that nobody wants to help me, please, I need know how do it for XCode.
Greetings
Re: Example dragging object and explosions for XCode
Posted: Wed Jun 01, 2011 9:35 am
by slembcke
If you download the latest Chipmunk from the Google Code page, the XCode project is in that.
http://code.google.com/p/chipmunk-physics/
Unless you downloaded Chipmunk from somewhere else, or it was packaged with something else, you already have the XCode project.
Re: Example dragging object and explosions for XCode
Posted: Wed Jun 01, 2011 10:16 am
by jpablo2003
I don't understand, how I do an example apart, only I need that.
Thank you