Rotating around an object - With an offset

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

Rotating around an object - With an offset

Post by Owl53 » Thu Dec 20, 2018 7:31 pm

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

Hi,

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;

t->setPosition(centrePos);
t->getSceneNode()->setOrientation(cameraRot);
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());
t->setPosition(testPosition);
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
0 x

saintnick
Halfling
Posts: 43
Joined: Tue Nov 27, 2018 1:41 am
x 1

Re: Rotating around an object - With an offset

Post by saintnick » Thu Dec 20, 2018 11:48 pm

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

t->setOrientation(centerNode->getOrientation());
0 x

Post Reply