Need help w/ World vs Local coordinates

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
1stAnd10
Prole
Posts: 22
Joined: Tue Nov 25, 2008 2:09 pm

Need help w/ World vs Local coordinates

Post 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?
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Need help w/ World vs Local coordinates

Post 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.
1stAnd10
Prole
Posts: 22
Joined: Tue Nov 25, 2008 2:09 pm

Re: Need help w/ World vs Local coordinates

Post 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?
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Need help w/ World vs Local coordinates

Post 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
Post Reply

Who is online

Users browsing this forum: No registered users and 195 guests