Example dragging object and explosions for XCode

Official forum for the Chipmunk2D Physics Library.
Post Reply
jpablo2003
Posts: 7
Joined: Tue May 31, 2011 9:13 am
Contact:

Example dragging object and explosions for XCode

Post 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.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Example dragging object and explosions for XCode

Post 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
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
jpablo2003
Posts: 7
Joined: Tue May 31, 2011 9:13 am
Contact:

Re: Example dragging object and explosions for XCode

Post by jpablo2003 »

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

Re: Example dragging object and explosions for XCode

Post by jpablo2003 »

would you can put to me two examples very simple, please.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Example dragging object and explosions for XCode

Post by slembcke »

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

Re: Example dragging object and explosions for XCode

Post by jpablo2003 »

Thank you but where find it?

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

Re: Example dragging object and explosions for XCode

Post by jpablo2003 »

Good morning, can anydody help me, please?

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

Re: Example dragging object and explosions for XCode

Post by jpablo2003 »

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

Greetings
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Example dragging object and explosions for XCode

Post 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.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
jpablo2003
Posts: 7
Joined: Tue May 31, 2011 9:13 am
Contact:

Re: Example dragging object and explosions for XCode

Post by jpablo2003 »

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

Thank you
Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests