Ragdolls in chipmunk.

Official forum for the Chipmunk2D Physics Library.
scorp
Posts: 29
Joined: Sat May 10, 2008 1:41 pm
Contact:

Ragdolls in chipmunk.

Post by scorp »

Trying to make a ragdoll. Knees should not bend forward, right? :mrgreen:

Of course, it is achievable with collision shapes... but that sucks.
Help! Urgently need better ideas!
Last edited by scorp on Mon May 19, 2008 9:02 am, edited 2 times in total.
scorp
Posts: 29
Joined: Sat May 10, 2008 1:41 pm
Contact:

Re: Joints with angle limitations. Possible? (making a ragdoll)

Post by scorp »

It seems that I'm not the first one who asked this question. Oops. :roll:
http://www.slembcke.net/forums/viewtopic.php?f=1&t=44
scorp
Posts: 29
Joined: Sat May 10, 2008 1:41 pm
Contact:

Re: Need ragdoll-making tips. Got any?

Post by scorp »

But i have another question:

I want the ragdoll to hold its pose. This was my plan:
rd.GIF
Red dot is the pivot, blue thing - cpDampedSpring with rest length a bit longer than the distance between anchors.

Plan did work, but not too well... lot's of glitches.
Any suggestions for plan B? :mrgreen:
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Need ragdoll-making tips. Got any?

Post by slembcke »

What was the issue? That should work alright.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
scorp
Posts: 29
Joined: Sat May 10, 2008 1:41 pm
Contact:

Re: Need ragdoll-making tips. Got any?

Post by scorp »

Doing more testing right now. Maybe I was wrong about cpDampedSpring causing glitches. I'll share my results here.

As for angle limitations, I used additional shapes instead of slide joints... works very nice... why the hell did I think that additional shapes sucked (see my first message)… :lol:
scorp
Posts: 29
Joined: Sat May 10, 2008 1:41 pm
Contact:

Re: Ragdolls in chipmunk.

Post by scorp »

Haven't played around with spring yet. Looks like I won't be needing it anyway.

Let's discuss general ragdoll making issues here. Topic of the message has been accordingly changed.

--------------------------------------------------


I'm working on a ragdoll-based game for iPhone, that's why ragdoll has to be as cpu-effective as possible.
My current ragdoll:
ragdoll.JPG

Red thingies limit the angles.

I really like how my ragdoll works, but keep wandering if additional shapes are more or less cpu-effective than using slide joints.

I'd be really grateful for all cpu-time-saving ideas.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: Ragdolls in chipmunk.

Post by slembcke »

Slide joints should be way cheaper than using more shapes. It's a simpler constraint, and doesn't require all of the hullabaloo that goes into collision detection.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
scorp
Posts: 29
Joined: Sat May 10, 2008 1:41 pm
Contact:

Re: Ragdolls in chipmunk.

Post by scorp »

And they are easier to use, as I have just discovered. :mrgreen:

Should have used them from the beginning instead of wasting time with shapes.
scorp
Posts: 29
Joined: Sat May 10, 2008 1:41 pm
Contact:

Re: Ragdolls in chipmunk.

Post by scorp »

New problem. :oops:

I need a way to address different body parts of N different ragdolls.
Like this:
player1.head->f.x=1000;
or
player2.shinR->t=-20000;

My plan was to create a RagDoll structure with cpBodies embedded in it.

typedef struct RagDoll
{
float BodyLength;
float BodyFat;
.... blah blah blah...
float Flexibility;

cpBody *head, *shinR, *thighR... etc etc;

}RagDoll;

Next step was writing a ragdoll-adding function.

void adddoll(RagDoll doll) //there is no space parameter yet, because currently I’m only using one space.
{

float BodyLength=doll.BodyLength;
float BodyFat=doll.BodyFat;

.... blah blah blah...

doll.head = cpBodyNew(0.2, cpMomentForCircle(0.2, 0, abs(SKX)*HeadSize, cpvzero));
doll.head->p = cpv(initX+SKX*(HeadSize/5), initY+SKY*(BodyLength/2+HeadSize));
cpSpaceAddBody(space,doll.head);

}


Ragdoll appears, but I can't address it's head. If I do, error appears "Unhandled exception at 0x004049cc in Chipmunk4MSVC2k3.exe: 0xC0000005: Access violation writing location 0x00000024."

Ok. Plan B.

cpBody *head; //additioanal cpBody
void adddoll(RagDoll doll)
{
.... blah blah blah...

head = cpBodyNew(0.2, cpMomentForCircle(0.2, 0, abs(SKX)*HeadSize, cpvzero));
head->p = cpv(initX+SKX*(HeadSize/5), initY+SKY*(BodyLength/2+HeadSize));
cpSpaceAddBody(space, head);
doll.head=head;
}

Same thing.

Plan C.

void adddoll(RagDoll doll)
{
.... blah blah blah...
cpBody *head; //additioanal cpBody, declared outside the function and structure

head = cpBodyNew(0.2, cpMomentForCircle(0.2, 0, abs(SKX)*HeadSize, cpvzero));
head->p = cpv(initX+SKX*(HeadSize/5), initY+SKY*(BodyLength/2+HeadSize));
cpSpaceAddBody(space, head);
}
player1.head=head;


It works! And it works with any number of players! But that's not very convinient.

adddoll(player1);
player1.head=head;
player1.shinR=shinR;
......................

adddoll(player2);
player2.head=head;
player2.shinR=shinR;
.....................

adddoll(player3);
player3.head=head;
player3.shinR=shinR;

etc etc etc

That sucks.


Why, why

adddoll(player1);
.................
doll.head=head; INSIDE the function

is not equivalent to

adddoll(player1);
.................
player1.head=head; OUTSIDE the function



I know it's not a chipmunk question. But I just don't get it (and can't find the answer in the net). Maybe someone here will help me.

Or maybe you can suggest a different method of addressing different parts of a ragdoll (presuming there are N automatically generated ragdolls)?

p.s.: Sorry for my not-so-good English.
chipmunkuser
Posts: 19
Joined: Fri May 09, 2008 4:48 pm
Contact:

Re: Ragdolls in chipmunk.

Post by chipmunkuser »

You have to make sure to allocate memory for any structure and pass in a pointer to it.
It's been awhile since I've done pure C structs (C++ and Obj-C now) so this may not be exactly right.

You could try:
void adddoll(struct RagDoll doll)

{


}
or alternately:
struct RagDoll doll, *dollPtr;
dollPtr = &doll;
dollPtr->head = 10;
void adddoll(dollPtr *doll)
{
doll->head = 10;
}

take a look at teh engine code to see how it's handled and check a C reference on passing a structure to functions.
Post Reply

Who is online

Users browsing this forum: No registered users and 18 guests