[Solved]Scaling

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
Dr.Tyler O.
Citizen
Posts: 58
Joined: Tue Jul 29, 2014 9:17 am
Location: United States

[Solved]Scaling

Post by Dr.Tyler O. »

First of all, I apologize if there are already topics that answer this question. I have looked but I didn't see anything that I thought could help provide a solution to my problem. Anyway, the issue is that, when using love.graphics.scale(), I want to be able to scale the graphics without changing the position at which I view them. If you download the attached .love file you will understand what I mean. I only wish for the ball to appear as though it is getting bigger/smaller without changing the perspective at which it is seen. And, just a side note, I'm not looking for any sort of code edit that changes the scale of the actual image.
Attachments
Scaling.love
Left Mouse Button: Increment the scale by 0.1
Right Mouse Button: Decrement the scale by 0.1
(2.57 KiB) Downloaded 105 times
Last edited by Dr.Tyler O. on Fri Jul 31, 2015 7:30 am, edited 1 time in total.
Any topic I have ever posted that I felt did not require a .love file, although they were requested, never required one so I would appreciate if you did not ask me to supply one unless you think that I am ignorant for not doing so.
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: Scaling

Post by micha »

The scaling is always applied with respect to the origin, which is in the upper left corner. If you want to scale from the center, then you can perform these three transformations in a row:
1) Translate (Move the screen center to the top left)
2) Scale
3) Translate (Move the top left back to the center)

Mathematically, these three transformations can be reduced to two.
1) Scale
2) Translate (correct for the offset)

To get the specific number for this second step you have to rearrange some terms. Translation means something is added to the coordinates. Scaling means they are multiplied. So the operations of the 3-transformation-solution are:

Code: Select all

x_out = ((x_in - tx) * s ) + tx
y_out = ((y_in - ty) * s ) + ty
(s is the scaling factor and (tx,ty) is the translation vector pointing from the origin to the center)
After the rearrangement you get

Code: Select all

x_out = x_in * s + (1-s) * tx
y_out = y_in * s  + (1-s) * ty
This is a scaling by factor s and a translation by (1-s)*(tx,ty)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest