SFML community forums

Help => General => Topic started by: bcvz on March 05, 2014, 08:09:36 pm

Title: sfml scenegraph and world transformations issue
Post by: bcvz on March 05, 2014, 08:09:36 pm
Hello,

I've built a SceneGraph almost same as the SFML game development book scenegraph

and I'm having trouble with transformations : I have a "TubeObstacle" class, inherited from Entity, which is composed of 2 SpriteNode

I set the velocity to (-300,0), everything moves fine, but when I try to get one of the SpriteNodes X position the output is always 0 :/


Obstacle.h http://pastebin.com/nhyP44yH cpp http://pastebin.com/xhPtNMc2
SpriteNode.h http://pastebin.com/TR4awU6E cpp http://pastebin.com/jvqTRdrT

Scenenode: https://github.com/SFML/SFML-Game-Development-Book/blob/master/08_Graphics/Include/Book/SceneNode.hpp

thanks
Title: Re: sfml scenegraph and world transformations issue
Post by: Nexus on March 05, 2014, 08:49:06 pm
I guess the relative position is indeed 0. Use getWorldPosition() for the absolute one.
Title: Re: sfml scenegraph and world transformations issue
Post by: bcvz on March 05, 2014, 09:33:43 pm
That's what I do, I call getWorldTransform(), here for SpriteNode's boundingRect :
http://pastebin.com/jvqTRdrT

sf::FloatRect SpriteNode::getBoundingRect()
{
        return getWorldTransform().transformRect(mSprite.getGlobalBounds());
}

And I output getBoundingRect.left here in Obstacle.cpp:
http://pastebin.com/xhPtNMc2

 // MChildren.at(0) is one of the SpriteNode's attached to the TubeObstacle Entity
std::cout << mChildren.at(0)->getBoundingRect().left << std::endl; // output is always 0, but his Parent is moving to left