thegreatpl

07-01-2011, 07:51 AM

Ok, so I am very new at coding opengl, and after getting partway through lighthouse 3d's tutorial for glut, I think it might be pretty easy to modify the code to allow me to remake a game I had made before in 3d (stupid stupid stupid...).

My basic idea was to add in a 3rd dimension of movement to the lighthouse movement code. So, I quickly copy the movement code, change the variables so they relate to Y, and think everything is dandy. Right up until I test it fully. Then I keep running into problems, which I think I have solved, only to find that it still is not working.

I'm not actually sure if this should be in this section of the forum, or another, since I think the fundermental problem is my maths.

The main problem areas of code are:

void computeDir(float deltaAngle)

{

angle += deltaAngle;

lx = sin(angle);

lz = -cos(angle);

//ly = -sin(angleY);

}

void computeY (float deltaY)

{

angleY+= deltaY;

ly = -sin(angleY);

lz = -cos(angleY);

//lx = sin(angle);

}

I am pretty sure that I should either be doing something with ly when calculating X, and lx when calculating Y. These functions are only called when there is a change to either deltaAngle or deltaY.

The code itself is to calculate the direction that the camera is pointing. Since I am trying to keep it nice and simple and am thus using gluLookAt, which I'm pretty sure is a glut function.

This code is used to display the camera. x, y, z are the coords of the camera, while the second row is the direction that the camara is facing.

gluLookAt( x, y, z,

x+lx, y+ly, z+lz,

0.0f, 1.0f, 0.0f);

ly, lx and lz represent the vector representing the camera's direction. They are also used in calculating the speed of the camera and drawing the "player" at the location of the camera.

Can someone please either tell me where my maths is wrong, or where my entire method is wrong and/or point me in the direction of a handy tutorial I can browse through at lesiure.

My basic idea was to add in a 3rd dimension of movement to the lighthouse movement code. So, I quickly copy the movement code, change the variables so they relate to Y, and think everything is dandy. Right up until I test it fully. Then I keep running into problems, which I think I have solved, only to find that it still is not working.

I'm not actually sure if this should be in this section of the forum, or another, since I think the fundermental problem is my maths.

The main problem areas of code are:

void computeDir(float deltaAngle)

{

angle += deltaAngle;

lx = sin(angle);

lz = -cos(angle);

//ly = -sin(angleY);

}

void computeY (float deltaY)

{

angleY+= deltaY;

ly = -sin(angleY);

lz = -cos(angleY);

//lx = sin(angle);

}

I am pretty sure that I should either be doing something with ly when calculating X, and lx when calculating Y. These functions are only called when there is a change to either deltaAngle or deltaY.

The code itself is to calculate the direction that the camera is pointing. Since I am trying to keep it nice and simple and am thus using gluLookAt, which I'm pretty sure is a glut function.

This code is used to display the camera. x, y, z are the coords of the camera, while the second row is the direction that the camara is facing.

gluLookAt( x, y, z,

x+lx, y+ly, z+lz,

0.0f, 1.0f, 0.0f);

ly, lx and lz represent the vector representing the camera's direction. They are also used in calculating the speed of the camera and drawing the "player" at the location of the camera.

Can someone please either tell me where my maths is wrong, or where my entire method is wrong and/or point me in the direction of a handy tutorial I can browse through at lesiure.