OpenGL Geometric Transformations. OpenGL Matrix Stacks Stack processing –The top of the stack is the “current” matrix –glPushMatrix(); // Duplicate the.

Slides:



Advertisements
Similar presentations
Computer Graphics Lecture 8 Arbitrary Viewing II: More Projection, Clipping and Mathematics of 3D Viewing.
Advertisements

CS 691 Computational Photography Instructor: Gianfranco Doretto 3D to 2D Projections.
Three Dimensional Viewing
Three-Dimensional Viewing Sang Il Park Sejong University Lots of slides are stolen from Jehee Lee’s.
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.
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.
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.
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.
Viewing Doug James’ CG Slides, Rich Riesenfeld’s CG Slides, Shirley, Fundamentals of Computer Graphics, Chap 7 Wen-Chieh (Steve) Lin Institute of Multimedia.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Implementation I Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
2/26/04© University of Wisconsin, CS559 Spring 2004 Last Time General Orthographic Viewing –Specifying cameras in world coordinates –Building world  view.
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.
Computer Graphics (fall 2009)
CS 376 Introduction to Computer Graphics 02 / 12 / 2007 Instructor: Michael Eckmann.
Two-Dimensional Viewing
UBI 516 Advanced Computer Graphics Three Dimensional Viewing
Advanced Computer Graphics Three Dimensional Viewing
3D Viewing.
Clipping Aaron Bloomfield CS 445: Introduction to Graphics Fall 2006 (Slide set originally by David Luebke)
Computer Graphics 2 – Dimensional Viewing.
CS 480/680 Computer Graphics Shading in OpenGL Dr. Frederick C Harris, Jr. Fall 2013.
Graphics Graphics Korea University cgvr.korea.ac.kr 3D Viewing 고려대학교 컴퓨터 그래픽스 연구실.
Computer Graphics Bing-Yu Chen National Taiwan University.
OpenGL Geometric Transformations. glMatrixMode(GL_MODELVIEW);
Geometric Transformations
CAP 4703 Computer Graphic Methods Prof. Roy Levow Chapter 5.
Three-Dimensional Viewing Jehee Lee Seoul National University.
University of North Carolina at Greensboro
2003CS Hons RW778 Graphics1 Chapter 7: Three-Dimensional Viewing Chapter 5: Camera with parallel projection Chapter 5: Camera with parallel projection.
Basic Perspective Projection Watt Section 5.2, some typos Define a focal distance, d, and shift the origin to be at that distance (note d is negative)
EEL Introduction to Computer Graphics
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
Three-Dimensional Viewing
Three-Dimensional Viewing Hearn & Baker Chapter 7
12/24/2015 A.Aruna/Assistant professor/IT/SNSCE 1.
Rendering Pipeline Fall, D Polygon Rendering Many applications use rendering of 3D polygons with direct illumination.
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
CS 376 Introduction to Computer Graphics 02 / 21 / 2007 Instructor: Michael Eckmann.
Chapter: Viewing.
Viewing. Classical Viewing Viewing requires three basic elements - One or more objects - A viewer with a projection surface - Projectors that go from.
3 DIMENSIONAL VIEWING Ceng 477 Introduction to Computer Graphics Computer Engineering METU.
CS552: Computer Graphics Lecture 12: 3D Clipping.
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.
Three Dimensional Viewing
Rendering Pipeline Fall, 2015.
University of North Carolina at Greensboro
CSCE 441 Computer Graphics 3-D Viewing
“Computer Science is no more about computers than astronomy is about telescopes.” Professor Edsger Dijkstra.
3D Clipping.
Three Dimensional Viewing
OpenGL 2D Viewing Pipeline
Lecture 13 Clipping & Scan Conversion
3D Viewing.
THREE-DIMENSIONAL VIEWING
COMPUTER GRAPHICS Clipping
Presentation transcript:

OpenGL Geometric Transformations

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

로보트 팔 만들기

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

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

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

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

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

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

Polygon Fill-Area Clipping Polyline vs polygon fill-area Early rejection is useful Clipping Window Bounding box of polygon fill area

Sutherland-Hodgman Polygon Clipping Clip against 4 infinite clip edges in succession

Sutherland-Hodgman Polygon Clipping Accept a series of vertices (polygon) and outputs another series of vertices Four possible outputs

Sutherland-Hodgman Polygon Clipping The algorithm correctly clips convex polygons, but may display extraneous lines for concave polygons

Weiler-Atherton Polygon Clipping For an outside-to-inside pair of vertices, follow the polygon boundary For an inside-to-outside pair of vertices, follow the window boundary in a clockwise direction

Weiler-Atherton Polygon Clipping Polygon clipping using nonrectangular polygon clip windows

Text Clipping All-or-none text clipping –Using boundary box for the entire text All-or-non character clipping –Using boundary box for each individual character Character clipping –Vector font: Clip boundary polygons or curves –Bitmap font: Clip individual pixels

