CS552: Computer Graphics Lecture 6: Viewing in 2D.

Slides:



Advertisements
Similar presentations
Computer Graphics - Graphics Programming -
Advertisements

มุมมองใน 2 มิติ (2-D Viewing)
OPEN GL. Install GLUT Download package di sini Dari devcpp, buka Tools->PackageManager-
Line and Curve Drawing Algorithms. Line Drawing x0x0 y0y0 x end y end.
Chapter 2: Graphics Programming
OPENGL.
#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);
CMPE 466 COMPUTER GRAPHICS Chapter 8 2D Viewing Instructor: D. Arifler Material based on - Computer Graphics with OpenGL ®, Fourth Edition by Donald Hearn,
© 2004, Tom Duff and George Ledin Jr1 Lectures OpenGL Introduction By Tom Duff Pixar Animation Studios Emeryville, California and George Ledin Jr Sonoma.
OpenGL (Graphics Library) Software Interface to graphics software Allows to create interactive programs that produce color images of moving 3D objects.
1 King ABDUL AZIZ University Faculty Of Computing and Information Technology CS 454 Computer graphics Two Dimensional Viewing Dr. Eng. Farag Elnagahy
CSC 461: Lecture 51 CSC461 Lecture 5: Simple OpenGL Program Objectives: Discuss a simple program Discuss a simple program Introduce the OpenGL program.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Computer Science,
IAT 3551 Computer Graphics Overview Color Displays Drawing Pipeline.
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.
Introduction to OpenGL M. Ramanathan STTP CAD 2011Introduction to OpenGL.
Introduction to OpenGL Jian Huang This set of slides are extracted from the Interactive OpenGL Programming course given by Dave Shreine, Ed Angel and Vicki.
CAP 4703 Computer Graphic Methods Prof. Roy Levow Lecture 2.
Computer Graphics, KKU. Lecture 131 Transformation and Viewing in OpenGL.
TWO DIMENSIONAL GEOMETRIC TRANSFORMATIONS CA 302 Computer Graphics and Visual Programming Aydın Öztürk
3D Viewing.
Graphics Systems and OpenGL. Business of Generating Images Images are made up of pixels.
1 Figures are extracted from Angel's book (ISBN x) The Human Visual System vs The Pinhole camera Human Visual System Visible Spectrum Pinhole.
Introduction to GL Geb Thomas. Example Code int main(int argc, char **argv) { glutInit(&argc, argv); glutInitDisplayMode ( GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
2 DIMENSIONAL VIEWING Ceng 477 Introduction to Computer Graphics Fall Computer Engineering METU.
DREAM PLAN IDEA IMPLEMENTATION Introduction to Computer Graphics Dr. Kourosh Kiani
Computing & Information Sciences Kansas State University CIS 536/636 Introduction to Computer Graphics Lecture 4 of 41 William H. Hsu Department of Computing.
Computer Graphics Chapter 6 Andreas Savva. 2 Interactive Graphics Graphics provides one of the most natural means of communicating with a computer. Interactive.
Introduction to OpenGL  OpenGL is a graphics API  Software library  Layer between programmer and graphics hardware (and software)  OpenGL can fit in.
Introduction to Computer Graphics Chapter 6 – 2D Viewing Pt 1 1.
Draw a Simple Object. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture blending.
Viewing and Transformation. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture.
CA 302 Computer Graphics and Visual Programming Lecture 2: Introduction to OpenGL Aydın Öztürk
Chun-Yuan Lin Introduction to OpenGL 2015/12/19 1 CG.
NoufNaief.net 1 TA: Nouf Al-Harbi.
CS552: Computer Graphics Lecture 4: 2D Graphics. Recap 2D Graphics Coordinate systems 2D Transformations o Translation o Scaling o Rotation Combining.
Chap 3 Viewing and Transformation
1 Programming with OpenGL Part 2: Complete Programs.
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Learning Objectives Affine transformations Affine transformations Translation Translation Rotation Rotation Scaling Scaling Reflection Reflection Shear.
A.Aruna/Assistant Professor/SNSCE
CS559: Computer Graphics Lecture 12: OpenGL - Transformation Li Zhang Spring 2008.
CS559: Computer Graphics Lecture 12: OpenGL: ModelView Li Zhang Spring 2010.
Introduction to Graphics Programming. Graphics API.
Introduction to Graphics Programming. Graphics: Conceptual Model Real Object Human Eye Display Device Graphics System Synthetic Model Synthetic Camera.
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
Computer Graphics Lecture 41 Viewing Using OpenGL Taqdees A. Siddiqi
학기 Chapter 5. Geometric Transformations 1.
INTRODUCTION TO OPENGL
Computer Graphics (Fall 2003) COMS 4160, Lecture 5: OpenGL 1 Ravi Ramamoorthi Many slides courtesy Greg Humphreys.
Program Studi S-1 Teknik Informatika FMIPA Universitas Padjadjaran
2D Viewing Pipeline.
3D Transformation Pipeline
Programming with OpenGL Part 2: Complete Programs
Materi Anatomi OpenGL Fungsi GLUT Posisi Kamera Proyeksi
OpenGL API 2D Graphic Primitives
Advanced Graphics Algorithms Ying Zhu Georgia State University
Programming with OpenGL Part 2: Complete Programs
Graphics Programming (I)
OpenGL (Open Graphics Library) Mr. B.A.Swamy Assistant Professor Dept of CSE.
גרפיקה ממוחשבת: מבוא ל-OpenGL
Computer Graphics, KKU. Lecture 13
Coordinate Systems and Transforming the Coordinates
Introduction to OpenGL
Line and Curve Drawing Algorithms
OpenGL program.
Programming with OpenGL Part 2: Complete Programs
Programming with OpenGL Part 2: Complete Programs
3D Viewing.
Programming with OpenGL Part 2: Complete Programs
Presentation transcript:

CS552: Computer Graphics Lecture 6: Viewing in 2D

Recap 3D World 3D Transformation Scaling, Translation is simple extension of 2D Rotation About Cartesian axis Arbitrary axis Coordinate transformation

Objective After completing this lecture the students will be able to Define different space Describe 2D Viewing pipeline Transform World coordinate to view coordinate Write program in OpenGL for 2D viewing

Coordinate representation

2D Viewing pipeline 1 World: xvmin xvmax yvmax yvmin Viewport Screen: Clipping window ywmax ywmin xwmin xwmax Clipping window: What do we want to see? Viewport: Where do we want to see it?

2D Viewing pipeline 2 World: Screen: Clipping window Viewport ywmax yvmax xwmin xwmax ywmin yvmin xvmin xvmax Clipping window: Panning…

2D Viewing pipeline 2 World: Screen: Clipping window Viewport ywmax yvmax xwmin xwmax ywmin yvmin xvmin xvmax Clipping window: Panning…

2D Viewing pipeline 3 World: Screen: Viewport ywmax yvmax ywmin yvmin xwmin xwmax xvmin xvmax Clipping window: Zooming…

2D Viewing pipeline 3 World: Screen: ywmax Viewport yvmax yvmin ywmin xwmin xwmax xvmin xvmax Clipping window: Zooming…

2D Viewing pipeline 4 MC: Modeling Coordinates WC: World Coordinates VC: Viewing Coordinates NC: Normalized Coordinates DC: Device Coordinates Apply model transformations Determine visible parts To standard coordinates Clip and determine pixels

Viewing coordinate clipping window Setup a viewing-coordinate system within the world-coordinate frame Origin for a two-dimensional viewing-co-ordinate frame V: the two-dimensional view up vector.

Viewing coordinate clipping window

World coordinate clipping window Define an orientation vector and choose a reference point

Normalization and Viewport Transformations In some packages the normalization and window-to-view port transformations are combined into one operation The view-port coordinates are often given in the range from 0 to 1 After clipping, the unit square containing the viewport is mapped to the output display device Viewport boundaries are specified in screen coordinates relative to the display window position.

Clipping Window into a Normalized Viewport Consider a view port defined with normalized co-ordinate values Object descriptions are transferred to this normalized space By a transformation that maintains the same relative placement of a point (relative to the clipping window)

Window to view port transformation

Window to view port transformation Solving these expressions for the viewport position Scaling factor Translating factor

Alternate approach Scale the clipping window to the size of the view port using a fixed-point position of (𝑥 𝑤 𝑚𝑖𝑛 , 𝑦 𝑤 𝑚𝑖𝑛 ) Translate (𝑥 𝑤 𝑚𝑖𝑛 , 𝑦 𝑤 𝑚𝑖𝑛 ) to (𝑥 𝑣 𝑚𝑖𝑛 , 𝑦 𝑣 𝑚𝑖𝑛 )

Clipping Window into a Normalized Square Another approach to two-dimensional viewing is Transform the clipping window into a normalized square Clip in normalized coordinates Transfer the scene description to a viewport specified in screen coordinates

Clipping Window into a Normalized Square = +1 = -1 Scaling factor = +1 = -1 Translating factor

Clipping Window into a Normalized Square Window to normalized square Normalized square to viewport ??

Clipping Window into a Normalized Square Scaling factor = +1 = -1 = +1 = -1 Translating factor

Clipping Window into a Normalized Square Window to normalized square Normalized square to viewport

Viewport to display Last step: position the viewport area in the display window Convention: lower-left corner of the viewport is placed at a coordinate position specified relative to the lower-left corner of the display window

How to do it in OpenGL? OpenGL library has no functions specifically for 2D viewing The 3D routines can be adapted to a 2D

OpenGL Projection Mode First select the projection mode To define a two-dimensional clipping window View port parameters are specified as

An Example #include <GL/glut.h> class wcPt2D { public: GLfloat x, y; }; void init (void) { /* Set color of display window to white. */ glClearColor (1.0, 1.0, 1.0, 0.0); /* Set parameters for world-coordinate clipping window. */ glMatrixMode (GL_PROJECTION); gluOrtho2D (-100.0, 100.0, - 100.0, 100.0); /** Set mode for constructing geometric transformation matrix. */ glMatrixMode (GL_MODELVIEW); }

An Example void triangle (wcPt2D *verts) { GLint k; glBegin (GL_TRIANGLES); for (k = 0; k < 3; k++) glVertex2f (verts [k].x, verts [k].y); glEnd ( ); }

An Example void displayFcn (void) { /* Define initial position for triangle. */ wcPt2D verts [3] = { {-50.0, -25.0}, {50.0, -25.0}, {0.0, 50.0} }; glClear (GL_COLOR_BUFFER_BIT); // Clear display window. glColor3f (0.0, 0.0, 1.0); // Set fill color to blue. glViewport (0, 0, 300, 300); // Set left viewport. triangle (verts); // Display triangle. /* Rotate triangle and display in right half of display window. */ glColor3f (1.0, 0.0, 0.0); // Set fill color to red. glViewport (300, 0, 300, 300); // Set right viewport. glRotatef (90.0, 0.0, 0.0, 1.0); // Rotate about z axis. triangle (verts); // Display red rotated triangle. glFlush ( ); }

An Example glutDisplayFunc (displayFcn); void main (int argc, char ** argv) { glutInit (&argc, argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutInitWindowPosition (50, 50); glutInitWindowSize (600, 300); glutCreateWindow ("Split-Screen Example"); init ( ); glutDisplayFunc (displayFcn); glutMainLoop ( ); }

Thank you Next Lecture: 2D Clipping