Page 1 of 1

Rotating individual shapes of a body?

Posted: Mon Aug 04, 2008 2:38 pm
by Das Gurke
At first I would like to thank anybody who contributed to chipmunk. It is a wonderful library and finally allowed me to get rid of my own (buggy) collision implementation. THANKS!

But I still have a couple of open questions ... Or better: a problem where I cant see any "chipmunk" way of solving it :( The scenario is as follows:

Firstoff: this is a topdown game;) Imagine some kind of Bots (similar to Tanks / Battlemechs, whatever you like) which consist of a basic shape. We refer to this as chassis in our game. Then there are all kinds of what we call modules, which can be attached to the chassis. These modules eg represent weapons, sensors, engines ... all kind of fancy stuff you could attach to a tank-like thing ;) The problem now is, that each of these modules need to be rotated separately. At least if we want to allow people to turn a turret or similar stuff ;) And these have been our thoughts so far:

1) Simply let every module track its shapes attached to tank and turn them around if needed. But this does not seem to be possible?
2) Assign an own body to every module and link these body's to the chassis via joints. But sadly there does not seem to be any joint, that is completely inflexible. We need to achieve a similar behavior, as if the body's were attached like shapes to a main body, but can be rotated.

I hope the problem is clear and I have simply overlooked something :( Any help is gladly appreciated!

Re: Rotating individual shapes of a body?

Posted: Fri Aug 08, 2008 1:34 am
by riq
Hi Das,
I think we are having the same problem after all :-)
I don't know what shapes are you using, but it might work if you rotate them manually. For example:

Code: Select all

   cpSegmentShape *shape = (cpSegmentShape*) theShapeThatNeedsToBeRotated;
   shape->a = cpv( x,y ) // multiply x & y with sin(a), cos(a)
   shape->b = cpv(xx,yy) // multiply xx & yy with sin(a), cos(a)

cheers,
riq.

Re: Rotating individual shapes of a body?

Posted: Fri Aug 08, 2008 6:42 am
by Das Gurke
I am using polygons. So you would alter all Verts of that polygon? Hmm, are you sure that this will work? It seems to be quite a hacky solution :( Nevertheless, if I can't find another solution, it seems to be something I have to consider.

But what just puzzled me was, that PolyShapes might have something to rotate them. I just found the cpPolyShapeAxis structure. Might this help me to rotate a poly shape? After all, there must be a way to rotate them, since they do rotate fine if the body rotates. There simply seems to be no documentation about it.

Re: Rotating individual shapes of a body?

Posted: Fri Aug 08, 2008 9:51 pm
by riq
Hi,
I know that manipulating cpSegments manually works. I've not tried rotating a polygon... I can't help you with this.
In case you find out how to rotate them, could you post it here ?

thanks,
riq.

Re: Rotating individual shapes of a body?

Posted: Sat Aug 09, 2008 1:24 am
by Das Gurke
Sure ;) I am currently waiting for my "physics expert" to make his move, when he is available again, we will take a look at our possibilities.

Re: Rotating individual shapes of a body?

Posted: Wed Aug 13, 2008 9:59 am
by Yohumbus
For the multiple body idea, you can effectively make inflexible joints by using two joints at different locations on the bodies