How to decrease first person shooting camera object in OpenGL

279 views Asked by At

I am making 3d open gl project which contain camera object as a shooting bullet but it is render with very big size and contain whole screen in white lines like this enter image description here

i want to display object as a center of camera with small size how to do this

code is here

static GLdouble ort1[] = { -200, 200, -33, 140 };
static GLdouble viewer[] = { 525, 25, -180 };
static GLdouble up[] = { 0, 1, 0 };

static GLdouble objec[] = { 525.0, 25, -350 };


    glClear(GL_COLOR_BUFFER_BIT);

        glLoadIdentity(); 
        gluLookAt(viewer[0], viewer[1], viewer[2], objec[0], objec[1], objec[2], 0, 1, 0);

        glMatrixMode(GL_PROJECTION);
        //glOrtho(-1, 1, -1, 1, -1, 100);
        glLoadIdentity();
        //gluPerspective(fov, 1.333, n, f);
        gluPerspective(fov, 1, 0.001, 1000);
        //gluPerspective(50, screenWidth / screenHeight, 0.000001, 2000);
        glPointSize(2.0);
        glMatrixMode(GL_MODELVIEW);
        //cube.drawFace(10, 20, 10, 22);
        drawFlorr();

        glPushMatrix();
        glTranslatef(viewer[0], viewer[1], viewer[2]); // Translation to the camera center
        glRotatef(camAngle * 57.2957795, 0, 1, 0); // Rotate to correspond to the camera
        //glTranslatef(0.016, 0, -0.05); // Offset to draw the object

        glutWireCone(0.005, 1, 20, 20);
        glPopMatrix();

i am new in game prgramming and stuck in this problem ?

1

There are 1 answers

0
Malcolm McLean On BEST ANSWER

You're not setting up the projection matrix correctly.

You need to set the mode to GL_PROJECTION, then set the projection matrix to look at the target (shooter's object of attention) and have a perspective correct with right field of view. Then set the modelview matrix, mode GL_MODELVIEW.

The gun sight needs to be placed so that it is looking at the camera, and the camera is looking at it. So on the line between the shooter's eyes and his object of attention, perpendicular to it. Do this in the modelview matrix, and call gluLookAt again, on the model.

(Ultimately projection and modelview get multiplied, but Open GL handles that for you).