Click to See Complete Forum and Search --> : [OpenGL] Almost camera


Miechu
May 2nd, 2006, 06:42 PM
i've implemented almost a camera ;)

i've got 6 variables:

float x_rotation;
float y_rotation;
float x_translation;
float y_translation;
float z_translation;

i do camera rotation like this:

x_rotation += (point.y-last_x);
y_rotation += (point.x-last_y);

where point is a struct for mouse position, and last_x/y is for last mouse pos...

now when i want to move i do it like this:

z_translation+=0.2f; //forward
z_translation-=0.2f; //backward

x_translation+=0.2f;//strafe
x_translation-=0.2f;//strafe

now for drawing:

glTranslatef(x_translation,y_translation,z_translation);
glRotatef(x_rotation,1.0f,0.0f,0.0f);
glRotatef(y_rotation,0.0f,1.0f,0.0f);

now the problem is, that this effects in being 'on a stick' - when i move somewhere & rotate (with mouse) - i'm rotating realetivly to (0,0,0), but i move correctly...

now if i change the drawing to:

glRotatef(x_rotation,1.0f,0.0f,0.0f);
glRotatef(y_rotation,0.0f,1.0f,0.0f);
glTranslatef(x_translation,y_translation,z_translation);

i'm rotating just fine... but i'm moving always absolutly... strafe is not always strafe - just moving on the x-axis...

i don't know if anyone will undersand this problem... but if there is a one... please explain it to me... (i'm lame in 3d math)

nolxev
May 3rd, 2006, 11:27 AM
Your way to implment a camera is wrong. Take a look at "gluLookAt" function that was developed for that purpose. It's within "glu.h". Do not forget to link "glu32.lib" library.

Miechu
May 3rd, 2006, 05:57 PM
everything's cool... but this does not solve my 'strafe problem' - i don't know how to calculate strafing... or call it: moving to right or left, depending on where are you looking... :(