Coordinate System.

Slides:



Advertisements
Similar presentations
OpenGL Computer Graphics
Advertisements

Computer Graphics - Graphics Programming -
CS2401-Computer Graphics &&
1 Gestione degli eventi Daniele Marini. 2 Pipe-line di OGL pixel data vertex data display list pixel operation evaluator rasterization per vertex op &
OPEN GL. Install GLUT Download package di sini Dari devcpp, buka Tools->PackageManager-
Okay, you have learned … OpenGL drawing Viewport and World Window setup main() { glViewport(0,0,300,200); glMatrixMode(GL_PROJECTION); glLoadIndentity();
Line and Curve Drawing Algorithms. Line Drawing x0x0 y0y0 x end y end.
Chapter 2: Graphics Programming
MAT 594CM S2010Fundamentals of Spatial ComputingAngus Forbes Overview Goals of the course: 1. to introduce real-time 3D graphics programming with openGL.
CMPE 466 COMPUTER GRAPHICS
Okay, you have learned … OpenGL drawing Viewport and World Window setup main() { glViewport(0,0,300,200); glMatrixMode(GL_PROJECTION); glLoadIndentity();
University of North Carolina at Greensboro
#include int line_width = 1; void Display( void ) { glEnable( GL_LINE_STIPPLE ); glClearColor (0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT);
CS 4731: Computer Graphics Lecture 4: 2D Graphic Systems
© 2004, Tom Duff and George Ledin Jr1 Lectures OpenGL Introduction By Tom Duff Pixar Animation Studios Emeryville, California and George Ledin Jr Sonoma.
University of North Carolina at Greensboro
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.
Viewing and Transformation
Raster Displays Images are composed of arrays of pixels displayed on a raster device. Two main ways to create images: –Scan and digitize an existing image.
OpenGL (I). What is OpenGL (OGL)? OGL is a 3D graphics & modeling library Can also use it to draw 2D objects.
Sierpinski Gasket Program
CSC461 Lecture 9: GLUT Callbacks Objectives Introduce double buffering for smooth animations Programming event input with GLUT.
UniS CS297 Graphics with Java and OpenGL Viewing, the model view matrix.
GLWidget Description Jason Goffeney 3/8/2006. GLWidget The GLWidget class extends the Qt QGLWidget. The QGLWidget is a Qt Widget that happens to have.
1 Working with Callbacks Yuanfeng Zhou Shandong University.
More on Drawing in OpenGL: Examples CSC 2141 Introduction to Computer Graphics.
WORKING WITH CALLBACKS Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico Angel: Interactive.
The Viewing Pipeline (Chapter 4) 5/26/ Overview OpenGL viewing pipeline: OpenGL viewing pipeline: – Modelview matrix – Projection matrix Parallel.
Korea University Korea University Computer Graphics Laboratory Computer Graphics Laboratory Jung Lee, Chapter 13.
CSE 470: Computer Graphics. 10/15/ Defining a Vertex A 2D vertex: glVertex2f(GLfloat x, GLfloat y); 2D vertexfloating pointopenGL parameter type.
Ch 2 Graphics Programming page 1 CSC 367 Coordinate Systems (2.1.2) Device coordinates, or screen coordinates (pixels) put limitations on programmers and.
1 Figures are extracted from Angel's book (ISBN x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole.
2D Coordinate Systems and Drawing
OpenGL The Viewing Pipeline: Definition: a series of operations that are applied to the OpenGL matrices, in order to create a 2D representation from 3D.
Draw a Simple Object. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture blending.
OpenGL Viewing and Modeling Transformation Geb Thomas Adapted from the OpenGL Programming Guidethe OpenGL Programming Guide.
Computer Graphics I, Fall 2010 Working with Callbacks.
Viewing and Transformation. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture.
Chun-Yuan Lin Introduction to OpenGL 2015/12/19 1 CG.
Projections. Viewports Windows can have separate viewports void glViewport(GLint x, GLint y, GLsizei width, GLsizei height ) x, y - Specify the lower.
Chap 3 Viewing and Transformation
Chi-Cheng Lin, Winona State University CS430 Computer Graphics Rendering Pipeline and Primitive Rasterization.
Drawing and Coordinate Systems. Coordinate Systems Screen Coordinate system World Coordinate system World window Viewport Window to viewport mapping.
CS552: Computer Graphics Lecture 6: Viewing in 2D.
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.
Introduction to OpenGL Muhammad Aamir Khan Lecturer, DCS, UOP.
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)
Introduction to Graphics Programming. Graphics API.
OpenGL CS418 Computer Graphics John C. Hart. OpenGL Based on GL (graphics library) by Silicon Graphics Inc. (SGI) Advantages: Runs on everything, including.
OpenGL CS418 Computer Graphics John C. Hart. OpenGL: Event-driven How in OpenGL? Programmer registers callback functions Callback function called when.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Working with Callbacks.
Computer Graphics Lecture 41 Viewing Using OpenGL Taqdees A. Siddiqi
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
Working with Callbacks
Reference1. [OpenGL course slides by Rasmus Stenholt]
Chapter #03 More Drawing Tools.
OpenGL (Open Graphics Library) Mr. B.A.Swamy Assistant Professor Dept of CSE.
Class 1: First Program.
WINDOWING AND CLIPPING
Working with Callbacks
Coordinate Systems and Transforming the Coordinates
WINDOWING AND CLIPPING
Computer Graphics, Lee Byung-Gook, Dongseo Univ.
Introduction to OpenGL
OpenGL program.
2D Graphics Lecture 4 Fri, Aug 31, 2007.
Computer Graphics 3Practical Lesson
CS297 Graphics with Java and OpenGL
Presentation transcript:

Coordinate System

glOrtho? glOrtho(0.0, 500.0, 0.0, 500.0, -1.0,1.0); Set the viewing volume Anything outside this volume will be clipped

Window Size glutInitWindowSize(320,240); Set the display window Can be any values However, distortion can occur due to different aspect ratio (w/h)

Different window size 320, 240 240, 320

Coordinate system the basic coordinate system of the screen window: coordinates that are essentially in pixels, extending from 0 to some value screenWidth -1 in x, and from 0 to some value screenHeight -1 in y. Clearly we want to make a separation between the values we use in a program to describe the geometrical objects and the size and position of the pictures of them on the display.

World window and viewport world coordinates: It is the usual Cartesian xy-coordinate system used in mathematics, based on whatever units are convenient. We define a rectangular world window in these world coordinates. The world window specifies which part of the “world” should be drawn. The understanding is that whatever lies inside the window should be drawn; whatever lies outside should be clipped away and not drawn. viewport is a rectangular in the screen window on the screen.

Viewport Transformation MyWindow w Clipping Window h x y void glViewport(Glint x, GLint y, GLsizei w, Glsizei h); Default viewport corresponds to entire window drawable area.

Doing it in OpenGL. For 2D drawing the world window is set by the function gluOrtho2D(), and the viewport is set by the function glViewport(). void gluOrtho2D(GLdouble left, GLdouble right, GLdouble bottom, Gldouble top); void glViewport(GLint x, GLint y, GLint width, GLint height); By default the viewport is the entire screen window: if W and H are the width and height of the screen window, respectively, the default viewport has lower left corner at (0, 0) and upper right corner at (W, H).

Example: Drawing a house Assume the screen Window size is 200x200 glOrtho(0.0, 10.0, 0.0, 15.0, -1.0, 1.0); //world window Five vertices 0 0 10 0 10 10 5 15 0 10 glViewport(0,0,100,100) Not specifying viewport

A distorted house glViewport(0,0, 200,100) Remember window size is 200x200 Distorted with respect to the original picture that were shown in the full viewing window (check the aspect ratio)

Proportionality forces the mappings to have a linear form: sx = A * x + C sy = B * y + D for some constants A, B, C and D. The constants A and B scale the x and y coordinates, and C and D shift (or translate) them.

Window to ViewPort Transformation

Because OpenGL uses matrices to set up all its transformations, gluOrtho2D() must be preceded by two functions glMatrixMode(GL_PROJECTION) and glLoadIdentity(). //Setwindow routine l, r, b, t Void setWindow(float, l, float r, float b, float t){ glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(l, r, b, t); // sets the window }

Tiling the screen window with the dinosaur motif.

Tiling the display with copies of the dinosaur. // set a fixed window (0, 640.0, 0, 480.0) for(int i = 0; i < 5; i++) // for each column for(int j = 0; j < 5; j++) // for each row { glViewport(i * 64, j * 44, 64, 44); // set the next viewport drawPolylineFile(“dino.dat”); // draw it again } if((i+j)%2) ==0) //set a fixed window (0, 640.0, 0, 480.0) using the set window routine else // set a fixed window (0, 640.0, 480.0, 0) //upside-down window

Drawing Dot with Mouse void myMouse(int button, int state, int x, int y) { if (button == GLUT_LEFT_BUTTON && state == GLUT_DOWN) drawDot(x, screenHeight -y); else if(button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN) exit(-1); } drawDot rountine? Void drawDot(GLint x Glint y){ glBegin(GL_POINTS): glVertex2i(x,y); glEnd;

Specifying a rectangle with the mouse. void myMouse(int button, int state, int x, int y){ static GLintPoint corner[2]; // a struct with GLint x and GLint y static int numCorners = 0; // initial value is 0 if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN){ corner[numCorners].x = x; corner[numCorners].y = screenHeight - y; // flip y coordinate numCorners++; // have another point if(numCorners == 2){ glRecti(corner[0].x, corner[0].y, corner[1].x, corner[1].y); //write this //procedure yourself numCorners = 0; // back to 0 corners}} else if(button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN) glClear(GL_COLOR_BUFFER_BIT); // clear the window glFlush(); }

A polyline drawer based on mouse clicks. void myMouse(int button, int state, int x, int y){ #define NUM 20 static GLintPoint List[NUM]; static int last = -1; // last index used so far // test for mouse button as well as for a full array if(button == GLUT_LEFT_BUTTON && state == GLUT_DOWN && last < NUM -1){ List[++last].x = x; // add new point to list List[ last].y = screenHeight - y; // window height is 480 glClear(GL_COLOR_BUFFER_BIT); // clear the screen glBegin(GL_LINE_STRIP); // redraw the polyline for(int i = 0; i <= last; i++) glVertex2i(List[i].x, List[i].y); glEnd(); glFlush();} else if(button == GLUT_RIGHT_BUTTON && state == GLUT_DOWN) last = -1; // reset the list to empty }

Freehand drawing with a fat brush. void myMovedMouse(int mouseX, int mouseY) { GLint x = mouseX; //grab the mouse position GLint y = screenHeight -mouseY; // flip it as usual GLint brushSize = 20; glRecti(x,y, x + brushSize, y + brushSize); glFlush(); }

An example of the keyboard callback function void myKeyboard(unsigned char theKey, int mouseX, int mouseY) { GLint x = mouseX; GLint y = screenHeight - mouseY; // flip the y value as always switch(theKey) case ‘p’: drawDot(x, y); // draw a dot at the mouse position break; case ‘E’: exit(-1); //terminate the program default: break; // do nothing }}