MORE OPENGL. Pramook Khungurn CS 4621, Fall 2011

Similar documents
COMP3421. Introduction to 3D Graphics

COMP3421. Introduction to 3D Graphics

COMP3421. Introduction to 3D Graphics

Computer Viewing Computer Graphics I, Fall 2008

Chapter 3 - Basic Mathematics for 3D Computer Graphics

Geometry: Outline. Projections. Orthographic Perspective

Describe the Orthographic and Perspective projections. How do we combine together transform matrices?

CSC Graphics Programming. Budditha Hettige Department of Statistics and Computer Science

Computer Graphics. Chapter 10 Three-Dimensional Viewing

Viewing Transformation

CS354 Computer Graphics Viewing and Modeling

The Viewing Pipeline adaptation of Paul Bunn & Kerryn Hugo s notes

Getting Started. Overview (1): Getting Started (1): Getting Started (2): Getting Started (3): COSC 4431/5331 Computer Graphics.

3D Graphics for Game Programming (J. Han) Chapter II Vertex Processing

Rasterization Overview

Overview. Viewing and perspectives. Planar Geometric Projections. Classical Viewing. Classical views Computer viewing Perspective normalization

CITSTUDENTS.IN VIEWING. Computer Graphics and Visualization. Classical and computer viewing. Viewing with a computer. Positioning of the camera

3D Viewing. With acknowledge to: Ed Angel. Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

CS380: Computer Graphics Viewing Transformation. Sung-Eui Yoon ( 윤성의 ) Course URL:

COMS 4160: Problems on Transformations and OpenGL

2D and 3D Viewing Basics

3D computer graphics: geometric modeling of objects in the computer and rendering them

OpenGL Transformations

CIS 636 Interactive Computer Graphics CIS 736 Computer Graphics Spring 2011

Three-Dimensional Graphics III. Guoying Zhao 1 / 67

CS 4204 Computer Graphics

1 Transformations. Chapter 1. Transformations. Department of Computer Science and Engineering 1-1

Computer Graphics. Basic 3D Programming. Contents

Computer Viewing. Prof. George Wolberg Dept. of Computer Science City College of New York

Fundamental Types of Viewing

Computer Viewing. CITS3003 Graphics & Animation. E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley

Notes on Assignment. Notes on Assignment. Notes on Assignment. Notes on Assignment

CSE 167: Introduction to Computer Graphics Lecture #4: Vertex Transformation

Overview of Projections: From a 3D world to a 2D screen.

CSE 167: Lecture #4: Vertex Transformation. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2012

COMP Computer Graphics and Image Processing. 5: Viewing 1: The camera. In part 1 of our study of Viewing, we ll look at ˆʹ U ˆ ʹ F ˆʹ S

COMP3421 Computer Graphics

Lecture 4. Viewing, Projection and Viewport Transformations

Overview. By end of the week:

Today. Rendering pipeline. Rendering pipeline. Object vs. Image order. Rendering engine Rendering engine (jtrt) Computergrafik. Rendering pipeline

CSE 167: Introduction to Computer Graphics Lecture #5: Projection. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2017

CS559: Computer Graphics. Lecture 12: OpenGL Transformation Li Zhang Spring 2008

1 (Practice 1) Introduction to OpenGL

Models and The Viewing Pipeline. Jian Huang CS456

Transforms 3: Projection Christian Miller CS Fall 2011

Pipeline Operations. CS 4620 Lecture 14

7. 3D Viewing. Projection: why is projection necessary? CS Dept, Univ of Kentucky

CS 381 Computer Graphics, Fall 2012 Midterm Exam Solutions. The Midterm Exam was given in class on Tuesday, October 16, 2012.

Spring 2013, CS 112 Programming Assignment 2 Submission Due: April 26, 2013

Viewing COMPSCI 464. Image Credits: Encarta and

Wire-Frame 3D Graphics Accelerator IP Core. C Library Specification

COMP3421. Week 2 - Transformations in 2D and Vector Geometry Revision

Projection: Mapping 3-D to 2-D. Orthographic Projection. The Canonical Camera Configuration. Perspective Projection

Advanced Computer Graphics (CS & SE )

Lecture 9 Sections 2.6, 5.1, 5.2. Wed, Sep 16, 2009

Transformations (Rotations with Quaternions) October 24, 2005

Lecture 4 of 41. Lab 1a: OpenGL Basics

Precept 2 Aleksey Boyko February 18, 2011

Viewing transformations. 2004, Denis Zorin

The View Frustum. Lecture 9 Sections 2.6, 5.1, 5.2. Robb T. Koether. Hampden-Sydney College. Wed, Sep 14, 2011

Android and OpenGL. Android Smartphone Programming. Matthias Keil. University of Freiburg

Prof. Feng Liu. Fall /19/2016

3D Viewing Episode 2

CS 543: Computer Graphics. Projection

Virtual Cameras and The Transformation Pipeline

