Jump to content
  • Advertisement
Sign in to follow this  
Ainokea

OpenGL Annoying camera problem.

This topic is 5396 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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: |-|-|-|-|-|-| |-|-|-|-|-|-| |-|-|-|-|-|-| |-|-|-|-|-|-| 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

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Dont u need to set viewport and stuff?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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'.

Share this post


Link to post
Share on other sites
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);

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!