transformations - hallym.ac.krgraphics.hallym.ac.kr/teach/2011/cg/src/09prac.pdf · 2011. 7....
TRANSCRIPT
![Page 1: Transformations - hallym.ac.krgraphics.hallym.ac.kr/teach/2011/cg/src/09prac.pdf · 2011. 7. 13. · OpenGL pipeline Model-View Projection Vertices Vertices ... Projection: to specify](https://reader034.vdocument.in/reader034/viewer/2022051805/5ff815bdb2a8fd0638704423/html5/thumbnails/1.jpg)
Transformations
6th W k 20116th Week, 2011
Line Preserving TransformationsLine-Preserving Transformations
■ Two classes of transformations of importance■ Two classes of transformations of importance to CG that preserves lines
AffineAffine and projectiveprojective transformationstransformations■■ AffineAffine and projectiveprojective transformationstransformations
■■ Homogeneous coordinatesHomogeneous coordinatesV i■ Vectors: (x, y, z, 0), points: (x, y, z, w)=(x/w, y/w, z/w, 1)
■ 4x4 matrices: modeling, viewing, and projection
■ OpenGL pipelineModel-View Projection
Vertices Vertices
■ Model-view: to position objects relative to camera■ Projection: to specify clipping volume and map
vertices to a normalized coordinate system
![Page 2: Transformations - hallym.ac.krgraphics.hallym.ac.kr/teach/2011/cg/src/09prac.pdf · 2011. 7. 13. · OpenGL pipeline Model-View Projection Vertices Vertices ... Projection: to specify](https://reader034.vdocument.in/reader034/viewer/2022051805/5ff815bdb2a8fd0638704423/html5/thumbnails/2.jpg)
OpenGL TransformationsOpenGL Transformations
■ Translation■ Translation
R t ti
void glTranslate{fd}(type dx, type dy, type dz);void glTranslate{fd}(type dx, type dy, type dz);
■ Rotationvoid glRotate{fd}(type angle, type ax, type ay, type az);void glRotate{fd}(type angle, type ax, type ay, type az);
■ Scalingvoid glScale{fd}(type sx, type sy, type sz);void glScale{fd}(type sx, type sy, type sz);
■ ConcatenationglMatrixMode(GL_MODELVIEW);glLoadIdentity();glTranslatef(xf, yf, zf);glRotatef(angle, ax, ay, az);lS l f( )glScalef(sx, sy, sz);glTranslate(-xf, -yf, -zf);
GLU Quadric ObjectsGLU Quadric Objects
■ Cylinders■ Cylinders■ Disks or partial disks■ Spheres
GLUquadricObj* gluNewQuadric( void );GLUquadricObj* gluNewQuadric( void );
void gluDeleteQuadric( GLUquadricObj *qobj );void gluDeleteQuadric( GLUquadricObj *qobj );
void gluCylinder(GLUquadricObj *qobj, GLdouble baseRadius, GLdouble topRadius,GLdouble height, GLint slices, GLint stacks);
void gluCylinder(GLUquadricObj *qobj, GLdouble baseRadius, GLdouble topRadius,GLdouble height, GLint slices, GLint stacks);
void gluDisk(GLUquadricObj *qobj, GLdouble innerRadius, GLdouble outerRadius,void gluDisk(GLUquadricObj *qobj, GLdouble innerRadius, GLdouble outerRadius,GLint slices, GLint loops);GLint slices, GLint loops);
void gluPartialDisk(GLUquadricObj *qobj, GLdouble innerRadius, GLdouble outerRadius,GLint slices, GLint loops, GLdouble startAngle, GLdouble sweepAngle);
void gluPartialDisk(GLUquadricObj *qobj, GLdouble innerRadius, GLdouble outerRadius,GLint slices, GLint loops, GLdouble startAngle, GLdouble sweepAngle);
void gluSphere(GLUquadricObj *qobj, GLdouble radius, GLint slices, GLint stacks);void gluSphere(GLUquadricObj *qobj, GLdouble radius, GLint slices, GLint stacks);
![Page 3: Transformations - hallym.ac.krgraphics.hallym.ac.kr/teach/2011/cg/src/09prac.pdf · 2011. 7. 13. · OpenGL pipeline Model-View Projection Vertices Vertices ... Projection: to specify](https://reader034.vdocument.in/reader034/viewer/2022051805/5ff815bdb2a8fd0638704423/html5/thumbnails/3.jpg)
GLUT Library (1)GLUT Library (1)
GLUT Library (2)GLUT Library (2)
■■ glut hglut h ( /Microsoft SDKs/Windows/v6 0A/Include/gl)■■ glut.hglut.h ( /Microsoft SDKs/Windows/v6.0A/Include/gl)
■■ glut32.libglut32.lib ( /Microsoft SDKs/Windows/v6.0A/Lib)
■■ glut32.dllglut32.dll ( Windows/system32)void glutWireSphere(GLdouble radius, GLint slices, Glint stacks);void glutSoildSphere(GLdouble radius, GLint slices, Glint stacks);void glutWireSphere(GLdouble radius, GLint slices, Glint stacks);void glutSoildSphere(GLdouble radius, GLint slices, Glint stacks);g p ( , , );g p ( , , );
void glutWireCone(GLdouble base, GLdouble height, GLint slices, Glint stacks);void glutSoildCone(GLdouble base, GLdouble height, GLint slices, Glint stacks);void glutWireCone(GLdouble base, GLdouble height, GLint slices, Glint stacks);void glutSoildCone(GLdouble base, GLdouble height, GLint slices, Glint stacks);
void glutWireCube(GLdouble size);void glutWireCube(GLdouble size);
void glutWireTorus(GLdouble inner, GLdouble outer, GLint sides, Glint slices);void glutSoildTorus(GLdouble inner, GLdouble outer, GLint sides, Glint slices);void glutWireTorus(GLdouble inner, GLdouble outer, GLint sides, Glint slices);void glutSoildTorus(GLdouble inner, GLdouble outer, GLint sides, Glint slices);
void glutWireTetrahedron();void glutWireTetrahedron();void glutWireCube(GLdouble size);void glutSoildCube(GLdouble size);void glutWireCube(GLdouble size);void glutSoildCube(GLdouble size);
void glutWireTeapot(GLdouble size);void glutSoildTeapot(GLdouble size);void glutWireTeapot(GLdouble size);void glutSoildTeapot(GLdouble size);
void glutWireTetrahedron();void glutSoildTetrahedron();void glutWireOctahedron();void glutWireOctahedron();void glutWireDodecahedron();
void glutWireTetrahedron();void glutSoildTetrahedron();void glutWireOctahedron();void glutWireOctahedron();void glutWireDodecahedron();void glutSoildTeapot(GLdouble size);void glutSoildTeapot(GLdouble size); void glutWireDodecahedron();void glutSoildDodecahedron();void glutWireIcosahedron();void glutWireIcosahedron();
void glutWireDodecahedron();void glutSoildDodecahedron();void glutWireIcosahedron();void glutWireIcosahedron();
![Page 4: Transformations - hallym.ac.krgraphics.hallym.ac.kr/teach/2011/cg/src/09prac.pdf · 2011. 7. 13. · OpenGL pipeline Model-View Projection Vertices Vertices ... Projection: to specify](https://reader034.vdocument.in/reader034/viewer/2022051805/5ff815bdb2a8fd0638704423/html5/thumbnails/4.jpg)
GLUT Library (3)GLUT Library (3)
GLUT Library (4)GLUT Library (4)
![Page 5: Transformations - hallym.ac.krgraphics.hallym.ac.kr/teach/2011/cg/src/09prac.pdf · 2011. 7. 13. · OpenGL pipeline Model-View Projection Vertices Vertices ... Projection: to specify](https://reader034.vdocument.in/reader034/viewer/2022051805/5ff815bdb2a8fd0638704423/html5/thumbnails/5.jpg)
GLUT Library (5)GLUT Library (5)
Drawing a Wire CubeDrawing a Wire Cube
![Page 6: Transformations - hallym.ac.krgraphics.hallym.ac.kr/teach/2011/cg/src/09prac.pdf · 2011. 7. 13. · OpenGL pipeline Model-View Projection Vertices Vertices ... Projection: to specify](https://reader034.vdocument.in/reader034/viewer/2022051805/5ff815bdb2a8fd0638704423/html5/thumbnails/6.jpg)
실행 결과 A Wire Cube실행 결과 – A Wire Cube
Hierarchical Models (1)Hierarchical Models (1)
■ Parts of a model depend on one another■ Parts of a model depend on one another■ If one part moves, it cause other parts to move
A Simple Robot Arm Hierarchical Representation
![Page 7: Transformations - hallym.ac.krgraphics.hallym.ac.kr/teach/2011/cg/src/09prac.pdf · 2011. 7. 13. · OpenGL pipeline Model-View Projection Vertices Vertices ... Projection: to specify](https://reader034.vdocument.in/reader034/viewer/2022051805/5ff815bdb2a8fd0638704423/html5/thumbnails/7.jpg)
Hierarchical Models (2)Hierarchical Models (2)
■ A figure can be constructed from GLU spheres■ A figure can be constructed from GLU spheres and cylinders
Hierarchical representation
Hierarchical Models (3)Hierarchical Models (3)
■ Ex) simple robot arm■ Ex) simple robot arm
gluCylinder( GLUqadricObj *q,gluCylinder( GLUqadricObj *q,g y ( q j q,GLdouble base_radius,GLdouble top_radius,GLdouble height,
g y ( q j q,GLdouble base_radius,GLdouble top_radius,GLdouble height,
BaseGLdouble height,GLint slices, Glint stacks );
GLdouble height,GLint slices, Glint stacks );
l tS lidC b ( GLd bl i )l tS lidC b ( GLd bl i )glutSolidCube( GLdouble size );glutWireCube( GLdouble size );glutSolidCube( GLdouble size );glutWireCube( GLdouble size );
Lower arm Upper arm
![Page 8: Transformations - hallym.ac.krgraphics.hallym.ac.kr/teach/2011/cg/src/09prac.pdf · 2011. 7. 13. · OpenGL pipeline Model-View Projection Vertices Vertices ... Projection: to specify](https://reader034.vdocument.in/reader034/viewer/2022051805/5ff815bdb2a8fd0638704423/html5/thumbnails/8.jpg)
Hierarchical Models (4)Hierarchical Models (4)
Hierarchical Models (5)Hierarchical Models (5)
![Page 9: Transformations - hallym.ac.krgraphics.hallym.ac.kr/teach/2011/cg/src/09prac.pdf · 2011. 7. 13. · OpenGL pipeline Model-View Projection Vertices Vertices ... Projection: to specify](https://reader034.vdocument.in/reader034/viewer/2022051805/5ff815bdb2a8fd0638704423/html5/thumbnails/9.jpg)
Hierarchical Models (6)Hierarchical Models (6)
Hierarchical Models (7)Hierarchical Models (7)
![Page 10: Transformations - hallym.ac.krgraphics.hallym.ac.kr/teach/2011/cg/src/09prac.pdf · 2011. 7. 13. · OpenGL pipeline Model-View Projection Vertices Vertices ... Projection: to specify](https://reader034.vdocument.in/reader034/viewer/2022051805/5ff815bdb2a8fd0638704423/html5/thumbnails/10.jpg)
실행 결과 Hierarchical Models실행 결과 – Hierarchical Models
연습 문제 (1)연습 문제 (1)
■ Cylinder를 회전시켜 옆면이 보이도록 만드시오■ Cylinder를 회전시켜 옆면이 보이도록 만드시오.
![Page 11: Transformations - hallym.ac.krgraphics.hallym.ac.kr/teach/2011/cg/src/09prac.pdf · 2011. 7. 13. · OpenGL pipeline Model-View Projection Vertices Vertices ... Projection: to specify](https://reader034.vdocument.in/reader034/viewer/2022051805/5ff815bdb2a8fd0638704423/html5/thumbnails/11.jpg)
Base ArmBase Arm
glPushMatrix( ) and glPopMatrix( )glPushMatrix( ) and glPopMatrix( )
■ Performing a transformation and then■ Performing a transformation and then returning to the same state as before its executionexecution
■ Ex) instance transformationglPushMatrix();glPushMatrix();
glTranslatef(.....);g ( )glRotatef(.....);glScalef(.....);
/* draw object here */
glPopMatrix();glPopMatrix();glPopMatrix();glPopMatrix();
![Page 12: Transformations - hallym.ac.krgraphics.hallym.ac.kr/teach/2011/cg/src/09prac.pdf · 2011. 7. 13. · OpenGL pipeline Model-View Projection Vertices Vertices ... Projection: to specify](https://reader034.vdocument.in/reader034/viewer/2022051805/5ff815bdb2a8fd0638704423/html5/thumbnails/12.jpg)
실행 결과 Base Arm실행 결과 – Base Arm
연습 문제 (2)연습 문제 (2)
■ Box를 평행이동 시켜 밑면 중심이 원점에 위치■ Box를 평행이동 시켜 밑면 중심이 원점에 위치시키시오.
![Page 13: Transformations - hallym.ac.krgraphics.hallym.ac.kr/teach/2011/cg/src/09prac.pdf · 2011. 7. 13. · OpenGL pipeline Model-View Projection Vertices Vertices ... Projection: to specify](https://reader034.vdocument.in/reader034/viewer/2022051805/5ff815bdb2a8fd0638704423/html5/thumbnails/13.jpg)
Lower ArmLower Arm
실행 결과 Lower Arm실행 결과 – Lower Arm
![Page 14: Transformations - hallym.ac.krgraphics.hallym.ac.kr/teach/2011/cg/src/09prac.pdf · 2011. 7. 13. · OpenGL pipeline Model-View Projection Vertices Vertices ... Projection: to specify](https://reader034.vdocument.in/reader034/viewer/2022051805/5ff815bdb2a8fd0638704423/html5/thumbnails/14.jpg)
Upper Arm (1)Upper Arm (1)
실행 결과 Upper Arm (1)실행 결과 – Upper Arm (1)
![Page 15: Transformations - hallym.ac.krgraphics.hallym.ac.kr/teach/2011/cg/src/09prac.pdf · 2011. 7. 13. · OpenGL pipeline Model-View Projection Vertices Vertices ... Projection: to specify](https://reader034.vdocument.in/reader034/viewer/2022051805/5ff815bdb2a8fd0638704423/html5/thumbnails/15.jpg)
연습 문제 (3)연습 문제 (3)
■ Upper arm의 밑면 중심이 원점에 놓이도록 평행■ Upper arm의 밑면 중심이 원점에 놓이도록 평행이동 시키시오.
Upper Arm (2)Upper Arm (2)
![Page 16: Transformations - hallym.ac.krgraphics.hallym.ac.kr/teach/2011/cg/src/09prac.pdf · 2011. 7. 13. · OpenGL pipeline Model-View Projection Vertices Vertices ... Projection: to specify](https://reader034.vdocument.in/reader034/viewer/2022051805/5ff815bdb2a8fd0638704423/html5/thumbnails/16.jpg)
실행 결과 Upper Arm (2)실행 결과 – Upper Arm (2)
연습 문제 (4)연습 문제 (4)
■ Base arm lower arm upper arm의 순서로 겹치■ Base arm, lower arm, upper arm의 순서로 겹치지 않게 배치하시오.
Viewing 파라미터를 변경하여 화면에 보이는 공간을■ Viewing 파라미터를 변경하여, 화면에 보이는 공간을넓히시오. (모든 오브젝트가 보이도록 만드시오.)
![Page 17: Transformations - hallym.ac.krgraphics.hallym.ac.kr/teach/2011/cg/src/09prac.pdf · 2011. 7. 13. · OpenGL pipeline Model-View Projection Vertices Vertices ... Projection: to specify](https://reader034.vdocument.in/reader034/viewer/2022051805/5ff815bdb2a8fd0638704423/html5/thumbnails/17.jpg)
Simple Robot Arm (1)Simple Robot Arm (1)
Simple Robot Arm (2)Simple Robot Arm (2)
![Page 18: Transformations - hallym.ac.krgraphics.hallym.ac.kr/teach/2011/cg/src/09prac.pdf · 2011. 7. 13. · OpenGL pipeline Model-View Projection Vertices Vertices ... Projection: to specify](https://reader034.vdocument.in/reader034/viewer/2022051805/5ff815bdb2a8fd0638704423/html5/thumbnails/18.jpg)
실행 결과 Simple Robot Arm (1)실행 결과 – Simple Robot Arm (1)
연습 문제 (5)연습 문제 (5)
■ Simple Robot Arm이 화면의 중앙에 놓이도록■ Simple Robot Arm이 화면의 중앙에 놓이도록Object 전체를 평행이동 시키시오.
![Page 19: Transformations - hallym.ac.krgraphics.hallym.ac.kr/teach/2011/cg/src/09prac.pdf · 2011. 7. 13. · OpenGL pipeline Model-View Projection Vertices Vertices ... Projection: to specify](https://reader034.vdocument.in/reader034/viewer/2022051805/5ff815bdb2a8fd0638704423/html5/thumbnails/19.jpg)
Simple Robot Arm (3)Simple Robot Arm (3)
실행 결과 Simple Robot Arm (2)실행 결과 – Simple Robot Arm (2)
![Page 20: Transformations - hallym.ac.krgraphics.hallym.ac.kr/teach/2011/cg/src/09prac.pdf · 2011. 7. 13. · OpenGL pipeline Model-View Projection Vertices Vertices ... Projection: to specify](https://reader034.vdocument.in/reader034/viewer/2022051805/5ff815bdb2a8fd0638704423/html5/thumbnails/20.jpg)
Transformation of Hierarchical Models
■ Ex) simple robot arm■ Ex) simple robot arm
Lower ArmBase Upper Arm
Base Arm Rotation (1)Base Arm Rotation (1)
![Page 21: Transformations - hallym.ac.krgraphics.hallym.ac.kr/teach/2011/cg/src/09prac.pdf · 2011. 7. 13. · OpenGL pipeline Model-View Projection Vertices Vertices ... Projection: to specify](https://reader034.vdocument.in/reader034/viewer/2022051805/5ff815bdb2a8fd0638704423/html5/thumbnails/21.jpg)
Base Arm Rotation (2)Base Arm Rotation (2)
GetAsyncKeyState( )GetAsyncKeyState( )
![Page 22: Transformations - hallym.ac.krgraphics.hallym.ac.kr/teach/2011/cg/src/09prac.pdf · 2011. 7. 13. · OpenGL pipeline Model-View Projection Vertices Vertices ... Projection: to specify](https://reader034.vdocument.in/reader034/viewer/2022051805/5ff815bdb2a8fd0638704423/html5/thumbnails/22.jpg)
Base Arm Rotation (3)Base Arm Rotation (3)
실행 결과 Base Arm Rotation실행 결과 – Base Arm Rotation
![Page 23: Transformations - hallym.ac.krgraphics.hallym.ac.kr/teach/2011/cg/src/09prac.pdf · 2011. 7. 13. · OpenGL pipeline Model-View Projection Vertices Vertices ... Projection: to specify](https://reader034.vdocument.in/reader034/viewer/2022051805/5ff815bdb2a8fd0638704423/html5/thumbnails/23.jpg)
연습 문제 (6)연습 문제 (6)
■ Lower arm과 upper arm도 회전이 되도록 프로■ Lower arm과 upper arm도 회전이 되도록 프로그램을 수정하시오.
↑와 ↓ 화살표키 lower arm의 회전■ ↑와 ↓ 화살표키 – lower arm의 회전■ PageUp 과 PageDown 키 – upper arm의 회전
■ Base arm이 평행이동 하도록 수정하시오.■ ‘A’와 ‘D’ – x축 방향으로 좌우 이동■ ‘W’와 ‘S’ – z축 방향으로 전후 이동
Rotation of a Simple Robot ArmRotation of a Simple Robot Arm