Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Transforming a sprite with a 3x3 matrix - where to start?  (Read 5252 times)

0 Members and 1 Guest are viewing this topic.

notnowlewis

  • Newbie
  • *
  • Posts: 9
    • View Profile
Transforming a sprite with a 3x3 matrix - where to start?
« on: July 08, 2013, 10:58:50 am »
I have no idea how the values in a 3x3 matrix work to transform a sprite. I have done a little reading on the math of matrix transformations, but I can seem to make the connection between the values in the matric and how the look of my sprite changes. Where can I find some good examples and tutorials on using them?

notnowlewis

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Transforming a sprite with a 3x3 matrix - where to start?
« Reply #1 on: July 08, 2013, 11:41:08 am »
So you know what I want to achieve, I want to take an image like this: http://i.imgur.com/qH8YCRS.png and apply a perspective effect, so it ends up like this: http://i.imgur.com/AUvpyKd.png

I know I can do that type of transformation in GIMP with a 3x3 matrix, but I want to understand *how* it works :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Transforming a sprite with a 3x3 matrix - where to start?
« Reply #2 on: July 08, 2013, 03:25:05 pm »
It's not going to work with SFML. This kind of perspective transformation requires depth values (which SFML doesn't have), otherwise the texture mapping will be incorrect.
Laurent Gomila - SFML developer

notnowlewis

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Transforming a sprite with a 3x3 matrix - where to start?
« Reply #3 on: July 08, 2013, 04:45:16 pm »
Ah, maybe I misunderstood or didn't explain myself very well. i don't want a 3d transform, I want to take a texture which is currently in a rectangle http://i.imgur.com/HYbDVos.png and squish it into a trapezoid http://i.imgur.com/uVl0d1y.png

Is that possible? Some of the reading I've done suggests "yes", some suggests "no". I just want to make sure in case I wasn't clear when i first asked :)
« Last Edit: July 08, 2013, 04:49:22 pm by notnowlewis »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Transforming a sprite with a 3x3 matrix - where to start?
« Reply #4 on: July 08, 2013, 05:03:53 pm »
It was very clear, and my answer still applies. There was a thread about this exact problem a few years ago, but I can't find it.
Laurent Gomila - SFML developer

notnowlewis

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Transforming a sprite with a 3x3 matrix - where to start?
« Reply #5 on: July 08, 2013, 05:35:10 pm »
Thanks, i tried searching but kept getting DB errors.

Thanks for clarifying things. I'll have to do a bit more thinking!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Transforming a sprite with a 3x3 matrix - where to start?
« Reply #6 on: July 08, 2013, 05:59:46 pm »
Quote
i tried searching but kept getting DB errors.
Don't keep all the forums selected, only check the relevant ones.
Laurent Gomila - SFML developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Transforming a sprite with a 3x3 matrix - where to start?
« Reply #7 on: July 08, 2013, 06:02:41 pm »
There's this (old) topic, not the one that I was looking for but it's the same issue:
http://en.sfml-dev.org/forums/index.php?topic=2893.0

I found the recent one on the french forum:
http://fr.sfml-dev.org/forums/index.php?topic=12121.0

If you don't understand you can just have a look at this picture:
https://en.wikipedia.org/wiki/File:Perspective_correct_texture_mapping.jpg
Laurent Gomila - SFML developer

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Transforming a sprite with a 3x3 matrix - where to start?
« Reply #8 on: July 08, 2013, 06:51:34 pm »
squish it into a trapezoid

As laurent said the depth part of what you want is impossible to do with SFML, but if all you want is a trapezoid then use an sf::VertextArray to draw your texture and on one edge move your points closer/farther away from each other.
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

notnowlewis

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Transforming a sprite with a 3x3 matrix - where to start?
« Reply #9 on: July 08, 2013, 07:00:12 pm »
squish it into a trapezoid

As laurent said the depth part of what you want is impossible to do with SFML, but if all you want is a trapezoid then use an sf::VertextArray to draw your texture and on one edge move your points closer/farther away from each other.

Would that clip the texture, or would I end up with the whole texture, but squished at one edge?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Transforming a sprite with a 3x3 matrix - where to start?
« Reply #10 on: July 08, 2013, 07:10:06 pm »
Quote
Would that clip the texture, or would I end up with the whole texture, but squished at one edge?
If you assign a rectangular texture area, it will be squished. But as I said (many times in this thread) it will lead to incorrect texture mapping as shown in the various links that I posted.
Laurent Gomila - SFML developer

notnowlewis

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Transforming a sprite with a 3x3 matrix - where to start?
« Reply #11 on: July 08, 2013, 07:22:03 pm »
Quote
Would that clip the texture, or would I end up with the whole texture, but squished at one edge?
If you assign a rectangular texture area, it will be squished. But as I said (many times in this thread) it will lead to incorrect texture mapping as shown in the various links that I posted.

Ah, I missed those, I didn't have notifications turned on for this thread.

Thanks for being patient with me, I really appreciate the time you put in on the forums, and on SFML. Also, I finally understand the issues now!