Today s class. Viewing transformation Menus Mandelbrot set and pixel drawing. Informationsteknologi

Similar documents
Getting Started. Overview (1): Getting Started (1): Getting Started (2): Getting Started (3): COSC 4431/5331 Computer Graphics.

More on Coordinate Systems. Coordinate Systems (3) Coordinate Systems (2) Coordinate Systems (5) Coordinate Systems (4) 9/15/2011

Computer Graphics. Chapter 5 Geometric Transformations. Somsak Walairacht, Computer Engineering, KMITL

GRAFIKA KOMPUTER. ~ M. Ali Fauzi

CS 4204 Computer Graphics

Computer Graphics Geometric Transformations

CSCI 4620/8626. The 2D Viewing Pipeline

Computer Graphics 7: Viewing in 3-D

Computer Graphics. Chapter 10 Three-Dimensional Viewing

CS 4204 Computer Graphics

COMP30019 Graphics and Interaction Three-dimensional transformation geometry and perspective

3D Graphics Pipeline II Clipping. Instructor Stephen J. Guy

Transformations Computer Graphics I Lecture 4

Lecture 4: Transformations and Matrices. CSE Computer Graphics (Fall 2010)

Drawing and Coordinate Systems

CSC 470 Computer Graphics

Computer Graphics. Bing-Yu Chen National Taiwan University

Fachhochschule Regensburg, Germany, February 15, 2017

OpenGL Transformations

Lecture 4 of 41. Lab 1a: OpenGL Basics

521493S Computer Graphics Exercise 1 (Chapters 1-3)

CSC 305 The Graphics Pipeline-1

Overview. Affine Transformations (2D and 3D) Coordinate System Transformations Vectors Rays and Intersections

12. Selection. - The objects selected are specified by hit records in the selection buffer. E.R. Bachmann & P.L. McDowell MV 4202 Page 1 of 13

CSE 167: Lecture #4: Vertex Transformation. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2012

CS 591B Lecture 9: The OpenGL Rendering Pipeline

Transformations Computer Graphics I Lecture 4

Representing 2D Transformations as Matrices

Drawing and Coordinate Systems

CSE528 Computer Graphics: Theory, Algorithms, and Applications

Today. Rendering pipeline. Rendering pipeline. Object vs. Image order. Rendering engine Rendering engine (jtrt) Computergrafik. Rendering pipeline

Graphics and Interaction Transformation geometry and homogeneous coordinates

COMP30019 Graphics and Interaction Transformation geometry and homogeneous coordinates

2D rendering takes a photo of the 2D scene with a virtual camera that selects an axis aligned rectangle from the scene. The photograph is placed into

Reading. Hierarchical Modeling. Symbols and instances. Required: Angel, sections , 9.8. Optional:

CSE328 Fundamentals of Computer Graphics

1 Transformations. Chapter 1. Transformations. Department of Computer Science and Engineering 1-1

Lecture 5: Viewing. CSE Computer Graphics (Fall 2010)

Transformations. CSCI 420 Computer Graphics Lecture 4

Computer Graphics. Chapter 7 2D Geometric Transformations

1 (Practice 1) Introduction to OpenGL

Evening s Goals. Mathematical Transformations. Discuss the mathematical transformations that are utilized for computer graphics

Prof. Feng Liu. Fall /19/2016

Transformations. Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

UNIT 2 2D TRANSFORMATIONS

C OMPUTER G RAPHICS Thursday

Announcements. Submitting Programs Upload source and executable(s) (Windows or Mac) to digital dropbox on Blackboard

Imaging and 2D Transforms

Computer Vision. Coordinates. Prof. Flávio Cardeal DECOM / CEFET- MG.

1 Projective Geometry

Part 3: 2D Transformation

Computer Graphics: Viewing in 3-D. Course Website:

Projection: Mapping 3-D to 2-D. Orthographic Projection. The Canonical Camera Configuration. Perspective Projection

Transforming Objects in Inkscape Transform Menu. Move

window World space (Object space)

CSE 167: Introduction to Computer Graphics Lecture #4: Vertex Transformation

UNIVERSITY OF NEBRASKA AT OMAHA Computer Science 4620/8626 Computer Graphics Spring 2014 Homework Set 1 Suggested Answers

Fundamental Types of Viewing

Institutionen för systemteknik

CS 543: Computer Graphics Midterm review. Emmanuel Agu

