我有一个简单的研究项目,代表一些太空恒星的系统。我有一颗恒星和几颗行星,卫星围绕恒星旋转。我正在使用深度缓冲区,但行星总是在恒星前面,即使行星应该被恒星遮挡。问题原因可能是什么?
void drawPlanet(float orbitRadius, float planetRadius, float daysInYear, float hoursInDay){
static float year = 0;
static float days = 0;
static float hours = 0;
glPushMatrix();
glRotatef(year, 0, 1, 0);
glTranslatef(orbitRadius, 0 ,0);
glRotatef(days, 1, 2, 0);
glutWireSphere(planetRadius, 20, 16);
drawLuna(0.3, 0.1, 30, 15);
glPopMatrix();
hours++;
days = hours/hoursInDay;
year=days/daysInYear;
}
void display(void){
glClear(GL_COLOR_BUFFER_BIT);
glLoadIdentity();
gluLookAt(0,0,5, 0, 0, 0, 0 ,1, 0);
glColor3f(1.0, 0.647059, 0.00);
glutSolidSphere(0.5, 20, 16);
glColor3b(197, 96, 63);
drawPlanet(2, 0.2, 50, 12);
drawPlanet(1, 0.15, 30, 15);
glFlush();
}
int main(int argc, char** argv)
{
....
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glEnable(GL_DEPTH_TEST);
....
}