Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

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.

share|improve this answer
    
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). –  Gamer007z Jan 19 '13 at 12:38
    
Why do you need an Ogre::Vector3? In any case, you can just create one: Ogre::Vector3(myWxPoint.x, myWxPoint.y, 0); –  Philip Allgaier Jan 19 '13 at 14:34

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 interectionResult = mouseray.intersects(plane) if(interectionResult.first) WORLDPOS = interectionResult.second;

I think this will help you.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.