CS230 : Computer Graphics Lecture 6: Viewing Transformations. Tamar Shinar Computer Science & Engineering UC Riverside

CT5510: Computer Graphics. Transformation BOCHANG MOON

OpenGL: Open Graphics Library. Introduction to OpenGL Part II. How do I render a geometric primitive? What is OpenGL

GEOMETRIC TRANSFORMATIONS AND VIEWING

CS 4204 Computer Graphics

Two Dimensional Viewing

Viewing COMPSCI 464. Image Credits: Encarta and

Computer Graphics: Two Dimensional Viewing

DHANALAKSHMI COLLEGE OF ENGINEERING, CHENNAI

EECE 478. Learning Objectives. Learning Objectives. Linear Algebra and 3D Geometry. Linear algebra in 3D. Coordinate systems

CMSC 425: Lecture 4 More about OpenGL and GLUT Tuesday, Feb 5, 2013

Computer Graphics with OpenGL ES (J. Han) Chapter IV Spaces and Transforms

Homework #1. Displays, Image Processing, Affine Transformations, Hierarchical modeling, Projections

Lecture 11: Callbacks. CITS 3003 Graphics & Animation

2D and 3D Transformations AUI Course Denbigh Starkey

Advanced Computer Graphics (CS & SE )

Viewing and Projection

Viewing and Projection

CHAPTER 1 Graphics Systems and Models 3

Better Interactive Programs

S U N G - E U I YO O N, K A I S T R E N D E R I N G F R E E LY A VA I L A B L E O N T H E I N T E R N E T

Computer Graphics Hands-on

Coordinate transformations. 5554: Packet 8 1

蔡侑庭 (Yu-Ting Tsai) National Chiao Tung University, Taiwan. Prof. Wen-Chieh Lin s CG Slides OpenGL 2.1 Specification

Three-Dimensional Viewing Hearn & Baker Chapter 7

Discrete Techniques. 11 th Week, Define a buffer by its spatial resolution (n m) and its depth (or precision) k, the number of

EXAMINATIONS 2017 TRIMESTER 2

Project Sketchpad. Ivan Sutherland (MIT 1963) established the basic interactive paradigm that characterizes interactive computer graphics:

Transformations. CSCI 420 Computer Graphics Lecture 5

Transformations. OpenGL Transformations. 4x4 Model-view Matrix (this lecture) OpenGL Transformation Matrices. 4x4 Projection Matrix (next lecture)

Lectures OpenGL Introduction

UNIT 2. Translation/ Scaling/ Rotation. Unit-02/Lecture-01

Overview of Projections: From a 3D world to a 2D screen.

Working Style of Program

Transformation Algebra

3D Rendering Pipeline (for direct illumination)

Modeling Objects by Polygonal Approximations. Linear and Affine Transformations (Maps)

Transformation Pipeline

7. 3D Viewing. Projection: why is projection necessary? CS Dept, Univ of Kentucky

Fall CSCI 420: Computer Graphics. 2.2 Transformations. Hao Li.

Transcription:

Today s class Viewing transformation Menus Mandelbrot set and pixel drawing Monday, November 2, 27 Computer Graphics - Class 7

The world & the window World coordinates describe the coordinate system used to model our scene Let the world coordinates obey the following relationships: wx min wx wx max wy min wy wy max The OpenGL code to set the world coordinates is: glmatrixmode (GL_PROJECTION); glloadidentity (); gluortho2d (wx min, wx max, wy min, wy max ); This code sets a window through which we view the scene Monday, November 2, 27 Computer Graphics - Class 7 2

The viewport The viewport defines the physical part of the display window that the image will appear in Let the viewport coordinates obey the following relationships: vx min vx vx max vy min vy vy max The OpenGL code to set the viewport is: glviewport (vx min, vy min, vx max -vx min, vy max -vy min ); The default viewport is the entire window Monday, November 2, 27 Computer Graphics - Class 7 3

Window to viewport mapping Observe that going from world coordinates to viewport coordinates is nothing more than a change of coordinate systems This is accomplished by a mapping We want this mapping to be proportional, to preserve relative positions of objects in the scene Monday, November 2, 27 Computer Graphics - Class 7 4

Derivation of mapping To preserve proportionality we have (in the x direction) vx vx max vx vx min min Solving for vx gives vx = vx wx max max vx wx min min wx = + wx wx Note that this involves a scaling and a shifting (or translation) max wx wx vx min min vx max min ( vx min wx min wx max wx min ) Monday, November 2, 27 Computer Graphics - Class 7 5

