OpenGL Geometric Transformations. glMatrixMode(GL_MODELVIEW);

Slides:



Advertisements
Similar presentations
Rezanje črt in poligonov. World window & viewport window viewport screen window world window.
Advertisements

CS 352: Computer Graphics Chapter 7: The Rendering Pipeline.
10/10/02 (c) 2002 University of Wisconsin, CS 559 Last Time Finished viewing: Now you know how to: –Define a region of space that you wish to view – the.
CHAPTER 12 Height Maps, Hidden Surface Removal, Clipping and Level of Detail Algorithms © 2008 Cengage Learning EMEA.
CS 551 / 645: Introductory Computer Graphics Clipping Lines and Polygons.
Computer Graphics, KKU. Lecture 81 Clipping on a Raster Display.
David Breen, William Regli and Maxim Peysakhov
1 Clipping. 2 Transformation Sequence X Y Z X Y Z X Y Z X Y Z Object Coords. Eye Coords. Clip Coords. Normalized Device Coords. Screen Coords. Implementation:
Two-Dimensional Viewing Jehee Lee Seoul National University.
Computer Graphics Viewing.
Clipping CSE 403 Computer Graphics Cohen Sutherland Algorithm (Line)
Viewing & Clipping In 2D. 2 of 44 Contents Windowing Concepts Clipping –Introduction –Brute Force –Cohen-Sutherland Clipping Algorithm Area Clipping –Sutherland-Hodgman.
CMPE 466 COMPUTER GRAPHICS Chapter 8 2D Viewing Instructor: D. Arifler Material based on - Computer Graphics with OpenGL ®, Fourth Edition by Donald Hearn,
2 D viewing Prepared by Elizabeth Isaac DCS, RSET.
Introduction to Computer Graphics Chapter 6 – 2D Viewing Pt 2 1.
March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Clipping Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Interpolation Clipping.
Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 111 Today’s class Clipping Parametric and point-normal form of lines Intersecting.
Vertices and Fragments I CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
1 King ABDUL AZIZ University Faculty Of Computing and Information Technology CS 454 Computer graphics Two Dimensional Viewing Dr. Eng. Farag Elnagahy
Visibility culling – Clipping. The visibility problem What polygons are visible? There are few visible polygons. –Avoid redundant processing Three classes.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Clipping.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Implementation I Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
2D Viewing. 2D viewing transformation is a mapping of world coordinate scene to device coordinates xw min xw max yw min yw max xv min xv max yv min yv.
Graphics Pipeline Clipping CMSC 435/634. Graphics Pipeline Object-order approach to rendering Sequence of operations – Vertex processing – Transforms.
2/26/04© University of Wisconsin, CS559 Spring 2004 Last Time General Orthographic Viewing –Specifying cameras in world coordinates –Building world  view.
UBI 516 Advanced Computer Graphics Two Dimensional Viewing ( Chapter 6 ) Aydın Öztürk Two Dimensional.
1 Computer Graphics Assistant Professor Dr. Sana’a Wafa Al-Sayegh 2 nd Semester ITGD3107 University of Palestine.
2-Dimension Viewing and Clipping
Clipping Apart from clipping to the view volume, clipping is a basic operation in many other algorithms –Breaking space up into chunks –2D drawing and.
CS 376 Introduction to Computer Graphics 02 / 12 / 2007 Instructor: Michael Eckmann.
Two-Dimensional Viewing
Clipping: Clipping is a process of dividing an object into visible and invisible positions and displaying the visible portion and discarding the invisible.
TWO DIMENSIONAL GEOMETRIC TRANSFORMATIONS CA 302 Computer Graphics and Visual Programming Aydın Öztürk
Geometric Transformations Jehee Lee Seoul National University.
Objectives Introduce basic implementation strategies Clipping Scan conversion.
Clipping Aaron Bloomfield CS 445: Introduction to Graphics Fall 2006 (Slide set originally by David Luebke)
CS 480/680 Computer Graphics Shading in OpenGL Dr. Frederick C Harris, Jr. Fall 2013.
OpenGL Geometric Transformations. OpenGL Matrix Stacks Stack processing –The top of the stack is the “current” matrix –glPushMatrix(); // Duplicate the.
2 DIMENSIONAL VIEWING Ceng 477 Introduction to Computer Graphics Fall Computer Engineering METU.
TWO-DIMENSIONAL VIEWING
Geometric Transformations
Graphics Graphics Korea University cgvr.korea.ac.kr 1 2D Viewing 고려대학교 컴퓨터 그래픽스 연구실.
Clipping Computer Graphics Cohen Sutherland Algorithm (Line)
Windows, Viewports, and Clipping
Three-Dimensional Viewing Jehee Lee Seoul National University.
Unit – IV 2D Viewing. 2 of 30 Contents Windowing Concepts The viewing pipeline viewing coordinate reference frame, window to view-port coordinate transformation,
EEL Introduction to Computer Graphics
Implementation of a Renderer Consider Programs are processd by the system line & polygon, outside the view volume Efficiently Understanding of the implementation.
Geometric Transformations Sang Il Park Sejong University Many slides come from Jehee Lee’s.
1Computer Graphics Implementation 1 Lecture 15 John Shearer Culture Lab – space 2
Introduction to Computer Graphics Chapter 6 – 2D Viewing Pt 3 1.
Clipping Primitives. Clipping line Clipping rectangle: – x min to x max – y min to y max A point (x,y) lies within a clip rectangle and thus displayed.
Graphics Graphics & Graphical Programming Lecture 23 - Viewing & Clipping.
A.Aruna/Assistant Professor/SNSCE
1 Geometric Transformations-II Modelling Transforms By Dr.Ureerat Suksawatchon.
Geometric Transformations. Transformations Linear transformations Rigid transformations Affine transformations Projective transformations T Global reference.
Computer Graphics Viewing. 2 of 30 Viewing in 2D Window in world coordinates. 45  250  Viewport in Device coords 250 x 250 Pixels.
Chapter 71 Computer Graphics - Chapter 7 From Vertices to Fragments Objectives are: How your program are processed by the system that you are using, Learning.
Two-Dimensional Viewing Hearn & Baker Chapter 6
Computer Graphics Clipping.
Computer Graphics CC416 Week 13 Clipping.
Transformations contd.
Computer Graphics Shading in OpenGL
2D Viewing & Clipping 한신대 류승택
OpenGL 2D Viewing Pipeline
Lecture 13 Clipping & Scan Conversion
Clipping Clipping Sutherland-Hodgman Clipping
Clipping University of British Columbia CPSC 314 Computer Graphics
COMPUTER GRAPHICS Clipping
Presentation transcript:

