[Solved] Shearing Factor?

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
Shadowraix
Prole
Posts: 4
Joined: Tue Jul 30, 2013 3:59 pm

[Solved] Shearing Factor?

Post by Shadowraix »

Alright, to start things off, I am completely new to Love2D, but I am decent with the actual Lua programming language. For the next few days i'll be a total narb at Love2D, so I apologize for asking such a simple question that I have yet to understand. I would just like an answer if you can provide one and i'll be on my way.
Back to the problem.

I was looking at the wiki and in the arguments of love.graphics.draw I saw something about the shearing factor on the X and Y axis. I have no clue what the shearing factor even is or what it is used for. I did a quick google search and had some slight trouble understanding what was being explained. A detailed explanation I would appreciate. An example of how it can be used would be appreciated as well.

Thanks in advance for anyone that can provide an answer! ^_^
Last edited by Shadowraix on Fri Aug 02, 2013 2:27 pm, edited 1 time in total.
User avatar
veethree
Inner party member
Posts: 877
Joined: Sat Dec 10, 2011 7:18 pm

Re: Shearing Factor?

Post by veethree »

" Shear is the translation along an axis (say, X axis) by an amount that increases linearly with another axis (Y). It produces shape distortions as if objects were composed of layers that are caused to slide over each other [].

Shear transformations are very useful in creating italic letters and slanted letters from regular letters. " - Best explanation i could find on google.
Source: http://cs.fit.edu/~wds/classes/cse5255/ ... shear.html
User avatar
Jasoco
Inner party member
Posts: 3726
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Shearing Factor?

Post by Jasoco »

Image

Shearing! (Using the love.graphics.shear() function.)
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: Shearing Factor?

Post by micha »

Don't be overwhelmed by the many arguments you can put into the drawing

Code: Select all

love.graphics.draw( drawable, x, y, r, sx, sy, ox, oy, kx, ky )
The parameters have default values, so if you don't know what shearing is or don't want to use it, you can just pass fewer arguments. So if you want to draw an unrotated, unscaled object it is enough to write

Code: Select all

love.graphics.draw( drawable, x, y)
User avatar
Shadowraix
Prole
Posts: 4
Joined: Tue Jul 30, 2013 3:59 pm

Re: Shearing Factor?

Post by Shadowraix »

Sorry for not replying quickly. Alright, I can see what shearing does thanks to the example. I'm assuming to get any results like in the example you would have to use something like a for loop so that you can smoothly transition it and such correct?

(To prevent from me having to make a new thread I would appreciate it if anyone can help me out on this. When using a while or repeat loop Love crashes. I tried using love.timer.sleep, but the program still stops responding. I was just experimenting with the keypressed function with repeat loops to see if I could get the same effect as putting key events inside love.update)
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: Shearing Factor?

Post by micha »

A for-loop (and while- and repeat- loops) would completely run within one frame. To get smooth transitions you have to change the parameters gradually over many frames. So a for-loop is not the right approach here.
Instead have a variable, that counts time:

Code: Select all

function love.update(dt)
timer = timer + dt
end
(Don't forget to initialize in the love.load() )
Then you can use the timer variable to do something with the shearing factor, for example:

Code: Select all

kx = math.sin(timer)
That would give you an oscillating result. Or

Code: Select all

kx = timer
For just an increase.

The key here is to have a variable that persists over many frames and is changed slightly in each frame.
User avatar
Shadowraix
Prole
Posts: 4
Joined: Tue Jul 30, 2013 3:59 pm

Re: Shearing Factor?

Post by Shadowraix »

micha wrote:A for-loop (and while- and repeat- loops) would completely run within one frame. To get smooth transitions you have to change the parameters gradually over many frames. So a for-loop is not the right approach here.
Instead have a variable, that counts time:

Code: Select all

function love.update(dt)
timer = timer + dt
end
(Don't forget to initialize in the love.load() )
Then you can use the timer variable to do something with the shearing factor, for example:

Code: Select all

kx = math.sin(timer)
That would give you an oscillating result. Or

Code: Select all

kx = timer
For just an increase.

The key here is to have a variable that persists over many frames and is changed slightly in each frame.
I see! Now I understand the use of shearing factor. I can use it to get some neat effects and such. Thanks for your help!
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 1 guest