CS 428: Fall Introduction to. Viewing and projective transformations. Andrew Nealen, Rutgers, /23/2009 1

Evening s Goals. Mathematical Transformations. Discuss the mathematical transformations that are utilized for computer graphics

COMP3421. Week 2 - Transformations in 2D and Vector Geometry Revision

One or more objects A viewer with a projection surface Projectors that go from the object(s) to the projection surface

Pipeline Operations. CS 4620 Lecture Steve Marschner. Cornell CS4620 Spring 2018 Lecture 11

OpenGL: Open Graphics Library. Introduction to OpenGL Part II. How do I render a geometric primitive? What is OpenGL

Announcements. Submitting Programs Upload source and executable(s) (Windows or Mac) to digital dropbox on Blackboard

Today s Agenda. Basic design of a graphics system. Introduction to OpenGL

Lecture 3 Sections 2.2, 4.4. Mon, Aug 31, 2009

Classical and Computer Viewing. Adapted From: Ed Angel Professor of Emeritus of Computer Science University of New Mexico

Transformation Pipeline

COMP3421. Vector geometry, Clipping

Class of Algorithms. Visible Surface Determination. Back Face Culling Test. Back Face Culling: Object Space v. Back Face Culling: Object Space.

Computer graphics MN1

CS293: Java Graphics with JOGL, Solutions

// double buffering and RGB glutinitdisplaymode(glut_double GLUT_RGBA); // your own initializations

CS4620/5620: Lecture 14 Pipeline

The Graphics Pipeline and OpenGL I: Transformations!

OpenGL. Toolkits.

Viewing with Computers (OpenGL)

Projection and viewing. Computer Graphics CSE 167 Lecture 4

CS 381 Computer Graphics, Fall 2008 Midterm Exam Solutions. The Midterm Exam was given in class on Thursday, October 23, 2008.

CS230 : Computer Graphics Lecture 6: Viewing Transformations. Tamar Shinar Computer Science & Engineering UC Riverside

CSC 470 Computer Graphics. Three Dimensional Viewing

Computer Viewing and Projection. Overview. Computer Viewing. David Carr Fundamentals of Computer Graphics Spring 2004 Based on Slides by E.

CSC 470 Computer Graphics

University of British Columbia CPSC 314 Computer Graphics Jan-Apr Tamara Munzner. Viewing 4. Page 1

Viewing and Modeling

API for creating a display window and using keyboard/mouse interations. See RayWindow.cpp to see how these are used for Assignment3

Transformations. Rotation and Scaling

Lecture 5: Viewing. CSE Computer Graphics (Fall 2010)

1 OpenGL - column vectors (column-major ordering)

INTRODUCTION TO COMPUTER GRAPHICS. It looks like a matrix Sort of. Viewing III. Projection in Practice. Bin Sheng 10/11/ / 52

3D Viewing Episode 2

Pipeline Operations. CS 4620 Lecture 10

Transcription:

MORE OPENGL Pramook Khungurn CS 4621, Fall 2011

SETTING UP THE CAMERA

Recall: OpenGL Vertex Transformations Coordinates specified by glvertex are transformed. End result: window coordinates (in pixels)

Recall: OpenGL Vertex Transformation 1 Transform Model Transform View Transform Projection Divide Perspective Transform Viewport 1 0 o o o w w z y x y x

Recall: View Transform Used to set the camera. Eye space is a coordinate system where: Eye is at (0,0,0). Look in negative z direction. Y-axis is up. View transform world space eye space

Recall: View Transform

LookAt Transform A simple way to set up the camera. Parameters eye = position of the camera in world space at = position that the camera looks at in world space up = vector in world space telling which direction is considered up

LookAt Transform in Action Eye Space y eye point at point World Space z up z y x x

glulookat glulookat(eyex, eyey, eyez, atx, aty, atz, upx, upy, upz) Set current matrix M = ML where L is the LookAt matrix. L transforms the coordinate so that: The origin of the new coordinate system is eye. The z direction is the direction from eye to at. z parallel to eye at y points in the general direction of up Much like camera setup in PA1.

Where to Use gllookat? Before the any modeling transforms. Most of the time: final GL2 gl = drawable.getgl().getgl2(); GLU glu = new GLU(); gl.glmatrixmode(gl2.gl_modelview); gl.glloadidentity(); glu.glulookat(0, 0, 5, 0, 0, 0, 0, 1, 0); gl.gltranslated(1, -1, 0); gl.glrotate(30, 0, 0, 1); Select and clear modelview matrix. View transform Modeling transform /* draw stuffs */

SETTING UP PROJECTION

Projection Transform eye space clip space Coordinates in clip space tells us which vertex we see. Decision process: visible vertices must satisfy: -1 x 1-1 y 1-1 z 1 This is called the canonical view volume. Projection transform also define 3D 2D mapping. Affects sense of depth.

Two Popular Projections orthographic perspective

