# Camera Movement

Outliver

14-09-2010 21:00:04

Hey guys!

I'm quite new to mogre and I fear I need some help.
I followed the tutorials to a greater or lesser extent but adjusted my cam to a bird's eye view
with a down looking angle of about -45 degrees.
Now if you hit space, you're able to move the camera with the left mouse button.

My Problem is:
Ogre moves the camera along its x and z axis, but due to the cam's pitch it moves up and down a bit,
so I need to move the camera along the world's x and z axis.
And I just can't figure out how.

Any Ideas?
Thanks in advance and sorry for my English >.<

Greetz

Beauty

15-09-2010 00:09:22

Hi Outliver,
welcome to our Mogre community.

I remember a solution by use of more than 1 SceneNode for the camera.
For example create a SceneNode for Yaw and a second one for Pitch and Roll.
The second one is a child of the first SceneNode.
When you apply movements to the Yaw SceneNode, then it's moving independent of the Pich and Roll setting of the second SceneNode. So it's easy to move a camera inside of an X-Z plane.

Here I found further information:
* Creating a simple first-person camera system
* 3rd person camera system tutorial

And here you find detailed information about quaternions:
* Quaternion and Rotation Primer

I hope this helps you.

15-09-2010 01:38:12

Camera.Move will move the camera according to the world axis and will disregard camera orientation (this sound like what you want)
Camera.MoveRelative will move the camera according to it's own axis, applying it's orientation (this is probably the one you're using)

Beauty

15-09-2010 10:12:04

Oh, one more feature which I learned now (-:

Outliver

15-09-2010 13:45:23

Good to know, but that tought me that my problem is harder to explain than I thought it was xD
Actually I do want the camera to move relatively, but not up and down according to its z-axis.
Maybe I need to recalculate the whole thing every frame according to the camera's current pitch or something.

@Beauty:
The idea of creating a SceneNode around the camera sounds like moving into the right direction.
Its orientation should be exactily the same as the camera's so I have to keep track of it, only the pitch should not be adapted.
Now, what remains is, that I can't get the Camera to be in another SceneNode.
Would you mind to post some code example, please?

Thank you both.

Beauty

15-09-2010 14:19:53

Now, what remains is, that I can't get the Camera to be in another SceneNode.
Would you mind to post some code example, please?

The solution is on the page Creating a simple first-person camera system which I told in my post above.
You just need to port the C++ code to C#.

I have no code snippet, but I try to write it now on the fly.

```// create camera Camera camera = Smgr.CreateCamera("camera"); // ... (add settings, add to viewport, ...) // attach to scene nodes SceneNode cameraYawNode = Smgr.RootSceneNode.CreateChildSceneNode("cameraYawNode"); SceneNode cameraPitchRollNode = cameraYawNode.CreateChildSceneNode("cameraPitchRollNode"); // attach to cameraYawNode cameraPitchRollNode.AttachObject(camera);```
Ok, done. I didn't test it.
For moving the camera: use cameraYawNode.
For Yaw rotation of the camera: use cameraYawNode.
For Pitch and Roll rotation: use cameraPitchRollNode.

For details of the SceneNode members, look to the Ogre::SceneNode Class Reference

Outliver

20-09-2010 12:23:08

Hey, thanks!

Works perfectly well so far. This is exactly the way I would have solved it, if I knew how

Now, there's still someting left:
It's about the rotation (yaw). The camera (i.e. cameraYawNode) seems to be moving along a curve around a circle center to the viewer's left side.
It feels like the cameraYawNode was a large box rotating around its top left edge but the cam's in its bottom right edge.

I don't know how to describe it better, so I created a little image. Left is how it should behave and right is how it actually does.

[attachment=0]cam.jpg[/attachment]

Any further help would be appreciated.

But thank you nevertheless, Beauty, for your solution!!!

Greetings from Germany

Beauty

20-09-2010 20:43:34

The pictures are good - now I know what you mean.

I suppose the reason is this:
When you rotate a SceneNode then it will be done around the point of origin of the coordinate system.
The problems comes up when you change the position of the SceneNode.
Then the rotation is still related to the point (0,0,0) and not related to the current position of the SceneNode.

1st solution:
On my university I learned to do this for each rotation:
* move the object to (0,0,0)
* rotate it
* move it back to it's old place
Then the problem is solved.
I'm not shure if this is also right for the SceneNodes of Ogre.

2nd solution:
Add one more SceneNode to your scene, which is only used for camera translation (moving).
To this add the cameraYawNode as child.
This is the way how I would do it.

Here my modified code snippet:
```// create camera Camera camera = Smgr.CreateCamera("camera"); // ... (add settings, add to viewport, ...) // attach to scene nodes SceneNode cameraPositonNode = Smgr.RootSceneNode.CreateChildSceneNode("cameraPositonNode"); SceneNode cameraYawNode = cameraPositonNode.CreateChildSceneNode("cameraYawNode"); // attach to cameraPositionNode SceneNode cameraPitchRollNode = cameraYawNode.CreateChildSceneNode("cameraPitchRollNode"); // attach to cameraYawNode cameraPitchRollNode.AttachObject(camera);```

For moving the camera: use cameraPositonNode.
For Yaw rotation of the camera: use cameraYawNode.
For Pitch and Roll rotation: use cameraPitchRollNode.

Maybe I should add this code snippet to the wiki. (if it works well)

Beauty

20-09-2010 20:54:23

Now I see such a solution was suggested on the wiki page Creating a simple first-person camera system.