Page 1 of 1

camera zoom. And button clicking

Posted: Wed Jul 25, 2012 6:17 pm
by baconhawka7x
I have my camera zoomed by 0.3. And I have a GUI system, where I want to test if the player is clicking on 'v.text'.

This is under love.mousepressed(x,y)
so if I have..

Code: Select all

if x > v.x and
x < v.x + medium:getWidth(v.text) and
y > v.y and
y < v.y + medium:getHeight() then
   click the button 
end
So, how would I change that so that it works with the camera zoom? (camera.scaleX,camera.scaleY).

Re: camera zoom. And button clicking

Posted: Wed Jul 25, 2012 7:40 pm
by juno
baconhawka7x wrote:I have my camera zoomed by 0.3. And I have a GUI system, where I want to test if the player is clicking on 'v.text'.

This is under love.mousepressed(x,y)
so if I have..

Code: Select all

if x > v.x and
x < v.x + medium:getWidth(v.text) and
y > v.y and
y < v.y + medium:getHeight() then
   click the button 
end
So, how would I change that so that it works with the camera zoom? (camera.scaleX,camera.scaleY).
This might work..
Multiply the text width and height by the camera scale.

Code: Select all

if x > v.x and
x < v.x + (medium:getWidth(v.text) * camera.scaleX) and
y > v.y and
y < v.y + (medium:getHeight()  * camera.scaleY) then
   click the button 
end

Re: camera zoom. And button clicking

Posted: Wed Jul 25, 2012 7:47 pm
by dreadkillz
You can take a look at my vrld's hump.camera or my camera mod for how to convert coordinates.

Re: camera zoom. And button clicking

Posted: Wed Jul 25, 2012 10:13 pm
by baconhawka7x
dreadkillz wrote:You can take a look at my vrld's hump.camera or my camera mod for how to convert coordinates.
Can I get a link?

Re: camera zoom. And button clicking

Posted: Wed Jul 25, 2012 10:20 pm
by josefnpat
baconhawka7x wrote:
dreadkillz wrote:You can take a look at my vrld's hump.camera or my camera mod for how to convert coordinates.
Can I get a link?
Yes

vrld's hump.camera:
https://www.google.com/search?sourceid= ... ump.camera

dreadkillz camera:
https://www.google.com/search?sourceid= ... llz+camera

Re: camera zoom. And button clicking

Posted: Wed Jul 25, 2012 10:24 pm
by baconhawka7x
uhh...All I'm seeing are more camera libraries.

Re: camera zoom. And button clicking

Posted: Thu Jul 26, 2012 12:17 am
by dreadkillz
You don't have to use them, just look at the code to get an idea of how it works. Here's a snippet that he has to convert coordinates between the "world" coordinates and "camera" coordinates:

Code: Select all

function camera:cameraCoords(x,y)
	local w,h = love.graphics.getWidth(), love.graphics.getHeight()
	x,y = vec.rotate(self.rot, x-self.x, y-self.y)
	return x*self.zoom + w/2, y*self.zoom + h/2
end

function camera:worldCoords(x,y)
	local w,h = love.graphics.getWidth(), love.graphics.getHeight()
	x,y = vec.rotate(-self.rot, vec.div(self.zoom, x-w/2, y-h/2))
	return x+self.x, y+self.y
So when you want your mouse to click a zoomed out or in box, you would want to convert the mouse coordinates into world coordinates, and then compare it to your box coordinates.

Re: camera zoom. And button clicking

Posted: Thu Jul 26, 2012 3:56 am
by baconhawka7x
thank you dreadkillz.