3D coordinate systems X Y Z Right-Hand Coordinate System X Y Z Left-Hand Coordinate System OpenGL uses this! Direct3D uses this!

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
David Luebke5/16/2015 Administrivia l Back on track: canceling OpenGL lecture 2 l Assignment 1 –Greg Yukl found an alternate XForms site:
Based on slides created by Edward Angel
Viewing and Transformation
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Computer Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
OpenGL and Projections
1 CSC461 Lecture 7: 3D Programming in OpenGL Objectives: Develop 2D and 3D examples -- Sierpinski gasket: a fractal Develop 2D and 3D examples -- Sierpinski.
OpenGL (II). How to Draw a 3-D object on Screen?
CS 4731: Computer Graphics Lecture 11: 3D Viewing Emmanuel Agu.
OpenGL Tutorial Jason Lawrence COS426 Precept Notes 2/16/04.
Noggin (BYU Students, SIGGRAPH 2006). Introduction to OpenGL Programming Rick Skarbez, Instructor COMP 575 September 11, 2007.
Development of Interactive 3D Virtual World Applications
3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla
Introduction to OpenGL M. Ramanathan STTP CAD 2011Introduction to OpenGL.
CS 470 Introduction to Computer Graphics Basic 3D in OpenGL.
Introduction to 3D viewing 3D is just like taking a photograph!
OpenGL A Brief Overview. What is OpenGL?  It is NOT a programming language.  It is a Graphics Rendering API consisting of a set of function with a well.
CSE 872 Dr. Charles B. Owen Advanced Computer Graphics1 CSE 872 Advanced Computer Graphics Charles B. Owen (Instructor) – 1138 E. B., MW 12:30-1:50pm.
1 OpenGL Basics A Graphics Standard ©Mel Slater, Anthony Steed
Open GL Programming Speaker: 彭任右 Date: 2005/10/3.
Computer Graphics, KKU. Lecture 131 Transformation and Viewing in OpenGL.
Geometric transformations The Pipeline
Chapter 5 Viewing.
Homogeneous Form, Introduction to 3-D Graphics Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 20,
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.
Intro to OpenGL Transformations CS 445/645 Introduction to Computer Graphics David Luebke, Spring 2003.
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 고려대학교 컴퓨터 그래픽스 연구실.
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
Chap 3 Viewing and Transformation
Lecture 2 Review OpenGL Libraries Graphics Overview Rendering Pipeline OpenGL command structure.
CS559: Computer Graphics Lecture 12: OpenGL - Transformation Li Zhang Spring 2008.
CS559: Computer Graphics Lecture 12: OpenGL: ModelView Li Zhang Spring 2010.
OpenGL: Introduction #include main() { OpenWindow() ; glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT); glOrtho(-1.0, 1.0, -1.0, 1.0, -1.0,
CS5500 Computer Graphics March 20, Computer Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts.
Implement of transformation,projection, viewing Hanyang University Jungsik Park.
CSC Graphics Programming Budditha Hettige Department of Statistics and Computer Science.
OpenGL LAB III.
CS380 LAB II OpenGL Donghyuk Kim Reference1. [OpenGL course slides by Rasmus Stenholt] Reference2. [
Computer Graphics Lecture 34. OpenGL Programming II Taqdees A. Siddiqi
CSC Graphic Programming Lecture 2 OpenGL Lightning.
Viewing 고려대학교 컴퓨터 그래픽스 연구실 kucg.korea.ac.kr.
Administrivia Back on track: canceling OpenGL lecture 2 Assignment 1
Viewing.
Computer Graphics - Chapter 5 Viewing
Computer Viewing.
Isaac Gang University of Mary Hardin-Baylor
Jason Lawrence COS426 Precept Notes 2/16/04
Reference1. [OpenGL course slides by Rasmus Stenholt]
Advanced Graphics Algorithms Ying Zhu Georgia State University
OpenGL (Open Graphics Library) Mr. B.A.Swamy Assistant Professor Dept of CSE.
Lecture 08 and 09 View & Projection
CSC4820/6820 Computer Graphics Algorithms Ying Zhu Georgia State University View & Projection.
Introduction to OpenGL
Type of View Perspective View COP(Center of Plane) Diminution of size
OpenGL program.
University of New Mexico
Computer Graphics 3Practical Lesson
Chapter 3 Viewing.
Presentation transcript:

3D coordinate systems X Y Z Right-Hand Coordinate System X Y Z Left-Hand Coordinate System OpenGL uses this! Direct3D uses this!

Visualizing in 3D X Y Z 1.0 z=1.0 x=1.0 y=1.0 A B C D E F G H Counter- clockwise

Rendering a Box in OpenGL We render the 6 faces as polygons –Polygons are specified as a list of vertices –Vertices are specified in counterclockwise order looking at the surface of the face! AB C D E F G H

OpenGL Polygon Rendering GLdouble size = 1.0; glBegin(GL_POLYGON); // front face glVertex3d(0.0, 0.0, size); glVertex3d(size, 0.0, size); glVertex3d(size, size, size); glVertex3d(0.0, size, size); glEnd();

OpenGL Conventions C library –All function names start with gl OpenGL is a retained mode graphics system –It has a state –glBegin(GL_POLYGON) puts us into a polygon rendering state.

OpenGL Types Basic numeric types –GLdouble = double –GLfloat = float –GLint = int –GLshort = short Mostly you’ll use GLdouble and GLfloat

Function suffixes Many functions have alternatives –Alternatives are specified by the suffix –glVertex2d 2 double parameters void glVertex2d(GLdouble x, GLdouble y); –glVertex3f 3 float parameters void glVertex3f(GLfloat x, GLfloat y, GLfloat z); –glVertex3fv void glVertex3fv(const GLfloat *v);

All of dem… glVertex2d, glVertex2f, glVertex2i, glVertex2s, glVertex3d, glVertex3f, glVertex3i, glVertex3s, glVertex4d, glVertex4f, glVertex4i, glVertex4s, glVertex2dv, glVertex2fv, glVertex2iv, glVertex2sv, glVertex3dv, glVertex3fv, glVertex3iv, glVertex3sv, glVertex4dv, glVertex4fv, glVertex4iv, glVertex4sv

Specifying a color (no lighting) glColor3f(red, green, blue); Most of the same suffixes apply… GLdouble size = 1.0; glColor3d(1.0, 0.0, 0.0);// red glBegin(GL_POLYGON); // front face glVertex3d(0.0, 0.0, size); glVertex3d(size, 0.0, size); glVertex3d(size, size, size); glVertex3d(size, 0.0, size); glEnd();

Moving to 3D Camera Configuration Parameters Tessellation Scene Graphs

Structure of Our Programs OnGLDraw() –Clear the buffers –Set up the camera –Position the camera –Configure OpenGL –Render whatever we are rendering –Flush

Clear the Buffers void CChildView::OnGLDraw(CDC *pDC) { // Clear to black... glClearColor(0.0f, 0.0f, 0.0f, 0.0f) ; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);...

Camera Configuration What does it take to describe a camera?

Describing a Camera Where it is in space  Eye location Which way it’s pointing  Or what it’s pointing at Which way is up Zoom characteristics  Field of view angle

Setting up the Camera Field of View (angle) Near clipping plane Far clipping plane Nothing is rendered that is:  Closer than the near clipping plane  Farther than the far clipping plane Aspect ratio = w/h w h

gluPerspective() void gluPerspective(GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar ); Fovy = Field of view angle –Degrees, usually less than 90 Aspect = Ratio of width/height of window zNear = distance to near clipping plane zFar = distance to far clipping plane glu = GL Utility

Important What do the numbers zFar, zNear represent? –Always select some unit for your application Inches, Feet, Meters, etc. In my sample application, I used inches

Using gluPerspective() // // Set up the camera // glMatrixMode(GL_PROJECTION); glLoadIdentity(); // Determine the screen size so // we can determine the aspect ratio int width, height; GetSize(width, height); GLdouble aspectratio = GLdouble(width) / GLdouble(height); // Set the camera parameters gluPerspective(25., // Field of view. aspectratio, // The aspect ratio. 10., // Near clipping 200.); // Far clipping

After this The camera is: –At the origin –Looking down the -Z axis

Positioning the Camera gluLookAt(eyex, eyey, eyez, atx, aty, atz, upx, upy, upz); Eye – Where the camera is located At – What the camera is looking at Up – Which direction is up –Can’t be the looking direction

Matrix Modes GL_PROJECTION –3D to 2D conversion –Camera parameters GL_MODELVIEW –Translation, rotation, etc. of Graphical Models –gluLookAt is a rotation and translation of your graphical model the camera is really at the origin and looking down the z axis.

Using gluLookAt() // Set the camera location glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluLookAt(50., 50., 50., // eye x,y,z 0., 0., 0., // center x,y,z 0., 1., 0.); // Up direction... Render from here on...

Some OpenGL Configurations // // Some standard parameters // // Enable depth test glEnable(GL_DEPTH_TEST); // Cull backfacing polygons glCullFace(GL_BACK); glEnable(GL_CULL_FACE);

Example: Showing the coordinate axis… if(m_showaxis) { glColor3d(0., 1., 1.); glBegin(GL_LINES); glVertex3d(0., 0., 0.); glVertex3d(12., 0., 0.); glVertex3d(0., 0., 0.); glVertex3d(0., 12., 0.); glVertex3d(0., 0., 0.); glVertex3d(0., 0., 12.); glEnd(); }

Example: A Cube void CChildView::Cube(GLdouble size) { GLdouble a[] = {0., 0., size}; GLdouble b[] = {size, 0., size}; GLdouble c[] = {size, size, size}; GLdouble d[] = {0., size, size}; GLdouble e[] = {0., 0., 0.}; GLdouble f[] = {size, 0., 0.}; GLdouble g[] = {size, size, 0.}; GLdouble h[] = {0., size, 0.}; glColor3d(0.8, 0., 0.); glBegin(GL_POLYGON); // Front glVertex3dv(a); glVertex3dv(b); glVertex3dv(c); glVertex3dv(d); glEnd();... ab c d ef gh See example program…