Viewing transformation We now have the necessary skills to understand the 2-D viewing transformation - how a 2-D image is positioned on the screen First, we set the viewing window, the range of coordinate values in x and y that we want displayed Next, we set the viewport, the range of physical pixels that we want the viewing window displayed in Monday, November 2, 27 Computer Graphics - Class 7 6

Viewing transformation steps Translate the window to the origin Scale by the ratio of the viewport dimensions to the window dimensions S = vx wx W = max max vx wx min min vy wy wx wy max max min min vy wy min min Monday, November 2, 27 Computer Graphics - Class 7 7

Viewing transformation steps (cont.) Translate the viewport to its correct spot The composite transformation is then given by the product of the three matrices V = vx vy min min M = VSW Monday, November 2, 27 Computer Graphics - Class 7 8

Three dimensions The real world is 3-dimensional, that is it takes 3 coordinates (x, y, z) to position a point in space In homogeneous coordinates we will use the vector [x y z ] T to represent a point in 3 dimensions Transformation matrices will now be 4 4 Monday, November 2, 27 Computer Graphics - Class 7 9

Monday, November 2, 27 Computer Graphics - Class 7 3-D scaling The 4 4 matrix to accomplish 3-D scaling is z y x s s s

Monday, November 2, 27 Computer Graphics - Class 7 3-D translation The 4 4 matrix to accomplish 3-D translation is z y x t t t

Monday, November 2, 27 Computer Graphics - Class 7 2 3-D reflections The 4 4 matrix to accomplish reflection in the y-z plane The 4 4 matrix to accomplish reflection in the x-z plane The 4 4 matrix to accomplish reflection in the x-y plane

3-D rotations The 4 4 matrix to accomplish rotation about the x-axis The 4 4 matrix to accomplish rotation about the y-axis The 4 4 matrix to accomplish rotation about the z-axis Monday, November 2, 27 Computer Graphics - Class 7 3 cosθ sinθ cosθ sinθ cosθ sinθ sinθ cosθ sinθ cosθ sinθ cosθ

Geometry for rotation about an arbitrary line in 3-D y ν ϕ L x z Monday, November 2, 27 Computer Graphics - Class 7 4

Steps for arbitrary rotation in 3-D Rotate -ϕ around z-axis to bring L to x-z plane Rotate -ν around y-axis to bring L to z- axis Rotate θ around z-axis Rotate ν around y-axis Rotate ϕ around z-axis Monday, November 2, 27 Computer Graphics - Class 7 5

OpenGL representation of points OpenGL uses a column vector to represent points: x y z Monday, November 2, 27 Computer Graphics - Class 7 6

OpenGL transformation matrices Model-view matrix (GL_MODELVIEW) Projection matrix (GL_PROJECTION) The current transformation matrix is the product of the above two matrices Monday, November 2, 27 Computer Graphics - Class 7 7

Computation of transformed point OpenGL computes the displayed point according to the equation P = MP Note that the transformation matrix (M) premultiplies the point Monday, November 2, 27 Computer Graphics - Class 7 8

OpenGL order of transformations When another transformation is applied, the new transformation matrix postmultiplies the current transformation matrix. This has the effect of applying the last transformation specified first and applying the first transformation specified last Monday, November 2, 27 Computer Graphics - Class 7 9

OpenGL transformations gltranslate{d,f} (x, y, z) glrotate{d,f} (angle, x, y, z) angle is in degrees rotation occurs around the vector (x, y, z) follows right-hand rule (counter clockwise if vector points toward the viewer) glscale{d,f} (x, y, z) glmultmatrix{d,f} (*m) m is a 6 element matrix column major ordering Monday, November 2, 27 Computer Graphics - Class 7 2

Affine transformations The transformations we have been discussing are called affine transformations They have the form P = MP Affine transformation properties: preserve lines parallel lines remain parallel proportional distances are preserved Monday, November 2, 27 Computer Graphics - Class 7 2

Window resizing When the window is resized, a default reshape callback function is executed to reset the viewport to the new window size This will distort your image, as the projection mapping is not changed Monday, November 2, 27 Computer Graphics - Class 7 22