Three-Dimensional Viewing Sang Il Park Sejong University Lots of slides are stolen from Jehee Lee’s

Viewing Pipeline

Virtual Camera Model Viewing Transformation –The camera position and orientation is determined Projection Transformation –The selected view of a 3D scene is projected onto a view plane

General 3D Viewing Pipeline Modeling coordinates (MC) World coordinates (WC) Viewing coordinates (VC) Projection coordinates (PC) Normalized coordinates (NC) Device coordinates (DC)

Viewing-Coordinate Parameters View point (eye point or viewing position) View-plane normal vector N

Viewing-Coordinate Parameters Look-at point P ref View-up vector V –N and V are specified in the world coordinates –V should be perpendicular to N, but it can be difficult to a direction for V that is precisely perpendicular to N

Viewing-Coordinate Reference Frame The camera orientation is determined by the uvn reference frame u n v

World-to-Viewing Transformation Transformation from world to viewing coordinates –Translate the viewing-coordinate origin to the world- coordinate origin –Apply rotations to align the u, v, n axes with the world x w, y w, z w axes, respectively u n v

World-to-Viewing Transformation

Perspective Projection Pin-hold camera model –Put the optical center (Center Of Projection) at the origin –Put the image plane (Projection Plane) in front of the COP –The camera looks down the negative z axis we need this if we want right-handed-coordinates

Parallel Projection Special case of perspective projection –Distance from the COP to the PP is infinite –Also called “parallel projection” –What’s the projection matrix? Image World Slide by Steve Seitz

Taxonomy of Geometric Projections geometric projections parallelperspective orthographicaxonometricoblique trimetric dimetric isometric cavaliercabinet single-pointtwo-pointthree-point

Orthographic Transformation Preserves relative dimension The center of projection at infinity The direction of projection is parallel to a principle axis Architectural and engineering drawings

Axonometric Transformation Orthogonal projection that displays more than one face of an object –Projection plane is not normal to a principal axis, but DOP is perpendicular to the projection plane –Isometric, dimetric, trimetric

Oblique Parallel Projections Projection plane is not normal to a principal axis, but DOP is perpendicular to the projection plane Only faces of the object parallel to the projection plane are shown true size and shape

Oblique Parallel Projections

Oblique Parallel Projections

Typically,  is either 30˚ or 45˚ L 1 is the length of the projected side edge –Cavalier projections L 1 is the same as the original length –Cabinet projections L 1 is the half of the original length

Oblique Parallel Projections Cavalier projections Cabinet projections

Perspective Projection Pin-hold camera model –Put the optical center (Center Of Projection) at the origin –Put the image plane (Projection Plane) in front of the COP –The camera looks down the negative z axis we need this if we want right-handed-coordinates

Perspective Projection Projection equations –Compute intersection with PP of ray from (x,y,z) to COP –Derived using similar triangles (on board) –We get the projection by throwing out the last coordinate:

Homogeneous coordinates Is this a linear transformation?

Homogeneous coordinates Trick: add one more coordinate: Converting from homogeneous coordinates homogeneous projection coordinates homogeneous viewing coordinates

Perspective Projection Projection is a matrix multiply using homogeneous coordinates: divide by third coordinate This is known as perspective projection –The matrix is the projection matrix –Can also formulate as a 4x4 divide by fourth coordinate

Perspective Projection The projection matrix can be much involved, if the COP is different from the origin of the uvn coordinates –See the textbook for the detailed matrix

Traditional Classification of Projections Three principle axes of the object is assumed –The front, top, and side face of the scene is apparent

Traditional Classification of Projections

Perspective-Projection View Volume Viewing frustum –Why do we need near and far clipping plane ?

Normalizing Transformation Transform an arbitrary perspective-projection view volume into the canonical view volume Step 1: from frustum to parallelepiped

Normalizing Transformation Transform an arbitrary perspective-projection view volume into the canonical view volume Step 2: from parallelepiped to normalized

OpenGL 3D Viewing Functions Viewing-transformation function –glMatrixMode(GL_MODELVIEW); –gluLookAt(x0,y0,z0,xref,yref,zref,vx,vy,vz); –Default: gluLookAt(0,0,0, 0,0,-1, 0,1,0); OpenGL orthogonal-projection function –glMatrixMode(GL_PROJECTION); –gluOrtho(xwmin,xwmax, ywmin,ywmax, dnear,dfar); –Default: gluOrtho(-1,1, -1,1, -1,1); –Note that dnear and dfar must be assigned positive values z near =-dnear and z far =-dfar The near clipping plane is the view plane

OpenGL 3D Viewing Functions OpenGL perspective-projection function –The projection reference point is the viewing-coordinate origin –The near clipping plane is the view plane –Symmetric: gluPerspective(theta,aspect,dnear,dfar) –General: glFrustum(xwmin,xwmax,ywmin,ywmax,dnear,dfar)