Box2D Forums

It is currently Fri May 24, 2013 8:32 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Wed May 02, 2012 12:35 pm 
Offline

Joined: Wed May 02, 2012 12:31 pm
Posts: 2
Hi everybody !

I'm learning how to use Box2D, and I wanted to try a simple physic render with a box falling to a line but it just doesn't work... The box keep falling through the line and I can't understand why...

Here is my code :

http://pastebin.com/Nb858uqv

If someone could give me a clue?

Thanks in advance


Top
 Profile  
 
PostPosted: Wed May 02, 2012 1:18 pm 
Offline

Joined: Tue Jun 24, 2008 8:25 pm
Posts: 1517
Location: Tokyo
The first thing I would suggest is to use Box2D's debug draw so that you can see exactly what it's doing.

Remember the SetAsBox function takes 'half-height' and 'half-width' values, and the body position will be the center of the box... it looks like you are drawing the box with the body position at the bottom left corner.


Top
 Profile  
 
PostPosted: Wed May 02, 2012 4:24 pm 
Offline

Joined: Wed May 02, 2012 12:31 pm
Posts: 2
I have cleaned a bit the code and make some changes but it still doesn't work, I really don't know where I'm wrong...

I convert Pixels to Meters when I set the position of my bodies, I convert Meters to Pixels when I set the position of my sfml object (draw) in the main loop...
And I take care put the good values as parameters for SetAsBox. But something is wrong...

First, when I set up my sfml object in converting meters to pixels, the box doesn't appear on the screen.
If i set up the position of the draw without converting, it draws, fall down and weirdly after some sec go a bit to the left... and the worst... it still fall down through the line...

I will look for Box2D's debug draw function, when I really don't know where is my mistake here :s

http://pastebin.com/XSx4p8X9


Top
 Profile  
 
PostPosted: Wed May 02, 2012 5:27 pm 
Offline

Joined: Sun Oct 25, 2009 3:28 am
Posts: 242
When you use SetAsEdge, the positions are relative to the body, not a world position. So the physics positions of the line shape in your code will be (100,1100) to (800,750) because the lineBody's position is (50,550) and the lineShape's ends' relative positions are (50,550) and (750,200). Subtracting the line ends' positions by the lineBody's position when you use SetAsEdge should fix it.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group