Difference between revisions of "Shear"
(Created page with "This function was borrowed from way's [https://love2d.org/forums/viewtopic.php?f=5&t=1692&p=16988 3D dice roller demo]. It performs a [https://en.wikipedia.org/wiki/...") |
m (Added missing property for the category page.) |
||
(2 intermediate revisions by one other user not shown) | |||
Line 20: | Line 20: | ||
end | end | ||
</source> | </source> | ||
+ | |||
+ | {{New feature|0.8.0| | ||
+ | This code has become obsolete as of version 0.8.0. | ||
+ | |||
+ | You can use [[love.graphics.shear]] to shear/skew the whole scene or the shear parameters in [[love.graphics.draw]] to shear/skew a single drawable. | ||
+ | |080}} | ||
[[Category:Snippets]] | [[Category:Snippets]] | ||
{{#set:Author=User:way}} | {{#set:Author=User:way}} | ||
{{#set:Author=User:Taehl}} | {{#set:Author=User:Taehl}} | ||
+ | {{#set:LOVE Version=<0.8.0}} | ||
{{#set:Description=Shear/skew graphics!}} | {{#set:Description=Shear/skew graphics!}} | ||
== Other Languages == | == Other Languages == | ||
{{i18n|Shear}} | {{i18n|Shear}} |
Latest revision as of 18:15, 11 November 2016
This function was borrowed from way's 3D dice roller demo. It performs a graphics shear (AKA "skew") coordinate transformation (which affects all following draws). It's recommended to perform a love.graphics.push before shearing.
function shear(ox, oy, xx, xy, yx, yy)
local atan2, acos, tan = math.atan2, math.acos, math.tan
local ex, ey, fx,fy = xx-ox, xy-oy, yx-ox, yy-oy
if ex*fy<ey*fx then ex,ey,fx,fy=fx,fy,ex,ey end
local e,f = (ex*ex+ey*ey)^.5, (fx*fx+fy*fy)^.5
ex,ey = ex/e, ey/e
fx,fy = fx/f, fy/f
local desiredOrientation=atan2(ey+fy,ex+fx)
local desiredAngle=acos(ex*fx+ey*fy)/2
local z=tan(desiredAngle)
local distortion=((1+z*z)/2)^.5
love.graphics.translate(ox, oy)
love.graphics.rotate(desiredOrientation)
love.graphics.scale(1, z)
love.graphics.rotate(-pi/4)
love.graphics.scale(e/distortion,f/distortion)
end
Available since LÖVE 0.8.0
This code has become obsolete as of version 0.8.0.
You can use love.graphics.shear to shear/skew the whole scene or the shear parameters in love.graphics.draw to shear/skew a single drawable.
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