Presentation is loading. Please wait.

Presentation is loading. Please wait.

광원 제어 하기.

Similar presentations


Presentation on theme: "광원 제어 하기."— Presentation transcript:

1 광원 제어 하기

2 종 류 고정된 광원 독립적으로 이동하는 광원 시점에 따라 광원 움직이기

3 종 류 고정

4 종 류 고정 독립 이동

5 종 류 고정 시점 이동 독립 이동

6 고정된광원 뷰잉 변화과 모델링 변환을 모두 수행한 후에 라이트의 위치 선정
glViewport(0, 0, (GLsizei) w, (GLsizei) h); //reshape() glMatrixMode(GL_PROJECTION); glLoadIdentity(); if(w <= h) glOrtho(-1.5, 1.5, -1.5*(GLfloat)h/(GLfloat)w, 1.5*(GLfloat)h/(GLfloat)h, -10.0, 10.0); else glOrtho(-1.5*(GLfloat)h/(GLfloat)w, 1.5*(GLfloat)h/(GLfloat)h, -1.5, 1.5, -10.0, 10.0); glMatrixMode(GL_MODELVIEW); GLfloat light_position[] = {1.0, 1.0, 1.0, 0.0}; //initial() glLightfv(GL_LIGHT0, GL_POSITION, light_position);

7 고정된광원 void init(void){
GLfloat mat_specular[] = {1.0, 1.0, 1.0, 1.0}; //반사광의 세기 GLfloat mat_shininess[] = {50.0}; //반사계수세기 GLfloat light_position[] = {1.0, 1.0, 1.0, 0.0};//광원위치 GLfloat white_light[] = {1.0, 1.0, 1.0, 1.0};//주변광의 세기 GLfloat wlmodel_ambient[] = {0.1, 0.1, 0.1, 1.0};//주변광의 세기 glClearColor(0.0, 0.0, 0.0, 0.0); //배경색 glShadeModel(GL_SMOOTH); /쉐이딩 방법 설정 glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); //재질의 반사광 glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);//하이라이트크기 glLightfv(GL_LIGHT0, GL_POSITION, light_position); // 광원의 위치 정의 glLightfv(GL_LIGHT0, GL_DIFFUSE, white_light); // 광원의 주변광 정의 glLightfv(GL_LIGHT0, GL_SPECULAR, white_light); // 광원의 반사광 정의 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, wlmodel_ambient); //전역적 주면광 세기 glEnable(GL_LIGHTING);//조명기능활성화 glEnable(GL_LIGHT0);//광원활성화 glEnable(GL_DEPTH_TEST);}

8 고정된광원 void display(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glutSolidSphere(1.0, 50, 40); glFlush(); } void reshape(int w, int h) glViewport(0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if(w <= h) glOrtho(-1.5, 1.5, -1.5*(GLfloat)h/(GLfloat)w, 1.5*(GLfloat)h/(GLfloat)h, -10.0, 10.0); else glOrtho(-1.5*(GLfloat)h/(GLfloat)w, 1.5*(GLfloat)h/(GLfloat)h, -1.5, 1.5, -10.0, 10.0); glMatrixMode(GL_MODELVIEW);

9 고정된광원 int main(int argc, char** argv) { glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(500,500); glutInitWindowPosition(100, 100); glutCreateWindow(argv[0]); init(); glutDisplayFunc(display); glutReshapeFunc(reshape); glutMainLoop(); return 0; }

10 Display()루틴에 넣어 spin만큼 이동
이동하는 광원 광원의 위치를 다시 설정하는 코드를 Display()루틴에 넣어 spin만큼 이동 GLfloat position[] = {0.0, 0.0, 1.5, 1.0}; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glPushMatrix(); glTranslatef(0.0, 0.0, -5.0); glRotated((GLdouble) spin, 1.0, 0.0, 0.0); glLightfv(GL_LIGHT0, GL_POSITION, position); glDisable(GL_LIGHTING); glEnable(GL_LIGHTING); glutWireCube(0.1); glPopMatrix(); glutSolidSphere(0.5, 50, 40); glFlush();

11 이동하는광원 void init(void) {
GLfloat mat_specular[] = {1.0, 1.0, 1.0, 1.0}; GLfloat mat_shininess[] = {50.0}; GLfloat light_position[] = {1.0, 1.0, 1.0, 0.0}; GLfloat white_light[] = {1.0, 1.0, 1.0, 1.0}; GLfloat wlmodel_ambient[] = {0.1, 0.1, 0.1, 1.0}; glClearColor(0.0, 0.0, 0.0, 0.0); glShadeModel(GL_SMOOTH); glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); glLightfv(GL_LIGHT0, GL_POSITION, light_position); glLightfv(GL_LIGHT0, GL_DIFFUSE, white_light); glLightfv(GL_LIGHT0, GL_SPECULAR, white_light); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, wlmodel_ambient); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_DEPTH_TEST); }

