Advanced Viewing Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, October 31, 2003.

Slides:



Advertisements
Similar presentations
MAT 594CM S2010Fundamentals of Spatial ComputingAngus Forbes Overview Goals of the course: 1. to introduce real-time 3D graphics programming with openGL.
Advertisements

Based on slides created by Edward Angel
Viewing and Transformation
1 3D modelling with OpenGL Brian Farrimond Robina Hetherington.
Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 5: Viewing
Objectives Learn to build arbitrary transformation matrices from simple transformations Learn to build arbitrary transformation matrices from simple transformations.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 OpenGL Transformations Ed Angel Professor of Computer Science, Electrical and Computer.
OpenGL (II). How to Draw a 3-D object on Screen?
CS 4731: Computer Graphics Lecture 11: 3D Viewing Emmanuel Agu.
Introduction to OpenGL Pipeline From Programmer View Tong-Yee Lee.
Hierarchical Transformations Hierarchical Models Scene Graphs
Introduction to 3D viewing 3D is just like taking a photograph!
Transformations Aaron Bloomfield CS 445: Introduction to Graphics
Mouse-Based Viewing & Navigation Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, November 3, 2003.
1 OpenGL Basics A Graphics Standard ©Mel Slater, Anthony Steed
Computer Graphics, KKU. Lecture 131 Transformation and Viewing in OpenGL.
OpenGL Matrices and Transformations Angel, Chapter 3 slides from AW, Red Book, etc. CSCI 6360.
TWO DIMENSIONAL GEOMETRIC TRANSFORMATIONS CA 302 Computer Graphics and Visual Programming Aydın Öztürk
The Viewing Pipeline (Chapter 4) 5/26/ Overview OpenGL viewing pipeline: OpenGL viewing pipeline: – Modelview matrix – Projection matrix Parallel.
Geometric transformations The Pipeline
Data Structures for Scenes, The Basics of Scene Graphs Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Friday,
CSE 470: Computer Graphics. 10/15/ Defining a Vertex A 2D vertex: glVertex2f(GLfloat x, GLfloat y); 2D vertexfloating pointopenGL parameter type.
Homogeneous Form, Introduction to 3-D Graphics Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 20,
Shadows via Projection Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, November 5, 2003.
Introduction to OpenGL 1. 2 OpenGL A Graphics rendering API introduced in 1992 by Silicon Graphics Inc Provide the low-level functions to access graphics.
Stages of Vertex Transformation To specify viewing, modeling, and projection transformations, you construct a 4 × 4 matrix M, which is then multiplied.
More on Advanced Interfaces, Image Basics Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, November 21, 2003.
VR & TRANSF Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Monday, February 23, 2004.
Computer Graphics Bing-Yu Chen National Taiwan University.
More on Drawable Objects, Hierarchical Objects Glenn G. Chappell U. of Alaska Fairbanks CS 481/681 Lecture Notes Wednesday, January.
Modeling with OpenGL Practice with OpenGL transformations.
OpenGL: Introduction Yanci Zhang Game Programming Practice.
CS 450: COMPUTER GRAPHICS PROJECTIONS SPRING 2015 DR. MICHAEL J. REALE.
OpenGL The Viewing Pipeline: Definition: a series of operations that are applied to the OpenGL matrices, in order to create a 2D representation from 3D.
OpenGL Viewing and Modeling Transformation Geb Thomas Adapted from the OpenGL Programming Guidethe OpenGL Programming Guide.
More on GLUT Programming Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, September 15, 2003.
Computer Graphics I, Fall 2010 OpenGL Transformations.
1/50 CS148: Introduction to Computer Graphics and Imaging Transforms CS148: Introduction to Computer Graphics and Imaging Transforms.
2 COEN Computer Graphics I Evening’s Goals n Discuss viewing and modeling transformations n Describe matrix stacks and their uses n Show basic geometric.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 OpenGL Transformations.
Viewing and Transformation. Pixel pipeline Vertex pipeline Course Map Transformation & Lighting Primitive assembly Viewport culling & clipping Texture.
The Camera Analogy ► Set up your tripod and point the camera at the scene (viewing transformation) ► Arrange the scene to be photographed into the desired.
Chapters 5 2 March Classical & Computer Viewing Same elements –objects –viewer –projectors –projection plane.
CGGM Lab. Tan-Chi Ho 2001 Viewing and Transformation.
Pop-Up Menus Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, September 26, 2003.
Foundations of Computer Graphics (Spring 2012) CS 184, Lecture 5: Viewing
Introduction to Computer Graphics: Viewing Transformations Rama C
Taxonomy of Projections FVFHP Figure Taxonomy of Projections.
Chap 3 Viewing and Transformation
Learning Objectives Affine transformations Affine transformations Translation Translation Rotation Rotation Scaling Scaling Reflection Reflection Shear.
1 OpenGL Transformations. 2 Objectives Learn how to carry out transformations in OpenGL ­Rotation ­Translation ­Scaling Introduce OpenGL matrix modes.
1 Geometric Transformations-II Modelling Transforms By Dr.Ureerat Suksawatchon.
Viewing and Projection. The topics Interior parameters Projection type Field of view Clipping Frustum… Exterior parameters Camera position Camera orientation.
Selection Mode, Introduction to Widgets Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 6, 2003.
Some Notes on 3-D Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, October 24, 2003.
CS 551 / 645: Introductory Computer Graphics Viewing Transforms.
CS5500 Computer Graphics March 20, Computer Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts.
Geometric Transformations Ceng 477 Introduction to Computer Graphics Computer Engineering METU.
OpenGL LAB III.
Introduction to 3-D Viewing Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 27, 2003.
The Modelview Stack Lecture 9 Wed, Sep 12, The Modelview Stack OpenGL maintains a stack of matrices. The matrix on top of the stack is the current.
School of Computer Science
Summary of Properties of 3D Affine Transformations
Introduction to the Mouse
Reference1. [OpenGL course slides by Rasmus Stenholt]
Computer Graphics (Spring 2003)
Projection in 3-D Glenn G. Chappell
More on Widgets, Misc. Topics
The Modelview Matrix Lecture 8 Mon, Sep 10, 2007.
Computer Graphics 3Practical Lesson
Presentation transcript:

