Example dragging object and explosions for XCode
-
- Posts: 7
- Joined: Tue May 31, 2011 9:13 am
- Contact:
Example dragging object and explosions for XCode
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.
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.
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Example dragging object and explosions for XCode
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.
I smooth out the mouse position and update it like this once every frame.
You can see all of the code here: http://code.google.com/p/chipmunk-physi ... munkDemo.c
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;
}
}
}
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;
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 7
- Joined: Tue May 31, 2011 9:13 am
- Contact:
Re: Example dragging object and explosions for XCode
Thank you, bay I want it the example for XCode.
-
- Posts: 7
- Joined: Tue May 31, 2011 9:13 am
- Contact:
Re: Example dragging object and explosions for XCode
would you can put to me two examples very simple, please.
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Example dragging object and explosions for XCode
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/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 7
- Joined: Tue May 31, 2011 9:13 am
- Contact:
Re: Example dragging object and explosions for XCode
Thank you but where find it?
I'm a bit lost.
I'm a bit lost.
-
- Posts: 7
- Joined: Tue May 31, 2011 9:13 am
- Contact:
Re: Example dragging object and explosions for XCode
Good morning, can anydody help me, please?
Thank you
Thank you
-
- Posts: 7
- Joined: Tue May 31, 2011 9:13 am
- Contact:
Re: Example dragging object and explosions for XCode
I see that nobody wants to help me, please, I need know how do it for XCode.
Greetings
Greetings
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Example dragging object and explosions for XCode
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.
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/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 7
- Joined: Tue May 31, 2011 9:13 am
- Contact:
Re: Example dragging object and explosions for XCode
I don't understand, how I do an example apart, only I need that.
Thank you
Thank you
Who is online
Users browsing this forum: No registered users and 6 guests