Page 1 of 1

Need help w/ World vs Local coordinates

Posted: Sat Dec 13, 2008 3:55 pm
by 1stAnd10
Could someone give me a quick tutorial on using world vs local coordinates?

Never done it before so just curious about where to even start. Once I can get going I can play with it and figure it out.

If I have a world that is set to X=2000, Y=2000. How does local coordinates relate to that?

If I set a body to 300,200 on the screen, is that world coordinates? Or local coordinates and then how do I relate that to world coordinates? It seems that a 3rd element needs to be there somewhere in what piece of the world is currently on screen, ie, a camera. Am I completely off base?

Re: Need help w/ World vs Local coordinates

Posted: Sat Dec 13, 2008 4:37 pm
by bartbes
I haven't used the physics library a lot, however I do now that in your example those are WORLD coordinates.
I always thought local coordinates are those in the objects itself, so the shape relative to the body.

Re: Need help w/ World vs Local coordinates

Posted: Sat Dec 13, 2008 4:38 pm
by 1stAnd10
So maybe I'm confusing local coordinates with screen coordinates which would make absolute sense. If that is the case, how do I translate world coordinates to screen coordinates?

Re: Need help w/ World vs Local coordinates

Posted: Sat Dec 13, 2008 5:31 pm
by bartbes
Well.. world coordinates - where the "viewport" begins.
If you have your 2000x2000 world and the screen is 800x600, you have to display only a certain part (or scale down), so if the topleft corner starts at coordinate (300, 450) you will get worldx - 300, worldy - 450.
Some pseudo-code: (xoffset and yoffset are the point in the world where the topleft corner of the screen is, and a is the object)

Code: Select all

a = bodyshapethingy
love.graphics.draw(a, a:getX() - xoffset, a:getY() - yoffset)
I hope you understand this, if you don't... I'll need to start learning to interact with people instead of computers :P