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

Author Topic: GetWorldPosition dont work  (Read 2770 times)

0 Members and 1 Guest are viewing this topic.

DuffCola

  • Newbie
  • *
  • Posts: 8
    • View Profile
GetWorldPosition dont work
« on: September 28, 2013, 10:23:58 pm »
Hello, this question are only for  reader from "SFML Game Development Book".
I have these methods:
        sf::Vector2f getWorldPosition()
        {
                return getWorldTransform() * sf::Vector2f();
        }
        sf::Transform getWorldTransform()
        {
                sf::Transform transform = sf::Transform::Identity;

                for (const SceneNode* node = this; node != nullptr; node = node->mParent)
                {
                        transform = node->getTransform() * transform;
                }

                return transform;
        }
 
If I use now  getWorldPosition I get a value for x how 2.5645e-034.
What is wrong?

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: GetWorldPosition dont work
« Reply #1 on: September 28, 2013, 10:28:05 pm »
In case you don't know, 2.5645e-034 means 2.5645 * 10 ^ -034, which is an extraordinarily small number.  It's probably the closest floating point number to zero in the precision you're using.  We call this a floating point rounding error.

Assuming you expected to get exact zeros out of this method, this might not even be a problem, depending on what you use these numbers for and how accurate you want these numbers to be.  I haven't read the book so I don't know offhand if this is a serious problem.
« Last Edit: September 28, 2013, 10:29:52 pm by Ixrec »

DuffCola

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: GetWorldPosition dont work
« Reply #2 on: September 28, 2013, 11:34:50 pm »
Teh problem is, that are not right coordinates.
I want check for absolut x position.

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: GetWorldPosition dont work
« Reply #3 on: September 28, 2013, 11:51:22 pm »
Oh.

Well what do you mean by "absolute position"?  All positions are relative to something.

Could you give a specific example where you expect a certain object to have some coordinates and this returns different ones?

DuffCola

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: GetWorldPosition dont work
« Reply #4 on: September 28, 2013, 11:55:48 pm »
He for exmaple :
http://s7.directupload.net/images/130928/kihrtrfs.png
The red dot is the origin from the first Sprite Node.
Now I want the coordinates from the 3. SpriteNode realtive to the origin(red dot).
The problem is that the 3. SpriteNode have the absolut position off x:600.
But If I use getWorldPosition I got for x and y these faulty float value. 
« Last Edit: September 28, 2013, 11:58:23 pm by DuffCola »

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: GetWorldPosition dont work
« Reply #5 on: September 28, 2013, 11:59:06 pm »
Ah, that makes sense.

It seems like the code should work in that case.  At this point I don't think I can tell you anything besides step through it with a debugger yourself and see where it goes wrong, or post a complete and minimal example so we can step through it with our debuggers.

DuffCola

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: GetWorldPosition dont work
« Reply #6 on: September 29, 2013, 09:50:11 am »
Here http://www.file-upload.net/download-8124509/getWorldPosition.7z.html.
I have made it so small I can.
(I have nether really worked with the debugger, know you a good tutorial?)

DuffCola

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: GetWorldPosition dont work
« Reply #7 on: September 29, 2013, 09:56:07 am »
Oh....
I have found my mistake myself....
I have made the return type from getWorldTransform as a constant referenz.

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: GetWorldPosition dont work
« Reply #8 on: September 29, 2013, 10:03:33 am »
Oh, and I was still telling VS where my SFML files were so I could compile your project.  Oh well. 

Still, in all seriousness, debugging is an absolutely vital skill.  You'll never finish a program longer than a few hundred lines if you don't learn how to use one.  At the same time IDEs make it so easy that you should have no trouble learning it no matter what crappy tutorial you start with.  In VS all you really do is make a debug build, click in the gray left-hand margin to set breakpoints on certain lines and when your program hits one, use the buttons in the debugging toolbar to do whatever you want from there.  I'll let you figure out the rest from there (eg variable watching) since it's all pretty intuitive.