openGL固定摄像头
openGL fixing camera?
此代码生成多维数据集。代码工作正常。但是,如果我增加顶点值,它不会显示在显示中。我想要更大的立方体,但更大的多维数据集不会显示在显示器中。我该怎么修??谢谢你的回答。。。
#define A glVertex3f (-0.5, 0.5, -0.5)
#define B glVertex3f (-0.5, -0.5, -0.5)
#define C glVertex3f ( 0.5, -0.5, -0.5)
#define D glVertex3f ( 0.5, 0.5, -0.5)
#define E glVertex3f (-0.5, 0.5, 0.5)
#define F glVertex3f (-0.5, -0.5, 0.5)
#define G glVertex3f ( 0.5, -0.5, 0.5)
#define H glVertex3f ( 0.5, 0.5, 0.5)
#define _USE_MATH_DEFINES
#include <cmath>
#include <stdlib.h>
#include <math.h>
#include <glut.h>
float distance = 5.0;
int longitude = 0, latitude = 0, ainc = 5;
int lastx = -1, lasty = -1;
void display (void)
{
float xc, yc, zc;
int type = GL_POLYGON; // or GL_LINE_LOOP
xc = distance * cos (latitude /180.0*M_PI) * cos (longitude/180.0*M_PI);
yc = distance * sin (latitude /180.0*M_PI);
zc = distance * cos (latitude /180.0*M_PI) * sin (longitude/180.0*M_PI);
glLoadIdentity ();
gluLookAt (xc, yc, zc, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Sides of the cube as loops or polygons, in anti-clockwise order.
glColor3f (1.0, 0.0, 0.0);
glBegin (type); A; B; C; D; glEnd(); // front
glColor3f (0.0, 1.0, 0.0);
glBegin (type); H; E; F; G; glEnd(); // back
glColor3f (0.0, 0.0, 1.0);
glBegin (type); B; C; G; F; glEnd(); // bottom
glColor3f (1.0, 0.0, 1.0);
glBegin (type); A; D; H; E; glEnd(); // top
glColor3f (0.0, 1.0, 1.0);
glBegin (type); A; E; F; B; glEnd(); // left
glColor3f (1.0, 1.0, 0.0);
glBegin (type); D; C; G; H; glEnd(); // right
glutSwapBuffers ();
}
void keyboard (unsigned char key, int x, int y)
{
switch (key) {
case 27: case 'q': case 'Q':
exit (EXIT_SUCCESS);
break;
}
}
void special (int key, int x, int y)
{
switch (key) {
case GLUT_KEY_UP:
distance *= 1.1;
break;
case GLUT_KEY_DOWN:
distance /= 1.1;
break;
}
glutPostRedisplay ();
}
void click (int button, int state, int x, int y)
{
if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) {
lastx = x;
lasty = y;
}
}
void mouse (int x, int y)
{
if (x > lastx) {
longitude = (longitude + ainc) % 360;
} else if (x < lastx) {
longitude = (longitude - ainc) % 360;
}
if (y > lasty) {
latitude = (latitude + ainc) % 360;
} else if (y < lasty) {
latitude = (latitude - ainc) % 360;
}
lastx = x;
lasty = y;
glutPostRedisplay ();
}
void reshape (int w, int h)
{
glViewport (0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective (65.0, (GLfloat) w / (GLfloat) h, 1.0, 20.0);
glMatrixMode (GL_MODELVIEW);
glLoadIdentity ();
glTranslatef (0.0, 0.0, -5.0);
}
int main (int argc, char *argv[])
{
glutInit (&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH);
glutCreateWindow (argv[0]);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluPerspective(50.0, 1.0, 3.0, 7.0);
glMatrixMode (GL_MODELVIEW);
glutDisplayFunc (display);
glutKeyboardFunc (keyboard);
glutSpecialFunc (special);
glutMouseFunc (click);
glutMotionFunc (mouse);
glutReshapeFunc (reshape);
glEnable (GL_DEPTH_TEST);
glutMainLoop ();
return EXIT_SUCCESS;
}
我怀疑是你的视角被打破了。你的近平面和远平面是3.0和7.0单位。如果将点移动到这些平面之外,它们将被删除。重塑窗口时也可以使用1.0和20.0,但除非有重塑事件,否则不会使用它们。
我不知道你的多维数据集使用了什么值,但我认为你超出了定义的范围。试着增加远近之间的差异,并确保你的立方体落在它们之间。
有关gluPerspective
的更多信息,请参阅文档。
要缩放对象的顶点,只需将它们乘以相同的数字。例如,如果要使立方体的大小增加一倍,请将所有顶点乘以2.0
。
如果立方体变得太大,以至于其正面位于"摄影机"后面,则它将不会渲染;如果设置不渲染面的"背面",则立方体将根本不会渲染(因为摄影机将在其中)。
您也可以使用glScalef(float x, float y, float z)
相关文章:
- OpenGL - 在抛出"__gnu_cxx::recursive_init_error"实例后终止调用?
- 了解 GLM- openGL 中的相机转换
- 如何在全屏模式下(在OpenGL中)使背景透明
- 为什么我不能使用 EGL 创建无头 OpenGl 上下文?
- OpenGL大的3D纹理(>2GB)非常慢
- OpenGl glm rotate
- C++atioglxx.pdb未加载错误glBufferData OpenGL
- OpenGL在启用深度测试时不会丢弃我的碎片
- OpenGL相机和相机空间转型的困惑
- OpenGL将纹理四边形渲染为(0,0)
- OpenGL 和 GLM 矩阵无法正确扩展,总是按比例缩小
- 发布旋转矩阵(openGL/glm)
- 如何在Visual Basic中使用矩形函数OpenGL绘制矩形
- 无法使用VAO和EBO(openGL)绘制多个对象
- 为什么我的点没有在 OpenGL 中绘制鼠标所在的位置?
- OpenGL 16 位模板缓冲区?
- 将QOpenGLWidget子类转换为使用Metal而不是OpenGL的子类是否可行?
- OpenCV 4.1.2 - 从网络摄像头获取帧并将其拆分
- openGL固定摄像头
- OpenGL+多个摄像头