Advanced Viewing Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Friday, October 31, 2003

31 Oct 2003CS 3812 Review: Projection in 3-D [1/3] We use the projection to handle camera properties. Perspective or parallel (orthogonal) projection. Wide or narrow angle. But not camera position & orientation. How do we determine wide & narrow angle using glFrustum or gluPerspective ? With gluPerspective, change the 1 st parameter (fovy). With glFrustum, multiply left, right, bottom, top by some number. Fancy projections can mess up screen text, buttons, etc. For these, use a separate gluOrtho2D projection. See printmatrix.cpp, on the web page, for sample code.

31 Oct 2003CS 3813 Review: Projection in 3-D [2/3] Computing Perspective Projection Based on the synthetic-camera model, we can find the coordinates of a projected point. We use similar triangles (outlined in red). z = –far z = –near Center of Projection (“eye”) (0, 0, 0) (x, y, z) Screen –z–z (x/[–z/near], y/[–z/near], –near) View Frustum

31 Oct 2003CS 3814 Review: Projection in 3-D [3/3] We can perform this projection using the following matrix. This matrix is not exactly what glFrustum produces, since it deals with right, left, top, bottom, far, too. But this gives the general idea.

31 Oct 2003CS 3815 Review: More on OpenGL Matrices [1/2] We store an OpenGL matrix in an array of 16 GLdouble ’s: GLdouble matrixd[16]; To put the model/view matrix into this array: glGetDoublev(GL_MODELVIEW_MATRIX, matrixd); This is column-major are the first column, not the first row. To restore the saved model/view matrix: glLoadMatrixd(matrixd); // Mode must be GL_MODELVIEW! More usefully, to multiply saved matrix by current matrix: glMultMatrixd(matrixd); // Mode must be GL_MODELVIEW!

