Jump to content
  • Advertisement
Sign in to follow this  

OpenGL dissapearing objects

This topic is 2153 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

i have a problem where whenever u move the camera all the object on screen disappear here is my code

class camera
        GLfloat eye[3];
        GLfloat up[3];
        GLfloat side[3];
        GLfloat look[3];
        GLfloat matrix[3][3];
        GLfloat vertMatrix[3];
        GLfloat tmpMatrix[3];
        { // Camera Position
            eye[0] = 0.0f;  eye[1] = 0.0f;  eye[2] =  0.0f;
            up[0] = 0.0f;   up[1] = 1.0f;   up[2] =  0.0f;
            side[0] = 1.0f; side[1] = 0.0f; side[2] =  0.0f;
            look[0] = 0.0f; look[1] = 0.0f; look[2] = -1.0f;
            matrix = {
            {side[0] - eye[0], up[0] - eye[0], look[0] - eye[0]},
            {side[1] - eye[1], up[1] - eye[1], look[1] - eye[1]},
            {side[2] - eye[2], up[2] - eye[2], look[2] - eye[2]}};
        void updatePosi()
            glLoadIdentity();// Update the camera
            gluLookAt( eye[0], eye[1], eye[2], look[0], look[1], look[2], up[0] - eye[0], up[1] - eye[1], up[2] - eye[2]);
        void translatePosi(GLfloat x1, GLfloat y1, GLfloat z1)
            matrix = {
            {side[0] - eye[0], up[0] - eye[0], look[0] - eye[0]},
            {side[1] - eye[1], up[1] - eye[1], look[1] - eye[1]},
            {side[2] - eye[2], up[2] - eye[2], look[2] - eye[2]}
            vertMatrix = { x1, y1, -z1};
            tmpMatrix =  {matrix[0][0] * vertMatrix[0] + matrix[0][1]* vertMatrix[0] + matrix[0][2]* vertMatrix[0],
            matrix[1][0] * vertMatrix[1] + matrix[1][1]* vertMatrix[1] + matrix[1][2]* vertMatrix[1],
            matrix[2][0] * vertMatrix[2] + matrix[2][1]* vertMatrix[2] + matrix[2][2]* vertMatrix[2]};
            eye[0] += tmpMatrix[0];  eye[1] += tmpMatrix[1];  eye[2] +=  tmpMatrix[2];
            up[0] += tmpMatrix[0];   up[1] += tmpMatrix[1];   up[2] +=  tmpMatrix[2];
            side[0] += tmpMatrix[0]; side[1] += tmpMatrix[1]; side[2] +=  tmpMatrix[2];
            look[0] += tmpMatrix[0]; look[1] += tmpMatrix[1]; look[2] += tmpMatrix[2];

void display()
    glClearColor( 0.0, 0.0f, 0.0, 1.0f);

int main(int argc, char **args)
    glutInit(&argc, args);
    glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH);
    glutInitWindowSize(500, 500);
    glutInitWindowPosition(100, 100);
    glutCreateWindow("opengl mycode");
    return 0;


i 'm am very new to opengl so any help would be appreciated. 

Share this post

Link to post
Share on other sites

You shouldn't need all of that matrix stuff. Also, I think you've misunderstood the lookat arguments--they are the place that the camera is looking, not the vector to that place. Also, you misunderstand the up arguments. They are relative to the camera's position.


Try gluLookAt(4.0,4.0,4.0, 0.0,0.0,0.0, 0.0,1.0,0.0);, which represents a camera at (4,4,4) looking towards the point (0,0,0), pointing mostly upwards.




Share this post

Link to post
Share on other sites

Are you perhaps incrementing the camera position on key presses?
Remember that you are incrementing the camera by that value every frame, so it could be that your camera moves so fast that the objects appear to disappear instantly.

If so, try using very small values for the translation function and see if it works.

EDIT: Also like Geometrian said, your matrix stuff is overly complicated. And you should keep your lookAt up vector at (0.0, 1.0, 0.0).

Edited by __SKYe

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!