OpenGL (II). How to Draw a 3-D object on Screen?

Slides:



Advertisements
Similar presentations
Computer Graphics - Viewing -
Advertisements

02/17/05CISC640/440 OpenGL Tutorial1 OpenGL Tutorial CISC 640/440 Computer Graphics TA: Qi Li/Mani Thomas
MAT 594CM S2010Fundamentals of Spatial ComputingAngus Forbes Overview Goals of the course: 1. to introduce real-time 3D graphics programming with openGL.
Using GLU/GLUT Objects GLU/GLUT provides very simple object primitives glutWireCube glutWireCone gluCylinder glutWireTeapot.
Computer Graphic Creator: Mohsen Asghari Session 2 Fall 2014.
1 Computer Graphics Chapter 8 3D Transformations.
The View Frustum and the Camera Lecture 19 Fri, Oct 10, 2003.
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,
CS 352: Computer Graphics Chapter 5: Viewing. Interactive Computer GraphicsChapter Overview Specifying the viewpoint Specifying the projection Types.
Viewing & Perspective CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2006.
CS 4731: Computer Graphics Lecture 11: 3D Viewing Emmanuel Agu.
3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla
CS 4731: Computer Graphics Lecture 9: Introduction to 3D Modeling Emmanuel Agu.
Introduction to 3D viewing 3D is just like taking a photograph!
Viewing & Perspective CSE167: Computer Graphics Instructor: Steve Rotenberg UCSD, Fall 2005.
UniS CS297 Graphics with Java and OpenGL Viewing, the model view matrix.
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.
Image Synthesis Rabie A. Ramadan, PhD 2. 2 Java OpenGL Using JOGL: Using JOGL: Wiki: You can download JOGL from.
Geometric transformations The Pipeline
CS559: Computer Graphics Lecture 9: Projection Li Zhang Spring 2008.
CSE 470: Computer Graphics. 10/15/ Defining a Vertex A 2D vertex: glVertex2f(GLfloat x, GLfloat y); 2D vertexfloating pointopenGL parameter type.
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.
Computer Graphics Bing-Yu Chen National Taiwan University.
Computer Graphics I, Fall 2010 Computer Viewing.
OpenGL: Introduction Yanci Zhang Game Programming Practice.
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 고려대학교 컴퓨터 그래픽스 연구실.
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.
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.
David Luebke1/5/2016 CS 551 / 645: Introductory Computer Graphics David Luebke
Taxonomy of Projections FVFHP Figure Taxonomy of Projections.
Chap 3 Viewing and Transformation
Coordinate Systems Lecture 1 Fri, Sep 2, The Coordinate Systems The points we create are transformed through a series of coordinate systems before.
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.
CS5500 Computer Graphics March 20, Computer Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts.
Coordinate Systems Lecture 20 Wed, Oct 15, Object Coordinates Each object has its own “local” coordinate system, called object coordinates. Normally.
Geometric Transformations Ceng 477 Introduction to Computer Graphics Computer Engineering METU.
OpenGL LAB III.
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.
Viewing 고려대학교 컴퓨터 그래픽스 연구실 kucg.korea.ac.kr.
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
Projection in 3-D Glenn G. Chappell
Type of View Perspective View COP(Center of Plane) Diminution of size
Computer Graphics 3Practical Lesson
Chapter 3 Viewing.
Presentation transcript:

OpenGL (II)

How to Draw a 3-D object on Screen?

Drawing a Scene Apply modeling and viewing transformations Apply projection transformation Clip if it lies outside the viewing volume Apply viewport transformation to display on the screen

Transformations Modeling Transformation Viewing Transformation Projection Transformation Viewport Transformation

Clip Coordinates ModelView Matrix Projection Matrix Perspective Division Viewport Transformation Eye Coordinates Normalized Device Coordinates Windows Coordinates Vertex Object Local Coordinates Stages of Vertex Transformations

Transformations in OGL Recall that once you define the attributes (such as color), all the subsequent objects are drawn using those attributes. Same rule applied for transformations Specify a transformation, and then this transformation is automatically applied to every object that is drawn, until the transformation is set again. Important: set transformations prior to drawing

Transformations in OGL Transformations have different purposes We discuss only two of OGL’s matrix types (the third is Texture matrix) Modelview matrix for moving objects or change of coordinates Projection matrix for projection Project objects from the world window to the viewport, and mapping the viewport to the graphics display window.

Transformations in OGL For each matrix type, OGL maintains a stack of matrices Stack: last in, first out To operate on a specific matrix type, call glMatrixMode(mode) Different modes: GL_MODELVIEW, GL_PROJECTION Once the matrix mode is set, perform various operations on the stack.

Matrix Stacks (Con ’ t) There are several routines for manipulating matrix stacks glPushMatrix() glPopMatrix() glLoadMatrix() glMultMatrix() glLoadIdentity() To avoid destroying the contents of the Modelview matrix, save the contents of the Modelview matrix and restore its contents after we are done.

