OpenGL LAB III.

Slides:



Advertisements
Similar presentations
Computer Graphics - Viewing -
Advertisements

CLASS 6 PERSPECTIVE CS770/870. Orthographic projections Isometric ObliqueIn isometric all distances along the major axes are the same.
Based on slides created by Edward Angel
Viewing and Transformation
Viewing and Projections
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Computer Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Foundations of Computer Graphics (Spring 2010) CS 184, Lecture 5: Viewing
CS 352: Computer Graphics Chapter 5: Viewing. Interactive Computer GraphicsChapter Overview Specifying the viewpoint Specifying the projection Types.
OpenGL and Projections
Viewing Doug James’ CG Slides, Rich Riesenfeld’s CG Slides, Shirley, Fundamentals of Computer Graphics, Chap 7 Wen-Chieh (Steve) Lin Institute of Multimedia.
OpenGL (II). How to Draw a 3-D object on Screen?
CS 4731: Computer Graphics Lecture 11: 3D Viewing Emmanuel Agu.
Introduction to 3D viewing 3D is just like taking a photograph!
Viewing and Projections
UBI 516 Advanced Computer Graphics Three Dimensional Viewing
Advanced Computer Graphics Three Dimensional Viewing
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.
The Viewing Pipeline (Chapter 4) 5/26/ Overview OpenGL viewing pipeline: OpenGL viewing pipeline: – Modelview matrix – Projection matrix Parallel.
Geometric transformations The Pipeline
CS559: Computer Graphics Lecture 9: Projection Li Zhang Spring 2008.
Viewing Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
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.
CAP 4703 Computer Graphic Methods Prof. Roy Levow Chapter 5.
Demetriou/Loizidou – ACSC330 – Chapter 5 Viewing Dr. Giorgos A. Demetriou Computer Science Frederick Institute of Technology.
Computer Graphics Bing-Yu Chen National Taiwan University.
Computer Graphics I, Fall 2010 Computer Viewing.
OpenGL: Introduction Yanci Zhang Game Programming Practice.
10/7/04© University of Wisconsin, CS559 Fall 2004 Last Time Transformations Homogeneous coordinates Directions Rotation Geometry 101 – Points, edges, triangles/polygons.
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.
Graphics Graphics Korea University kucg.korea.ac.kr Viewing 고려대학교 컴퓨터 그래픽스 연구실.
Basic Perspective Projection Watt Section 5.2, some typos Define a focal distance, d, and shift the origin to be at that distance (note d is negative)
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.
Projections. Viewports Windows can have separate viewports void glViewport(GLint x, GLint y, GLsizei width, GLsizei height ) x, y - Specify the lower.
©2005, Lee Iverson Lee Iverson UBC Dept. of ECE EECE 478 Viewing and Projection.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Classical Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Classical Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Taxonomy of Projections FVFHP Figure Taxonomy of Projections.
Chap 3 Viewing and Transformation
CS559: Computer Graphics Lecture 9: 3D Transformation and Projection Li Zhang Spring 2010 Most slides borrowed from Yungyu ChuangYungyu Chuang.
CS559: Computer Graphics Lecture 12: OpenGL - Transformation Li Zhang Spring 2008.
Viewing and Projection. The topics Interior parameters Projection type Field of view Clipping Frustum… Exterior parameters Camera position Camera orientation.
Viewing Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
CS5500 Computer Graphics March 20, Computer Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts.
CSC Graphics Programming Budditha Hettige Department of Statistics and Computer Science.
CS380 LAB II OpenGL Donghyuk Kim Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
Viewing. Classical Viewing Viewing requires three basic elements - One or more objects - A viewer with a projection surface - Projectors that go from.
Computer Graphics Lecture 41 Viewing Using OpenGL Taqdees A. Siddiqi
CS 490: Computer Graphics Chapter 5: Viewing. Interactive Computer GraphicsChapter Overview Specifying the viewpoint Specifying the projection Types.
OpenGL Matrices and Transformations Angel, Chapter 3 slides from AW, Red Book, etc. CSCI 6360/4360.
CSC Graphics Programming
Viewing 고려대학교 컴퓨터 그래픽스 연구실 kucg.korea.ac.kr.
Viewing.
Computer Graphics - Chapter 5 Viewing
Computer Viewing.
Courtesy of Drs. Carol O’Sullivan / Yann Morvan Trinity College Dublin
Reference1. [OpenGL course slides by Rasmus Stenholt]
Advanced Graphics Algorithms Ying Zhu Georgia State University
Lecture 08 and 09 View & Projection
CSC4820/6820 Computer Graphics Algorithms Ying Zhu Georgia State University View & Projection.
Computer Graphics, KKU. Lecture 13
Last Time Canonical view pipeline Projection Local Coordinate Space
Type of View Perspective View COP(Center of Plane) Diminution of size
Computer Graphics 3Practical Lesson
Chapter 3 Viewing.
Presentation transcript:

