본문 바로가기
Language/C++ & openGL

오픈지엘 이동 회전 크기 복합 변환

by javapp 자바앱 2020. 5. 23.
728x90

void MyDisplay()

{

             glClear(GL_COLOR_BUFFER_BIT);

             /*기준선*/

             glBegin(GL_LINES);

             glColor3f(1, 0, 0);          // X

             glVertex3f(-1, 0, 0);       glVertex3f(1, 0, 0);

             glColor3f(0, 1, 0);          // Y

             glVertex3f(0, -1, 0);       glVertex3f(0, 1, 0);

             glColor3f(0, 0, 1);          // Z

             glVertex3f(0, 0, -1);       glVertex3f(0, 0, 1);

             glEnd();

 

            

            

             glTranslatef(0.7, 0.7, 0);

             glRotatef(45, 0, 0, 1);

             glScalef(2, 2, 2);

 

            

             /*P 사각형*/

             glBegin(GL_POLYGON);

             glColor3f(0, 0, 255);

             glVertex3f(0.1, 0.1, 0);

             glVertex3f(-0.1, 0.1, 0);

             glVertex3f(-0.1, -0.1, 0);

             glVertex3f(0.1, -0.1, 0);

             glVertex3f(0.1, 0.1, 0);

             glEnd();

 

             glLoadIdentity();

             glTranslatef(-0.5, 0, 0);

             glScalef(1, 1, 0.5);

             glRotatef(45, 0, 0, 1);

 

             /*P 사각형*/

             glBegin(GL_POLYGON);

             glColor3f(0, 0, 255);

             glVertex3f(0.1, 0.1, 0);

             glVertex3f(-0.1, 0.1, 0);

             glVertex3f(-0.1, -0.1, 0);

             glVertex3f(0.1, -0.1, 0);

             glVertex3f(0.1, 0.1, 0);

             glEnd();

 

 

             glFlush();

}

 


함수 호출과 물체 변환은 반대가 된다.

 


             
glTranslatef(0.7, 0.7, 0);

             glRotatef(45, 0, 0, 1);

             glScalef(2, 2, 2);

물체변환은 회전후 이동을 하게 된다.

             glRotatef(45, 0, 0, 1);

             glTranslatef(0.7, 0.7, 0);

             glScalef(2, 2, 2);

반대의 순서가 될 경우

물체는 이동후 회전을 하고 되고

이러한 결과를 갖게 된다.

 

댓글