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

Author Topic: RenderTexture question  (Read 7967 times)

0 Members and 1 Guest are viewing this topic.

Ockonal

  • Jr. Member
  • **
  • Posts: 58
    • ICQ Messenger - 449909010
    • View Profile
    • WinCode
Re: RenderTexture question
« Reply #15 on: October 24, 2012, 03:53:21 pm »
Thanks for the great reply!

I think, today I gonna suspend coding and learn more about coordinates, matricies, etc. :)
The only thing, transformPoint returns me coordinates like: (-0.68; 0.4), (-0.685, 0.477). I think they are in [-1;-1].
Developing 2d engine&game using: sfml, box2d, librocket, spark2, zoom&zoost, thor

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: RenderTexture question
« Reply #16 on: October 24, 2012, 04:00:29 pm »
Quote
The only thing, transformPoint returns me coordinates like: (-0.68; 0.4), (-0.685, 0.477). I think they are in [-1;-1].
Yes, sorry I forgot that. You need to convert these normalized coordinates to viewport coordinates, so this is a linear conversion from (-1, -1, 1, 1) to (0, 0, width, height).
x = (x + 1) * width / 2;
y = (y + 1) * height / 2;
Maybe you'll also need to invert the Y axis (y = height - y), I don't remember.

Sorry that you need this ugly hack to solve your problem.
Laurent Gomila - SFML developer

Ockonal

  • Jr. Member
  • **
  • Posts: 58
    • ICQ Messenger - 449909010
    • View Profile
    • WinCode
Re: RenderTexture question
« Reply #17 on: October 24, 2012, 04:47:23 pm »
Thanks ;) Maybe you are going to add some another function inverse to convertCoords before sfml 2.0 release?

The new code is:

        sf::View *cam = prmDisplayManager->getCamera();
        sf::Vector2f size = cam->getSize();

        leftTop     = cam->getTransform().transformPoint(leftTop);
        rightBottom = cam->getTransform().transformPoint(rightBottom);

        leftTop.x = (leftTop.x + 1) * size.x / 2;
        leftTop.y = (leftTop.y + 1) * size.y / 2;
        leftTop.y = size.y - leftTop.y;

        rightBottom.x = (rightBottom.x + 1) * size.x / 2;
        rightBottom.y = (rightBottom.y + 1) * size.y / 2;
        rightBottom.y = size.y - rightBottom.y;

        std::cout << leftTop.x << "; " << leftTop.y << std::endl;

        sf::IntRect rect = sf::IntRect(leftTop.x, leftTop.y, rightBottom.x, rightBottom.y);

It almost works! Especially leftTop. But something seems to be wrong with rightBottom. Look at the video (I hope it won't be hard for you to look video taken from 2 monitors). In console you can see the std::cout I wrote in code (leftTop coords).

Developing 2d engine&game using: sfml, box2d, librocket, spark2, zoom&zoost, thor

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: RenderTexture question
« Reply #18 on: October 24, 2012, 04:53:57 pm »
Quote
Maybe you are going to add some another function inverse to convertCoords before sfml 2.0 release?
I don't know. If it doesn't break the API, it can be done later.

Quote
It almost works! Especially leftTop. But something seems to be wrong with rightBottom.
You must use the size of the target (the render-texture), not the size of the view.
If they are the same in your application, it won't solve your problem though :)

And, most important: who's that girl? ;D
Laurent Gomila - SFML developer

Ockonal

  • Jr. Member
  • **
  • Posts: 58
    • ICQ Messenger - 449909010
    • View Profile
    • WinCode
Re: RenderTexture question
« Reply #19 on: October 25, 2012, 09:42:48 am »
>And, most important: who's that girl?
I wish her to be my wife.:D But it's just a nice wallpaper :(

So, the bug has been destroyed! The problem was in sf::IntRect and and rightBottom width/global coords conversion.

Thanks!
Developing 2d engine&game using: sfml, box2d, librocket, spark2, zoom&zoost, thor

Ockonal

  • Jr. Member
  • **
  • Posts: 58
    • ICQ Messenger - 449909010
    • View Profile
    • WinCode
Re: RenderTexture question
« Reply #20 on: October 25, 2012, 12:38:17 pm »
And a small another problem: camera movement works fine but scaling doesn't :(. Maybe I have to look at something when I transform my points using camera?
Developing 2d engine&game using: sfml, box2d, librocket, spark2, zoom&zoost, thor

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: RenderTexture question
« Reply #21 on: October 25, 2012, 12:44:02 pm »
Quote
camera movement works fine but scaling doesn't
You scale what? And what's the result?
Laurent Gomila - SFML developer

Ockonal

  • Jr. Member
  • **
  • Posts: 58
    • ICQ Messenger - 449909010
    • View Profile
    • WinCode
Re: RenderTexture question
« Reply #22 on: October 25, 2012, 12:50:46 pm »
Oh man, sorry. The problem disappears O_o. Sorry for disturbing you.
Developing 2d engine&game using: sfml, box2d, librocket, spark2, zoom&zoost, thor

 

anything