How to make a dumbbell ?

Official forum for the Chipmunk2D Physics Library.

How to make a dumbbell ?

Postby wissme » Fri Feb 04, 2011 9:56 am

Hi !
I am just starting to try Chipmunk (old version, around 2.5, please don't tell me to use another more recent version, I'm not in C and use a special FFI). I want to make a dumbbell, so I make two balls and I join them by a joint. But the joint acts as a spring. I would like it to be rigid. How can I do that ? Thanks a lot !
-w
wissme
 
Posts: 5
Joined: Fri Feb 04, 2011 9:27 am

Re: How to make a dumbbell ?

Postby slembcke » Fri Feb 04, 2011 10:38 am

Wow, that is old. It doesn't really matter though, what you want to do is still possible.

You can have multiple shapes attached to the same body with the C API. It's possible that the wrapper took this ability away. In the C API, you don't really add shapes to a body, you simple tell each shape which body it's attached to when you create it. This means that you can create multiple shapes that are attached to the same body.

In C you would do it something like this:
Code: Select all
cpBody *body = cpBodyNew(...);
cpShape *shape1 = cpCircleShapeNew(body, ...);
cpShape *shape2 = cpCircleShapeNew(body, ...);
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: How to make a dumbbell ?

Postby wissme » Fri Feb 04, 2011 11:10 am

You tell me to do 1 body and several shapes ?
But in my case, I have 3 bodies, right ? Two balls and a segment.
Should I add one shape around them ?

-w
wissme
 
Posts: 5
Joined: Fri Feb 04, 2011 9:27 am

Re: How to make a dumbbell ?

Postby slembcke » Fri Feb 04, 2011 11:21 am

What you want is to have 1 body and 3 shapes then. What you want is 1 single rigid object, you represent that creating one rigid body and giving it a shape by adding a few collision shapes for it.
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: How to make a dumbbell ?

Postby wissme » Fri Feb 04, 2011 11:44 am

Well, I still don't see. Maybe can I narrow the problem to having a ball with a rigid stick firmly attached.
What would I use to build the body ? cpMomentForCircle ? cpMomentForSegment ?....
Could you show me the C code ? It's probably a snip when you know the software, but my ideas are not that clear. That should give me a start...
Thanks !

-w
wissme
 
Posts: 5
Joined: Fri Feb 04, 2011 9:27 am

Re: How to make a dumbbell ?

Postby slembcke » Fri Feb 04, 2011 12:42 pm

The moment of inertia is additive like mass.

Here's a nice verbose example in C:
Code: Select all
// offset of the weights
cpFloat offset = 10.0f;

// centers of the weights
cpVect center1 = cpv( offset, 0.0f);
cpVect center2 = cpv(-offset, 0.0f);

cpFloat mass = 1.234;
cpFloat radius = 3.0f;
cpFloat moment = cpMomentForCircle(mass/2.0f, 0.0f, radius, center1) + cpMomentForCircle(mass/2.0f, 0.0f, radius, center2);

cpBody *body = cpBodyNew(mass, moment);
cpShape *shape1 = cpCircleShapeNew(body, radius, center1);
cpShape *shape2 = cpCircleShapeNew(body, radius, center2);
cpShape *shape3 = cpSegmentShapeNew(body, center1, center2);


The moment of inertia for both circles will actually be identical, as the offset distance is the same. In this case, you could simplify the moment to:
Code: Select all
cpFloat moment = cpMomentForCircle(mass, 0.0f, radius, center1);


I left out the moment of the segment. You don't really need it as it will make a pretty small difference. The bar isn't going to weigh much, and then you need to figure out how to split up the mass. Another thing to keep in mind is that these functions are really only helping you estimate the moment. As long as you are within a few factors of the correct number, people won't really notice and stability won't suffer.
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: How to make a dumbbell ?

Postby wissme » Sat Feb 05, 2011 3:31 am

Thanks a lot, I appreciate very much ! I will translate this in Scheme :

(define offset 10.0)
(define center1 (cpv offset 0.0)
etc.

By the way, Jay McCarthy has done an FFI interface with your C API to be used with Racket (http://racket-lang.org) which is the major dialect of the Scheme language. His port should be in :
http://planet.plt-scheme.org
but I don't see it today, maybe is he updating the (old 2.5) port to latest Chipmunk version ?... You will find something there :
http://planet.plt-scheme.org/display.ss ... hangerep=2
wissme
 
Posts: 5
Joined: Fri Feb 04, 2011 9:27 am

Re: How to make a dumbbell ?

Postby wissme » Sat Feb 05, 2011 4:36 am

I forgot : do you mean I will have no joint do define ?...
wissme
 
Posts: 5
Joined: Fri Feb 04, 2011 9:27 am

Re: How to make a dumbbell ?

Postby slembcke » Sat Feb 05, 2011 11:42 am

No joints. You just have one body, so there is nothing to join together.
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


Return to Chipmunk2D Physics

Who is online

Users browsing this forum: No registered users and 0 guests

cron