31 Oct 2003CS 3816 Review: More on OpenGL Matrices [2/2] How would you write glTranslate * yourself? void myglTranslate(double x, double y, double z) { GLdouble m[16]; // The translation matrix m[ 0] = 1.; m[ 4] = 0.; m[ 8] = 0.; m[12] = x; m[ 1] = 0.; m[ 5] = 1.; m[ 9] = 0.; m[13] = y; m[ 2] = 0.; m[ 6] = 0.; m[10] = 1.; m[14] = z; m[ 3] = 0.; m[ 7] = 0.; m[11] = 0.; m[15] = 1.; glMultMatrixd(m); // Multiply it } Why don’t I set GL_MODELVIEW mode in this function?

31 Oct 2003CS 3817 Advanced Viewing: Problem & Solution So far, we have always created the model/view transformation from scratch for each frame. This can get unwieldy if an increasingly long sequence of transformations must be remembered. Consider “flying”. Solution Keep the current state of a sequence of transformations in a matrix. Modify the matrix appropriately when a new transformation is added. In the display function, just do glMultMatrix *.

31 Oct 2003CS 3818 Advanced Viewing: Example 1: “Zoom & Pan” [1/2] In traditional zoom & pan (with a real camera): Zoom means changing the wide/narrow-angle properties of the lens. Pan means rotating the camera. We will misuse these terms somewhat, in order to make a more helpful example. Our “zoom” will scale the world. Our “pan” will translate it. We will use model/view for both of these. Think: What is a problem with panning while zoomed in close?

31 Oct 2003CS 3819 Advanced Viewing: Example 1: “Zoom & Pan” [2/2] Suppose we handle “zoom & pan” with a saved viewing matrix. What do we do to this matrix, in order to pan? Translate, then do the saved transformations. Result is the new transformation. What do we do to this matrix, in order to zoom? Scale, then do the saved transformations. Result is the new transformation. How do we use this matrix in the display function? Load it ( glLoadMatrixd ). Or do whatever else needs to be done first, then multiply by it ( glMultMatrixd ).

31 Oct 2003CS Advanced Viewing: Handling the Saved Matrix Don’t forget to initialize the saved matrix. glMatrixMode(GL_MODELVIEW); glPushMatrix(); ***** Transformation commands go here? ***** glGetDoublev(GL_MODELVIEW_MATRIX, your_matrix_variable ); glPopMatrix(); Whenever you do anything with the model/view transformation, use push & pop. Changing the matrix alters the display. So post a redisplay event whenever you change the matrix outside the display function. Generally, to alter a saved model/view matrix outside the display function: glPushMatrix(); glLoadIdentity(); // May not be necessary ***** Transformation commands go here ***** glMultMatrixd( your_matrix_variable ); // If this is appropriate glGetDoublev(GL_MODELVIEW_MATRIX, your_matrix_variable ); glPopMatrix(); glutPostRedisplay();

31 Oct 2003CS Advanced Viewing: Example 2: A Driving Interface Imagine a car at the center of the window, driving through the city streets. How can we turn our zoom-pan interface into a 2-D driving-style interface (viewed from above) with only minimal modifications? Change the pan-left and pan-right code to do rotations about the z-axis.

31 Oct 2003CS Advanced Viewing: Example 3: Flying [1/2] We implemented the first two examples using a saved matrix to hold viewing transformations. Viewing transform’s = camera motions. Okay, the “zoom” part didn’t quite fit this model … The ultimate generality in camera motions is achieved in “flying”. Flying = moving in the viewing direction & rotating about the camera. How do we fly forward? Put a +z translation before (in the code) all previous transformations. How to we turn? Put a y-axis (or x-axis, for going up & down) rotation before (in the code) all previous transformations.

31 Oct 2003CS Advanced Viewing: Example 3: Flying [2/2] Wouldn’t it be nicer to use the mouse? Yes. We’ll talk about that next time.