body::getGlobalPosition inconsistent?

Grom

17-02-2007 17:10:09

For some reason I'm getting a very strange error. I have a basic situation where all I'm doing is logging the position of a body. It doesn't move. It's global position should therefore stay the same, right?

I have a body "b", and I call this every frame:

Vector3 at = b->getGlobalPosition();
LogManager::getSingleton().logMessage("AT " + StringConverter::toString(at.x) + " " + StringConverter::toString(at.y) + " " + StringConverter::toString(at.z));


which should consistently spit out "AT 0 0 0" but instead I get:

11:59:09: AT 0 0 0
11:59:09: AT 2.69379e-008 0.787 0
11:59:09: AT 2.57434e-008 0.9444 0
11:59:09: AT 2.57434e-008 0.9444 0
11:59:09: AT 2.52375e-008 0.97588 0
11:59:09: AT 2.49881e-008 0.982176 0
11:59:09: AT 2.47424e-008 0.983435 0
1


the x value goes out of range after the first time, and it changes, as does the y value.

Any idea what might be going on here?

betajaen

17-02-2007 18:29:16

Hmm. E means exponential right? So if my math is correct:

The body position is:


0.0000000247424 0.983435 0


The Y value may be due to the height of the body. I am guessing 2 metres? So half of that is the Y center, which is roughly right.

Grom

17-02-2007 19:04:45

hrm? except why is it changing, it goes up to 9 and eventually levels off at 4.5719e-009. How do I get the body's global position into useable numbers?

betajaen

17-02-2007 19:17:51

That is the global position. Remember gravity is pulling the body through the floor, which in kind the floor is pushing it back. So there will be small errors like that, probably due to floating point errors.

But anything that ends with e-009 is very small. It's 4.5719 nanometers which is tiny, it's roughly smaller than a single cell in your body.

If you want to make absolutely certain then you can get the NxVec3 from b->mActor->getGlobalPosition();