Example dragging object and explosions for XCode

Official forum for the Chipmunk2D Physics Library.

Example dragging object and explosions for XCode

Postby jpablo2003 » Tue May 31, 2011 9:14 am

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.
jpablo2003
 
Posts: 7
Joined: Tue May 31, 2011 9:13 am

Re: Example dragging object and explosions for XCode

Postby slembcke » Tue May 31, 2011 10:52 am

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
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: Example dragging object and explosions for XCode

Postby jpablo2003 » Tue May 31, 2011 10:57 am

Thank you, bay I want it the example for XCode.
jpablo2003
 
Posts: 7
Joined: Tue May 31, 2011 9:13 am

Re: Example dragging object and explosions for XCode

Postby jpablo2003 » Tue May 31, 2011 10:59 am

would you can put to me two examples very simple, please.
jpablo2003
 
Posts: 7
Joined: Tue May 31, 2011 9:13 am

Re: Example dragging object and explosions for XCode

Postby slembcke » Tue May 31, 2011 11:05 am

That file, ChipmunkDemo.c, is included with Chipmunk and there is an XCode project.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: Example dragging object and explosions for XCode

Postby jpablo2003 » Tue May 31, 2011 11:20 am

Thank you but where find it?

I'm a bit lost.
jpablo2003
 
Posts: 7
Joined: Tue May 31, 2011 9:13 am

Re: Example dragging object and explosions for XCode

Postby jpablo2003 » Wed Jun 01, 2011 1:45 am

Good morning, can anydody help me, please?

Thank you
jpablo2003
 
Posts: 7
Joined: Tue May 31, 2011 9:13 am

Re: Example dragging object and explosions for XCode

Postby jpablo2003 » Wed Jun 01, 2011 8:37 am

I see that nobody wants to help me, please, I need know how do it for XCode.

Greetings
jpablo2003
 
Posts: 7
Joined: Tue May 31, 2011 9:13 am

Re: Example dragging object and explosions for XCode

Postby slembcke » Wed Jun 01, 2011 9:35 am

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.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
User avatar
slembcke
Site Admin
 
Posts: 4164
Joined: Tue Aug 14, 2007 7:13 pm

Re: Example dragging object and explosions for XCode

Postby jpablo2003 » Wed Jun 01, 2011 10:16 am

I don't understand, how I do an example apart, only I need that.

Thank you
jpablo2003
 
Posts: 7
Joined: Tue May 31, 2011 9:13 am


Return to Chipmunk2D Physics

Who is online

Users browsing this forum: No registered users and 2 guests