2D Graphics Lecture 4 Fri, Aug 31, 2007.

Slides:



Advertisements
Similar presentations
CGPage: 1 We can define a window as a rectangular region of the world coordinate space, and the viewport as a rectangular region of the device coordinate.
Advertisements

Coordinate System.
Okay, you have learned … OpenGL drawing Viewport and World Window setup main() { glViewport(0,0,300,200); glMatrixMode(GL_PROJECTION); glLoadIndentity();
Line clipping: Line clipping algorithm is method of eliminate lines of outside area of the object,so outside of object viewing is Removed. Typically, any.
Okay, you have learned … OpenGL drawing Viewport and World Window setup main() { glViewport(0,0,300,200); glMatrixMode(GL_PROJECTION); glLoadIndentity();
Clipping Lines Lecture 7 Wed, Sep 10, The Graphics Pipeline From time to time we will discuss the graphics pipeline. The graphics pipeline is the.
Computer Graphics using OpenGL, 3 rd Edition F. S. Hill, Jr. and S. Kelley Chapter 3 Additional Drawing Tools Ureerat Suksawatchon Department of Computer.
Informationsteknologi Monday, November 12, 2007Computer Graphics - Class 71 Today’s class Viewing transformation Menus Mandelbrot set and pixel drawing.
HCI 530 : Seminar (HCI) Damian Schofield. HCI 530: Seminar (HCI) Transforms –Two Dimensional –Three Dimensional The Graphics Pipeline.
CS 352: Computer Graphics Chapter 5: Viewing. Interactive Computer GraphicsChapter Overview Specifying the viewpoint Specifying the projection Types.
Mapping between Scene and Screen. Screen (0, W-1) (W-1, H-1) (W-1, 0)(0, 0) Projection Plane (Xmin, Ymin)(Xmax, Ymin) (Xmax, Ymax) (Xmin, Ymax) Screen.
University College Dublin1 Clipping u Clipping is the removal of all objects or part of objects in a modelled scene that are outside the real-world window.
Projection Projection - the transformation of points from a coordinate system in n dimensions to a coordinate system in m dimensions where m
Introduction to 3D viewing 3D is just like taking a photograph!
Textures – Magnification and Minification Lecture 30 Mon, Nov 17, 2003.
Using Graphics Libraries Lecture 3 Mon, Sep 1, 2003.
Windowing and clipping
Events and Coordinates Lecture 5 Fri, Sep 5, 2003.
CS 376 Introduction to Computer Graphics 02 / 12 / 2007 Instructor: Michael Eckmann.
The Viewing Pipeline (Chapter 4) 5/26/ Overview OpenGL viewing pipeline: OpenGL viewing pipeline: – Modelview matrix – Projection matrix Parallel.
Section 1.1 Graphs and Graphing Utilities. Points and Ordered Pairs.
GRAFIKA KOMPUTER ~ M. Ali Fauzi. Drawing 2 D Graphics.
2 COEN Computer Graphics I Evening’s Goals n Discuss the mathematical transformations that are utilized for computer graphics projection viewing.
CSE 470: Computer Graphics. 10/15/ Defining a Vertex A 2D vertex: glVertex2f(GLfloat x, GLfloat y); 2D vertexfloating pointopenGL parameter type.
Computer Information Technology – Section 4-12 Some text and examples used with permission from: Note: We not endorsing or promoting.
Project 6 Tumbling Cube Fri, Nov 21, 2003 Due Mon, Dec 8, 2003.
Histograms Lecture 14 Sec Tue, Sep 26, 2006.
Computer Graphics Zhen Jiang West Chester University.
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)
Chapters 5 2 March Classical & Computer Viewing Same elements –objects –viewer –projectors –projection plane.
Foundations of Computer Graphics (Spring 2012) CS 184, Lecture 5: Viewing
Histograms Lecture 14 Sec Fri, Feb 8, 2008.
Taxonomy of Projections FVFHP Figure Taxonomy of Projections.
Drawing and Coordinate Systems. Coordinate Systems Screen Coordinate system World Coordinate system World window Viewport Window to viewport mapping.
Histograms Lecture 18 Sec Tue, Feb 17, 2004.
Project 2 Function Plotter Mon, Sep 22, 2003 Due Mon, Sep 29, 2003.
Coordinate Systems Lecture 1 Fri, Sep 2, The Coordinate Systems The points we create are transformed through a series of coordinate systems before.
Computer Graphics using OpenGL, 3 rd Edition F. S. Hill, Jr. and S. Kelley Chapter 3 Additional Drawing Tools PART I.
Chapter #03 More Drawing Tools 1. Viewport 2 Do not have use the entire window for the image: glViewport(x,y,w,h) Values in pixels (screen coordinates)
Coordinate Systems Lecture 20 Wed, Oct 15, Object Coordinates Each object has its own “local” coordinate system, called object coordinates. Normally.
OpenGL LAB III.
Section 1.1 Graphs and Graphing Utilities
COMP261 Lecture 4 Graphs 3 of 3.
Computer Graphics Lecture 14 CLIPPING I Taqdees A. Siddiqi
3D Technologies for the Web
Navigating in 3D MAX V part 1.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2016
Courtesy of Drs. Carol O’Sullivan / Yann Morvan Trinity College Dublin
Introduction to the Mouse
Coordinate Reference Frames
Web Games Programming Creating Split-View Cameras and Camera Overlays.
CSCE 441 Computer Graphics 3-D Viewing
Understanding the Viewing Rectangle/Window of the Graphing Calculator
Chapter #03 More Drawing Tools.
Lab 7 Viewing.
Intro to lighting (Chapter 11)
WINDOWING AND CLIPPING
Section 1.1 Graphs and Graphing Utilities
Section 1.1 Graphs and Graphing Utilities
Computer Graphics Lecture 20
Rasterizing Lines 1 Lecture 32 Mon, Nov 12, 2007.
Graphing Calculator Lesson 1: Graphing Lines and Finding Intercepts
WINDOWING AND CLIPPING
Introduction to OpenGL
OpenGL program.
The View Frustum Lecture 10 Fri, Sep 14, 2007.
Histograms Lecture 14 Sec Fri, Feb 8, 2008.
Window to Viewport Transformations
Guilford County SciVis V part 1
Presentation transcript:

2D Graphics Lecture 4 Fri, Aug 31, 2007

2D Graphics In two-dimensional graphics, objects are drawn as 3D objects, except: The z-coordinate is ignored. Objects are projected orthographically onto the xy-plane. Depth testing is turned off. The last object drawn appears on top.

gluOrtho2D(xmin, xmax, ymin, ymax); 2D Graphics Since there is no perspective viewing, we need only keep track of the x and y world coordinates at the edges of the viewport. We will call these xmin, xmax, ymin, and ymax. The function call to gluPerspective() will be replaced by gluOrtho2D(xmin, xmax, ymin, ymax);

The Reshape Function void reshape(int w, int h) { if (w > 0 && h > 0) xmin = … // Calculate new bounds xmax = … // if necessary ymin = … ymax = … screenWidth = w; screenHeight = h; glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(xmin, xmax, ymin, ymax); glViewport(0, 0, w, h); glutPostRedisplay(); } return;

glViewport(0, 0, width, height); The Viewport The viewport is the part of the window in which the scene is displayed. Normally, this is the entire window. Typically, we initialize the window size to 640 × 480. The function call glViewport(0, 0, width, height); establishes the viewport on the screen.

Viewport Coordinates The coordinates are based on the “gridlines” between the pixels.

Viewport Coordinates The coordinates are based on the “gridlines” between the pixels. (0, 480) (640, 480) pixel (0, 0) (640, 0)

Viewport Coordinates Pixel (i, j) is located between gridlines x = i and x = i + 1, and y = j and y = j + 1. y = j + 1 pixel (i, j) y = j point (i, j) x = i x = i + 1

Viewport Coordinates The corner pixels. pixel (0, 479)

World Coordinates To make the two-dimensional world coordinates identical with the viewport coordinates, let xmin = 0 ymin = 0 xmax = screenWidth ymax = screenHeight

World Coordinates More typically, we place the origin in world coordinates at the center of the screen. Then we assign new boundaries accordingly. For example, xmin = -4.0; xmax = 4.0; ymin = -3.0; // Aspect ratio 4/3 ymax = 3.0;

Resizing the Window When we resize the window, the two most common ways to redraw the scene are Distort the scene proportionally. Keep the scene a constant size and keep the upper-left corner fixed.

Distorting the Scene If we change the viewport without changing the world-coordinates boundaries, then the scene will be distorted. That is, if we do not recompute xmin, xmax, ymin, and ymax, the scene will be distorted.

Distorting the Scene The scene will be stretched or contracted in both the x and y directions.

Distorting the Scene Read Run

Constant Size, Fixed Corner We may want to keep the objects in the window the same size whether the window size is increased or decreased. We simply show more or less of the scene. The question is, what part of the scene should be added or deleted?

Constant Size, Fixed Corner For simplicity, assume that the window border is pulled down and to the right. (xmax, ymax) screenHeight h screenWidth (xmin, ymin) w

Constant Size, Fixed Corner Many applications keep the upper-left corner of the scene fixed. Thus, xmin and ymax remain unchanged. xmax and ymin must be recomputed.

Constant Size, Fixed Corner Read Run

Constant Size, Fixed Corner In the x-direction, the extent has been changed by the fraction w/screenWidth. Therefore, xmax = xmin + (w/screenWidth)*(xmax – xmin); Similarly, ymin = ymax – (h/screenHeight)*(ymax – ymin);

Constant Size, Fixed Center Sometimes we may want to expand the scene equally in all directions, keeping the center point in the center.

Constant Size, Fixed Center Read Run

Constant Size, Fixed Center (xmax, ymax) screenHeight h screenWidth w (xmin, ymin)

Constant Size, Fixed Center The old center was at ((xmin + xmax)/2, (ymin + ymax)/2) The new screen width is w/screenWidth*(xmax – xmin). Half of this amount should be added to and subtracted from the center to give the new xmax and xmin.

Constant Size, Fixed Center xmin = (xmax + xmin)/2 – (w/screenWidth)*(xmax – xmin)/2 xmax = (xmax + xmin)/2 + Similar calculations give ymin and ymax.