如何在 OpenGL 中减少第一人称拍摄相机对象
How to decrease first person shooting camera object in OpenGL
我正在制作 3d open gl 项目,其中包含作为射击子弹的相机对象,但它以非常大的尺寸渲染并且包含整个屏幕的白线,就像这样
我想将小尺寸的物体显示为相机的中心如何做到这一点
代码在这里
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();
我是游戏编程的新手,遇到了这个问题?
您没有正确设置投影矩阵。
您需要将模式设置为GL_PROJECTION,然后将投影矩阵设置为注视目标(射手的关注对象)并具有正确的视角和正确的视野。
然后设置modelview矩阵,mode GL_MODELVIEW.
需要放置瞄准具,使其正对着相机,而相机也正对着它。所以在射击者的眼睛和他的注意力对象之间的线上,垂直于它。在模型视图矩阵中执行此操作,并在模型上再次调用 gluLookAt。
(最终投影和模型视图成倍增加,但 Open GL 会为您处理)。
我正在制作 3d open gl 项目,其中包含作为射击子弹的相机对象,但它以非常大的尺寸渲染并且包含整个屏幕的白线,就像这样
我想将小尺寸的物体显示为相机的中心如何做到这一点
代码在这里
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();
我是游戏编程的新手,遇到了这个问题?
您没有正确设置投影矩阵。
您需要将模式设置为GL_PROJECTION,然后将投影矩阵设置为注视目标(射手的关注对象)并具有正确的视角和正确的视野。 然后设置modelview矩阵,mode GL_MODELVIEW.
需要放置瞄准具,使其正对着相机,而相机也正对着它。所以在射击者的眼睛和他的注意力对象之间的线上,垂直于它。在模型视图矩阵中执行此操作,并在模型上再次调用 gluLookAt。
(最终投影和模型视图成倍增加,但 Open GL 会为您处理)。