제가 만들려고 하는 것은 3차원 공간상에 지구를 만들고, 23.5도 기울인 뒤 회전시키는 것인데요. <div>라이트 위치를 고정시켜놨는데.. 회전할 때 라이트가 같이 돌아버리네요 ㅠㅠ</div> <div><br /></div> <div>혹시나해서 라이트 관련 코드들을 Rotate 위로 전부 옮겨봤는데 .. 역시 결과는 같아요 ㅠㅠ</div> <div>무엇이 문제일까요 ..?ㅠㅠ</div> <div><br /></div> <div>혹시나해서 코드 첨부합니다!</div> <div>도중에 제가 .. 주석처리 해놓고 .. 안지운 부분들이 몇몇있는데 신경쓰지 않으셔도 됩니다 ㅠㅠ</div> <div><br /></div> <div>-----------------------------------------------------------------------------------------------------------------------</div> <div><br /></div> <div><div>#include "stdafx.h"</div> <div>#include "GL\glut.h"</div> <div>#include "GL\gl.h"</div> <div>#include "GL\glu.h"</div> <div>#include <math.h></div> <div><br /></div> <div>#define M 32</div> <div>#define N 64</div> <div>#define PI 3.141592265358979</div> <div><br /></div> <div><br /></div> <div>int angle =30;</div> <div><br /></div> <div><br /></div> <div>void myIdle(int i)</div> <div>{</div> <div><span style="white-space:pre;"> </span></div> <div><span style="white-space:pre;"> </span>angle+=1;</div> <div><span style="white-space:pre;"> </span>glutPostRedisplay();</div> <div><span style="white-space:pre;"> </span>glutTimerFunc(33, myIdle, 0);</div> <div><br /></div> <div><span style="white-space:pre;"> </span>return;</div> <div>}//애니매이션 효과를 주고싶을 때</div> <div><br /></div> <div><br /></div> <div>void myReshape(int w, int h)</div> <div>{</div> <div><span style="white-space:pre;"> </span>printf("%d %d",w,h);</div> <div><span style="white-space:pre;"> </span></div> <div><span style="white-space:pre;"> </span>return ;</div> <div>}//정삭 작동 확인 위한 함수</div> <div><br /></div> <div><br /></div> <div>void Render()</div> <div>{</div> <div><span style="white-space:pre;"> </span>glClearColor(0,1,1,0.2);//전체 배경색 설정</div> <div><span style="white-space:pre;"> </span>glClear(GL_COLOR_BUFFER_BIT+GL_DEPTH_BUFFER_BIT);</div> <div><br /></div> <div><span style="white-space:pre;"> </span>glMatrixMode(GL_PROJECTION);</div> <div><span style="white-space:pre;"> </span>//glLoadIdentity();</div> <div><br /></div> <div><span style="white-space:pre;"> </span>// -- Perspective ---</div> <div><span style="white-space:pre;"> </span>gluPerspective(0,1,0.00001,1000);</div> <div><br /></div> <div><span style="white-space:pre;"> </span>//glMatrixMode(GL_MODELVIEW);</div> <div><span style="white-space:pre;"> </span>glLoadIdentity();</div> <div><br /></div> <div><br /></div> <div><span style="white-space:pre;"> </span></div> <div><br /></div> <div><span style="white-space:pre;"> </span>glPolygonMode(GL_FRONT_AND_BACK,GL_LINE);</div> <div><br /></div> <div><span style="white-space:pre;"> </span>glEnable(GL_DEPTH_TEST);</div> <div><span style="white-space:pre;"> </span>glEnable(GL_LIGHTING);</div> <div><span style="white-space:pre;"> </span>glEnable(GL_LIGHT0);</div> <div><br /></div> <div><span style="white-space:pre;"> </span></div> <div><span style="white-space:pre;"> </span>float dgray[4]={0.2,0.2,0.2,0.2};</div> <div><span style="white-space:pre;"> </span>float lgray[4]={0.8,0.8,0.8,0.8};</div> <div><span style="white-space:pre;"> </span>float white[4]={1,1,1,1};</div> <div><br /></div> <div><span style="white-space:pre;"> </span>float position[4]={5,5,-5,2};</div> <div><br /></div> <div><span style="white-space:pre;"> </span>glLightfv(GL_LIGHT0, GL_POSITION, position);</div> <div><span style="white-space:pre;"> </span>glLightfv(GL_LIGHT0, GL_DIFFUSE, white);</div> <div><span style="white-space:pre;"> </span>glLightfv(GL_LIGHT0, GL_SPECULAR, white);</div> <div><span style="white-space:pre;"> </span>glLightfv(GL_LIGHT0, GL_AMBIENT, dgray);</div> <div><br /></div> <div><span style="white-space:pre;"> </span>glMaterialfv (GL_FRONT_AND_BACK, GL_AMBIENT, dgray);</div> <div><span style="white-space:pre;"> </span>glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE, lgray);</div> <div><span style="white-space:pre;"> </span>glMaterialfv (GL_FRONT_AND_BACK, GL_SPECULAR, white);</div> <div><span style="white-space:pre;"> </span>glMaterialfv (GL_FRONT_AND_BACK, GL_SHININESS, white);</div> <div><br /></div> <div><span style="white-space:pre;"> </span>glLightf(GL_LIGHT0,GL_SHININESS,1000);</div> <div><br /></div> <div><span style="white-space:pre;"> </span></div> <div><span style="white-space:pre;"> </span>glTranslatef(0,0,1.3);</div> <div><span style="white-space:pre;"> </span>//glLoadIdentity();</div> <div><span style="white-space:pre;"> </span></div> <div><span style="white-space:pre;"> </span>//glTranslatef(0,0,0.0);</div> <div><span style="white-space:pre;"> </span>glRotatef(-23.5, 0, 0, 1);</div> <div><span style="white-space:pre;"> </span>glRotatef(angle,0,1,0);</div> <div><br /></div> <div><br /></div> <div><span style="white-space:pre;"> </span>for(int j=0-64; j <= M-64 ; j++)</div> <div><span style="white-space:pre;"> </span>{</div> <div><br /></div> <div><span style="white-space:pre;"> </span>float phi1=PI/2-PI*j/(float)M;</div> <div><span style="white-space:pre;"> </span>float phi2=PI/2-PI*(j+1)/(float)M;</div> <div><br /></div> <div><span style="white-space:pre;"> </span>float y1 = sinf(phi1);</div> <div><span style="white-space:pre;"> </span>float y2 = sinf(phi2);</div> <div><span style="white-space:pre;"> </span>float r1 = cosf(phi1);</div> <div><span style="white-space:pre;"> </span>float r2 = cosf(phi2);</div> <div><br /></div> <div><span style="white-space:pre;"> </span>glBegin(GL_TRIANGLE_STRIP);</div> <div><br /></div> <div><span style="white-space:pre;"> </span>for(int i=0-32 ; i<=N-32 ; i++)</div> <div><span style="white-space:pre;"> </span>{</div> <div><span style="white-space:pre;"> </span>float theta=PI/2-PI*2*i/(float)N;</div> <div><span style="white-space:pre;"> </span>glNormal3f(r1*cosf(theta),y1,r1*sinf(theta));</div> <div><span style="white-space:pre;"> </span>glVertex3f(r1*cosf(theta),y1,r1*sinf(theta));</div> <div><span style="white-space:pre;"> </span>glNormal3f(r2*cosf(theta),y2,r2*sinf(theta));</div> <div><span style="white-space:pre;"> </span>glVertex3f(r2*cosf(theta),y2,r2*sinf(theta));</div> <div><span style="white-space:pre;"> </span></div> <div><br /></div> <div><span style="white-space:pre;"> </span>}</div> <div><span style="white-space:pre;"> </span>}</div> <div><br /></div> <div><br /></div> <div><br /></div> <div><span style="white-space:pre;"> </span>glEnd();</div> <div><br /></div> <div><br /></div> <div><br /></div> <div><span style="white-space:pre;"> </span>glutSwapBuffers();</div> <div>}</div></div> <div><br /></div> <div><br /></div> <div><div>int _tmain(int argc, _TCHAR* argv[])</div> <div>{</div> <div><br /></div> <div><span style="white-space:pre;"> </span>glutInit(&argc,argv);</div> <div><span style="white-space:pre;"> </span>glutInitDisplayMode(GLUT_RGB+GLUT_DOUBLE+GLUT_MULTISAMPLE);//초기화</div> <div><span style="white-space:pre;"> </span>glutInitWindowSize(540,480);//window size</div> <div><span style="white-space:pre;"> </span>glutInitWindowPosition(0,0);//window position</div> <div><span style="white-space:pre;"> </span>glutCreateWindow("Earth");//window name</div> <div><br /></div> <div><span style="white-space:pre;"> </span>glutDisplayFunc(Render);</div> <div><span style="white-space:pre;"> </span>glutReshapeFunc(myReshape);</div> <div><br /></div> <div><span style="white-space:pre;"> </span>myIdle(1);</div> <div><span style="white-space:pre;"> </span>glutTimerFunc(33,myIdle,0);</div> <div><span style="white-space:pre;"> </span>glutMainLoop();</div> <div><br /></div> <div><span style="white-space:pre;"> </span></div> <div><br /></div> <div><span style="white-space:pre;"> </span>return 0;</div> <div>}</div></div>
댓글 분란 또는 분쟁 때문에 전체 댓글이 블라인드 처리되었습니다.