OpenGL – 조명(태양계)

(광원) , ,  달, , 금성의 , 금성의 위성의 위성

#include GLint theta = 0; GLint pi = 0; GLint pi2 = 0; GLint s = 0;GLint v = 0;GLint v2 = 0;GLdouble radius=1; GLfloat mat_amb[4] = {1.0,0.0,0.0,1.0};GLfloat mat_dif[4] = {0.6,0.2,0.6,0.0}; GLfloat mat_spc[4] = {0.8,0.2,0.8,0.5};GLfloat mat_emi[4] = {0.1,0.1,0.0,0.0};GLfloat mat_shi[4] = {100.0}; GLfloat mat_emi_sun[4] = {1.0, 0.1, 0.0, 0.0};GLfloat mat_emi_other[4] = {1.0, 0.5, 0, 0.0};GLfloat mat_dif_sun[4] = {0.4, 0.1, 0.3, 0.0}; GLfloat mat_dif_venus[4] = {0, 0.8, 0.8, 0.0}; GLfloat mat_dif_venus2[4] = {1, 0.3, 0, 0.0}; GLfloat mat_dif_earth[4] = {0, 0, 1, 0.0}; GLfloat mat_dif_moon[4] = {0.8, 0.8, 0, 0.0}; void init_light(void) {   static GLfloat lit_amb[4]={1.0, 1.0, 1.0, 0.0};    static GLfloat lit_dif[4]={1.0, 1.0, 1.0, 0.0};     static GLfloat lit_spc[4]={1.0, 1.0, 1.0, 0.0};    static GLfloat lit_pos[4]={0,0,0,1};    glLightfv(GL_LIGHT0, GL_AMBIENT, lit_amb);     glLightfv(GL_LIGHT0, GL_DIFFUSE, lit_dif);     glLightfv(GL_LIGHT0, GL_SPECULAR, lit_spc);     glLightfv(GL_LIGHT0, GL_POSITION, lit_pos);     glEnable(GL_LIGHT0);     glEnable(GL_LIGHTING);     } void Display(void){    //glMatrixMode(GL_MODELVIEW);    glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);    glEnable(GL_DEPTH_TEST);    glLoadIdentity();    //glShadeModel(GL_FLAT);    init_light();    glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT, mat_amb);    glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR, mat_spc);    glMaterialfv(GL_FRONT_AND_BACK,GL_SHININESS, mat_shi);    // 태양    GLfloat sun[] = {1,0,0,1};    glMaterialfv(GL_FRONT, GL_AMBIENT, mat_emi_sun);    glScalef(1.0,1.0,1.0);    glColor3f(1, 0, 0);    glRotatef(s+50, 0, 0, 1);    glutSolidSphere(0.7,20,20);         // 지구    glPushMatrix();    GLfloat earth[] = { 0,0,0.7,1 };    glMaterialfv(GL_FRONT, GL_AMBIENT, mat_dif_earth);    GLfloat light_earth[] = { 0,0,0.7,1 };    glLightfv(GL_LIGHT1, GL_AMBIENT, light_earth);    glColor3f(0, 0, 1);    //glPushMatrix();    glRotatef(theta+50, 0, 0, 1);    glTranslatef(4, 0, 0);    glutSolidSphere(0.3, 20, 20);         // 달    glPushMatrix();    GLfloat moon[] = { 0.5,1,1,1 };    glMaterialfv(GL_FRONT, GL_AMBIENT, mat_dif_moon);    GLfloat light_moon[] = { 0.2,0.7,0.7,1 };    glLightfv(GL_LIGHT2, GL_AMBIENT, light_moon);    //glColor3f(0,0,0);    glColor3f(0.8, 0.8, 0);    glRotatef(pi, 0.0f, 0.0f, 1.0f);    glTranslatef(0.8, 0.0f, 0.0f);    glutSolidSphere(0.15, 20, 20);    glPopMatrix();    glPopMatrix();         // 금성    //glPushMatrix();    glPushMatrix();//GLfloat geum[] = { 0,1,1,0 };glMaterialfv(GL_FRONT, GL_AMBIENT, mat_emi_other);GLfloat light_geum[] = { 0.2,0.7,0.7,1  };glLightfv(GL_LIGHT3, GL_AMBIENT, light_geum);glColor3f(1, 0.5, 0);glRotatef(pi2, 0.0f, 1, 1.0f);glTranslatef(1.8, 0.0f, 0.0f);glutSolidSphere(0.25, 20, 20);//glPopMatrix();    // 금성 위성glPushMatrix();// glPushMatrix();GLfloat vinus[] = { 0.5,1,1,1 };glMaterialfv(GL_FRONT, GL_AMBIENT, mat_dif_venus);GLfloat light_vinus[] = { 0.2,0.7,0.7,1 };glLightfv(GL_LIGHT2, GL_AMBIENT, light_vinus);glColor3f(0, 0.8, 0.8);glRotatef(v, 0, 0.0f, 1.0f);glTranslatef(1.5, 0, 0.0f);glutSolidSphere(0.15, 20, 20); // 금성 위성의위성glPushMatrix();GLfloat vinus2[] = { 0.5,1,1,1 };glMaterialfv(GL_FRONT, GL_AMBIENT, mat_dif_venus2);GLfloat light_vinus2[] = { 0.2,0.7,0.7,1 };glLightfv(GL_LIGHT2, GL_AMBIENT, light_vinus2);//glColor3f(0,0,0);glColor3f(1, 0.3, 0);glRotatef(0.0f, v2, 0.0f, 1.0f);glTranslatef(0, 0.7, 0.0f);glutSolidSphere(0.1, 20, 20);glPopMatrix();glPopMatrix();    glPopMatrix();    glFlush();            glutSwapBuffers();} void reshape(int h, int w) {glMatrixMode(GL_PROJECTION);glOrtho(-5, 5, -5, 5, -5, 5);gluLookAt(0, 0, -2, 0, 0, 0, 0, 1, 0);glMatrixMode(GL_MODELVIEW);// glFlush();    } void MyTimer(int Value){       theta = (theta+10) 퍼.센트 360;       s = (s) 퍼.센트 360;   v = (v + 30) 퍼.센트 360;   v2 = (v2 + 240) 퍼.센트 360;       //glutPostRedisplay();       pi = (pi + 30) 퍼.센트 360;       pi2 = (pi2+10) 퍼.센트 360;       glutPostRedisplay();        //glutTimerFunc(100,MyTimer,1);        glutTimerFunc(200, MyTimer, 1);} int main(void){glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);glutInitWindowSize(500, 500);glLoadIdentity();glutCreateWindow(“OpenGL”);//init_light();glutDisplayFunc(Display);//glutTimerFunc(100,MyTimer,1);glutTimerFunc(100, MyTimer, 1);//glutIdleFunc(Idletest);glutReshapeFunc(reshape);glutMainLoop();}

>

>