Difference between revisions of "Tutorial:Graphic Transformations"
m |
m |
||
Line 56: | Line 56: | ||
[[Category:Tutorials]] | [[Category:Tutorials]] | ||
− | {{#set:LOVE Version=0. | + | {{#set:LOVE Version=0.8.0}} |
{{#set:Description=Covers the basic of using graphic transformations}} | {{#set:Description=Covers the basic of using graphic transformations}} | ||
== Other Languages == | == Other Languages == | ||
{{i18n|Tutorial:Graphic Transformations}} | {{i18n|Tutorial:Graphic Transformations}} |
Revision as of 14:47, 22 August 2013
This tutorial covers the basics of using graphic transformations.
Contents
love.graphics.push/love.graphics.pop
These two functions allow you to save and return to the previous transformation state. Every push must be paired up with a pop, and each pair can also be called within another push/pop.
Here's an example:
function love.draw()
love.graphics.push() -- store the previous transformation state
-- shift the coordinate system down 10, right 10
love.graphics.translate(10,10)
love.graphics.point(0,0)
love.graphics.pop() -- return to the previous transformation state
love.graphics.point(0,0) -- the origin is back @ (0,0)
end
Order of Transformations
Graphic transformations are not commutative. This means the call order affects the final result.
Here's an example:
function love.draw()
love.graphics.push()
love.graphics.translate(10,10)
love.graphics.scale(-1,-1)
love.graphics.point(10,10) -- the point is located @ global (0,0)
love.graphics.pop()
love.graphics.scale(-1,-1)
love.graphics.translate(10,10)
love.graphics.point(10,10) -- the point is located @ global (-20,-20)
end
There are two ways to visualize the above code.The first way is to think of each transformation as relative to the new coordinate system from previous transformations. For example, the scaling to the first point would be applied relative to the new origin at (10,10).
The second way (which is more intuitive in my humble opinion) is to visualize each transformation in REVERSE ORDER relative to the global coordinate system. Let's take the first point as an example. Scaling is applied first and places the new point @ (-10,-10). Lastly, the translation moves the new point to (0,0).
See Also
Other Languages
Dansk –
Deutsch –
English –
Español –
Français –
Indonesia –
Italiano –
Lietuviškai –
Magyar –
Nederlands –
Polski –
Português –
Română –
Slovenský –
Suomi –
Svenska –
Türkçe –
Česky –
Ελληνικά –
Български –
Русский –
Српски –
Українська –
עברית –
ไทย –
日本語 –
正體中文 –
简体中文 –
Tiếng Việt –
한국어
More info