Page 1 of 2
Ragdolls in chipmunk.
Posted: Sat May 10, 2008 1:56 pm
by scorp
Trying to make a ragdoll. Knees should not bend forward, right?
Of course, it is achievable with collision shapes... but that sucks.
Help! Urgently need better ideas!
Re: Joints with angle limitations. Possible? (making a ragdoll)
Posted: Sat May 10, 2008 4:06 pm
by scorp
It seems that I'm not the first one who asked this question. Oops.
http://www.slembcke.net/forums/viewtopic.php?f=1&t=44
Re: Need ragdoll-making tips. Got any?
Posted: Sat May 10, 2008 4:19 pm
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?

Re: Need ragdoll-making tips. Got any?
Posted: Mon May 12, 2008 12:43 am
by slembcke
What was the issue? That should work alright.
Re: Need ragdoll-making tips. Got any?
Posted: Mon May 12, 2008 3:37 am
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)…

Re: Ragdolls in chipmunk.
Posted: Mon May 19, 2008 9:55 am
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.
Re: Ragdolls in chipmunk.
Posted: Mon May 19, 2008 5:37 pm
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.
Re: Ragdolls in chipmunk.
Posted: Mon May 19, 2008 6:12 pm
by scorp
And they are easier to use, as I have just discovered.
Should have used them from the beginning instead of wasting time with shapes.
Re: Ragdolls in chipmunk.
Posted: Sat May 24, 2008 9:33 am
by scorp
New problem.
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.
Re: Ragdolls in chipmunk.
Posted: Sat May 24, 2008 4:22 pm
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.