Camera Position (5.6) we specify the position and orientation of the camera to determine what will be seen. use gluLookAt (eye x, y, z, at x, y, z, up.

Slides:



Advertisements
Similar presentations
Computer Graphics - Viewing -
Advertisements

Computer Graphics 2D & 3D Transformation.
MAT 594CM S2010Fundamentals of Spatial ComputingAngus Forbes Overview Goals of the course: 1. to introduce real-time 3D graphics programming with openGL.
Viewing and Transformation
OpenGL (II). How to Draw a 3-D object on Screen?
CS 4731: Computer Graphics Lecture 11: 3D Viewing Emmanuel Agu.
2IV60 Computer Graphics 2D transformations
2D Transformations x y x y x y. 2D Transformation Given a 2D object, transformation is to change the object’s Position (translation) Size (scaling) Orientation.
2D Transformations Unit - 3. Why Transformations? In graphics, once we have an object described, transformations are used to move that object, scale it.
Introduction to 3D viewing 3D is just like taking a photograph!
Transformations of Objects CVG lab. Introduction  Affine transformations : Affine transformations are a fundamental cornerstone of computer graphics.
Viewing and Projections
Transformations Dr. Amy Zhang.
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
CS559: Computer Graphics Lecture 9: Projection Li Zhang Spring 2008.
Homogeneous Form, Introduction to 3-D Graphics Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 20,
CAP4730: Computational Structures in Computer Graphics 3D Transformations.
10/3/02 (c) 2002 University of Wisconsin, CS 559 Last Time 2D Coordinate systems and transformations.
Computer Graphics Bing-Yu Chen National Taiwan University.
16/5/ :47 UML Computer Graphics Conceptual Model Application Model Application Program Graphics System Output Devices Input Devices API Function.
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.
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.
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
Affine Transformation. Affine Transformations In this lecture, we will continue with the discussion of the remaining affine transformations and composite.
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.
Transformations Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
©2005, Lee Iverson Lee Iverson UBC Dept. of ECE EECE 478 Viewing and Projection.
Introduction to Computer Graphics: Viewing Transformations Rama C
Taxonomy of Projections FVFHP Figure Taxonomy of Projections.
Learning Objectives Affine transformations Affine transformations Translation Translation Rotation Rotation Scaling Scaling Reflection Reflection Shear.
Viewing and Projection. The topics Interior parameters Projection type Field of view Clipping Frustum… Exterior parameters Camera position Camera orientation.
CS 551 / 645: Introductory Computer Graphics Viewing Transforms.
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.
OpenGL Matrices and Transformations Angel, Chapter 3 slides from AW, Red Book, etc. CSCI 6360/4360.
Forward Projection Pipeline and Transformations CENG 477 Introduction to Computer Graphics.
Visible Surface Detection
Geometric Transformations
Summary of Properties of 3D Affine Transformations
CSCE 441 Computer Graphics 3-D Viewing
CSC461: Lecture 20 Parallel Projections in OpenGL
Modeling 101 For the moment assume that all geometry consists of points, lines and faces Line: A segment between two endpoints Face: A planar area bounded.
CSC461: Lecture 19 Computer Viewing
Fundamentals of Computer Graphics Part 5 Viewing
Three Dimensional Viewing
Unit-5 Geometric Objects and Transformations-II
CSC4820/6820 Computer Graphics Algorithms Ying Zhu Georgia State University Transformations.
CSC4820/6820 Computer Graphics Algorithms Ying Zhu Georgia State University View & Projection.
Chapters 5/4 part2 understanding transformations working with matrices
Computer Graphics Imaging
Transformations 3 University of British Columbia
Computer Graphics (Spring 2003)
Chapter V Vertex Processing
Last Time Canonical view pipeline Projection Local Coordinate Space
Transformations 고려대학교 컴퓨터 그래픽스 연구실 kucg.korea.ac.kr.
Three-Dimensional Graphics
Transformations in OpenGL
Viewing (Projections)
Geometric Objects and Transformations (II)
Viewing (Projections)
Computer Graphics Computer Viewing
Rendering – Matrix Transformations and the Graphics Pipeline
Presentation transcript:

Camera Position (5.6) we specify the position and orientation of the camera to determine what will be seen. use gluLookAt (eye x, y, z, at x, y, z, up x, y, z) Up vector determines head tilt. It is most often (0, 1, 0). Be aware if you are looking down on the scene then the up vector must be different! this command modifies the ModelView matrix and should generally be done first after setting the matrix to identity glMatrixMode (GL_MODELVIEW); glLoadIdentity(); gluLookAt (5, 5, 5, 0, 0, 0, 0, 1, 0); This has the effect of transforming all vertices from the camera frame to the world frame with the camera at the origin facing the negative Z direction.

Projection There are many different ways to draw 3D objects in drafting and freehand drawing. Computer graphics uses only two of them. Think of each projection as a different kind of lens on the camera. Viewing Volume Determines what will be seen. Objects (or portions of objects) not within the view volume will be clipped. Parallel Projection / Orthographic Preserves correct length even when objects are far away. This is an artificial projection but is useful for architects and engineers. The viewing volume is a 3D box. glMatrixMode (GL_PROJECTION); glLoadIdentity(); glOrtho (left, right, bottom, top, near, far);

Perspective Perspective Projection Creates foreshortening, the appearance that objects farther away are smaller. This is more realistic. The viewing volume is a truncated pyramid called a frustum. glMatrixMode (GL_PROJECTION); glLoadIdentity(); gluPerspective (view angle, aspect, near, far); view angle is defined in degrees and can be considered a zoom lens 0 - 180 aspect ration is width divided by height (1.0) near and far should always be positive with respect to camera

Affine Transformations (5.3) Skim 5.2 for background material on 2D transformations Homogeneous Coordinates 3D points are represented in 4D to make calculations easier p(x, y, z, w) w is usually set to 1 vector (x, y, z, w) w is usually set to 0 Affine Transformations convert one point into another p’ = f(p) different functions are used for different transformations straight lines are maintained rotation, scaling, and translation apply to each point of an object 4x4 matrices help to make the process more efficient p’ = Mp this is post multiplication the book refers to points as a column [x y z w]T Group Activity P1 = (3, 5, 7, 1) P2 = Identity * P1;

Translation displaces a point a fixed amount in x, y, and z shape and size remain the same p’ = p + displacement Translation matrix 1 0 0 Tx 0 1 0 Ty 0 0 1 Tz 0 0 0 1 Group Activity Tx = 3, y = 4, Tz = 5 P1 = (1, 2, 3, 1); P2 = Mt * P1;

Rotation about an axis by a number of degrees shape and size remain the same positive rotation goes counter clockwise parameters must be in radians x’ = x cos(O) - y sin(O) y’ = x sin (O) + y cos(O) Rotate about X axis 1 0 0 0 0 c -s 0 0 s c 0 0 0 0 1 Different matrices for rotation about Y or Z

Scaling generally about the origin non uniform stretching along one or more axes about a fixed point if S > 1 then object gets bigger Scaling matrix Sx 0 0 0 0 Sy 0 0 0 0 Sz 0 0 0 0 1 Group Activity Sx = 1.5, Sy = 2.5, Sz = 0 P1 = (2, 2, 2, 1); P2 = M * P1; Shear We will not cover the shear transformation

Composing Transformations (5.3.2) Concatenating matrices has the effect of applying one at a time M = S Rx Ry Rz T Note that matrices are multiplied in reverse order (right to left) Warning! The order of concatenation makes a difference Rotating about X and then Y is not the same as the inverse A series of transformations is applied with concatenation newObj = T * R * S * Obj An alternative is to multiply the matrices only once to be more efficient M = T * R * S newObj = M * Obj Rotation about a spcecific point instead of the origin M = T R (-T)

Viewing Pipeline (5.6) Several parameters must be provided to determine the final image: camera position, projection style and viewing volume. Transformation pipeline Keep in mind the transformations that all vertices go through and the order that it occurs. display <-- projection <-- view <-- model <-- vertex OpenGL has two built in transformation matrices: projection and modelview. Notice that the view and model matrices are combined into one. It is therefore critical to apply the view transformations BEFORE the model transformations.

Viewing Pipeline objects re defined in modeling coordiates or object space (centered about the origin) vertices are multiplied by the Model portion of the matrix to position the object in world space vertices are then multiplied by the View portion of the matrix based on the position of the camera and converted to viewing space vertices are multiplied by the projection matrix to create image space

OpenGL matrix operations OpenGL maintains two global matrices Projection - for projection paramters Modelview - for transformation All vertices are transformed before drawn. They are multipled by both matrices Post multiplication is used, therefore you must perform the transformation in opposite order that you would expect TRSp Operations glMatrixMode(GL_MODELVIEW) glLoadIdentity() glLoadMatrixf(M) resets top matrix glPushMatrix() copy the top stack and place the copy on top glPopMatrix() replace the top matrix with the previous one Concatenation glMultMatrixf(M) multiplies current Matrix times M

OpenGL Transformations glTranslatef(x,y,z) multiplies current matrix to cause a translation MV = MV * M glRotatef(degrees, x, y, z) multiplies current matrix to cause a rotation of the specified degrees about the specified axis. glScalef(x, y, z) multiplies current matrix to cause scaling about the X, Y, and Z axes

Small uisGL Example // look at ~grissom/367uisGL.h uisObject cube; uisMatrix M, S, T; // initialize structure from external object file infile.open(“cube.obj”); infile >> cube; // set transformation matrix from scene description file S.setScaling(x,y,z); T.setTranslation(x,y,z); M= T * S; cube.setTransformation(M); // transform all points at the beginning cube = M * cube; // render the object face by face

Hidden Surface Removal 5.5 Backface Removal You do not see the back side of an object. Decision must be made on a face by face case with respect to the viewer position. Hidden Surface Removal the elimination of parts of objects that are obscured by other objects Rotating Cube example from Ch 5.6 Object Space algorithms attempt to dispaly objects in an appropriate order. (painters algorithm) Image Space algorithms work on a pixel by pixel basis to determine which to display. The ordering of the objects is not important. (z-buffer)

Backface removal Not covered in the book or by OpenGL Identify which objects are facing towards the viewing Calculate normal vector to face Calculate vector from face to eye Calculate the angle between the two if greater than 90 then not visible Use dot product, if <= 0 then not visible uisGL Code uisObject Obj; uisFace F; uisVertex P1, P2, P3; uisVector V1, V2, N; V1 = P2 - P1; V2 = P3 - P1; N = V1 | V2; V1 = Eye - P1; if (V1 * N) <= 0 not visible

Z buffer algorithm Image space algorithm maintain the z value for each pixel as a face is rasterized only replace the current pixel with one that is closer to the viewer this takes alot of memory called a Z -buffer OpenGL does this for us glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH); glEnable(GL_DEPTH_TEST); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); We will use this method but it does not help in wireframe mode

Walking Thru A Scene Notice the subtle difference between rotating the object compared to moving the viewer run cubeview.c Rotate cube with mouse Move viewer with key presses x, X, y, Y, z, Z