Rotating around an object - With an offset

Problems building or running the engine, queries about how to use features etc.
Post Reply
Posts: 92
Joined: Sat Jul 22, 2017 2:32 pm
x 4

Rotating around an object - With an offset

Post by Owl53 »

Ogre Version: :?: 1.11
Operating System: Windows 10
Render System: OpenGL


I have an object that rotates around a central point with its rotation to match the camera view, with the following code:

Code: Select all

//t is a transform class that contains the Ogre SceneNode
Ogre::Quaternion cameraRot = mCamera->getSceneNode()->getOrientation();
Ogre::Vector3 cameraDir = cameraRot * Ogre::Vector3::NEGATIVE_UNIT_Z;

What I would then like to do, is move the object further away (half the size of the object) from the central point but in the direction that the camera is looking.

I have tried using the following code:

Code: Select all

Ogre::Vector3 testPosition = t->getPosition() + (cameraDir * (mBoundingBox.getHalfSize() * t->getScale());
This works for the initial rotation, but when I then rotate the camera, this object rotates around the further point out, not around the central point. I thought that moving the object back to the central point to do the rotation, then moving it away again after in the camera direction would work, but it clearly doesn't.

I was wondering if it was because of some local/world rotation conflict or something, but I've tried every theory I've had to solve the problem, without success.

Thanks in advance

User avatar
Posts: 51
Joined: Tue Nov 27, 2018 1:41 am
x 4

Re: Rotating around an object - With an offset

Post by saintnick »

I think you could create a scene node at center position and rotate it however you need. Then set the orientation of your node to the center scene node's orientation.

Code: Select all


Post Reply