1
\$\begingroup\$

I am working on a case where when the mouse is moved upwards, the camera must also move upwards.

I understand that for mouse picking we perform ray casting along a plane. I think my case is little different, the camera movements(x,y,z) must be linked with mouse movement(x,y) in all directions.

I am using the OGRE 3D engine.

\$\endgroup\$

2 Answers 2

1
\$\begingroup\$

Ogre3D itself cannot handle that situation as it is a pure rendering engine, hence you need some input library. The standard solution for Ogre applications is using OIS which even comes bundled with Ogre.

What you then need to do is to create an OIS::MouseListener (e.g. by letting your main application class inherit from it) that will deal with your mouse move events and react accordingly, in your case rotate the camera.

bool YourClassInheritingMouseListener::mouseMoved(const OIS::MouseEvent &evt)
{
    m_pCamera->yaw(Degree(evt.state.X.rel * -0.1f));
    m_pCamera->pitch(Degree(evt.state.Y.rel * -0.1f));

    return true;
}

For a more complete example have a look at the BasicOgreFramework I created which handles mouse movements to rotate the camera as well as keyboard input to move the camera.

\$\endgroup\$
2
  • \$\begingroup\$ Thanks for this lightning reply Philip...I understand and have tried OIS couple of times on a sample tutorials.It works Great!!! :-) But I'm puzzled with an scenario where the input is provided from wxWidget using wxMouseEvent docs.wxwidgets.org/2.8/wx_wxmouseevent.html. ie.,I get 2 points of form wxPoint(X,Y). I'm stuck with converting this to Ogre::Vector(x,y,z). \$\endgroup\$
    – Gamer007z
    Jan 19, 2013 at 12:38
  • \$\begingroup\$ Why do you need an Ogre::Vector3? In any case, you can just create one: Ogre::Vector3(myWxPoint.x, myWxPoint.y, 0); \$\endgroup\$ Jan 19, 2013 at 14:34
1
\$\begingroup\$

I faced similiar issue. I then understood that we need to unproject the mouse co-ord to local co-ord. For doing this follow below :

  1. Form a mouse ray depening on your screen size.

    mouseray = camera->getCameraToViewportRay(screenPos.x/width,screenPos.y/height);
    
  2. Create a plane which must be parallel to camera and at any position.

    plane = plane(camera->getDerivedDirection(),vector3(0,0,0));
    
  3. check weather the mouse ray hits the plane on which camera is projected.

    std::pair<bool,dist> interectionResult  = mouseray.intersects(plane)
    if(interectionResult.first)
        WORLDPOS = interectionResult.second;
    

I think this will help you.

\$\endgroup\$

You must log in to answer this question.

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