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

Author Topic: what does combine function do  (Read 1876 times)

0 Members and 1 Guest are viewing this topic.

EGYPTIAN CODER

  • Newbie
  • *
  • Posts: 32
    • View Profile
    • Email
what does combine function do
« on: December 09, 2016, 07:55:05 pm »
there is just one small problem still exist in chapt3 from SFML GAME DEVELOPMENT;
in this code
virtual void                    draw(sf::RenderTarget& target, sf::RenderStates states) const
{
        // Apply transform of current node
        states.transform *= getTransform();
       

        // Draw node and children with changed transform
        drawCurrent(target, states);
        drawChildren(target, states);
}
 
what (*=) or (combine) do in this code (I have read the documentation about this function but still cant understand what it is doing)
==========================
and just another small question  .in the above function (draw)
draw current and  draw children take the same state  ???
how this is possible. and there is three planes draw themselves in three different locations.


G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: what does combine function do
« Reply #1 on: December 10, 2016, 11:35:45 am »
states.transform *= getTransform();
is equivalent to
states.transform = states.transform * getTransform();
and to
states.transform.combine(getTransform());
It multiplies states.transform by the sf::Transform returned by getTransform() and assign it to states.transform.
More simply, it gives you an sf::Transform that does what the 2 other sf::Transform would do if they were successively applied.

EGYPTIAN CODER

  • Newbie
  • *
  • Posts: 32
    • View Profile
    • Email
Re: what does combine function do
« Reply #2 on: December 10, 2016, 07:27:24 pm »
how about just a little example and I'll be very grateful
« Last Edit: December 10, 2016, 08:11:50 pm by Laurent »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: what does combine function do
« Reply #3 on: December 10, 2016, 08:15:00 pm »
The code where you first found it is supposed to be an example ::)

But well, here it is:
sf::Transform t1;
t1.translate(x, y); // translates

sf::Transform t2;
t2.rotate(angle); // rotates

sf::Transform t3;
t3 = t1 * t2; // translates and rotate

And please stop abusing of the formatting options.
Laurent Gomila - SFML developer