Computer Graphics: Two Dimensional Viewing Clipping and Normalized Window By: A. H. Abdul Hafez Abdul.hafez@hku.edu.tr, 1
Outlines 1. End 2
Transformation between 2 coordinate systems To transform positioned object descriptions from xy coordinates to x'y' coordinates, we set up a transformation that superimposes the x'y' axes onto the xy axes. This is done in two steps: 1. Translate so that the origin (x 0, y 0 ) of the x'y' system is moved to the origin (0, 0) of the xy system 2. Rotate the x' axis onto the x axis. 3
Transformation between 2 coordinate systems Specify a vector V that indicates the direction for the positive y' axis And we obtain the unit vector u along the x' axis by applying a 90 o clockwise rotation to vector v: Example: 4
2D viewing pipeline A clipping window is the section of a two-dimensional scene that is selected for display, because all parts of the scene outside the selected section are "clipped off. Sometimes the clipping window is alluded to as the world window or the viewing window. Graphics packages also allow us to control the placement within the display window using another "window" called the viewport. Objects inside the clipping window are mapped to the viewport, and it is the viewport that is then positioned within the display window. 5
2D viewing pipeline The clipping window selects what we want to see; the viewport indicates where it is to be viewed on the output device. World: What do we want to see? Screen: Where do we want to see it? A clipping window and associated viewport, specified as rectangles aligned with the coordinate axes 6
2D viewing pipeline The mapping of a two-dimensional, world-coordinate scene description to device coordinates is called a two-dimensional viewing transformation. To make the viewing process independent of the requirements of any output device, graphics systems convert object descriptions to normalized coordinates and apply the clipping routines. Some systems use normalized coordinates in the range from 0 to 1, and others use a normalized range from -1 to 1. 7
2D viewing pipeline example object 8
Viewing-coordinate clipping Window A viewing-coordinate frame is moved into coincidence with the world frame by a) applying a translation matrix T to move the viewing origin to the world origin, then b) applying a rotation matrix R to align the axes of the two systems. 9
Viewport Transformation scale and translate A point (xw, yw) in a world-coordinate clipping window is mapped to viewport coordinates (xv, yv), within a unit square, so that the relative positions of the two points in their respective rectangles are the same. 10
Viewport Transformation scale and translate Scale the clipping window to the size of the viewport using a fixedpoint position of (xw min, yw min ). (xw min, yw min ). (xv min, yv min ). Translate (xw min, yw min ) to (xv min, yv min ). (xv min, yv min ). 11 (xw min, yw min ).
Viewport Transformation The scaling factors required to keep the relative position of the two points (xw, yw) and (xv, yv) invariant are given as If the two scale factors are unequal, then the aspect-ratio changes : distortion! 12
Viewport Transformation Scale the clipping window to the size of the viewport using a fixedpoint position of (xw min, yw min ). Translate (xw min, yw min ) to (xv min, yv min ). 13
Viewport Transformation Clipping window to Normalized square Normalized square to screen viewport 14
2D viewing using OpenGL To prevent distortion, make sure that: (ywmax ywmin)/(xwmax xwmin) = vpwidth/vpheight 15
2D Clipping Clipping: removing parts outside clipping window Many algorithms: points, lines, fill-area, curves, Save point P = (x,y) if it s in the box Clipping straight-line segments using a standard rectangular clipping window 16
2D Clipping Cohen-Sutherland algorithm: Assign to each point a four-bit region code C; 1 is outside, 0 is inside A possible ordering for the clipping window boundaries corresponding to the bit positions in the Cohen- Sutherland endpoint region code. The nine binary region codes for identifying the position of a line endpoint, relative to the clippingwindow boundaries. 17
2D Clipping Cohen-Sutherland algorithm: Assign to each point a four-bit region code C; 1 is outside, 0 is inside Fast test on status end points line with codes C0 en C1 : if [C0 (bitwise-or) C1 = 0000], then completely in; else if [C0 (bitwise-and) C1 <> 0000], then completely out; else: fast intersection-calculation using codes 18
The end of the Lecture Thanks for your time Questions are welcome 19