Projection Transform in OpenGL OpenGL stores projection transform matrix. To choose the matrix: gl.glmatrixmode(gl2.gl_projection) Any matrix manipulation commands can be used. gl.glloadidentity gl.glloadmatrix gl.gltranslated, gl.glrotated, gl.glscaled There are specific commands to specify projection matrix.

Specifying Orthographic Projection Specifying the prism of view volume in eye space. Defined by 3 pairs of numbers: left, right --- extent in x axis top, bottom --- extent in y axis near, far --- extent in -z axis (because we look in -z direction) View volume: {(x,y,z) : left x right, top y bottom, near -z far}

Orthographic View Volume

Orthographic Projection Matrix 1 0 0 0 2 0 0 0 2 0 0 0 2 n f n f n f b t b t b t l r l r l r Details in Chapter 7 of Shirley & Marschner

OpenGL Commands GL2.glOrtho(left, right, bottom, top, near, far) Set M = MO where O is the orthographic projection matrix. GLU.gluOrtho2D(left, right, bottom, top) Just a glortho with near = 0 and far = 1 Before using any of the above, use the following commands: gl.glmatrixmode(gl2.gl_projection); gl.glloadidentity(); to choose the right matrix mode, and clear the projection matrix.

Specifying Perspective Projection Specify six numbers like orthographic projection. But now, we re defining a frustum. frustum = capped pyramid

Perspective Projection Matrix 0 1 0 0 2 0 0 0 2 0 0 0 2 n f fn n f f b n t b t b t n l r l r l r n Details in Chapter 7 of Shirley & Marschner

OpenGL Commands GL2.glFrustum(left, right, bottom, top, near, far) Set M = MP where P is the perspective projection matrix. GLU.gluPerspective(fovy, aspect, near, far) Call glfrustum with: top = near * tan(fovy / 2) bottom = -top right = aspect * top left = -right

gluperspective fovy = field of view Y Angle of corresponding to the height of the near cap. aspect = aspect ratio of the near cap. View volume:

glfrustum VS gluperspective glfrustum Can create frustra not symmetric around x and y axes. Harder to set up. Useful in rendering rooms with windows. gluperspective Frustra are symmetric around x and y axes. Easy to setup due to intuitive parameters. Less flexible. Good for viewing from the eye.

Demo 14

DEPTH TEST

Visibility and Rendering Order So far: What s drawn afterwards overwrites what s drawn before.

Actual Drawing Code glcolor3d(0.5, 1, 0.5); glbegin(gl_triangles); glvertex3d(0, 0.5, 0); glvertex3d(-0.5, -0.5, 0); glvertex3d(0.5, -0.5, 0); glend(); glcolor3d(1, 0.5, 0.5); glbegin(gl_triangles); glvertex3d(0, -0.75, 1); glvertex3d(0.40, 0, 1); glvertex3d(-0.40, 0.30, -1); glend();

In 3D, should look like this

Depth Test Functionality to simulate occlusion due to depth in 3D. Nearer objects occlude farther objects. To turn on: gl.glenable(gl2.gl_depth_test); To turn off: gl.gldisable(gl2.gl_depth_test); Algorithm: z-buffer (aka depth buffer) Store depth value at each pixel. Keep the fragment from object with the lowest z from viewer.

Depth Test and glclear Now, we have two buffers to worry about. Color buffer Depth buffer When calling glclear, must clear both buffers. gl.glclear(gl2.gl_color_buffer_bit GL2.GL_DEPTH_BUFFER_BIT); Set the value to fill the depth buffer with glcleardepth. Most of the time: gl.glcleardepth(1.0); 1.0 is the maximum depth used by OpenGL.

ANIMATION

Repaint Call GLCanvas.repaint() to have it draw stuffs again. Non-blocking Just send a message to GLCanvas. Method returns immediately GLCanvas schedules a redraw as soon as possible. When? Inside GLEventListener.resize( ). Inside keyboard/mouse handler.

Creating Animation Two approaches. Swing s Timer JOGL s Animator

java.swing.timer Have main class implement ActionListener. Create instance of Timer in class. timer = new Timer(33, this); 1 st argument: delay between ticking in milliseconds. 2 nd argument: instance of ActionListener Call timer.start(); I call this in GLEventListener.init. Don t want timer to update the framebufer before it s ready. Implement the actionperformed method If source of event = timer, then Update states. Call canvas.repaint();

JOGL s Animator Two variants: Animator Call GLCanvas.display repeatedly. Short pause between calls. FPSAnimator Call GLCanvas.display periodically to achieve target frame rate. Avoid using all CPU time. We ll use this one.

JOGL s Animator Create animator = new FPSAnimator(30); Argument: target frames per second Call animator.add(canvas). Register the canvas with the animator. Perform all state updates in GLEventListener.display().

Comparison Swing s Timer Use event dispatch thread No need to worry about concurrency. State update separated from display. More code. More flexible. JOGL s Animator Create it s own thread Possible concurrency issues. Must perform state update in display(). Less code. Less flexible.