OpenGL Geometric Transformations

glMatrixMode(GL_MODELVIEW);

OpenGL Geometric Transformations Basic Transpormation: –glLoadIdentity(); –glTranslatef(tx, ty, tz); –glRotatef(theta, vx, vy, vz); angle-axis (vx, vy, vz) is automatically normalized –glScalef(sx, sy, sz); –glLoadMatrixf(Glfloat elems[16]); Multiplication –glMultMatrixf(Glfloat elems[16]); –The current matrix is postmultiplied by the matrix –Column major

OpenGL Geometric Transformations Getting the current matrix value: –glGetFloatv (GL_MODELVIEW_MATRIX, GLfloat elems[16]); Column major GLfloat mat [16]; glGetFloatv (GL_MODELVIEW_MATRIX, mat); GLfloat mat [16]; glGetFloatv (GL_MODELVIEW_MATRIX, mat);

OpenGL Geometric Transformations Matrix Direct Manipulation: –glLoadMatrixf(GLfloat elems[16]); Column major –glMultMatrixf(GLfloat elems[16]); The current matrix is postmultiplied by the matrix glLoadIdentity(); glMultMatrixf (M1); glMultMatrixf (M2); glLoadIdentity(); glMultMatrixf (M1); glMultMatrixf (M2); M = M1∙M2

