0
\$\begingroup\$

In Ogre3d, what's the difference between methods Camera::getPosition() and Camera::getPositionForViewUpdate(), official documentation doesn't says much:

/** Get the derived position of this frustum. */
const Vector3& getPositionForViewUpdate(void) const;

/** Retrieves the camera's position.*/
const Vector3& getPosition(void) const;

Thanks!

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

You probably don't want to call getPositionForViewUpdate, preferring instead getPosition or (as I'll explain below) getRealPosition.


getPosition returns the camera's mPosition member variable, while getPositionForViewUpdate returns the camera's mRealPosition member.

So what's the difference in these members?

An Ogre camera can optionally be attached to a scene node parent. When this is done, the camera's position (mPosition) is considered relative to the parent node. mRealPosition is always the world-space position of the camera.

When the camera is considered dirty and needs to be updated (for example, if it was moved between the current frame and the last), Ogre will check if the camera is parented to a node and if so compute the real position based on the local position relative to the parent. You can see this in the source code here:

// Ok, we're out of date with SceneNode we're attached to
mLastParentOrientation = mParentNode->_getDerivedOrientation();
mLastParentPosition = mParentNode->_getDerivedPosition();
mRealOrientation = mParentNode->convertLocalToWorldOrientation(mOrientation);
mRealPosition = mParentNode->convertLocalToWorldPosition(mPosition);
mRecalcView = true;
mRecalcWindow = true;

But if the camera's not attached to a parent, it simply does:

mRealOrientation = mOrientation;
mRealPosition = mPosition;

So in general, getPosition returns the camera's local position relative to its parent. If it has no parent, this will be the camera's position in world space. getPositionForViewUpdate will return the camera's position in world space regardless, however, it does not force an update of the camera because it is expected that getPositionForViewUpdate is only called during an update; it's an optimization.

In the general case if you want to get the camera's world position without having to think about whether or not the camera has a parent, call getRealPosition, which forces the update of mRealPosition if applicable before returning it.

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .