Difference between revisions of "Talk:love.graphics.translate"

(Created page with 'Camera shake ahoy!')
 
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
Camera shake ahoy!
 
Camera shake ahoy!
 +
 +
--[[User:Meevere|Meevere]] ([[User talk:Meevere|talk]]) 20:47, 5 March 2023 (CET)
 +
Does this article provide misleading information, or am I stupid..
 +
 +
This article says that if I make `translate(dx,dy)` then when I call draw(x,y), I would effectively get draw(x+dx,y+dy)
 +
Then, if I would like to scale something around a point, I would use this piece of code:
 +
<source lang="lua">
 +
function scale_around(origin, scale)
 +
love.graphics.push()
 +
love.graphics.translate(-origin[1],-origin[2]) -- Because if I would call something at the origin I would like to stay it still
 +
love.graphics.scale(scale)
 +
love.graphics.translate(origin[1], origin[2])
 +
end
 +
</source>
 +
But it only works if I swap the signs for origin. Is that a bug or am I doing something wrong?
 +
 +
Sorry for late reply, but wiki talk pages aren’t checked as frequently as forums, so please post questions to forum.
 +
 +
Scale scales from 0, 0, so you have to translate your screen, so that your point is at 0, 0, that’s why you have to swap signs in your code. Also, when you are reversing transform, you may need to multiply it by inverse scale, because coordinate system dimensions are also scaled.
 +
--[[User:Andlac028|Andlac028]] ([[User talk:Andlac028|talk]]) 12:08, 10 March 2023 (UTC)
 +
 +
 +
Yeah, due to time of reply I actually solved it myself after a bit of tinkering :D
 +
I just thought that transformations are done in order that they are written, but it's actually not the case. It first applies the bottom translation, then it scales, and then goes the top translation. That's why I needed to swap signs. The order of transformations isn't even talked about in the transformations page.
 +
--[[User:Meevere|Meevere]] ([[User talk:Meevere|talk]]) 21:09, 11 March 2023 (CET)

Latest revision as of 20:10, 11 March 2023

Camera shake ahoy!

--Meevere (talk) 20:47, 5 March 2023 (CET) Does this article provide misleading information, or am I stupid..

This article says that if I make `translate(dx,dy)` then when I call draw(x,y), I would effectively get draw(x+dx,y+dy) Then, if I would like to scale something around a point, I would use this piece of code:

function scale_around(origin, scale)
	love.graphics.push()
	love.graphics.translate(-origin[1],-origin[2]) -- Because if I would call something at the origin I would like to stay it still
	love.graphics.scale(scale)
	love.graphics.translate(origin[1], origin[2])
end

But it only works if I swap the signs for origin. Is that a bug or am I doing something wrong?

Sorry for late reply, but wiki talk pages aren’t checked as frequently as forums, so please post questions to forum.

Scale scales from 0, 0, so you have to translate your screen, so that your point is at 0, 0, that’s why you have to swap signs in your code. Also, when you are reversing transform, you may need to multiply it by inverse scale, because coordinate system dimensions are also scaled. --Andlac028 (talk) 12:08, 10 March 2023 (UTC)


Yeah, due to time of reply I actually solved it myself after a bit of tinkering :D I just thought that transformations are done in order that they are written, but it's actually not the case. It first applies the bottom translation, then it scales, and then goes the top translation. That's why I needed to swap signs. The order of transformations isn't even talked about in the transformations page. --Meevere (talk) 21:09, 11 March 2023 (CET)