I'm trying to figure out how to skew a Sprite with Transform 2D, as it was suggested by @bojidar-bg here.
Problem is the Transform2D class docs are in are written in a language I don't speak, and the tutorial is also not much better:
Affine inverse
The affine inverse is a matrix that does the inverse operation of another matrix,
no matter if the matrix has scale or the axis vectors are not orthogonal.
The affine inverse is calculated with the affine_inverse() method:
var mi = m.affine_inverse()
pos = m.xform(pos)
pos = mi.xform(pos)
# pos is unchanged
If the matrix is orthonormal, then:
# if m is orthonormal, then
pos = mi.xform(pos)
# is the same is
pos = m.xform_inv(pos)
So I still don't know how to skew.
A skew example would be nice. Especially since the only alternative to skew anything apparently is to write Shader code which is not much easier either.
A matrix is used similarly to a turtle. The turtle most likely had a matrix inside (and you are likely learning this many years after discovering Santa is not real).
???
At a certain point, if you're going to be using matrix transformations, you're going to have to have some understanding of matrix math. None of this is Godot-specific, it's covered in any Linear Algebra course. See this Khan Academy article for example.
Let me point out, this is separate from your suggestion in the other thread of an in-editor way to do this. I think that's a good discussion, and should continue.
However, in the specific case of the Transform/Transform2D reference, they are about using transformation matrices, so they're going to be math-intensive. If you understand the math, those docs are fine for demonstrating how to use the transform methods.
Aside from the reference, I agree that the tutorial needs improvement. I cleaned up the vector math one a while ago, but haven't had a chance to tackle the transforms one.
Thank you for your reply and taking the time to clean up these docs!
I am aware this is Linear Algebra and someone with a math background will be able to follow this tutorial.
However all I want it to do is to skew a Sprite. Do you think it should be a requirement to have studied math or GLSL in order to skew a Sprite in Godot?
I think it's fine that this is not already built into the Godot editor (though of course I would prefer if it was), we cannot have everything at once,
But if the only way to do it is the hard way, I would at least hope this route is explained somewhere to the regular folk. Skewing is not something that obscure or rare after all. Even your parents did it, to make you. ;)
The matrices and transforms tutorial does need serious updating, see also #1353 and #2174
A matrix is used similarly to a turtle. The turtle most likely had a matrix inside (and you are likely learning this many years after discovering Santa is not real).
What in the world? It seems that this has existed since back when the docs repo began. In any case, that's got to go, and I think I'll rewrite this article this weekend.
But to provide some immediate help:
Skew the sprite to lean left: t.x = (1, 0) t.y = (1, 1) (for right, make t.y.x negative)
Skew the sprite to be vertically distorted: t.x = (1, 1) t.y = (0, 1) (likewise you can negate t.x.y)
Thank you!
and I think I'll rewrite this article this weekend.
That will be fantastic. Tag me when you submit the PR and I'll review.
Please feel free to use anything from here if it's helpful:
http://kidscancode.org/godot_recipes/math/transforms/
Most helpful comment
The matrices and transforms tutorial does need serious updating, see also #1353 and #2174
What in the world? It seems that this has existed since back when the docs repo began. In any case, that's got to go, and I think I'll rewrite this article this weekend.
But to provide some immediate help:
Skew the sprite to lean left: t.x = (1, 0) t.y = (1, 1) (for right, make t.y.x negative)
Skew the sprite to be vertically distorted: t.x = (1, 1) t.y = (0, 1) (likewise you can negate t.x.y)