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

Author Topic: sf::Matrix3::GetInverse() Question [Fixed]  (Read 3857 times)

0 Members and 1 Guest are viewing this topic.

Imbue

  • Full Member
  • ***
  • Posts: 104
    • View Profile
sf::Matrix3::GetInverse() Question [Fixed]
« on: October 05, 2008, 05:11:06 am »
Hi, could someone please tell me what I'm doing wrong here.

I'm expecting to move a point from 0, 0 to 10, 10, and then back to 0, 0. However, the last operation doesn't work and the point stays at 10, 10. Here is the code:

Code: [Select]
   sf::Vector2f center(0, 0);
    sf::Vector2f offset(10, 10);
    sf::Vector2f scale(1, 1);

    sf::Matrix3 m;
    m.SetFromTransformations(center, offset, 0.0, scale);


    sf::Vector2f v(0, 0); //Show starting point.
    std::cout << v.x << "\t" << v.y << "\n";

    v = m.Transform(v); //Move by 10 (x and y).
    std::cout << v.x << "\t" << v.y << "\n";

    v = m.GetInverse().Transform(v); //Move backwards (doesn't seem to do anything).
    std::cout << v.x << "\t" << v.y << "\n";


The output from this is:
Quote
0   0
10   10
10   10


I also can't seem to get multiplication to work. If I add "m *= m;" to the code then I'd expect the offset to double, but I can't get that to work either.

What am I doing wrong? Are these functions not supposed to do what I think they should? Thanks.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
sf::Matrix3::GetInverse() Question [Fixed]
« Reply #1 on: October 05, 2008, 09:03:02 am »
You're not supposed to use the Matrix3 class directly. But anyway, it should work as expected.

The GetInverse function should work fine, but it obviously doesn't ;)
I'll check it as soon as possible.

Thanks for your feedback.
Laurent Gomila - SFML developer

Imbue

  • Full Member
  • ***
  • Posts: 104
    • View Profile
sf::Matrix3::GetInverse() Question [Fixed]
« Reply #2 on: October 05, 2008, 10:25:55 am »
Quote from: "Laurent"
You're not supposed to use the Matrix3 class directly.
Well, I am sub-classing sf::Drawable. Since GetMatrix() is a protected function, I assume I'm at the right level of abstraction. If GetInverse() really is broken, then sf::Drawable::TransformToLocal() probably is too.

I'll look for the bug too. I just wanted to make sure I wasn't doing something obviously wrong before I put too much time into it.

Thanks.

Imbue

  • Full Member
  • ***
  • Posts: 104
    • View Profile
sf::Matrix3::GetInverse() Question [Fixed]
« Reply #3 on: October 07, 2008, 01:20:55 am »
I did a few more tests on this. I don't think that GetInverse() is actually broken, perhaps. I think there is instead a logic error with the way that you're packing a 3x3 matrix into a 4x4 one.

If I do:
Code: [Select]
   sf::Matrix3 m(1, 0, 10,
                  0, 1, 10,
                  0, 0, 1);
then GetInverse() does work as expected. But if the matrix is made with SetFromTransformations() then it doesn't work.

It seems that the difference between the two is at 2, 2 (myData[14]). If myData[14] is forced to 1.0, then the math seems to work perfect but it renders incorrectly. If myData[14] is left at zero (how it's currently implemented) then the rendering works but multiplication and inversion is broken.

I've tried some different things to fix it. Unfortunately I don't know much about matrices.

Thanks.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
sf::Matrix3::GetInverse() Question [Fixed]
« Reply #4 on: October 10, 2008, 05:31:50 pm »
Hi

I fixed the matrix calculations. The problem was how I was mapping a 3x3 matrix to a 4x4 one.

Now everything seems to work fine.

Thanks a lot for your help :)
Laurent Gomila - SFML developer

Imbue

  • Full Member
  • ***
  • Posts: 104
    • View Profile
sf::Matrix3::GetInverse() Question [Fixed]
« Reply #5 on: October 11, 2008, 08:20:58 am »
I don't know if you seen my earlier message (I deleted it). I thought there might be another bug, but it was just me being really stupid. :oops: Sorry.


Anyway, thanks a ton! It works perfect now. :D

Better than perfect. It's doing exactly what I need.

Thanks!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
sf::Matrix3::GetInverse() Question [Fixed]
« Reply #6 on: October 11, 2008, 09:44:10 am »
Great ;)
Laurent Gomila - SFML developer