Hello. Please, I need help.
I create a box (a shape) with cpBoxShapeNew. Ok, fine. The problem is when I draw it with SFML. The graphic is displaced right-bottom from the body. Very odd. With circles, poly and segments all ok. Any advice? Thanks.
Drawing boxes correctly and no displaced.
-
- Posts: 5
- Joined: Wed Sep 29, 2010 7:12 am
- Contact:
- slembcke
- Site Admin
- Posts: 4166
- Joined: Tue Aug 14, 2007 7:13 pm
- Contact:
Re: Drawing boxes correctly and no displaced.
How are you drawing them? Need a bit more to go on then that.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
-
- Posts: 5
- Joined: Wed Sep 29, 2010 7:12 am
- Contact:
Re: Drawing boxes correctly and no displaced.
In each step in a custom UpdatePosition from body position is setted the image position. Inside the custom UpdatePosition is called before the next code the chipmunk UpdatePosition.
Code: Select all
//...
pos = cpBodyGetPos(body);
sfShape_SetPosition(shape, pos.x, pos.y);
- pat
- Posts: 53
- Joined: Tue Jul 20, 2010 7:55 pm
- Contact:
Re: Drawing boxes correctly and no displaced.
not sure if this is it, But cpBoxShapeNew will make the box centered. So if its like the bottom right of the image is drawing at the origin (so cpBoxShapeNew(20,20) would be -10 to +10 in each direction), then when your calling sfShape_SetPosition or whatever, you'd need to do pos.x - givenWidth/2, pos.y - givenHeight/2 . Or maybe i'm not understanding the issue.
-
- Posts: 5
- Joined: Wed Sep 29, 2010 7:12 am
- Contact:
Re: Drawing boxes correctly and no displaced.
You are right Pat. Aparently your solution works until the body start to rotate... When the body rotate the image starts to displace. Anyway thanks.
I've attached two images for see better the issue. bd2.png is the object rotated 180 º. bd1 a few degrees.
I've attached two images for see better the issue. bd2.png is the object rotated 180 º. bd1 a few degrees.
-
- Posts: 81
- Joined: Fri Aug 27, 2010 1:00 am
- Contact:
Re: Drawing boxes correctly and no displaced.
if your having issues with the other shapes you can look at the drawObject method in the examples
if your using opengl or any matix based display you can use this coed snipet
http://code.google.com/p/chipmunk-physi ... ulSnippets
if your using opengl or any matix based display you can use this coed snipet
http://code.google.com/p/chipmunk-physi ... ulSnippets
- pat
- Posts: 53
- Joined: Tue Jul 20, 2010 7:55 pm
- Contact:
Re: Drawing boxes correctly and no displaced.
so you could then do.teri wrote:You are right Pat. Aparently your solution works until the body start to rotate... When the body rotate the image starts to displace. Anyway thanks.
I've attached two images for see better the issue. bd2.png is the object rotated 180 º. bd1 a few degrees.
Code: Select all
cpVect vOffset = cpvsub(body->pos, cpvrotate(cpvmult(cpv(givenWidth, givenHeight), 0.5f), body->rot));
sfShape_SetPosition(shape, vOffset.x, vOffset.y);
-
- Posts: 5
- Joined: Wed Sep 29, 2010 7:12 am
- Contact:
Re: Drawing boxes correctly and no displaced.
Solved. Reading this thread: http://www.sfml-dev.org/forum/viewtopic ... er+utility i found the solution. I've deleted all the code that fixes the shape position for a box. Then i've wrote just this line in the box constructor:
Im finally happy . Thanks to everyone. Maybe I should have put this thread in SFML forums.
Code: Select all
sfShape_SetCenter(shape, width/2, height/2);
Who is online
Users browsing this forum: No registered users and 6 guests