OpenGL LAB III

Outline Viewing Transformation Projection and Orthographic Projection

Transformation pipeline Stages of vertex transformation Modelview Matrix Projection Matrix Viewport Mapping Object coords Camera coords Normalized coords Window coords

Transformation pipeline Matrices are set up on stacks Matrix commands are post-multiplied onto the current matrix The last command issued is the first transformation applied to the object Can save/restore the current matrix

Transformation pipeline Save / Restore the current matirx: glPushMatrix() glPopMatrix() Change the current matrix stack: glMatrixMode(Glenum mode) GL_MODELVIEW, GL_PROJECTION, GL_TEXTURE

Modelview transformation Modeling transformation Model local coordinates → world coordinates Viewing transformation world coordinates → eye coordinates

Viewing Transformation Another change of coordinate systems Maps points from world space into eye space Viewing position is transformed to the origin Viewing direction is oriented along some axis A viewing volume is defined Combined with modeling transformation to form the modelview matrix in OpenGL

Camera View Camera coordinate system The camera is located at the origin The camera’s optical axis is along one of the coordinate axes (-z in OpenGL convention) The up axis (y axis) is aligned with the camera’s up direction We can greatly simplify the clipping and projection steps in this frame The viewing transformation can be expressed using the rigid body transformations discussed before

Viewing Transformation Steps Viewing transformation should align the world and camera coordinate frames We can transform the world frame to the camera frame with a rotation followed a translation Rotate Translate

Intuitive Camera Specification How to specify a camera gluLookAt (eyex, eyey, eyez, centerx, centery, centerz, upx, upy, upz) (eyex, eyey, eyez): Coordinates of the camera (eye) location in the world coordinate system (centerx, centery, centerz): the look-at point, which should appear in the center of the camera image, specifies the viewing direction (upx, upy, upz): an up-vector specifies the camera orientation by defining a world space vector that should be oriented upwards in the final image This intuitive specification allows us to specify an arbitrary camera path by changing only the eye point and leaving the look-at and up vectors untouched Or we could pan the camera from object to object by leaving the eye-point and up-vector fixed and changing only look-at point

Example void display() { glClear(GL_COLOR_BUFFER | GL_DEPTH_BUFFER_BIT); glColor3f(0.0, 1.0, 0.0); glLoadIdentity(); gluLookAt(0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 1.0, 1.0, 0.0); glutWireTeapot(0.5); glFlush(); }

Tutorials Change your camera view based on key inputs ‘q’ : eyex +0.1, ‘i’ : eyex -0.1 ‘w’ : eyey + 0.1, ‘o’ : eyey -0.1 ‘e’ : eyez +0.1, ‘p’ : eyez -0.1 ‘a’ : centerx +0.1, ‘j’ : centerx -0.1 ‘s’ : centery +0.1, ‘k’ : centery -0.1 ‘d’ : centerz +0.1, ‘l’ : centerz -0.1 ‘z’ : upx +0.1, ‘b’ : upx -0.1 ‘x’ : upy +0.1, ‘n’ : upy -0.1 ‘c’ : upz +0.1, ‘m’ : upz -0.1

Tutorials Set camera view to following figures

The Matrix for glLookAt (u, v, w, eye) forms the viewing coordinate system w = eye – look u = up × w v = w × u The matrix that transforms coordinates from world frame to viewing frame. dx = - eye · u dy = - eye · v dz = - eye · w

Setup Camera Since viewing transformation is a rotation and translation transformation. We can use glRotatef() and glTranslatef() instead of gluLookAt() In the previous example (view a scene at origin from (10, 0, 0) ), we can equivalently use glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glRotatef(45, 0, 0, 1); Since the viewing transformation is applied after modeling transformations, it should be set before modeling transformations.

Set Viewing Transformation Furthermore, glTranslatef() and glRotatef() can be used to define custom viewing control. Example void display() { … glRotatef(angle, axisx, axisy, axisz); glTranslatef(xpos, ypos, zpos); }

Projection Transformations The projection transformation maps all of our 3-D coordinates onto our desired viewing plane. Greatly simplified by using the camera (viewing) frame. projection matrices do not transform points from our affine space back into the same space. Projection transformations are not affine and we should expect projection matrices to be less than full rank

Orthographic Projection The simplest form of projection simply project all points along lines parallel to the z-axis (x, y, z)->(x, y, 0) Here is an example of an parallel projection of our scene. Notice that the parallel lines of the tiled floor remain parallel after orthographic projection

Orthographic Projection The projection matrix for orthographic projection is simple: Notice the units of the transformed points are still the same as the model units. We need to further transform them to the screen space. OpenGL functions for orthographic projection gluOrtho2D(left, right, bottom, top), glOrtho(left, right, bottom, top, near, far)

Perspective Projection Perspective projection is important for making images appear realistic. causes objects nearer to the viewer to appear larger than the same object would appear farther away Note how parallel lines in 3D space may appear to converge to a single point when viewed in perspective.

Viewing Frustum and Clipping The right picture shows the view volume that is visible for a perspective projection window, called viewing frustum It is determined by a near and far cutting planes and four other planes Anything outside of the frustum is not shown on the projected image, and doesn’t need to be rendered The process of remove invisible objects from rendering is called clipping

OpenGL Perspective Projection Set viewing frustum and perspective projection matrix glFrustum(left,right,bottom,top,near,far) left and right are coordinates of left and right window boundaries in the near plane bottom and top are coordinates of bottom and top window boundaries in the near plane near and far are positive distances from the eye along the viewing ray to the near and far planes Projection actually maps the viewing frustum to a canonical cube the preserves depth information for visibility purpose.

The OpenGL Perspective Matrix Matrix M maps the viewing frustum to a NDC (canonical cube) We are looking down the -z direction

Near/Far and Depth Resolution It may seem sensible to specify a very near clipping plane and a very far clipping plane Sure to contain entire scene But, a bad idea: OpenGL only has a finite number of bits to store screen depth Too large a range reduces resolution in depth - wrong thing may be considered “in front” Always place the near plane as far from the viewer as possible, and the far plane as close as possible

Perspective Projection If the viewing frustum is symmetrical along the x and y axes. It can be set using gluPerspective() gluPerspective(θ,aspect,n,f) θ: the field of view angle aspect: the aspect ratio of the display window (width/height)

Set a view int main( int argc, char* argv[] ) { … glutReshapeFunc( reshape ); } void reshape(int width, int height) { glViewport(0, 0, width, height); glMatrixMode(GL_PROJECTION); glLoadIdentity(); double aspect = width/double(height); gluPerspective(45, aspect, 1, 1024); }

Next time Lighting and Texture mapping