|
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?
|