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

Author Topic: sfml scenegraph and world transformations issue  (Read 1801 times)

0 Members and 1 Guest are viewing this topic.

bcvz

  • Newbie
  • *
  • Posts: 17
    • View Profile
sfml scenegraph and world transformations issue
« 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

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: sfml scenegraph and world transformations issue
« Reply #1 on: March 05, 2014, 08:49:06 pm »
I guess the relative position is indeed 0. Use getWorldPosition() for the absolute one.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

bcvz

  • Newbie
  • *
  • Posts: 17
    • View Profile
Re: sfml scenegraph and world transformations issue
« Reply #2 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




 

anything