SFML community forums
Help => Graphics => Topic started by: Imbue 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:
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:
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.
-
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.
-
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.
-
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: 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.
-
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 :)
-
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!
-
Great ;)