0

i am new to ogre and have read the basic tutorials but unable to understand how to create a orbit camera with mouse wheel zooming.

here is my camera code

// Create the scene node(orbit camera)
node = mSceneMgr->getRootSceneNode()->createChildSceneNode("orbit", Ogre::Vector3(0, 100, -150));
node->attachObject(mCamera);

// create the second camera node(freecam)
node = mSceneMgr->getRootSceneNode()->createChildSceneNode("free", Ogre::Vector3(0, 100, 400));

// create the third camera node (3rd person robot cam)
node = mSceneMgr->getRootSceneNode()->createChildSceneNode("robocam", Ogre::Vector3(0, 100, -80));

And here is my keypress function

bool BasicTutorial05::processUnbufferedInput(const Ogre::FrameEvent& evt)
{
    Ogre::Vector3 transVector1 = Ogre::Vector3::ZERO;
    if (cam1 == true)//when cam 1 is selected, bool cam1 will be true;
    {
        if (mKeyboard->isKeyDown(OIS::KC_S)) 
        {
            mSceneMgr->getSceneNode("orbit")->pitch(Ogre::Radian(-0.012f));
        }
        if (mKeyboard->isKeyDown(OIS::KC_W))
        {
            mSceneMgr->getSceneNode("orbit")->pitch(Ogre::Radian(0.012f));
        }
        if (mKeyboard->isKeyDown(OIS::KC_A))
        {
            mSceneMgr->getSceneNode("orbit")->yaw(Ogre::Radian(0.012f));
        }
        if (mKeyboard->isKeyDown(OIS::KC_D))
        {
            mSceneMgr->getSceneNode("orbit")->yaw(Ogre::Radian(-0.012f));
        }
    }
    mSceneMgr->getSceneNode("orbit")->translate(transVector1 *evt.timeSinceLastFrame,      Ogre::Node::TS_LOCAL);
}

and the mouse wheel zooming

//zooming for orbit camera
Ogre::Vector3 transVector2 = Ogre::Vector3::ZERO;
if (mMouse->getMouseState().Z.rel != 0){
    transVector2.z = -mMouse->getMouseState().Z.rel;
}

but i can able to sort of orbit around the point where the camera is but only when i use the wheel scroll zoom, instead of rotating around a point it rotates where the camera is. How do i change it that it only rotates at a point?

Etherealone
  • 3,488
  • 2
  • 37
  • 56
user2640299
  • 25
  • 1
  • 8

1 Answers1

0

Create two nodes for your camera - the first one is the target and it's placed at the point you want to rotate around.

The second node should be created at some distance from the first one. You should attach it as the child of the target and attach your camera to this node. Finally, you should point your camera at the target node (the first one).

With this setup you'll just need to put your target node at the point of your interest and rotate it as you want. The camera position will follow the target, because it's his child. And by moving your camera node closer to the target node you can change your zoom level.

kolenda
  • 2,741
  • 2
  • 19
  • 30