The Viewing Pipeline adaptation of Paul Bunn & Kerryn Hugo s notes

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

Computer Graphics. Chapter 10 Three-Dimensional Viewing

Describe the Orthographic and Perspective projections. How do we combine together transform matrices?

CS 4204 Computer Graphics

Computer Viewing Computer Graphics I, Fall 2008

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

Geometry: Outline. Projections. Orthographic Perspective

CS354 Computer Graphics Viewing and Modeling

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

Viewing Transformation

Fundamental Types of Viewing

CS380: Computer Graphics Viewing Transformation. Sung-Eui Yoon ( 윤성의 ) Course URL:

OpenGL Transformations

CSC 470 Computer Graphics. Three Dimensional Viewing

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

Notes on Assignment. Notes on Assignment. Notes on Assignment. Notes on Assignment

CSC 470 Computer Graphics

Advanced Computer Graphics (CS & SE )

Lecture 4. Viewing, Projection and Viewport Transformations

The View Frustum. Lecture 9 Sections 2.6, 5.1, 5.2. Robb T. Koether. Hampden-Sydney College. Wed, Sep 14, 2011

COMP Computer Graphics and Image Processing. 5: Viewing 1: The camera. In part 1 of our study of Viewing, we ll look at ˆʹ U ˆ ʹ F ˆʹ S

Overview. Viewing and perspectives. Planar Geometric Projections. Classical Viewing. Classical views Computer viewing Perspective normalization

CITSTUDENTS.IN VIEWING. Computer Graphics and Visualization. Classical and computer viewing. Viewing with a computer. Positioning of the camera

Spring 2013, CS 112 Programming Assignment 2 Submission Due: April 26, 2013

COMP3421. Introduction to 3D Graphics

3D Viewing. With acknowledge to: Ed Angel. Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

CIS 636 Interactive Computer Graphics CIS 736 Computer Graphics Spring 2011

Lecture 3 Sections 2.2, 4.4. Mon, Aug 31, 2009

Transformation Pipeline

Lecture 9 Sections 2.6, 5.1, 5.2. Wed, Sep 16, 2009

COMS 4160: Problems on Transformations and OpenGL

CS4202: Test. 1. Write the letter corresponding to the library name next to the statement or statements that describe library.

Order of Transformations

Computer Viewing. Prof. George Wolberg Dept. of Computer Science City College of New York

Computer Graphics. Chapter 7 2D Geometric Transformations

Computer Graphics. Bing-Yu Chen National Taiwan University

Three-Dimensional Graphics III. Guoying Zhao 1 / 67

Prof. Feng Liu. Fall /19/2016

Viewing with Computers (OpenGL)

CSC Graphics Programming. Budditha Hettige Department of Statistics and Computer Science

Viewing. Reading: Angel Ch.5

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

3D Viewing Episode 2

GRAFIKA KOMPUTER. ~ M. Ali Fauzi

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

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

Rendering Pipeline and Coordinates Transforms

COMP3421. Introduction to 3D Graphics

CSE 690: GPGPU. Lecture 2: Understanding the Fabric - Intro to Graphics. Klaus Mueller Stony Brook University Computer Science Department

Fachhochschule Regensburg, Germany, February 15, 2017

Overview. By end of the week:

Surface Graphics. 200 polys 1,000 polys 15,000 polys. an empty foot. - a mesh of spline patches:

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

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

3D Graphics for Game Programming (J. Han) Chapter II Vertex Processing

Transformations (Rotations with Quaternions) October 24, 2005

Graphics and Visualization

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

Viewing COMPSCI 464. Image Credits: Encarta and

2D and 3D Viewing Basics

CSC 470 Computer Graphics

Models and The Viewing Pipeline. Jian Huang CS456

MORE OPENGL. Pramook Khungurn CS 4621, Fall 2011

Computer Graphics. Basic 3D Programming. Contents

Computer Viewing. CITS3003 Graphics & Animation. E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley

Mouse Ray Picking Explained

GL_MODELVIEW transformation

COMP3421. Introduction to 3D Graphics

1 (Practice 1) Introduction to OpenGL

CS 428: Fall Introduction to. Viewing and projective transformations. Andrew Nealen, Rutgers, /23/2009 1

Computer Graphics. Transformations. CSC 470 Computer Graphics 1

CS 4204 Computer Graphics

Chapter 3 - Basic Mathematics for 3D Computer Graphics

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

CS 591B Lecture 9: The OpenGL Rendering Pipeline

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