Modeling Transformation Positions and orients the objects Rotation: glRotate{fd}(angle, x, y, z) Translation: glTranslate{fd}(x, y, z) Scaling: glScale{fd}(x, y, z)

Modeling Transformation (Con ’ t) World space Model space

Transformation Example In OGL, whenever you draw, the points are automatically transformed using the current Modelview matrix. Common way of object transformations in OGL Push the matrix stack. Apply all desired transformations Draw your objects (the transformations will be applied automatically) Pop the matrix stack.

Post-multiplication MM M M MT M MTR glPushMatrix() glTranslate() glRotate()

Order of Transformations Specify the transformations in the reverse order of the way you conceptualize them Specify Conceptualize M1M2vM1M2v

Order of Transformations (Con ’ t) Example 1: TRv glTranslatef(2.0,0.0,0.0) glRotatef(45.0,0.0,0.0,1.0)

Order of Transformations (Con ’ t) Example 2: RTv glRotatef(45.0,0.0,0.0,1.0) glTranslatef(2.0,0.0,0.0)

Transformation Example First attempt Rotation command glRotatef(angle_in_degree, x, y, z); Rotation is performed about the origin of the coordinate system. Translation command glTranslatef(x, y, z); glPushMatrix(); // save the current matrix glRotatef(20, 0, 0, 1); // rotate by 20 degrees CCW glRectf(x-2, y-2, x+2, y+2); // draw the rectangle glPopMatrix(); // restore the old matrix glPushMatrix(); // save the current matrix glRotatef(20, 0, 0, 1); // rotate by 20 degrees CCW glTranslatef(x, y, 0);// apply translation glRectf(-2, -2, 2, 2); // draw the rectangle glPopMatrix(); // restore the old matrix equivalent

Transformation Example Correct way glPushMatrix(); // save the current matrix glTranslatef(x, y, 0);// apply translation glRotatef(20, 0, 0, 1); // rotate by 20 degrees CCW glRectf(-2, -2, 2, 2); // draw the rectangle glPopMatrix(); // restore the old matrix

OpenGL viewing Modelview transformation Modeling transformation: local coordinates  world coordinates Viewing transformation: world coordinates  eye coordinates

Modelview Matrix Pulling the camera back from the object (viewing transformation)  moving the object away from the camera (modeling transformation) Thus, both viewing and modeling transformations are stored in the modelview matrix stack

Viewing Transformation Position and aim the camera gluLookAt(eyex, eyey, eyez, centerx, centery, centerz, upx, upy, upz) Default location at origin looking down the negative z-axis x y z

Viewing Transformation (Con ’ t) Center position Eye position Up vector

OpenGL viewing gluLookAt(eye.x, eye.y, eye.z, center.x, center.y, center.z, up.x, up.y, up.z) Viewing direction: center – eye Up is the upward direction Viewing direction and up vector  eye coordinate system X axis points to the right of viewer Y axis points upward Z axis points to the back of viewer Generate a matrix, which is postmultiplied to the top- of-the-stack matrix on the Modelview stack Thus, must be called before any modeling transformations

OpenGL viewing Default OpenGL viewing (if no gluLookAt is specified) Eye is at origin of world space Looking down the negative z axis of world space Up vector is positive y axis The viewing transformation matrix is identity matrix (i.e. eye coordinate system = world coordinate system)

Viewing Transformation (Con ’ t) Default location gluLookAt(4.0, 2.0, 1.0, 2.0, 4.0, -3.0, 2.0, 2.0, - 1.0)

OpenGL projection glOrtho(), gluPerspective() or glFrustum() Produce a matrix which is stored in the projection matrix stack All geometry objects are already transformed to the eye coordinate system before projection transformation is applied The parameters of these functions are with respect to the eye coordinate system The parameters define 6 clipping planes To simplify clipping, the viewing space is transformed into a canonical view volume (all coordinates in [-1, +1])

OpenGL orthographic projection glOrtho(left, right, bottom, top, near, far) left, right, bottom, top are coordinates in eye space left, right are the x-coordinate limits bottom, top are the y-coordinate limits near, far are signed distances from the eye to the near and far clipping planes (e.g., near = 2, far = 15 mean the clipping planes are at z=-2 and z= -15)

OpenGL perspective projection The center of projection and the portion of the projection plane that map to the final image form an infinite pyramid. The sides of the pyramid are clipping planes. All of the clipping planes bound the viewing frustum. In OpenGL, PP = near plane

OpenGL perspective projection glFrustum(left, right, bottom, top, near, far) View frustum may not be centered along view vector Less often used than gluPerspective() gluPerspective(fov_y, aspect_ratio, near, far) fov_y is vertical field-of-view in degrees aspect ratio = width / height near, far are distances from eye to two clipping planes must be positive Keep them close so as to maximize depth precision