float ColorePannello(float k)
{
// Calculates the color of the loading panel (the moving white light)
k=1-k/var.fattpannello;//var.fattpannello是逐渐减小的,也就是说对于同一个传进来的参数k,返回值逐渐减小。也就是偏于0.
//对于相同的var.fattpannello随着传入的k的增大,相应的返回值逐渐减小,也就是偏于0.
//所以这里就出现了三个趋势,随着var.pannello的减小,整体的亮度是减小的直至消失。
//一个绕(0.0, 0.0,0.2)为中心的圆弧上的点为中心的由内到外亮度逐渐减小的亮斑。
//距离中心点越远的点即k值越大,则返回值越小,则z坐标越小,则相应的离屏幕越近。
//这里也产生了光照效果。在没有光照的情况下,使用glColor3f或glColor4f决定了物体的亮度,无论在有纹
//理还是没有纹理的情况下。
return k;
}
void Pannello(void) // Loading Panel
{
int x,y;
float xf,yf,zf=(float)0.2;
float fx,fy;
float d1,d2,d3,d4;
gluLookAt(0,0,2.2,0,0,0,0.0f,1.0f,0.0f);//调节视点,相应的视景体也将发生改变,从而影响到glTranslatef的效果。默认视点位于
//(0.0, 0.0, 0.0)处。通过调用这个函数,视点沿Z轴正方向远离默认视点,相应的
//将会变小。
fx=(float)1/BUFCX; // For the texture coordinates
fy=(float)1/BUFCY;
// Draws the background
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[3]);
for(y=0;y<BUFCY-1;y++)
{
for(x=0;x<BUFCX-1;x++)
{
xf=sin(var.an*3.141/90);
yf=cos(var.an*3.141/90);//定义了一个圆心为(0.0, 0.0)的圆弧。
d1=sqrt( (bufC[x][y].x-xf)*(bufC[x][y].x-xf)+(bufC[x][y].y-yf)*(bufC[x][y].y-yf)+(bufC[x][y].z-zf)*(bufC[x][y].z-zf) );
d2=sqrt( (bufC[x+1][y].x-xf)*(bufC[x+1][y].x-xf)+(bufC[x+1][y].y-yf)*(bufC[x+1][y].y-yf)+(bufC[x+1][y].z-zf)*(bufC[x+1][y].z-zf) );
d3=sqrt( (bufC[x+1][y+1].x-xf)*(bufC[x+1][y+1].x-xf)+(bufC[x+1][y+1].y-yf)*(bufC[x+1][y+1].y-yf)+(bufC[x+1][y+1].z-zf)*(bufC[x+1][y+1].z-zf) );
d4=sqrt( (bufC[x][y+1].x-xf)*(bufC[x][y+1].x-xf)+(bufC[x][y+1].y-yf)*(bufC[x][y+1].y-yf)+(bufC[x][y+1].z-zf)*(bufC[x][y+1].z-zf) );
//bufC是x,y分别是+-1.25,+-0.92,z轴为-0.1的矩形区域。
d1=ColorePannello(d1);
d2=ColorePannello(d2);
d3=ColorePannello(d3);
d4=ColorePannello(d4);
glBegin(GL_QUADS);
glColor3f(d1,d1,d1); d1*=8; glTexCoord2f((float)x*fx,(float)y*fy); glVertex3f(bufC[x][y].x,bufC[x][y].y,d1*bufC[x][y].z);
glColor3f(d2,d2,d2); d2*=8; glTexCoord2f((float)x*fx+fx,(float)y*fy); glVertex3f(bufC[x+1][y].x,bufC[x+1][y].y,d2*bufC[x+1][y].z);
glColor3f(d3,d3,d3); d3*=8; glTexCoord2f((float)x*fx+fx,(float)y*fy+fy); glVertex3f(bufC[x+1][y+1].x,bufC[x+1][y+1].y,d3*bufC[x+1][y+1].z);
glColor3f(d4,d4,d4); d4*=8; glTexCoord2f((float)x*fx,(float)y*fy+fy); glVertex3f(bufC[x][y+1].x,bufC[x][y+1].y,d4*bufC[x][y+1].z);
glEnd();
}
}
glDisable(GL_TEXTURE_2D);
// Move the light around the screen center
var.an+=0.2;
var.fattpannello-=0.002;
if(var.fattpannello<=(float)0.244)
{
var.fattpannello=(float)2.5;
var.an=0;
}
}