12 이동하는광원 void display(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glutSolidSphere(1.0, 50, 40); glFlush(); } void reshape(int w, int h) glViewport(0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if(w <= h) glOrtho(-1.5, 1.5, -1.5*(GLfloat)h/(GLfloat)w, 1.5*(GLfloat)h/(GLfloat)h, -10.0, 10.0); else glOrtho(-1.5*(GLfloat)h/(GLfloat)w, 1.5*(GLfloat)h/(GLfloat)h, -1.5, 1.5, -10.0, 10.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity();}

13 이동하는광원 int main(int argc, char** argv) { glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(500,500); glutInitWindowPosition(100, 100); glutCreateWindow(argv[0]); init(); glutDisplayFunc(display); glutReshapeFunc(reshape); glutMainLoop(); return 0; }

14 gluLookAt의 변화에 따라 라이트도 변화
시점을 따르는 광원 빛의 위치를 (0,0,0)으로 지정 gluLookAt의 변화에 따라 라이트도 변화 void reshape(int w, int h) { GLfloat light_position[]={0.0, 0.0, 0.0, 1,0}; glViewport(0, 0, (GLint) w, (GLint)h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(40.0, (GLfloat)w / (GLfloat) h, 1.0, 100.0); glMatrixMode(GL_MODELVIEW); glLightfv(GL_LIGHT0,GL_POSITION, light_position); }

15 시점을 따르는 광원 static float s=5, t=0; void init(void) {
//GLfloat mat_specular[] = {0.5, 0.5, 0.5, 0.5}; GLfloat mat_shininess[] = {50.0}; GLfloat light_position[] = {1.0, 1.0, 1.0, 0.0}; GLfloat white_light[] = {0.7, 0.7, 0.7, 1.0}; GLfloat wlmodel_ambient[] = {0.1, 0.1, 0.1, 1.0}; glClearColor(0.0, 0.0, 0.0, 0.0); glShadeModel(GL_SMOOTH); glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular); glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess); //glLightfv(GL_LIGHT0, GL_POSITION, light_position); glLightfv(GL_LIGHT0, GL_DIFFUSE, white_light); glLightfv(GL_LIGHT0, GL_SPECULAR, white_light); glLightModelfv(GL_LIGHT_MODEL_AMBIENT, wlmodel_ambient); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glEnable(GL_DEPTH_TEST);}

16 시점을 따르는 광원 void display(void) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); gluLookAt(0, 0, s, t, 0, 0, 0, 1, 0); glutSolidTorus(0.5, 0.85, 10, 20); glFlush(); glutSwapBuffers(); } void reshape(int w, int h) GLfloat light_position[]={0.0, 0.0, 0.0, 1,0}; glViewport(0, 0, (GLint) w, (GLint)h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(40.0, (GLfloat)w / (GLfloat) h, 1.0, 100.0); glMatrixMode(GL_MODELVIEW); glLightfv(GL_LIGHT0,GL_POSITION, light_position);

17 시점을 따르는 광원 void mouse(int button, int state, int x, int y) {
switch(button){ case GLUT_LEFT_BUTTON: if(state==GLUT_DOWN){ s = s ; t = t ; glutPostRedisplay(); } break; default:

18 시점을 따르는 광원 int main(int argc, char** argv) { glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(800,800); glutInitWindowPosition(100, 100); glutCreateWindow(argv[0]); init(); glutDisplayFunc(display); glutReshapeFunc(reshape); glutMouseFunc(mouse); glutMainLoop(); return 0; }

19 질의 응답

20 감사합니다


Download ppt "광원 제어 하기."

Similar presentations


Ads by Google