I have the following problem - I am trying to implement a mouse rotation in my application where I rotate the camera around an object (mouseButton1 pressed = rotate, mouseButton2 pressed = pan).
I looked at and studied the "Lights, Camera, Action" tutorial (http://www.ogre3d.org/docs/Tutorials/3_ ... otion.html) where something similar is being discussed. However, there are several differences to my application:
- I am not using ExampleApplication and ExampleFrameListener - I have written my own application class and I am actually trying to rotate the camera in it's own listener
- I try to rotate the camera using the mouse - the rotation should be dependent on the mouse movement (move mouse left -> rotate left until the button is released, etc. - you get the picture)
Now here's my problem:
I have the mRotatingNode attached to the object I want to rotate around and mCamera attached to mRotatingNode, just like in the tutorial. When I call:
Code: Select all
mRotatingNode->rotate(Vector3::UNIT_Y, (Radian)1.0*evt.timeSinceLastFrame);I came to the conclusion that it is because the getMouseRelativeX() method never returns anything else besides 0.0. So my program is not tracking the mouse movement. The question is why? What do I need to start, include, etc. in the constructor, so the program will track my mouse?
And now for the code
First, my class is derived only from FrameListener:
Code: Select all
class PAnalyzerMouseListener : public FrameListenerThis is my constructor:
Code: Select all
PAnalyzerMouseListener::PAnalyzerMouseListener(RenderWindow* window, Camera* camera, SceneNode* centralNode) {
mWindow = window;
mCamera = camera;
mCentralNode = centralNode;
mTranslateVector = Vector3::ZERO;
mRotX = 0.0;
mRotY = 0.0;
// create a node to act as the central rotation point
mRotatingNode = static_cast<SceneNode*>(mCentralNode->createChild());
mRotatingNode->attachObject(mCamera);
mCamera->moveRelative(Vector3(0.0, 0.0, 200.0));
mCamera->lookAt(0.0, 0.0, 0.0);
mEventProcessor = new EventProcessor();
mEventProcessor->initialise(mWindow);
OverlayManager::getSingleton().createCursorOverlay();
mInputReader = mEventProcessor->getInputReader();
mInputReader->setBufferedInput(false, true);
mEventProcessor->startProcessingEvents();
}
Now for the processUnbufferedMouseInput() method:
Code: Select all
bool PAnalyzerMouseListener::processUnbufferedMouseInput(const FrameEvent& evt) {
if (mInputReader->getMouseButton(0)) {
mRotX = Degree(-mInputReader->getMouseRelativeX()*0.13);
mRotY = Degree(-mInputReader->getMouseRelativeY()*0.13);
}
else if (mInputReader->getMouseButton(1)) {
mTranslateVector.x += mInputReader->getMouseRelativeX() * 0.13;
mTranslateVector.y -= mInputReader->getMouseRelativeY() * 0.13;
}
return true;
}
And last is the frameStarted() method:
Code: Select all
bool PAnalyzerMouseListener::frameStarted(const FrameEvent &evt) {
mInputReader->capture();
GuiContainer* cursor = OverlayManager::getSingleton().getCursorGui();
cursor->setMaterialName("Cursor/default");
cursor->setDimensions(32.0/mWindow->getHeight(), 32.0/mWindow->getWidth());
cursor->show();
processUnbufferedMouseInput(evt);
mRotatingNode->rotate(Vector3::UNIT_Y, mRotX*evt.timeSinceLastFrame);
return true;
}
Code: Select all
mMouseListener = new PAnalyzerMouseListener(mWindow, mCamera, mBoxNode);
mRoot->addFrameListener(mMouseListener);
