Rotation 회전
OpenGL 2019. 12. 13. 14:43 |반응형
It describes how to rotate objects.
OpenGL에서 오브젝트 회전 하기.
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | #include <gl/glut.h> GLfloat angle = 0.0f; void MyDisplay(); void MyTimer(int value); int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); glutCreateWindow("OpenGL Rotation"); glutDisplayFunc(MyDisplay); glutTimerFunc(20, MyTimer, 1); glutMainLoop(); return 0; } void MyDisplay() { glClear(GL_COLOR_BUFFER_BIT); // 1st teapot, right, CCW glPushMatrix(); glRotatef(45.0f, 1.0f, 0.0f, 0.0f); // 45 degrees rotation around X-Axis to see the direction of the rotation. glTranslatef(0.5f, 0.0f, 0.0f); // Changing the order of calling this Translate().. glRotatef(angle, 0.0f, 1.0f, 0.0f); // and this Rotate() will affect how it spins. (rotation and revolution) glutWireTeapot(0.3); glPopMatrix(); // 2nd teapot, left, CW glPushMatrix(); // glPushMatrix pushes the current matrix stack down by one, duplicating the current matrix. That is, after a // glPushMatrix call, the matrix on top of the stack is identical to the one below it. glRotatef(45.0f, 1.0f, 0.0f, 0.0f); glTranslatef(-0.5f, 0.0f, 0.0f); glRotatef(-angle, 0.0f, 1.0f, 0.0f); glutWireTeapot(0.3); glPopMatrix(); //glPopMatrix pops the current matrix stack, replacing the current matrix with the one below it on the stack. glutSwapBuffers(); } void MyTimer(int value) { angle += 1.0f; if (angle >= 360.0f) { angle = 0.0f; } glutPostRedisplay(); glutTimerFunc(20, MyTimer, 1); } |
Run the program and see the directions of each rotation.
반응형
'OpenGL' 카테고리의 다른 글
Boundary and nonboundary edge flags 다각형의 경계선 설정하기 (0) | 2019.12.20 |
---|---|
Simple Solar System 간단한 태양계 그리기 (4) | 2019.12.17 |
Keeping the aspect ratio 종횡비 유지하기 (0) | 2019.12.12 |
GLUT(freeglut)으로 간단한 OpenGL 예제 만들기 (0) | 2019.11.24 |