Reshape callback function You may register your own reshape callback function using glutreshapefunc() If you do, be sure to reset the viewport in it using glviewport() Monday, November 2, 27 Computer Graphics - Class 7 23

Example reshape callback function void reshape (GLsizei w, GLsizei h) /* This function gets called whenever the window is resized. */ { /* Adjust the clipping rectangle. */ glmatrixmode (GL_PROJECTION); glloadidentity (); gluortho2d (., w -,., h - ); } /* Adjust the viewport. */ glviewport (,, w, h); Monday, November 2, 27 Computer Graphics - Class 7 24

Pop-up menus Attached to a mouse button glutcreatemenu() used to create a menu and to register the menu s callback function glutaddmenuentry() used to add an entry string and its code to the menu Code is used in menu s callback function to decide which menu entry was selected Monday, November 2, 27 Computer Graphics - Class 7 25

Pop-up menus (cont.) glutaddsubmenu() adds a menu as a sub-menu to the indicated menu glutattachmenu() attaches a mouse button to the current menu Monday, November 2, 27 Computer Graphics - Class 7 26

Example program MenuDemo program is an example of popup menus and window resizing Monday, November 2, 27 Computer Graphics - Class 7 27

The Mandelbrot set Given two complex numbers, c and z, and the complex plane, C The Mandelbrot set is defined by { c C lim z i <> under z i+ = z i2 + c, z = (, ) } Choose c. After each iteration see if z > 2. If yes, stop, z. If not, c is in Mandelbrot set. Use a reasonable number of iterations. Monday, November 2, 27 Computer Graphics - Class 7 28

Example c =.5 +.5i (note this is also z ) z 2 = c 2 + c =.5 +.i z 3 = -.25 +.5i z 4 = -.6875 -.25i z 5 = 3.2855625 +.34375i z 5 > 2, so.5 +.5i is not in the Mandelbrot set Monday, November 2, 27 Computer Graphics - Class 7 29

Fixed points c = -.2 +.5i z 2 = -.4 +.3i z 3 = -.29 +.254i z 4 = -.2497 +.438i After 8 iterations the value of z is -.249227 +.333677i From this point on, z 2 + c = z Therefore, c is called a fixed point of the function Since z =.46479, c is in the Mandelbrot set Monday, November 2, 27 Computer Graphics - Class 7 3

Generating the picture Pick a region of the complex plane For each point in the region look at the result of the z = z 2 + c transformation after a given number of iterations If z < 2 then c is in the Mandelbrot set - color it black If z > 2 then c is not in the Mandelbrot set - choose color based on the number of iterations it took to exceed 2 in magnitude Monday, November 2, 27 Computer Graphics - Class 7 3

Boundary area The boundary of the Mandelbrot set is a fractal Chaotic behavior is exhibited there You can zoom in on a point and see new details Image at left is centered at -.3 +.75i with a width of. Monday, November 2, 27 Computer Graphics - Class 7 32

Bitblts A rectangular block of pixels (bits) is known as a bit block Operations that work on bit blocks are known as bit-block transfer (bitblt) operations Monday, November 2, 27 Computer Graphics - Class 7 33

Logic operations Applied bit by bit between the source image and the destination buffer Enable by glenable (GL_COLOR_LOGIC_OP); glenable (GL_INDEX_LOGIC_OP); Specify by gllogicop (op); Some possible ops are: GL_COPY GL_OR GL_XOR Monday, November 2, 27 Computer Graphics - Class 7 34

Exclusive or The most interesting logical operation If applied twice in succession, you get back to the starting state: x = x y y Monday, November 2, 27 Computer Graphics - Class 7 35

Pop-up menus revisited Let M be an array of bits representing a menu that is stored off screen (in what is known as a backing store) Let S be the part of the screen that contains an image over which the menu will appear Consider the sequence of operations: S S M M S M (original contents of screen now stored where menu was) S S M (menu now on screen) Monday, November 2, 27 Computer Graphics - Class 7 36

Example program MandelbrotZoom.cpp draws the Mandelbrot set using pixel drawing gldrawpixels (width, height, format, type, pixel_array) draws at current raster position format indicates kind of data type indicates data type see the OpenGL Reference Manual for symbolic constants that can be used glrasterpos{234}{sifd}[v]() sets the current raster position glreadpixels (x, y, width, height, format, type, pixel_array) reads pixel array beginning at lower left corner (x, y) Monday, November 2, 27 Computer Graphics - Class 7 37