简体   繁体   English

如何减少OpenGL中的第一人称拍摄相机对象

[英]How to decrease first person shooting camera object in OpenGL

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我正在制作 3d open gl 项目,其中包含相机对象作为射击子弹,但它以非常大的尺寸渲染并包含像这样的白线的整个屏幕在此处输入图片说明

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 ?我是游戏编程的新手并陷入了这个问题?

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.您需要将模式设置为 GL_PROJECTION,然后设置投影矩阵以查看目标(射手的注意对象)并具有正确视野的正确透视。 Then set the modelview matrix, mode GL_MODELVIEW.然后设置modelview矩阵,模式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.在模型视图矩阵中执行此操作,并在模型上再次调用 gluLookAt。

(Ultimately projection and modelview get multiplied, but Open GL handles that for you). (最终投影和模型视图会成倍增加,但 Open GL 会为您处理)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM