|-|-|-|-|-|-|
|-|-|-|-|-|-|
|-|-|-|-|-|-|
|-|-|-|-|-|-|
But I want something that has depth like the camera tutorials at
gametutorials
Here is my code for drawing the ground:
void DrawGround()
{
// Turn the lines GREEN
glColor3ub(0, 255, 0);
// Draw a 1x1 grid along the X and Z axis'
for(float i = -50; i <= 50; i += 1)
{
// Start drawing some lines
glBegin(GL_LINES);
// Do the horizontal lines (along the X)
glVertex3f(-50, 0, i);
glVertex3f(50, 0, i);
// Do the vertical lines (along the Z)
glVertex3f(i, 0, -50);
glVertex3f(i, 0, 50);
// Stop drawing lines
glEnd();
}
}
and here is what my camera code looks like:
//------------------snip-----------------
//here are my vectors for position, view(where its looking) and //what way the camera thinks is up
Vector3 pos(0.0, 0.0, 0.0);
Vector3 view(0.0, 1.5, 0.5);
Vector3 up(0.0f,0.0f,0.5f);
//-------------------snip-----------------
//and now I tell opengl where to look
gluLookAt(pos.x,pos.y,pos.z,view.x,view.y,view.z,up.x,up.y,up.z);
//-------------------snip-----------------
EDIT:hmm maybe this should have been in the math forum
Annoying camera problem.
Im writing a tanks clone (to get away from my enging wichis starting to get boring) and already I am having problems. When I try to draw the ground I get a grid that looks something like this:
It looks to me like you've defined the z-axis as your up-axis (in glulookat). Therefore the level plane infront of you (where you want the grid to lay) is in the xy-plane.
Your grid code assumes the y-axis is the up-axis (as it's always set to 0 for both sets of lines, and you want the lines at 'ground' height).
Try changing your vertex code to:
glVertex3f(-50, i, 0);
glVertex3f(50, i, 0);
glVertex3f(i, -50, 0);
glVertex3f(i, 50, 0);
HTH,
Jim.
Your grid code assumes the y-axis is the up-axis (as it's always set to 0 for both sets of lines, and you want the lines at 'ground' height).
Try changing your vertex code to:
glVertex3f(-50, i, 0);
glVertex3f(50, i, 0);
glVertex3f(i, -50, 0);
glVertex3f(i, 50, 0);
HTH,
Jim.
The only thing I notice is that both the grid and your camera are at y = 0. If you can see anything, then it sounds like you have an orthographic projection set up. You need to use a perspective projection (glFrustum instead of glOrtho) to get any kind of 'depth'.
either draw everything using z as your up, or change
Vector3 up(0.0f,0.0f,0.5f);
to
Vector3 up(0.0f,0.5f,0.0f);
Vector3 up(0.0f,0.0f,0.5f);
to
Vector3 up(0.0f,0.5f,0.0f);
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement