Projections and Transformations in OpenGL

Similar documents
Image Processing and Computer Graphics. Rendering Pipeline. Matthias Teschner. Computer Science Department University of Freiburg

Realtime 3D Computer Graphics Virtual Reality

CS 4204 Computer Graphics

CS 4204 Computer Graphics

4BA6 - Topic 4 Dr. Steven Collins. Chap. 5 3D Viewing and Projections

521493S Computer Graphics. Exercise 2 & course schedule change

Geometry for Computer Graphics

Transformations in the pipeline

INTRODUCTION TO RENDERING TECHNIQUES

Monash University Clayton s School of Information Technology CSE3313 Computer Graphics Sample Exam Questions 2007

Given a point cloud, polygon, or sampled parametric curve, we can use transformations for several purposes:

3D Viewing. Chapter 7. Projections. 3D clipping. OpenGL viewing functions and clipping planes

Basic Problem: Map a 3D object to a 2D display surface. Analogy - Taking a snapshot with a camera

Aston University. School of Engineering & Applied Science

Lecture 3: Coordinate Systems and Transformations

The Geometry of Perspective Projection

Computer Graphics Labs

Geometric Camera Parameters

Essential Mathematics for Computer Graphics fast

Lecture Notes. Fundamentals of Computer Graphics. Prof. Michael Langer School of Computer Science McGill University

Graphics Pipeline in a Nutshell

LINES AND PLANES CHRIS JOHNSON

Introduction to Computer Graphics

Solving Simultaneous Equations and Matrices

Lecture 2: Homogeneous Coordinates, Lines and Conics

Pro/ENGINEER Wildfire 4.0 Basic Design

Android and OpenGL. Android Smartphone Programming. Matthias Keil. University of Freiburg

Q27.1 When a charged particle moves near a bar magnet, the magnetic force on the particle at a certain point depends

α = u v. In other words, Orthogonal Projection

Orthogonal Projections

Geometric Transformation CS 211A

From 3D to 2D: Orthographic and Perspective Projection Part 1

3D Math Overview and 3D Graphics Foundations

3 Orthogonal Vectors and Matrices

B2.53-R3: COMPUTER GRAPHICS. NOTE: 1. There are TWO PARTS in this Module/Paper. PART ONE contains FOUR questions and PART TWO contains FIVE questions.

Adding vectors We can do arithmetic with vectors. We ll start with vector addition and related operations. Suppose you have two vectors

Least-Squares Intersection of Lines

Geometric Constraints

B4 Computational Geometry

GUI GRAPHICS AND USER INTERFACES. Welcome to GUI! Mechanics. Mihail Gaianu 26/02/2014 1

Projective Geometry: A Short Introduction. Lecture Notes Edmond Boyer

SketchUp Instructions

Mechanics lecture 7 Moment of a force, torque, equilibrium of a body

Relating Vanishing Points to Catadioptric Camera Calibration

Solution Guide III-C. 3D Vision. Building Vision for Business. MVTec Software GmbH

KEANSBURG SCHOOL DISTRICT KEANSBURG HIGH SCHOOL Mathematics Department. HSPA 10 Curriculum. September 2007

Notes on Orthogonal and Symmetric Matrices MENU, Winter 2013

Chapter 2 - Graphics Programming with JOGL

Introduction to 2D and 3D Computer Graphics Mastering 2D & 3D Computer Graphics Pipelines

w = COI EYE view direction vector u = w ( 010,, ) cross product with y-axis v = w u up vector

How To Draw A Billiards Ball In Gta 3D With Texture Mapping (Gta 3) On A Computer Or 2D Or Gta 2D (Gt) On Your Computer Or Computer Or Your Computer (Or Your Computer)

TWO-DIMENSIONAL TRANSFORMATION

Essay 5 Tutorial for a Three-Dimensional Heat Conduction Problem Using ANSYS Workbench

A Short Introduction to Computer Graphics

Vector Math Computer Graphics Scott D. Anderson

Number Sense and Operations

2x + y = 3. Since the second equation is precisely the same as the first equation, it is enough to find x and y satisfying the system

SYNTHESIZING FREE-VIEWPOINT IMAGES FROM MULTIPLE VIEW VIDEOS IN SOCCER STADIUM

2D Geometric Transformations

is in plane V. However, it may be more convenient to introduce a plane coordinate system in V.

1 Symmetries of regular polyhedra

Fractions and Linear Equations

Section Continued

Solutions to Math 51 First Exam January 29, 2015

The Car Tutorial Part 1 Creating a Racing Game for Unity

MATH APPLIED MATRIX THEORY

We can display an object on a monitor screen in three different computer-model forms: Wireframe model Surface Model Solid model

COMP175: Computer Graphics. Lecture 1 Introduction and Display Technologies

Anamorphic Projection Photographic Techniques for setting up 3D Chalk Paintings

GRADES 7, 8, AND 9 BIG IDEAS

Cross product and determinants (Sect. 12.4) Two main ways to introduce the cross product

Rotation Matrices and Homogeneous Transformations

11.1. Objectives. Component Form of a Vector. Component Form of a Vector. Component Form of a Vector. Vectors and the Geometry of Space

Vector Notation: AB represents the vector from point A to point B on a graph. The vector can be computed by B A.

CATIA: Navigating the CATIA V5 environment. D. CHABLAT / S. CARO Damien.Chablat@irccyn.ec-nantes.fr

Orthogonal Diagonalization of Symmetric Matrices

What is Visualization? Information Visualization An Overview. Information Visualization. Definitions

LEAVING CERT DCG SCHEME OF WORK

EQUATIONS and INEQUALITIES

The Essentials of CAGD

MATHS LEVEL DESCRIPTORS

2. SPATIAL TRANSFORMATIONS

A Novel Multitouch Interface for 3D Object Manipulation

Linear Equations. Find the domain and the range of the following set. {(4,5), (7,8), (-1,3), (3,3), (2,-3)}

Vector has a magnitude and a direction. Scalar has a magnitude

What is Linear Programming?

Thin Lenses Drawing Ray Diagrams

13 MATH FACTS a = The elements of a vector have a graphical interpretation, which is particularly easy to see in two or three dimensions.

Geometry of Vectors. 1 Cartesian Coordinates. Carlo Tomasi

The process components and related data characteristics addressed in this document are:

Equations Involving Lines and Planes Standard equations for lines in space

Algebra 1 Course Title

Math 241, Exam 1 Information.

Technical Drawing Specifications Resource A guide to support VCE Visual Communication Design study design

Cortona3D Viewer. User's Guide. Copyright ParallelGraphics

Metrics on SO(3) and Inverse Kinematics

Taking Inverse Graphics Seriously

Transcription:

Image Processing and Computer Graphics Projections and Transformations in OpenGL Matthias Teschner Computer Science Department University of Freiburg

Motivation for the rendering of objects in 3D space, a planar view has to be generated 3D space is projected onto a 2D plane considering external and internal camera parameters position, orientation, focal length in homogeneous notation, 3D projections can be represented with a 4x4 transformation matrix University of Freiburg Computer Science Department Computer Graphics - 2

Examples left images 3D scene with a view volume right images projections onto the viewplane top-right parallel projection top-bottom perspective projection [Song Ho Ahn] University of Freiburg Computer Science Department Computer Graphics - 3

Outline 2D projection 3D projection OpenGL projection matrix OpenGL transformation matrices University of Freiburg Computer Science Department Computer Graphics - 4

Projection in 2D a 2D projection from v onto l maps a point p onto p' p' is the intersection of the line through p and v with line l v is the viewpoint, center of perspectivity l is the viewline the line through p and v is a projector v is not on the line l, p v University of Freiburg Computer Science Department Computer Graphics - 5

Projection in 2D if the homogeneous component of the viewpoint v is not equal to zero, we have a perspective projection projectors are not parallel if v is at infinity, we have a parallel projection projectors are parallel perspective projection parallel projection University of Freiburg Computer Science Department Computer Graphics - 6

Classification location of viewpoint and orientation of the viewline determine the type of projection parallel (viewpoint at infinity, parallel projectors) orthographic (viewline orthogonal to the projectors) oblique (viewline not orthogonal to the projectors) perspective (non-parallel projectors) one-point (viewline intersects one principal axis, i.e. viewline is parallel to a principal axis, one vanishing point) two-point (viewline intersects two principal axis, two vanishing points) University of Freiburg Computer Science Department Computer Graphics - 7

General Case a 2D projection is represented by matrix University of Freiburg Computer Science Department Computer Graphics - 8

Example e.g. d=-1, (1,2) T is mapped to (0,1) T University of Freiburg Computer Science Department Computer Graphics - 9

Discussion matrices M and M represent the same transformation therefore, and represent the same transformation x is mapped to zero, y is scaled depending on x moving d to infinity results in parallel projection University of Freiburg Computer Science Department Computer Graphics - 10

Discussion parallel projection University of Freiburg Computer Science Department Computer Graphics - 11

Discussion maps p to p' x = 0 maps p to p' y = -d p y maps p with p w =1 to p' w = p x - d University of Freiburg Computer Science Department Computer Graphics - 12

Discussion 2D transformation in homogeneous form w x and w y map the homogeneous component w of a point to a value w' that depends on x and y therefore, the scaling of a point depends on x and / or y in perspective 3D projections, this is generally employed to scale the x- and y- component with respect to z, its distance to the viewer University of Freiburg Computer Science Department Computer Graphics - 13

Outline 2D projection 3D projection OpenGL projection matrix OpenGL transformation matrices University of Freiburg Computer Science Department Computer Graphics - 14

Projection in 3D a 3D projection from v onto n maps a point p onto p' p' is the intersection of the line through p and v with plane n v is the viewpoint, center of perspectivity n is the viewplane the line through p and v is a projector v is not on the plane n, p v University of Freiburg Computer Science Department Computer Graphics - 15

General Case a 3D projection is represented by a matrix University of Freiburg Computer Science Department Computer Graphics - 16

Example e.g. d=-1, (1,2,0) T is mapped to (0,1,0) T University of Freiburg Computer Science Department Computer Graphics - 17

Example parallel projection onto the plane z = 0 with viewpoint / viewing direction v = (0,0,1,0) T x- and y-component are unchanged, z is mapped to zero remember that M and M with, e. g., =-1 represent the same transformation University of Freiburg Computer Science Department Computer Graphics - 18

Outline 2D projection 3D projection OpenGL projection matrix perspective projection parallel projection OpenGL transformation matrices University of Freiburg Computer Science Department Computer Graphics - 19

View Volume in OpenGL, the projection transformation maps a view volume to the canonical view volume the view volume is specified by its boundary left, right, bottom, top, near far the canonical view volume is a cube from (-1,-1,-1) to (1,1,1) (l, t, f) (x, y, f) [Song Ho Ahn] this transformation implements this transformation implements orthographic projection perspective projection University of Freiburg Computer Science Department Computer Graphics - 20

OpenGL Projection Transform the projection transform maps from eye coordinates to clip coordinates (w-component is not necessarily one) to normalized device coordinates NDC (x and y are normalized with respect to w, w is preserved for further processing) the projection transform maps the x-component of a point from (left, right) to (-1, 1) the y-component of a point from (bottom, top) to (-1, 1) the z-component of a point from (near, far) to (-1, 1) in OpenGL, near and far are negative, so the mapping incorporates a reflection (change of right-handed to left-handed) however, in OpenGL functions, usually the negative of near and far is specified which is positive University of Freiburg Computer Science Department Computer Graphics - 21

Perspective Projection to obtain x- and y-component of a projected point, the point is first projected onto the near plane (viewplane) [Song Ho Ahn] note that n and f denote the negative near and far values University of Freiburg Computer Science Department Computer Graphics - 22

Mapping of x p and y p to (-1, 1) [Song Ho Ahn] University of Freiburg Computer Science Department Computer Graphics - 23

Projection Matrix from we get clip coordinates with normalized device coordinates University of Freiburg Computer Science Department Computer Graphics - 24

Mapping of z e to (-1, 1) z e is mapped from (near, far) or (-n, -f) to (-1, 1) the transform does not depend on x e and y e so, we have to solve for A and B in University of Freiburg Computer Science Department Computer Graphics - 25

Mapping of z e to (-1, 1) z e =-n with w e =1 is mapped to z n =-1 z e =-f with w e =1 is mapped to z f =1 the complete matrix is University of Freiburg Computer Science Department Computer Graphics - 26

Perspective Projection Matrix the matrix transforms the view volume, the pyramidal frustum to the canonical view volume pyramidal frustum [Song Ho Ahn] University of Freiburg Computer Science Department Computer Graphics - 27

Perspective Projection Matrix projection matrix for negated values for n and f (OpenGL) projection matrix for actual values for n and f University of Freiburg Computer Science Department Computer Graphics - 28

Symmetric Setting the matrix simplifies for r = -l and t = -b University of Freiburg Computer Science Department Computer Graphics - 29

Near Plane nonlinear mapping of z e : varying resolution / accuracy due to fix-point representation of depth values in the depth buffer z n z n z n z e z e z e do not move the near plane too close to zero University of Freiburg Computer Science Department Computer Graphics - 30

Far Plane setting the far plane to infinity is not too critical z n z e University of Freiburg Computer Science Department Computer Graphics - 31

Outline 2D projection 3D projection OpenGL projection matrix perspective projection parallel projection OpenGL transformation matrices University of Freiburg Computer Science Department Computer Graphics - 32

Parallel Projection the view volume is represented by a cuboid left, right, bottom, top, near, far [Song Ho Ahn] the projection transform maps the cuboid to the canonical view volume University of Freiburg Computer Science Department Computer Graphics - 33

Mapping of x e, y e, z e to (-1,1) all components of a point in eye coordinates are linearly mapped to the range of (-1,1) [Song Ho Ahn] linear in x e, y e, z e combination of scale and translation University of Freiburg Computer Science Department Computer Graphics - 34

Orthographic Projection Matrix general form simplified form for a symmetric view volume University of Freiburg Computer Science Department Computer Graphics - 35

Outline 2D projection 3D projection OpenGL projection matrix OpenGL transformation matrices University of Freiburg Computer Science Department Computer Graphics - 36

OpenGL Matrices objects are transformed from object to eye space with the GL_MODELVIEW matrix objects are transformed from eye space to clip space with the GL_PROJECTION matrix colors are transformed with the color matrix GL_COLOR texture coordinates are transformed with the texture matrix GL_TEXTURE University of Freiburg Computer Science Department Computer Graphics - 37

Matrix Stack each matrix type has a stack the matrix on top of the stack is used glmatrixmode(gl_projection); choose a matrix stack glloadidentity(); glfrustum(left, right, bottom, top, near, far); the top element is replaced with I 4 projection matrix P is generated the top element on the stack is multiplied with P resulting in I 4 P University of Freiburg Computer Science Department Computer Graphics - 38

Matrix Stack glmatrixmode(gl_modelview); glloadidentity(); gltranslatef(x,y,z); glrotatef(alpha,1,0,0); choose a matrix stack the top element is replaced with I 4 translation matrix T is generated the top element on the stack is multiplied with T resulting in I 4 T rotation matrix R is generated the top element on the stack is multiplied with R resulting in I 4 T R note that objects are rotated by R, followed by the translation T University of Freiburg Computer Science Department Computer Graphics - 39

Matrix Stack glmatrixmode(gl_modelview); glloadidentity(); gltranslatef(x,y,z); glrotatef(alpha,1,0,0); glpush(); gltranslatef(x,y,z); glpop(); choose a matrix stack the top element is replaced with I 4 the top element is I 4 T the top element is I 4 T R the top element I 4 T R is pushed into the stack the newly generated top element is initialized with I 4 T R the top element is I 4 T R T the top element is replaced by the previously stored element I 4 T R University of Freiburg Computer Science Department Computer Graphics - 40

OpenGL Matrix Functions glpushmatrix(): push the current matrix into the current matrix stack. glpopmatrix(): pop the current matrix from the current matrix stack. glloadidentity(): set the current matrix to the identity matrix. glloadmatrix{fd}(m): replace the current matrix with the matrix m. glloadtransposematrix{fd}(m) : replace the current matrix with the rowmajor ordered matrix m. glmultmatrix{fd}(m): multiply the current matrix by the matrix m, and update the result to the current matrix. glmulttransposematrix{fd}(m): multiply the current matrix by the row-major ordered matrix m, and update the result to the current matrix. glgetfloatv(gl_modelview_matrix, m): return 16 values of GL_MODELVIEW matrix to m. note that OpenGL functions expect column-major matrices in contrast to commonly used row-major matrices University of Freiburg Computer Science Department Computer Graphics - 41

Modelview Example objects are transformed with V -1 M V=T v R v the camera is oriented and then translated M 1..4 =T 1..4 R 1..4 implementation choose the GL_MODELVIEW stack initialize with I 4 rotate with R v -1 translate with T v -1 push translate with T 1 rotate with R 1 render object M 1 pop objects are oriented and then translated I 4 R v -1 R v -1 T v -1 = V -1 R v -1 T v -1 R v -1 T v -1 T 1 R v -1 T v -1 T 1 R 1 R v -1 T v -1 M 1 M 3 M 2 University of Freiburg Computer Science Department Computer Graphics - 42 V M 4 [Akenine-Moeller et al.: Real-time Rendering]

Summary 2D projection 3D projection OpenGL projection matrix perspective projection parallel projection OpenGL transformation matrices University of Freiburg Computer Science Department Computer Graphics - 43

References Duncan Marsh: "Applied Geometry for Computer Graphics and CAD", Springer Verlag, Berlin, 2004. Song Ho Ahn: "OpenGL", http://www.songho.ca/. University of Freiburg Computer Science Department Computer Graphics - 44