gpt4 book ai didi

c++ - 把相机放在我的天空盒里

转载 作者:行者123 更新时间:2023-11-28 08:26:52 25 4
gpt4 key购买 nike

所以我正在做家庭作业,我已经成功地创建了我的天空盒,它看起来是正确的,唯一的问题是我的相机在天空盒之外。

我尝试了 gluLookAt 命令,想着也许这会让我专注于盒子,但它没有用。这是我现在拥有的代码。如果有人能让我知道我做错了什么,将不胜感激:

 gluLookAt(
0,0,0,
0,0,0
0,1,0);
glPushMatrix();
//load identity matrix
glLoadIdentity();

//update x, y and z rotation directions
glRotatef(currentRotation[1], 1.0, 0.0, 0.0); //x rotation
glRotatef(currentRotation[2], 0.0, 1.0, 0.0); //y rotation
glRotatef(currentRotation[3], 0.0, 0.0, 1.0); //z rotation
/*
//update scale of display
glScalef(currentScaling[1],
currentScaling[2],
currentScaling[3]);*/

//translate the image
glTranslatef(currentTranslation[1],
currentTranslation[2],
currentTranslation[3]);

/* Clear buffers */
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_TEXTURE_2D); // Enable texturing from now on


//front quadrant
glBindTexture(GL_TEXTURE_2D,frontTextureId); // select which texture to use
glBegin(GL_QUADS);
glColor3f(1.0, 1.0, 1.0);
glTexCoord2f(1.0 ,0.0); glVertex3f(-0.5, 0.5, 0.5);
glTexCoord2f(0.0 ,0.0); glVertex3f(0.5, 0.5, 0.5);
glTexCoord2f(0.0 ,1.0); glVertex3f(0.5, 0.5, -0.5);
glTexCoord2f(1.0 ,1.0); glVertex3f(-0.5, 0.5, -0.5);
glEnd();

//left quadrant
glBindTexture(GL_TEXTURE_2D, leftTextureId);
glBegin(GL_QUADS);
glColor3f(1.0, 1.0, 1.0);
glTexCoord2f(0.0, 1.0); glVertex3f(-0.5, 0.5, -0.5);
glTexCoord2f(1.0, 1.0); glVertex3f(-0.5, -0.5, -0.5);
glTexCoord2f(1.0, 0.0); glVertex3f(-0.5, -0.5, 0.5);
glTexCoord2f(0.0, 0.0); glVertex3f(-0.5, 0.5, 0.5);
glEnd();

//back quadrant
glBindTexture(GL_TEXTURE_2D, backTextureId);
glBegin(GL_QUADS);
glColor3f(1.0, 1.0, 1.0);
glTexCoord2f(1.0, 1.0); glVertex3f(0.5, -0.5, -0.5);
glTexCoord2f(1.0, 0.0); glVertex3f(0.5, -0.5, 0.5);
glTexCoord2f(0.0, 0.0); glVertex3f(-0.5, -0.5, 0.5);
glTexCoord2f(0.0, 1.0); glVertex3f(-0.5, -0.5, -0.5);
glEnd();

//right quadrant
glBindTexture(GL_TEXTURE_2D, rightTextureId);
glBegin(GL_QUADS);
glColor3f(1.0, 1.0, 1.0);
glTexCoord2f(1.0, 1.0); glVertex3f(0.5, 0.5, -0.5);
glTexCoord2f(1.0, 0.0); glVertex3f(0.5, 0.5, 0.5);
glTexCoord2f(0.0, 0.0); glVertex3f(0.5, -0.5, 0.5);
glTexCoord2f(0.0, 1.0); glVertex3f(0.5, -0.5, -0.5);
glEnd();

//up quadrant
glBindTexture(GL_TEXTURE_2D, upTextureId);
glBegin(GL_QUADS);
glColor3f(1.0, 1.0, 1.0);
glTexCoord2f(0.0, 0.0); glVertex3f(-0.5, -0.5, 0.5);
glTexCoord2f(1.0, 0.0); glVertex3f(-0.5, 0.5, 0.5);
glTexCoord2f(1.0, 1.0); glVertex3f(0.5, 0.5, 0.5);
glTexCoord2f(0.0, 1.0); glVertex3f(0.5, -0.5, 0.5);
glEnd();

//down quadrant
glBindTexture(GL_TEXTURE_2D, downTextureId);
glBegin(GL_QUADS);
glColor3f(1.0, 1.0, 1.0);
glTexCoord2f(0.0, 0.0); glVertex3f(-0.5, -0.5, -0.5);
glTexCoord2f(0.0, 1.0); glVertex3f(-0.5, 0.5, -0.5);
glTexCoord2f(1.0, 1.0); glVertex3f(0.5, 0.5, -0.5);
glTexCoord2f(1.0, 0.0); glVertex3f(0.5, -0.5, -0.5);
glEnd();

感谢您提供的任何帮助!

最佳答案

我认为你的问题出在 glulookat 上

尝试使用这个值

 gluLookAt(0.0, 0.0 , 2.0 , 
0.0, 0.0, 0.0,
0.0, 1.0, 0.0);

关于c++ - 把相机放在我的天空盒里,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3743527/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com