gpt4 book ai didi

openGL旋转与光照问题

转载 作者:行者123 更新时间:2023-12-02 06:57:36 25 4
gpt4 key购买 nike

我想在我的世界里画一辆车。但是当我的车旋转时,我的照明有问题,当汽车旋转时,灯的位置似乎发生了变化;但是当我用 glut 函数绘制简单的立方体时,它可以正常工作。

无效 mydisplay(){

glLoadIdentity()
glDisable(GL_LIGHT0);
glColorMaterial ( GL_FRONT_AND_BACK, GL_DIFFUSE) ;
glColor3f(1.0,1.0,1.0);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
p2[0]=50.0;
p2[1]=3.0;
p2[2]=0.0;
glLightfv(GL_LIGHT0,GL_POSITION,p2);
glEnable(GL_LIGHT0);
gluLookAt(50.0,3.0,0.0,0.0,0.0,0.0,0.0,1.0,0.0);
glPushMatrix();
glRotatef(tet,0.0,1.0,0.0);
glutSolidCube(20);
glPopMatrix();
tet+=3.141592653/4;
glutSwapBuffers();

}

当 glutSolidCube(20);更改我的绘图代码,它的工作方式很糟糕我的代码:

无效绘图(){

glEnableClientState(GL_VERTEX_ARRAY);
GLfloat CubeVertex[]={ -20.0,0.0,10.0,//\/\/\/\/\/\\\///\/\/\/\/\/\/\/\/\/\/\/\/\/\/
-20.0,0.0,-10.0,
-20.0,3.0,-10.0,
-20.0,3.0,10.0, ///BIG CUBE
20.0,0.0,10.0,
20.0,0.0,-10.0,
20.0,3.0,-10.0,
20.0,3.0,10.0,////////\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/
-10.0,3.0,10.0,
-10.0,3.0,-10.0,
-10.0,5.0,-10.0,
-10.0,5.0,10.0, //SMALL CUBE
10.0,3.0,10.0,
10.0,3.0,-10.0,
10.0,5.0,-10.0,
10.0,5.0,10.0,//\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\//
-100.0,-2.4,100.0,
-100.0,-2.4,-100.0, //FLOOR
100.0,-2.4,100.0,
100.0,-2.4,-100.0
};//\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\\/\//
GLubyte big_back[]={0,3,2,1};
GLubyte big_front[]={4,5,6,7};
GLubyte big_left[]={4,0,3,7};
GLubyte big_right[]={1,2,6,5};
GLubyte big_up[]={2,3,7,6};
GLubyte big_down[]={0,1,5,4};
GLubyte small_back[]={9,10,11,8};
GLubyte small_front[]={12,13,14,15};
GLubyte small_left[]={8,11,15,12};
GLubyte small_right[]={9,10,14,13};
GLubyte small_up[]={10,11,15,14};
GLubyte floor[]={16,17,19,18};
GLsizei count[]={4,4,4,4,4,4,4,4,4,4,4,4};
GLvoid* indices[12]={big_back,big_front,big_left,big_right,big_up,big_down,small_back,small_front,small_left,small_right,small_up,floor};
glVertexPointer(3,GL_FLOAT,0,CubeVertex);
for(int i=0;i<12;i++){//////////////////glMultiDrawElement////////////////
if(count[i]>0)
glDrawElements(GL_QUADS,count[i],GL_UNSIGNED_BYTE,indices[i]);
}//////////////////////////////glMultiDrawElements//////////////////////

}

谢谢。

最佳答案

您可以在这里找到答案:http://www.opengl.org/resources/faq/technical/lights.htm部分:18.050 如何让我的灯光移动或不移动并控制灯光位置?

关于openGL旋转与光照问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3306524/

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