Transformation Matrix

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
SCARD
Prole
Posts: 45
Joined: Tue Sep 04, 2012 12:44 pm

Transformation Matrix

Post by SCARD »

Hi there!

Is there a way to save the current transformation matrix calculated by scaling-, translating- and rotating-function in a lua-table?
I have to send this matrix to a shader.
Knaimhe
Prole
Posts: 34
Joined: Mon Jan 23, 2012 7:23 pm

Re: Transformation Matrix

Post by Knaimhe »

Admittedly, I've never worked with transformation matrices, but I've done some normal transformation/rotation/scaling.
Can you not create an empty matrix and copy the data into that?
http://www.lua.org/pil/11.2.html
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: Transformation Matrix

Post by micha »

As far as I know you cannot directly access the transformation matrix, love uses. Maybe you can overwrite the transformation function from love.graphics (.translate .scale .rotate) so that they also output a transformation matrix.

In case you are not familiar with it. Each transformation has the form

Code: Select all

x_new = A*x_old + t
where x_old and x_new are column vectors containing coordinates, A is the 2x2-transformation matrix and t is the translation (also a column vector).

Rotation is t = (0;0) and A = [cos(alpha), -sin(alpha); sin(alpha), cos(alpha)]
Scaling is t = (0;0) and A = [s, 0; 0, s]
Translation is t = (t1;t2) and A = [1, 0; 0, 1]
("," means next element in same row and ";" means next row)

If you use multiple transformations after each other, you have to insert the first x_new into the second equation as x_old. You then find the transformation matrix and the translation vector by calculating a matrix-matrix product and a matrix-vector product respectively.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot], Google [Bot] and 4 guests