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

Author Topic: Questions about the scene graph example  (Read 2239 times)

0 Members and 3 Guests are viewing this topic.

hal1001

  • Newbie
  • *
  • Posts: 11
    • View Profile
    • Email
Questions about the scene graph example
« on: August 15, 2014, 01:14:37 am »
http://sfml-dev.org/tutorials/2.1/graphics-transform.php#object-hierarchies-scene-graph

I'm probably missing something here, but the Node in the example is an abstract class, but owns a private m_transform member variable with no transformations. This Transform is passed into the onRender function of the derived class, but the SpriteNode does nothing with it. So the only way I can see the m_transform member variable as useful is if the Node had a protected method that returned it so SpriteNode could use it for its own transformation, or if SpriteNode had its own Transform member variable and it was combined with the m_transform passed through. What am I not understanding from the example?

My high level understanding is that this pattern is meant for a scene graph where one transformation can be "relative" to a parent transformation. Is that right?

Also, I've seen this in C++ a few different times, but I can't find documentation on combining pointers:

sf::Transform combinedTransform = parentTransform * m_transform;

states.transform *= getTransform();

Are these overloaded operators that know internally how to resolve a "combination", or is there another term for this where I can read more?

Thanks!

Brian

zsbzsb

  • Hero Member
  • *****
  • Posts: 1409
  • Active Maintainer of CSFML/SFML.NET
    • View Profile
    • My little corner...
    • Email
Re: Questions about the scene graph example
« Reply #1 on: August 15, 2014, 04:52:24 am »
A '*' in C++ does not always indicate a pointer, it can be also be multiplication (of numeric types) or can be overloaded operator of a class. As for what it does exactly with the transform class, you should always refer to the documentation.


http://sfml-dev.org/documentation/2.1/classsf_1_1Transform.php#a85ea4e5539795f9b2ceb7d4b06736c8f
Motion / MotionNET - Complete video / audio playback for SFML / SFML.NET

NetEXT - An SFML.NET Extension Library based on Thor

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Questions about the scene graph example
« Reply #2 on: August 15, 2014, 09:19:59 am »
In the definition of the Node class:

    // ... functions to transform the node

So every instance of a derived Node class will have (depending on what you need) functions such as setPosition, setRotation, ... If you want the full set, Node can directly inherit from sf::Transformable.

And yes, transformations are always relative to the parent node. They are combined (with the multiplication operator) at draw time.
Laurent Gomila - SFML developer

hal1001

  • Newbie
  • *
  • Posts: 11
    • View Profile
    • Email
Re: Questions about the scene graph example
« Reply #3 on: August 15, 2014, 03:02:18 pm »
Thanks zsbzsb and Laurent for the additional clarification. This was really helpful.

One of my implementations from a "Node" type class does inherit from Transformable, but now that you mentioned it I think it makes more sense to me to move that up to the abstract class.

Thanks again!

 

anything