# Box2D Forums

 It is currently Mon May 20, 2013 9:31 am

 All times are UTC - 8 hours [ DST ]

 Page 1 of 1 [ 1 post ]
 Print view Previous topic | Next topic
Author Message
 Post subject: World coordinates & camera, how to mix with box2d?Posted: Sun Apr 08, 2012 2:53 am

Joined: Sun Apr 08, 2012 2:24 am
Posts: 3
Hi!

So I've already got a working camera and world coordinates.
Now I'm trying to integrate box2d into this. I've successfully got it running within my app but I realized a problem.
My world coordinates look like this:
WorldX, WorldY, PixelsWithinWorldX, PixelsWithinWorldY
One world coordinate represents 256 actual pixels. WorldX and Y can be negative numbers aswell. PixelsWithinWorld can only be 0 -> 255. Once 256 is reached a world coordinate is increased and pixelswithinworld starts backat 0.
0,0,0,0 would be the center of the world.
1,0,0,0 would be 256 pixels to the right.

-2,1,64,3 would be -512 pixels to left + 64 = -448 pixels left and 256+3 pixels down.
so -2,1,64,3 translates to -448,259

Sure, I simply set these coordinates to box2d representations of the static/dynamic bodies within the world. But float is a rather small value and will quickly go out of bounds once you create a little larger world.

Next up is the camera problem. The default resolution is 800x600 but will probably change later.
I intend to save each world section as WorldX,WorldY.txt so "0,0.txt" will keep all objects in world coords 0,0.
And depending on the resolution it will only keep as much in the memory.

Now back to the problem with box2d. I move around the camera to 2000,2000,0,0.
That's: 512000 pixels right, and 512000 pixels down.
How do I represent these large world coordinates in the box2d space?

Obviously at that position I will not have the physical objects in memory for those at 0,0,0,0, only those around the camera location.
I could displace everything by the number of pixels moved X if I moved far enough to the right (or left).
ie:
if (movedX > 512) {
moveAllObjects 512 pixels left.
}

That way the box2d representations will never be out of bounds.
Say I have a character 24x32 pixels large at position 0,0,40,0. How should I represent this body in box2d?
I read somewhere 0.1f should be one pixel in box2d. Right now I have actual pixels, but I dunno if I can represent them like that.

What do you guys think? Any help would be appreciated?

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 1 post ]

 All times are UTC - 8 hours [ DST ]

#### Who is online

Users browsing this forum: No registered users and 1 guest

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

 Search for: