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

Similar documents
Computer Graphics. Chapter 10 Three-Dimensional Viewing

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

OpenGL Transformations

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

Advanced Computer Graphics (CS & SE )

20 GLuint objects; 36 Scale += 0.1; 37 break; 38 case GLUT_KEY_DOWN:

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

CS 591B Lecture 9: The OpenGL Rendering Pipeline

Fundamental Types of Viewing

Books, OpenGL, GLUT, GLUI, CUDA, OpenCL, OpenCV, PointClouds, and G3D

Chapter 13 Selection and Feedback

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

Matrix-Rechnung I ' z =... Universität Frankfurt

Computer Graphics. Chapter 7 2D Geometric Transformations

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

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

Books, OpenGL, GLUT, CUDA, OpenCL, OpenCV, PointClouds, G3D, and Qt

C OMPUTER G RAPHICS Thursday

Lecture 4. Viewing, Projection and Viewport Transformations

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

CSC 470 Computer Graphics

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

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

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

Lecture 4 of 41. Lab 1a: OpenGL Basics

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

Precept 2 Aleksey Boyko February 18, 2011

Computer Graphics. Bing-Yu Chen National Taiwan University


Transformation Pipeline

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

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

Fachhochschule Regensburg, Germany, February 15, 2017

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

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

Viewing Transformation

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

CS 428: Fall Introduction to. Transformations in OpenGL + hierarchical modeling. Andrew Nealen, Rutgers, /21/2009 1

Using GLU/GLUT Objects

Introduction to 3D Graphics with OpenGL. Z-Buffer Hidden Surface Removal. Binghamton University. EngiNet. Thomas J. Watson

Modeling with Transformations

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

Viewing and Projection

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

Two possible ways to specify transformations. Each part of the object is transformed independently relative to the origin

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

To Do. Computer Graphics (Fall 2008) Course Outline. Course Outline. Methodology for Lecture. Demo: Surreal (HW 3)

Hierarchical Modeling: Tree of Transformations, Display Lists and Functions, Matrix and Attribute Stacks,

Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

OpenGL. Toolkits.

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

Computer Graphics (Basic OpenGL)

GRAFIKA KOMPUTER. ~ M. Ali Fauzi

OpenGL: Setup 3D World

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

Transformation, Input and Interaction. Hanyang University

CS354 Computer Graphics Viewing and Modeling

Order of Transformations

Introduction to OpenGL

Better Interactive Programs

Rasterization Overview

part 3 Martin Samuelčík Room I4

CIS 636 Interactive Computer Graphics CIS 736 Computer Graphics Spring 2011

// double buffering and RGB glutinitdisplaymode(glut_double GLUT_RGBA); // your own initializations

GL_MODELVIEW transformation

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

Lecture 4 Advanced Computer Graphics (CS & SE )

Viewing and Projection

3.1 Viewing and Projection

OpenGL. 1 OpenGL OpenGL 1.2 3D. (euske) 1. Client-Server Model OpenGL

E.Order of Operations

1 (Practice 1) Introduction to OpenGL

Computer Viewing Computer Graphics I, Fall 2008

Graphics Pipeline & APIs

Interaction Computer Graphics I Lecture 3

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

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

Prof. Feng Liu. Fall /19/2016

Basic Graphics Programming

An Interactive Introduction to OpenGL Programming

Three-Dimensional Graphics III. Guoying Zhao 1 / 67

Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

Introduction to OpenGL

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

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

VISIBILITY & CULLING. Don t draw what you can t see. Thomas Larsson, Afshin Ameri DVA338, Spring 2018, MDH

Introduction to OpenGL Transformations, Viewing and Lighting. Ali Bigdelou

CS418 OpenGL & GLUT Programming Tutorial (IV) MP2 Bonus/Object Picking. Presented by : Wei-Wen Feng 2/20/2008

Interaction. CSCI 480 Computer Graphics Lecture 3

API for creating a display window and using keyboard/mouse interations. See RayWindow.cpp to see how these are used for Assignment3

Graphics Pipeline & APIs

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

Graphics and Visualization

CS 381 Computer Graphics, Fall 2008 Midterm Exam Solutions. The Midterm Exam was given in class on Thursday, October 23, 2008.

Computer graphics MN1

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

GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW

CS 4204 Computer Graphics

Computer Graphics (CS 4731) Lecture 11: Implementing Transformations. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

Viewing and Modeling

Transcription:

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

Review: from 3D world to 2D pixels 1. Transformations are represented by matrix multiplication. o Modeling o Viewing o Projection 2. Clipping volume used to throw out objects. 3. Correspondance between transformed coordinates and screen pixels.

Camera Analogy Setup tripod and point camera at scene (viewing transformation) Arrange scene to be photograph (modeling transformation) Choose a camera lens or zoom (projection transformation) Determine how large final image should be (viewport transformation)

Vertex Tranformation Pipeline

Cube Example void display(void) { glclear(gl_color_buffer_bit); glcolor3f(1.0, 1.0, 1.0); glloadidentity(); /* viewing transformation */ glulookat(0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0); glscalef(1.0, 2.0, 1.0); /* modeling transformation */ glutwirecube (1.0); glflush(); } void reshape(int w, int h) { glviewport(0, 0, (GLsizei) w, (GLsizei) h); glmatrixmode(gl_projection); glloadidentity(); glfrustum(-1.0, 1.0, -1.0, 1.0, 1.5, 20.0); glmatrixmode (GL_MODELVIEW); }

Viewing and Modeling Transformations Viewing and modeling transformations are inextricably related in OpenGL and are in fact combined into a single modelview matrix o Do you want to move the camera in one direction, or move the object in the opposite direction? o Each way of thinking about transformations has advantages and disadvantages, but in some cases one way more naturally matches the effect of the intended transformation.

Transformation Order Matters gltranslatef() glrotate() draw_flower_pot() glrotatef() gltranslatef() draw_flower_pot()

Grand, Fixed Coordinate System Matrix multiplications affect the position, orientation, and scaling of your model. Transformations move object in fixed global coordinate system. Multiplications occur in opposite order from how they appear in code.

Moving a Local Coordinate System Instead of fixed coordinate system, image a local coordinate system that is tied to the object you are drawing. All operations occur relative to this changing coordinate system (and thus multiplications are same order as in the code) Extremely useful for hierarchical objections (i.e arms, legs, joints). Scaling may be problematic (translations move by a multiple since they are stretch).

Transformation Order Redux gltranslatef() glrotate() draw_flower_pot() glrotatef() gltranslatef() draw_flower_pot()

Modelview Duality There is no real difference between moving an object backward and moving the reference system forward. Viewing transformation, therefore, is essentially nothing but a modeling transformation that you apply to the viewer before drawing objects

Modeling Transformations gltranslatef glscalef glrotatef

Viewing Transformations Changes position and orientation of viewport. Camera moves in opposite direction as objects. To set viewing transformation: o gltranslate, glrotate o GluLookAt Viewing transformations must be called before any modeling transformations are performed.

glulookat Construct a scene around origion or some convenient location, and then want to look at it from an arbitrary point. glulookat: let's you specify location of viewpoint, a reference point toward which a camera is aimed, and which direction is up.

Projection Transformations The purpose of the projection transformation is to define a viewing volume. Determine how an object is projected onto the screen. Defines which objects or portions of objects are clipped out of final image. Viewpoint exists at one end of viewing volume. Two main types of projections: o Perspective o Orthogonal

Perspective Projection Major characteristic is foreshortening: Farther an object is from the camera, the smaller it appears in the final image. Viewing volume is a frustrum of a pyramid. o Objects inside volume are projected toward apex of pyramid. o Objects closer to viewpoint appear larger.

glfrustrum, gluperspective

Orthographic Projection Parallel projection, all the polygons are drawn onscreen with exactly the relative dimensions specified. Used often for 2D drawing purposes where you want an exact correspondence between pixels and drawing units. o CAD, blueprints, text, on-screen menus

Hidden Surface Removal Remove surfaces that should not be visible to viewer. OpenGL provides z-buffer algorithm (depth buffer).

Z Buffer Algorithm As polygons are rasterized, hardware keeps track of depth or z buffer: o Initially, depth value is registered to far side of viewing volume o For each fragment, we compute the depth (distance from viewer). If this depth is closer to viewer than current value, then we update color value and depth Otherwise, we disregard it. Code: glutinitdisplaymode(glut_double GLUT_RGB GLUT_DEPTH); glenable(gl_depth_test); glclear(gl_color_buffer_bit GL_DEPTH_BUFFER_BIT);

Reversing the Pipeline How do we map from a mouse coordinate to object coordinates? o Have to reverse the transformation process to map from window coordinates back to object space. o gluunproject performs this reversal Works best with orthographic projections Requires a wz argument, which specifies the depth: 0.0: near clipping plane 1.0: far clipping plane

gluunproject Example GLdouble modelview[16]; GLdouble projection[16]; GLint viewport[4]; double wx, wy, wz, ox, oy, oz; glgetdoublev(gl_modelview_matrix, modelview); glgetdoublev(gl_projection_matrix, projection); glgetintegerv(gl_viewport, viewport); wx = MouseX; wy = viewport[3] - MouseY - 1; glreadpixels((int)wx, (int)wy, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &wz); gluunproject(wx, wy, wz, modelview, projection, viewport, &ox, &oy, &oz);

Picking Logical operation that allows user to identify object on the display. OpenGL provides a mechanism called selection: Adjust clipping region and viewport. Keep track of primitives rendered into region near the cursor. Possible selected primitives stored in a hit list.

Start picking GLint viewport[4]; glgetintegerv(gl_viewport, viewport); // Get viewport information glselectbuffer(sbsize, SelectBuffer); // Setup hit buffer glrendermode(gl_select); // Switch to selection mode glinitnames(); // Setup name stack glmatrixmode(gl_projection); // Adjust projection to limit glpushmatrix(); glloadidentity(); // area we are interested in // (5x5 area around mouse position) glupickmatrix(mousex, viewport[3] MouseY, 5, 5, viewport); gluperspective(45.0, (GLdouble)(WindowWidth)/(GLdouble)(WindowHeight), 0.1, 1000.0); glmatrixmode(gl_modelview); // draw scene

Stop picking GLint hits; glmatrixmode(gl_projection); glpopmatrix(); glmatrixmode(gl_modelview); hits = glrendermode(gl_render); if (hits > 0) process_hits(hits, SelectBuffer);

Process Hits void process_hits(glint hits, GLuint *buffer){ GLuint names; GLuint *bp = buffer; for (GLint i = 0; i < hits; i++) { names = bp; // # names, min, max, name0,... bp += 3; } // process hits bp += names;

Resources/Credits OpenGL Programming Guide: http://glprogramming.com/red/chapter03.html OpenGL Super Bible: http://www.opengl-doc.com/sams- OpenGL.SuperBible.Third/0672326019/ch04lev1se c2.html