Camera movement demo3

Zep

10-03-2009 15:54:55

I'm currently trying the camera movement as written in the demo 3 (collisionCallbacks), but the movement really weird..

At the original position, the forward, backward, left and right movements are good, but things gone mad when i'm rotating the camera (using the mouse), and the movement does not follow the camera orientation at all.
Same for the rotation of the msnCam node, it seems that the rotation suffers from gimbal lock...

I do not understand the problem because i looked the code on the ExampleFrameListener, and the movements and the rotations are done in the same way, the only difference is, in the demo, their are applied on a SceneNode rather than the Camera object...

melven

10-03-2009 16:36:49

It would be useful if you paste your code in here in order to find the problem...


I think there were different approaches to realize the camera movement:
-You can attach the camera to a SceneNode like in the demo code and apply the transformations to the SceneNode. The trick here is that the yaw is applied relative to global space. This should avoid the gimbal locks and is usually the behaviour you would expect.
(this is done in the official OgreNewt demos)
-You can achieve the same behaviour by using a usual Node and applying only the yaw and the translation to the Node and apply the pitch to the camera directly...
-With Ogre 1.6 (I don't know if the function existed before) you can apply all your transformations to the camera directly and get the same result, if you fix the yaw-axis to the y-axis (method setFixedYawAxis).
(If this is, what you want, then have a look at the demos of the unofficial ogrenewt-branch for newton 2.0 http://svn.ogre3d.org/svnroot/ogreaddon ... t/newton20 )

It can also be useful to create a body for the camera, so you don't move into objects, but then you need to move the body around (e.g. using the force-callback) for the translation (the rotational part of your movement can still be applied to the camera directly).

Zep

10-03-2009 17:08:21

I did not paste the code because it is the same as the code of the demo...I forgot to mention that, but the issue occurs also in the demo..

OgreNewtApplication.cpp

// msnCam is the SceneNode..
msnCam = mSceneMgr->getRootSceneNode()->createChildSceneNode();
msnCam->attachObject( mCamera );
mCamera->setPosition(0.0, 0.0, 0.0);
msnCam->setPosition( 0.0, 2.0, 22.0);
//...


OgreNewtFrameListener.h

bool OgreNewtFrameListener::frameStarted(const FrameEvent &evt)
{
Vector3 trans, strafe, vec;
Quaternion quat;

quat = msnCam->getOrientation();

vec = Vector3(0.0,0.0,-0.5);
trans = quat * vec;

vec = Vector3(0.5,0.0,0.0);
strafe = quat * vec;

mKeyboard->capture();
mMouse->capture();

msnCam->pitch( Degree(mMouse->getMouseState().Y.rel * -0.5) );
msnCam->yaw( Degree(mMouse->getMouseState().X.rel * -0.5), SceneNode::TS_WORLD );

if (mKeyboard->isKeyDown(OIS::KC_UP))
msnCam->translate(trans);

if (mKeyboard->isKeyDown(OIS::KC_DOWN))
msnCam->translate(trans * -1.0);

if (mKeyboard->isKeyDown(OIS::KC_LEFT))
msnCam->translate(strafe * -1.0);

if (mKeyboard->isKeyDown(OIS::KC_RIGHT))
msnCam->translate(strafe);


timer -= evt.timeSinceLastFrame;


if (mKeyboard->isKeyDown(OIS::KC_ESCAPE))
return false;

return true;
}


But i do not understand how it could be useful to create a body for the camera...won't it be more difficult, or less intuitive for the user, to move the camera (i mean its body) using the force callback rather than applying a simple translation on the node ?

melven

10-03-2009 18:26:51

The purpose of creating a body for the camera is that you can't move through objects any more! This would be the only difference for the player. The behaviour of the camera movement can be the same if it is implemented correctly.

Concerning the error: what version of Ogre are you using?
Have you checked the corresponding code in the demos from the unofficial ogrenewt?

Zep

10-03-2009 18:57:22

That's obviously right ^^' i did not thought about that because the type of camera i currently want is just a free camera whose its only purpose is for debugging

And then a had a look in the demo3 from the unofficial ogrenewt, and apparently it just removes the msnCam node and translates directly the Camera object with moveRelative().

Thanks for your answers melven !


[edit] : The rotation of the camera is fixed, surely thanks to the setFixedYawAxis() method, but the camera translation still does not follows the orientation :/

melven

11-03-2009 10:55:47

So you are now using the same code as in the unofficial OgreNewt demos for the camera?
For me this seems to work fine... Can you check if your camera is attached to any other Node? Then you should possibly try "getDerivedOrientation" instead of "getOrientation" in order to retrieve the correct direction of the movement.

Zep

11-03-2009 12:28:07

Yeah i have the same code as the demo's for the camera movement, and there's no node attached to the camera.

I have already tried getDerivedOrientation() and the result is just the same :/
I add that I have already disabled the camera controls from the ExampleFrameListener class (from which OgreNewtFrameListener inherit).