Hello,
i am trying to understand the meaning of
" Overload of binary operator * to combine two transforms. This call is equivalent to calling Transform(left).combine(right). "
but I can't understand this. I am reading the book "SFML Game Development" and I reached this part where I have to wirte this:
HPP FILE:
class SceneNode : public sf::Transformable, public sf::Drawable, private sf::NonCopyable
{
...
private:
sf::Transform getWorldTransform() const;
SceneNode *mParent;
...
};
CPP FILE:
sf::Transform SceneNode::getWorldTransform() const
{
sf::Transform transform = sf::Transform::Identity;
for (const SceneNode* node = this; node != nullptr; node = node->mParent)
transform = node->getTransform() * transform;
return transform;
}
If a SceneNode is a child, it means it has a parent, we store it in mParent, we have a function which attaches children.
I understand what we are trying to do here, but I don't understand why this for loop should give us the complete transform of the world. We are multiplying our transform with the one our parent has, and if our parent has a parent too, we are multiplying transform with it either and so on. But why should this give us the complete world transform?
For example our position is (50, 50), position of our parent is (10, 10).
So transform * child-transform is (500, 500). Is this our world transform???
I don't get it, I'm sorry, I'm to stupid for that. What is the purpose of '*' operator?