티스토리 뷰

프로그래밍/OpenGL

태양계모델링

문정환 2008. 10. 31. 07:39
///////코드 6-6 태양계모델링//
#include<glut.h>
#include<gl.h>
#include<glu.h>
static int Day=0,Time=0;
void MyDisplay()
{
 glClear(GL_COLOR_BUFFER_BIT);
 glMatrixMode(GL_MODELVIEW);
 glLoadIdentity();
 glColor3f(1.0,0.0,0.0);
 glutSolidSphere(0.2,20,16);
 glPushMatrix();
 glRotatef((GLfloat)Day,0.0,1.0,0.0);
 glTranslatef(0.7,0.0,0.0);
 glRotatef((GLfloat)Time,0.0,1.0,0.0);
 glColor3f(0.5,0.6,0.7);
 glutWireSphere(0.1,10,8);
 glPushMatrix();
  glRotatef((GLfloat)Time,0.0,1.0,0.0);
  glTranslatef(0.2,0.0,0.0);
  glColor3f(0.9,0.8,0.2);
  glutWireSphere(0.04,10,8);
  glPopMatrix();
  glPopMatrix();
  glutSwapBuffers();
}
void MyKeyboard(unsigned char key, int x, int y)
{
 switch(key){
 case 'd':
  Day=(Day+10)%360;
  glutPostRedisplay();
  break;
 case 't':
  Time=(Time+5)%360;
  glutPostRedisplay();
  break;
 default:
  break;
 }
}
int main(int argc, char** argv)
{
 glutInit(&argc,argv);
 glutInitDisplayMode(GLUT_RGB|GLUT_DOUBLE);
 glutInitWindowSize(500,500);
 glutInitWindowPosition(0,0);
 glutCreateWindow("태양계");
 glClearColor(1.0,1.0,1.0,1.0);
 glMatrixMode(GL_PROJECTION);
 glLoadIdentity();
 glOrtho(-1.0,1.0,-1.0,1.0,-1.0,1.0);
 glutDisplayFunc(MyDisplay);
 glutKeyboardFunc(MyKeyboard);
 glutMainLoop();
 return 0;
}

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함