OpenGL GLUT Animation Function GLUT Idle Callback fuction: –Idling: when there is nothing to do. Redraw the scene: glutIdleFunc ( MyIdle ); void MyIdle() { … // things to do … // when Idling } void MyIdle() { … // things to do … // when Idling } glutPostRedisplay ( );

Smooth display for animation Double Buffering: Using two buffers

Smooth display for animation OpenGL Double Buffering: –Enabling double buffering –Swapping buffers after drawing glutInitDisplayMode (GLUT_DOUBLE); glClear (GL_COLOR_BUFFER_BIT); … glutSwapBuffers (); glFlush(); glClear (GL_COLOR_BUFFER_BIT); … glutSwapBuffers (); glFlush();

바람개비 ( 풍차 ) 만들기

로보트 팔 만들기

로보트 팔 만들기 2

Hierarchical Modeling A hierarchical model is created by nesting the descriptions of subparts into one another to form a tree organization

OpenGL Matrix Stacks Stack processing –The top of the stack is the “current” matrix –glPushMatrix(); // Duplicate the current matrix at the top –glPopMatrix(); // Remove the matrix at the top

Homework #2 다각형을 이용하여 움직이는 2 차원 아름다운 애니 메이션 만들기 Push/Pop Matrix 를 사용하여 2 단계 이상의 계층적 인 움직임 디자인을 할 것 –Ex): 태양계 시스템 ( 태양  지구  달 ) 사람의 움직임 ( 몸  어깨  팔꿈치  손목  손 ) 숙제제출 : 이메일 제출 (Screenshot, code, report) 숙제마감 : 4 월 28 일 수요일 23 시 59 분까지

Viewing Part I: Two-Dimensional Viewing Sang Il Park Sejong University Lots of slides are stolen from Jehee Lee’s

Viewing Pipeline

Two-Dimensional Viewing Two dimensional viewing transformation –From world coordinate scene description to device (screen) coordinates

Normalization and Viewport Transformation World coordinate clipping window Normalization square: usually [-1,1]x[-1,1] Device coordinate viewport

OpenGL 2D Viewing Projection Mode –glMatrixMode(GL_PROJECTION); GLU clipping-window function –gluOrtho2D(xwmin,xwmax,ywmin,ywmax); –Normalized to [-1,1]x[-1,1] OpenGL viewport function –glViewport(xvmin,xvmax,yvmin,yvmax);

GLUT window Functions: glutInitWindowPosition glutInitWindowSize glutCreateWindow glutDestroyWindow glutSetWindow/glutGetWindow ….. And more! See the text book pp 346~354

Clipping Remove portion of output primitives outside clipping window Two approaches –Clip during scan conversion: Per-pixel bounds check –Clip analytically, then scan-convert the modified primitives

Two-Dimensional Clipping Point clipping – trivial Line clipping –Cohen-Sutherland –Cyrus-beck –Liang-Barsky Fill-area clipping –Sutherland-Hodgeman –Weiler-Atherton Curve clipping Text clipping

Line Clipping Basic calculations: –Is an endpoint inside or outside the clipping window? –Find the point of intersection, if any, between a line segment and an edge of the clipping window. Both endpoints inside: trivial accept One inside: find intersection and clip Both outside: either clip or reject

Cohen-Sutherland Line Clipping One of the earliest algorithms for fast line clipping Identify trivial accepts and rejects by bit operations above belowrightleft Bit Clipping window

Cohen-Sutherland Line Clipping Compute region codes for two endpoints If (both codes = 0000 ) trivially accepted If (bitwise AND of both codes  0000) trivially rejected Otherwise, divide line into two segments –test intersection edges in a fixed order. (e.g., top-to-bottom, right-to-left) Clipping window

Cohen-Sutherland Line Clipping Fixed order testing and clipping cause needless clipping (external intersection)

Cohen-Sutherland Line Clipping This algorithm can be very efficient if it can accept and reject primitives trivially –Clip window is much larger than scene data Most primitives are accepted trivially –Clip window is much smaller than scene data Most primitives are rejected trivially Good for hardware implementation

Cyrus-Beck Line Clipping Use a parametric line equation Reduce the number of calculating intersections by exploiting the parametric form Notations –E i : edge of the clipping window –N i : outward normal of E i –An arbitrary point P Ei on edge E i

Cyrus-Beck Line Clipping

Solve for the value of t at the intersection of P 0 P 1 with the edge –N i · [P(t) - P Ei ] = 0 and P(t) = P 0 + t(P 1 - P 0 ) –letting D = (P 1 - P 0 ), –Where N i  0 D  0 (that is, P 0  P 1 ) N i · D  0 (if not, no intersection)

Cyrus-Beck Line Clipping Given a line segment P 0 P 1, find intersection points against four edges –Discard an intersection point if t  [0,1] –Label each intersection point either PE (potentially entering) or PL (potentially leaving) –Choose the smallest (PE, PL) pair that defines the clipped line

Cyrus-Beck Line Clipping Cyrus-Beck is efficient when many line segments need to be clipped Can be extended easily to convex polygon (rather than upright rectangle) clip windows

Liang-Barsky Line Clipping Liang-Barsky optimized Cyrus-Beck for upright rectangular clip windows P(x 1,y 1 ) Q(x 2.y 2 ) tBtB tTtT tRtR tLtL

Liang-Barsky Line Clipping T B RL tTtT tBtB

Nicholl-Lee-Nicholl Line Clipping Divide more cases and reduce the computation. (1) (2) (3)

General Clipping Window Line clipping using nonrectangular polygon clip windows –Convex polygon Cyrus-Beck algorithm can be readily extended –Concave polygon Split the concave polygon into convex polygons Vector Method for Concave Splitting Calculate edge-vector cross products in a counterclockwise order If any z component turns out to be negative, the polygon is concave