#include <windows.h> #include <gl\gl.h> #include <gl\glu.h> #include <gl\glaux.h> static LPCTSTR lpszAppName = "Solar System"; static HINSTANCE hInstance; GLfloat whiteLight[] = { 0.2f, 0.2f, 0.2f, 1.0f }; GLfloat sourceLight[] = { 0.8f, 0.8f, 0.8f, 1.0f }; GLfloat lightPos[] = { 0.0f, 0.0f, 0.0f, 1.0f }; float xRot = 0.0f; float yRot = 0.0f; inline void glRGB(int x, int y, int z) { glColor3ub((GLubyte)x, (GLubyte)y, (GLubyte)z); } LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam); // í~E~\í~T~L릿 // void SetDCPixelFormat(HDC hDC) { int nPixelFormat; static PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), // Size of this structure 1, // Version of this structure PFD_DRAW_TO_WINDOW | // Draw to Window (not to bitmap) PFD_SUPPORT_OPENGL | // Support OpenGL calls in window PFD_DOUBLEBUFFER, // Double buffered PFD_TYPE_RGBA, // RGBA Color mode 24, // Want 24bit color 0,0,0,0,0,0, // Not used to select mode 0,0, // Not used to select mode 0,0,0,0,0, // Not used to select mode 32, // Size of depth buffer 0, // Not used to select mode 0, // Not used to select mode PFD_MAIN_PLANE, // Draw in main plane 0, // Not used to select mode 0,0,0 }; // Not used to select mode // Choose a pixel format that best matches that described in pfd nPixelFormat = ChoosePixelFormat(hDC, &pfd); // Set the pixel format for the device context SetPixelFormat(hDC, nPixelFormat, &pfd); } void ChangeSize(GLsizei w, GLsizei h) { if(h == 0) h = 1; // Set Viewport to window dimensions glViewport(0, 0, w, h); // Calculate aspect ratio of the window GLfloat fAspect = (GLfloat)w/(GLfloat)h; // Set the perspective coordinate system glMatrixMode(GL_PROJECTION); glLoadIdentity(); // field of view of 45 degrees, near and far planes 1.0 and 425 gluPerspective(45.0f, fAspect, 1.0, 425.0); // Modelview matrix reset glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } // í~E~\í~T~L릿 ë~A~] // void SetupRC() { glEnable(GL_DEPTH_TEST); glFrontFace(GL_CCW); glEnable(GL_CULL_FACE); glEnable(GL_LIGHTING); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, whiteLight); glLightfv(GL_LIGHT0, GL_DIFFUSE, sourceLight); glLightfv(GL_LIGHT0, GL_POSITION, lightPos); glEnable(GL_LIGHT0); glEnable(GL_COLOR_MATERIAL); glColorMaterial(GL_FRONT, GL_AMBIENT_AND_DIFFUSE); glShadeModel(GL_SMOOTH); glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClearDepth(1.0f); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LEQUAL); glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); } void RenderScene() { static float fFar = -300.0f; static float fMoonRot = 0.0f; static float fVenusRot = 0.0f; static float fEarthRot = 0.0f; static float fMercuryRot = 0.0f; static float fMarsRot = 0.0f; static float fJupiterRot = 0.0f; static float fSaturnRot = 0.0f; static float fUranusRot = 0.0f; static float fNeptuneRot = 0.0f; static float fPlutoRot = 0.0f; glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glMatrixMode(GL_MODELVIEW); glPushMatrix(); // í~C~\ì~V~Q glLightfv(GL_LIGHT0, GL_POSITION, lightPos); glTranslatef(0.0f, 0.0f, fFar); glRGB(255,100,0); auxSolidSphere(30.0f); glRotatef(xRot, 1.0f, 0.0f, 0.0f); glRotatef(yRot, 0.0f, 1.0f, 0.0f); // ì~H~Xì~D± glPushMatrix(); glLightfv(GL_LIGHT0, GL_POSITION, lightPos); glRotatef(fMercuryRot, 0.0f, 1.0f, 0.0f); glRGB(0,0,255); glTranslatef(50.0f, 0.0f, 0.0f); auxSolidSphere(2.0f); glPopMatrix(); // ê¸~Hì~D± glPushMatrix(); glLightfv(GL_LIGHT0, GL_POSITION, lightPos); glRotatef(fVenusRot, 1.0f, 1.0f, 0.0f); glRGB(200,100,255); glTranslatef(0.0f, 0.0f, -70.0f); auxSolidSphere(5.0f); glPopMatrix(); // ì§~@구 glPushMatrix(); glLightfv(GL_LIGHT0, GL_POSITION, lightPos); glRotatef(fEarthRot, 1.0f, 0.0f, 0.0f); glRGB(0,255,255); glTranslatef(0.0f, 0.0f, -90.0f); auxSolidSphere(6.0f); // ë~K¬ glRGB(200,200,200); glRotatef(fMoonRot, 1.0f, 0.0f, 0.0f); glTranslatef(0.0f, 0.0f, -8.0f); auxSolidSphere(1.0f); fMoonRot += 10.0f; if(fMoonRot > 360.0f) fMoonRot = 0.0f; glPopMatrix(); // í~Y~Tì~D± glPushMatrix(); glLightfv(GL_LIGHT0, GL_POSITION, lightPos); glRotatef(fMarsRot, -1.0f, 1.0f, 0.0f); glRGB(255,0,0); glTranslatef(0.0f, 0.0f, -110.0f); auxSolidSphere(4.0f); glPopMatrix(); // 목ì~D± glPushMatrix(); glLightfv(GL_LIGHT0, GL_POSITION, lightPos); glRotatef(fJupiterRot, 1.0f, -1.0f, 0.0f); glRGB(255,100,0); glTranslatef(0.0f, 0.0f, -130.0f); auxSolidSphere(10.0f); glPopMatrix(); // í~F| ì~D± glPushMatrix(); glLightfv(GL_LIGHT0, GL_POSITION, lightPos); glRotatef(fSaturnRot, 0.0f, 0.0f, 1.0f); glRGB(255,100,0); glTranslatef(160.0f, 0.0f, 0.0f); auxSolidSphere(9.0f); glPopMatrix(); // ì²~\ì~Y~Uì~D± glPushMatrix(); glLightfv(GL_LIGHT0, GL_POSITION, lightPos); glRotatef(fUranusRot, 0.0f, 1.0f, 0.0f); glRGB(255,50,0); glTranslatef(190.0f, 0.0f, 0.0f); auxSolidSphere(8.0f); glPopMatrix(); // í~U´ì~Y~Uì~D± glPushMatrix(); glLightfv(GL_LIGHT0, GL_POSITION, lightPos); glRotatef(fNeptuneRot, 1.0f, 0.0f, 0.0f); glRGB(0,255,255); glTranslatef(0.0f, 0.0f, -220.0f); auxSolidSphere(7.0f); glPopMatrix(); // ëª~Eì~Y~Uì~D± glPushMatrix(); glLightfv(GL_LIGHT0, GL_POSITION, lightPos); glRotatef(fPlutoRot, 1.0f, 1.0f, 0.0f); glRGB(255,255,255); glTranslatef(0.0f, 0.0f, -240.0f); auxSolidSphere(5.0f); glPopMatrix(); fMercuryRot += 10.0f; if(fMercuryRot > 360.0f) fMercuryRot = 0.0f; fVenusRot += 9.0f; if(fVenusRot > 360.0f) fVenusRot = 0.0f; fEarthRot += 8.0f; if(fEarthRot > 360.0f) fEarthRot = 0.0f; fMarsRot += 6.0f; if(fMarsRot > 360.0f) fMarsRot = 0.0f; fJupiterRot += 8.0f; if(fJupiterRot > 360.0f) fJupiterRot = 0.0f; fSaturnRot += 9.0f; if(fSaturnRot > 360.0f) fSaturnRot = 0.0f; fUranusRot += 10.0f; if(fUranusRot > 360.0f) fUranusRot = 0.0f; fNeptuneRot += 9.0f; if(fNeptuneRot > 360.0f) fNeptuneRot = 0.0f; fPlutoRot += 8.0f; if(fPlutoRot > 360.0f) fPlutoRot = 0.0f; glPopMatrix(); glFlush(); } int APIENTRY WinMain(HINSTANCE hInst, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { MSG msg; WNDCLASS wc; HWND hWnd; hInstance = hInst; wc.style = CS_HREDRAW | CS_VREDRAW; wc.lpfnWndProc = (WNDPROC) WndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = hInstance; wc.hIcon = NULL; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = NULL; wc.lpszMenuName = NULL; wc.lpszClassName = lpszAppName; if(RegisterClass(&wc) == 0) return FALSE; hWnd = CreateWindow( lpszAppName, lpszAppName, WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 50, 50, 800, 600, NULL, NULL, hInstance, NULL); if(hWnd == NULL) return FALSE; ShowWindow(hWnd,SW_SHOW); UpdateWindow(hWnd); while( GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } return msg.wParam; } LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { static HGLRC hRC; static HDC hDC; switch (message) { case WM_CREATE: hDC = GetDC(hWnd); SetDCPixelFormat(hDC); hRC = wglCreateContext(hDC); wglMakeCurrent(hDC, hRC); SetupRC(); SetTimer(hWnd, 101, 50, NULL); break; case WM_DESTROY: KillTimer(hWnd, 101); wglMakeCurrent(hDC,NULL); wglDeleteContext(hRC); PostQuitMessage(0); break; case WM_SIZE: ChangeSize(LOWORD(lParam), HIWORD(lParam)); break; case WM_PAINT: RenderScene(); SwapBuffers(hDC); ValidateRect(hWnd,NULL); break; case WM_TIMER: InvalidateRect(hWnd, NULL, FALSE); break; case WM_KEYDOWN: switch(wParam) { case VK_UP : xRot += 5.0f; break; case VK_DOWN : xRot -= 5.0f; break; case VK_LEFT : yRot += 5.0f; break; case VK_RIGHT: yRot -= 5.0f; break; } break; default: return (DefWindowProc(hWnd, message, wParam, lParam)); } return (0L); } //ì~X¤..졸ë~]¼ ì~K| 기í~U~Xë~K¤. ì~]´ë~_° 기ë~J¥ ì~X¤ë~X~Pì¼~@ ì~U~Lì~O~X? ì~Z°ì~Y~@~ //ì~C~A민ì~]´í~X~U temp í~N~Xì~]´ì§~@ì~W~P ì~M¨ì~^~Hë~M~X걸--; format pythonë~O~D ë~P~\ë~K¤. ì~^~Pë°~Të~J~T ì~U~Hë~P~Xë~M~Të~]¼