rotating a static body graphic.

Official forum for the Chipmunk2D Physics Library.
ijerry
Posts: 9
Joined: Tue Sep 28, 2010 8:08 am
Contact:

rotating a static body graphic.

Post by ijerry »

Hi

I have a graphic resource png wall 150 heigh x 3 width wich is vertically alligned in the graphic.

how can i plot this on the screen at 45 degrees

Should i create a new graphic resource which is rotated 45 degrees or can i rotate it within the code.

It is also being added as a static body in chipmunk.

if so how is it done ?
aisman
Posts: 145
Joined: Tue Mar 04, 2008 2:21 am
Contact:

Re: rotating a static body graphic.

Post by aisman »

Put the PNG into a sprite.
After this you can rotate the sprite.
Chipmunk4PB: The fastest way to write games together with PureBasic and the Chipmunk physics engine.
ijerry
Posts: 9
Joined: Tue Sep 28, 2010 8:08 am
Contact:

Re: rotating a static body graphic.

Post by ijerry »

Thats the question how does one rotate the graphic.

It is rectangular, it is a static wall usually, but in this case i want to initialize its position by rotating it and indirectly rotating the shape.

Below is the code after which i want to rotate graphic and cpbody/cpshape ?

Thank you.

cpBody *staticBody = cpBodyNew(INFINITY, INFINITY);
cpShape *shape;
CCSprite * wallsprite = [CCSprite spriteWithSpriteFrameName:@"verticalwallshort.png"];
[vsheet addChild:wallsprite];
wallsprite.position = ccp(x,y);
int num = 4;
CGPoint verts[] = {
ccp(-3,-28),
ccp(-3, 28),
ccp( 3, 28),
ccp( 3,-28),
};
staticBody->p = ccp(x, y);
cpShape* newShape = cpPolyShapeNew(staticBody, 4, verts, cpv(0.0f, 0.0f));
newShape->e = 0.5; newShape->u = 0.5; newShape->collision_type = 2;

cpSpaceAddStaticShape(space,newShape);
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: rotating a static body graphic.

Post by slembcke »

Your Cocos2D and Chipmunk code doesn't reference the other in any way. What prevents you from setting wallSprite.rotation = 45?
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
ijerry
Posts: 9
Joined: Tue Sep 28, 2010 8:08 am
Contact:

Re: rotating a static body graphic.

Post by ijerry »

Apologies over confusion. Thank you for response. I will have a go now.
ijerry
Posts: 9
Joined: Tue Sep 28, 2010 8:08 am
Contact:

Re: rotating a static body graphic.

Post by ijerry »

The graphic rotates but the shape / body does not rotate

Is there any thing i am missing
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: rotating a static body graphic.

Post by slembcke »

You are already attaching the poly shape to it's own body, so just rotate that too. staticBody.a = CC_DEGREES_TO_RADIANS(45).
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
ijerry
Posts: 9
Joined: Tue Sep 28, 2010 8:08 am
Contact:

Re: rotating a static body graphic.

Post by ijerry »

There must be something else .... this is still not doing the job ?

cpBody *staticBody = cpBodyNew(INFINITY, INFINITY);
cpShape *shape;
CCSprite * wallsprite = [CCSprite spriteWithSpriteFrameName:@"verticalwallshort.png"];
[vsheet addChild:wallsprite];
wallsprite.position = ccp(x,y);

int num = 4;
CGPoint verts[] = {
ccp(-3,-28),
ccp(-3, 28),
ccp( 3, 28),
ccp( 3,-28),
};
staticBody->p = ccp(x, y);
cpShape* newShape = cpPolyShapeNew(staticBody, 4, verts, cpv(0.0f, 0.0f));
newShape->e = 0.5; newShape->u = 0.5; newShape->collision_type = 2;
wallsprite.rotation=45;
staticBody->a = CC_DEGREES_TO_RADIANS(45);
cpSpaceAddStaticShape(space,newShape);
ijerry
Posts: 9
Joined: Tue Sep 28, 2010 8:08 am
Contact:

Re: rotating a static body graphic.

Post by ijerry »

The image rotates but the physics body remains the same vertical ?
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: rotating a static body graphic.

Post by slembcke »

Depending on the version of Chipmunk you are using, you might have to rotate the body before attaching the static shape to it.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Post Reply

Who is online

Users browsing this forum: No registered users and 26 guests