蔡侑庭 (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

One or more objects A viewer with a projection surface Projectors that go from the object(s) to the projection surface

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

CSE528 Computer Graphics: Theory, Algorithms, and Applications

Viewing. Announcements. A Note About Transformations. Orthographic and Perspective Projection Implementation Vanishing Points

CSE 167: Introduction to Computer Graphics Lecture #5: Projection. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2017

Modeling Transform. Chapter 4 Geometric Transformations. Overview. Instancing. Specify transformation for objects 李同益

Classical and Computer Viewing. Adapted From: Ed Angel Professor of Emeritus of Computer Science University of New Mexico

Precept 2 Aleksey Boyko February 18, 2011

CSE452 Computer Graphics

Introduction to OpenGL Transformations, Viewing and Lighting. Ali Bigdelou

Viewing transformations. 2004, Denis Zorin

CS559: Computer Graphics. Lecture 12: OpenGL Transformation Li Zhang Spring 2008

Computer Graphics 7: Viewing in 3-D

CSE328 Fundamentals of Computer Graphics

1 OpenGL - column vectors (column-major ordering)

3D Viewing. CMPT 361 Introduction to Computer Graphics Torsten Möller. Machiraju/Zhang/Möller

Computer Graphics Geometric Transformations

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

Rasterization Overview

Perspective transformations

To Do. Demo (Projection Tutorial) Motivation. What we ve seen so far. Outline. Foundations of Computer Graphics (Fall 2012) CS 184, Lecture 5: Viewing

Wire-Frame 3D Graphics Accelerator IP Core. C Library Specification

Transcription:

The Viewing Pipeline adaptation of Paul Bunn & Kerryn Hugo s notes What is it? The viewing pipeline is the procession of operations that are applied to the OpenGL matrices, in order to create a 2D representation from 3D geometry. These processes can be broken up into three major areas: The movement of the object is called a modeling transformation. The movement of the camera is called a viewing transformation. The conversion from 3D to 2D is called a projection transformation. The Modeling Transformation The modeling transformations are those such as gltranslate (), glrotatef () and glscalef (), which dictate the movement of the object in local coordinates. These operations are applied to the modelview matrix, as opposed to the projection matrix. To begin transformation of this matrix, we need to specify it in the matrix mode function, then initialize the matrix to the Identity matrix, and perform your transformations thereafter: glmatrixmode(gl_modelview); glloadidentity(); glpushmatrix(); //store current matrix glrotate{f,d}(f/d,x,y,z); gltranslate{fd}(a, b, c); glscale{f/d}(a, b, c); glpopmatrix(); //restore current matrix

Because all coordinates are stored as 4D values, we can manipulate the coordinates with the 4x4 transformation matrix. For a homogeneous coordinate v and a matrix M: v' = Mv, where M is the modified ModelView matrix. Translation gltranslate{fd}(a, b, c); C' = CT, where T= 1 0 0 a 0 1 0 b 0 0 1 c (x+a, y+b, z+c, 1) = T (x, y, z, 1) Scaling glscale{fd}(a, b, c); C' = CS, where S = a 0 0 0 0 b 0 0 0 0 c 0 (xa, yb, zc, 1) = S (x, y, z, 1) Note that scaling is performed relative to the origin of the current coordinate system. Rotation glrotate{fd}(a, x, y, z); where a is the (right-handed) rotation angle, given in degrees, and (x, y, z) define the axis of rotation. C' = CR, where R = 0 M 0 0 where M is a general 3x3 rotation matrix. Note the following three special cases of rotation about the coordinate axes. Rotation about the x-axis glrotatef(a, 1.0, 0.0, 0.0); R = 1 0 0 0 0 cos(a) -sin(a) 0 0 sin(a) cos(a) 0

Rotation about the y-axis glrotatef(a, 0.0, 1.0, 0.0); R = cos(a) 0 sin(a) 0 0 1 0 0 -sin(a) 0 cos(a) 0 Rotation about the z-axis glrotatef(a, 0.0, 0.0, 1.0); R = cos(a) -sin(a) 0 0 sin(a) cos(a) 0 0 0 0 1 0 Like scaling, rotation is performed relative to the origin of the current coordinate system. Viewing Transformations The default OpenGL viewpoint is located at the origin, looking down the negative Z- axis. The geometry that we wish to view must either by moved to a position from which it can be seen from the default viewpoint, or the viewpoint must be moved so that it can see the geometry. Note that the modeling and viewing transformations have an inverse relationship: rotating the model geometry in a positive direction about the X-axis is equivalent to rotating the viewpoint in a negative direction about the X-axis. It is possible to build a viewing transformation by concatenating a series of translations and rotations, however, this can be quite complex. Instead, OpenGL provides a simplified function to define the transformation. Note that although the modeling and viewing transformations can be considered logically separate operations, OpenGL concatenates all of the modeling and viewing transformations into a single matrix (i.e. the ModelView Matrix). A separate matrix is provided to perform the projection transformation. double eyex, eyey, eyez; /* viewpoint */ double referx, refery, referz; /* reference point */ double upx, upy, upz; /* view up vector */

glulookat(eyex, eyey, eyez, referx, refery, referz, upx, upy, upz); where (eyex,eyey,eyez) is the viewpoint, (referx,refery,referz) is a point along the desired line of sight (if the point is at the center of the scene being looked at, it is usually referred to as the reference point), and (upx,upy,upz) is the view up vector. How To Move The Camera Supposing the eye point is fixed: To pan the camera (like shaking your head left and right): Move the reference point horizontally. To tilt the camera (like nodding your head up and down): Move the reference point vertically. To rock the camera (like tilting your head left and right): Let the eye point to the reference point be the normal vector of a plane A; change the direction of the up vector so that it s projection onto A rotates left and right. Projection Transformations OpenGL provides two types of projection transformations: orthographic and perspective. Each of these transformations defines a volume of space called a frustum. Only geometry that is inside of the frustum is displayed on the screen; any portion of geometry that is outside of the frustum is clipped. Orthographic Projection Given by: double left, right, bottom, top, near, far; glortho(left, right, bottom, top, near, far); which defines a rectangular parallelepiped frustum. An orthographic projection projects a 3D point v onto the 2D near clipping plane (sometimes called the picture plane) by constructing a ray through v that is parallel to the viewing direction, i.e. the Z-axis in the eye coordinate system. The (x,y) position on the picture plane where the ray intersects the plane is the 2D projection of v. In other words, if v is expressed in the eye coordinate system as (x,y,z), then the orthographic projection is (x,y).

Perspective Projection Given by: double fov, aspect, near, far; gluperspective(fov, aspect, near, far); which defines a truncated pyramid frustum. A perspective projection projects a 3D point v onto the 2D picture plane by constructing a ray through v that passes through the viewpoint direction, i.e. the origin of the eye coordinate system. The (x,y) position on the picture plane where the ray intersects the plane is the 2D projection of v. In other words, if v is expressed in the eye coordinate system as (x,y,z), then the perspective projection is (near*x/z, near*y/z). Perspective projection produces images that appear more realistic; it more closely mimics the operation of the human eye. This perspective projection can also be achieved by the OpenGL command glufrustum (), which can be used to mimic the behavior of gluperspective (). The frustum command has the added functionality of being able to accommodate off-axis projections, whereas gluperspective only produces symmetrical / on-axis projections (Please look at Kerryn s notes for more info on this function). Building the Pipeline Because all of the transformation matrices are multiplied on the right: C' = CM And the multiplication of a vertex coordinate with the transformation matrices also occurs on the right: v' = Cv The matrix that is farthest to the right is applied to the vertex first.

We can represent the viewing pipeline as follows: v' = PMv Where P is the projection matrix (orthographic / perspective transformations) and M is the modelview matrix (modeling and viewing transformations). Since the modelview matrix can be thought of logically as separate viewing and modeling transformations: v' = PVMv where V is the viewing matrix and M is the modeling matrix. Note that first we apply the modeling transformation to orient the geometric model, then we apply the viewing transformation to define the eye coordinate system, and finally we perform the projection from 3D to 2D. The 2D picture plane forms the world coordinate window, which can be mapped to the screen viewport. The viewport can hence be used to stretch the 2D scene if necessary (i.e. W/H ratio of window can be 2x W/H ratio of world window): Since the order of the transformations is significant, we want to invoke the OpenGL functions is the proper order, i.e. in the reverse order in which they will be applied. glviewport(...); /* screen viewport */ glmatrixmode(gl_projection); /* specify the projection matrix */ glloadidentity(); /* initialize to identity */ gluperspective(...); /* or glortho(...) */ glmatrixmode(gl_modelview); /* specify the modelview matrix */ glloadidentity(); /* initialize to identity */ glulookat(...); /* specify viewing transformation */ gltranslate(...); /* modeling transformations, */ glscale(...); /* as necessary */ glrotate(...);...