PDA

View Full Version : Flight simulator type camera control



elroy
10-09-2000, 09:04 PM
I've been playing around trying to add new camera movement for my 3D engine. I had the simple orbit method and wanted to add a fly-throught type, basically like you are in a plane and can adjust the yaw,pitch and roll via keyboard and joystick. I posted some questions earlier and that got me on the right track but I'm still having problems.

Currently I save the camera position and rotation angles x, y,z. what I want is to have the new angles that are inputed to act on the current direction. I've got it mostly working but it still is a bit quirky.
This has certainly been solved before and I did search the newsgroup but didn't find what I was looking for.

I have a couple of questions, should I use rotation angles (eulers) I've read that this causes problems. Does anyone have any good resources/links that they can point me to? I'm fine with the general operations Matrix mult etc. but I'm having problems getting the coordinate transformations to work in all cases.

Thanks for any resources!

elroy

Teofuzz
10-09-2000, 10:52 PM
Exactly I don't know if my code solves your problem... I know how to move in a Descent-like way. You can look at: http://wwwbbs.dei.unipd.it/fuzz
then look the code (link 'listati' at the bottom of the page) of 'camera.cc' (you need other files, such as 'matrix.cc').
This page is rather old (dos engine!) but the transformations for the camera movements still remain.
Now, with some adjustments I use it with opengl (I used other convenctions for the axes).
Sorry this page is only in italian!
But C++ code is international.

elroy
10-10-2000, 03:09 PM
Thanks for the link. I skimmed through it and it seemed to confirm what I was trying.

I would like to get input though on what I'm currently using to see if there is a better way to do it. Any input would be greatly appreciated.

Here is some Psuedo code for what I'm doing

Currently I keep info on
camera_pos.x,y,z // current camera postion
Camera_angle.rotx,roty,rotz // current camera rotation.

So here is what I do and it seems to work okay, though there may be a better way.

Get Input()
{
if rotation adjustment
set change for x,y, or z rotation
if translation,
Calculate direction of camera using x and y rotation, then move position in that direction.
}

Change ViewPoint
{
GetInput
// apply new rotations, for now only one rotation would be non zero...
glRotatef(change_in_rot_z, 0,0,1);
glRotatef(change_in_rot_y, 0,1,0);
glRotatef(change_in_rot_x, 1,0,0);

// now apply current rotation
glRotatef(current_rot_z, 0,0,1);
glRotatef(current_rot_y, 0,1,0);
glRotatef(current_rot_x, 1,0,0);

// now translate to new position
glTranslatef(posx,posy,posz);

// now get matrix
glGetFloatv(GL_MODELVIEW_MATRIX, matrix);

//now calculate new angles from matrix, I will use these next time through, and also to calculate new direction.
CalulateNewAngle(matrix,current_rot_x,current_rot_ y,current_rot_z);


}

Kwan
06-23-2006, 06:42 AM
You can look at my camera tutorial.

http://kengine.sourceforge.net/tutorial/vc/camera-eng.htm

This tutorial describe the descent, first person and spectate camera moving.