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

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


Books, OpenGL, GLUT, GLUI, CUDA, OpenCL, OpenCV, PointClouds, and G3D

Precept 2 Aleksey Boyko February 18, 2011

Books, OpenGL, GLUT, CUDA, OpenCL, OpenCV, PointClouds, G3D, and Qt

To Do. Computer Graphics (Fall 2008) Course Outline. Course Outline. Methodology for Lecture. Demo: Surreal (HW 3)

CS418 OpenGL & GLUT Programming Tutorial (I) Presented by : Wei-Wen Feng 1/30/2008

Basic Graphics Programming

Introduction to OpenGL

Computer graphics MN1

Using OpenGL with CUDA

Lecture 4 of 41. Lab 1a: OpenGL Basics

Modeling Transform. Chapter 4 Geometric Transformations. Overview. Instancing. Specify transformation for objects 李同益

1 (Practice 1) Introduction to OpenGL

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

Computer Graphics. Chapter 10 Three-Dimensional Viewing

Duc Nguyen CSE 420 Computer Graphics 10/10/2018 Homework 1

Introduction to Computer Graphics with OpenGL/GLUT

Programming with OpenGL Part 3: Three Dimensions

Lecture 3. Understanding of OPenGL programming

Teacher Assistant : Tamir Grossinger Reception hours: by - Building 37 / office -102 Assignments: 4 programing using

Outline. Other Graphics Technology. OpenGL Background and History. Platform Specifics. The Drawing Process

Graphics and Computation Introduction to OpenGL

Order of Transformations

Computer Graphics Introduction to OpenGL

C++ is Fun Part 13 at Turbine/Warner Bros.! Russell Hanson

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

by modifying the glutinitwindowsize() function you can change the screen size to whatever you please.

Lectures OpenGL Introduction

Programming using OpenGL: A first Introduction

Computer Graphics (Basic OpenGL)

Computer Graphics Primitive Attributes

Graphics Programming. August 31, Programming of the Sierpinski gasket. Programming with OpenGL and C/C++

Basic Graphics Programming

Interaction Computer Graphics I Lecture 3

Transformation, Input and Interaction. Hanyang University

11/1/13. Basic Graphics Programming. Teaching Assistant. What is OpenGL. Course Producer. Where is OpenGL used. Graphics library (API)

GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW

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

Display Lists in OpenGL

Chapter 3: Modeling Transformation

Graphics Programming

Transformation Pipeline

Viewing Transformation

Programming with OpenGL Part 2: Complete Programs Computer Graphics I, Fall

1.2 Basic Graphics Programming

COMPUTER GRAPHICS LAB # 3

Announcement. Homework 1 has been posted in dropbox and course website. Due: 1:15 pm, Monday, September 12

Geometry: Outline. Projections. Orthographic Perspective

Source code: #include <iostream>

Computer Graphics. Making Pictures. Computer Graphics CSC470 1

Drawing Primitives. OpenGL basics

6. Make use of glviewport() to display two sine curves on the same screen, one on the

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

Interaction. CSCI 480 Computer Graphics Lecture 3

Fundamental Types of Viewing

Cameras (and eye) Ideal Pinhole. Real Pinhole. Real + lens. Depth of field

Introduction to OpenGL: Part 2

Announcements OpenGL. Computer Graphics. Spring CS4815

Computer Graphics. OpenGL

RECITATION - 1. Ceng477 Fall

C OMPUTER G RAPHICS Thursday

Transformations (Rotations with Quaternions) October 24, 2005

UNIT 7 LIGHTING AND SHADING. 1. Explain phong lighting model. Indicate the advantages and disadvantages. (Jun2012) 10M

Image Rendering. Rendering can be divided into three sub-problems. Image Formation The hidden surface problem visibility determination steps

Announcements OpenGL. Computer Graphics. Autumn 2009 CS4815

Exercise 1 Introduction to OpenGL

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

OpenGL/GLUT Intro. Week 1, Fri Jan 12

CS 4204 Computer Graphics

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

OpenGL refresher. Advanced Computer Graphics 2012

Graphics Programming. 1. The Sierpinski Gasket. Chapter 2. Introduction:

CS354 Computer Graphics Viewing and Modeling

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

Programming with OpenGL Part 1: Background

QUESTION 1 [10] 2 COS340-A October/November 2009

Graphics Hardware and OpenGL

FAKULTI TEKNOLOGI MAKLUMAT DAN KOMUNIKASI BITM INTERACTIVE COMPUTER GRAPHICS LAB SESSION 4. C++ - OpenGL

COS340A Assignment 1 I Pillemer Student# March 25 th 2007 p1/15

Comp 410/510 Computer Graphics Spring Programming with OpenGL Part 2: First Program

2/3/16. Interaction. Triangles (Clarification) Choice of Programming Language. Buffer Objects. The CPU-GPU bus. CSCI 420 Computer Graphics Lecture 3

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

Lecture 3 Advanced Computer Graphics (CS & SE )

COMP 371/4 Computer Graphics Week 1

OpenGL. What it is: Client-server model Network transparent. Computer Graphics

An Interactive Introduction to OpenGL Programming

Interaction. CSCI 420 Computer Graphics Lecture 3

Chapter 13 Selection and Feedback

OpenGL Tutorial. Ceng 477 Introduction to Computer Graphics

CS 4731 Lecture 3: Introduction to OpenGL and GLUT: Part II. Emmanuel Agu

CS 543 Lecture 1 (Part 3) Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

Computer graphics MN1

Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

Rendering Pipeline/ OpenGL

CS Computer Graphics: OpenGL, Continued

CS Computer Graphics: OpenGL, Continued

Visualizing Molecular Dynamics

Abel J. P. Gomes LAB. 1. INTRODUCTION TO OpenGL

BOUNCING BALL IMRAN IHSAN ASSISTANT PROFESSOR

Transcription:

CS559: Computer Graphics Lecture 2: OpenGL Transformation Li Zhang Spring 28

Today Transformation in OpenGL Reading Chapter 3

Last time

Primitive Details glpolygonmode(glenum face, GLenum mode); face: GL_FRONT, GL_BACK mode: GL_POINT, GL_LINE, GL_FILL glpolygonmode(gl_front, GL_FILL); glrectf(,,, ); glpolygonmode(gl_back, GL_LINE); glrectf(,,, );

Primitive Details Determine Polygon Orientation area( PP P 4) 2 3P = area ( PP 2Q2Q ) + area( P2 P3 Q3Q2 ) area( P3 P4 Q4Q3 ) area( P4 PQ 4Q ) Q 3 Q 4 Q 2 y P 4 P 3 P 2 area = N n= 2 ( x i + x i+ )( yi+ yi ) N N N = + N xi yi+ xi yi xi+ yi+ x 2 n= n= n= n= = 2 N ( xi yi+ xi+ yi ) n= Orientation == sign of the area i+ y i Q Stokes' R dxdy = R P Theorem xdy x

Icosahedron Normal Vectors

Icosahedron //initial icosahedron Static float t[2][3][3] = { ; void display(void) {

Icosahedron //initial icosahedron Static float t[2][3][3] = { ; void display(void) { //clear buffer //set up viewport and frustum if (animation) angle+=.3; if (angle>36) angle =36.; glloadidentity(); glrotatef(angle,,,);

Icosahedron //initial icosahedron Static float t[2][3][3] = { ; void display(void) { //clear buffer //set up viewport and frustum if (animation) angle+=.3; if (angle>36) angle =36.; glloadidentity(); glrotatef(angle,,,); // subdivide each face of the triangle for (int i = ; i < 2; i++) { Subdivide(t[i][], t[i][], t[i][2], subdiv);

Icosahedron //initial icosahedron Static float t[2][3][3] = { ; void display(void) { //clear buffer //set up viewport and frustum if (animation) angle+=.3; if (angle>36) angle =36.; glloadidentity (); glrotatef(angle,,,); // subdivide each face of the triangle for (int i = ; i < 2; i++) { Subdivide(t[i][], t[i][], t[i][2], subdiv); glflush(); glutswapbuffers();

Icosahedron void Subdivide(GLfloat v[3], GLfloat v2[3], GLfloat v3[3], int depth) {

Icosahedron void Subdivide(GLfloat v[3], GLfloat v2[3], GLfloat v3[3], int depth) { if (depth == ) { glcolor3f(.5,.5,.5); glbegin(gl_triangles); glvertex3fv(v); glvertex3fv(v2); glvertex3fv(v3); glend();

Icosahedron void Subdivide(GLfloat v[3], GLfloat v2[3], GLfloat v3[3], int depth) { if (depth == ) { glcolor3f(.5,.5,.5); glbegin(gl_triangles); glvertex3fv(v); glvertex3fv(v2); glvertex3fv(v3); glend(); else { GLfloat v2[3], v23[3], v3[3]; for (int i = ; i < 3; i++) { v2[i] = (v[i]+v2[i])/2.; v23[i] = (v2[i]+v3[i])/2.; v3[i] = (v3[i]+v[i])/2.; Normalize(v2); Normalize(v23); Normalize(v3);

Icosahedron void Subdivide(GLfloat v[3], GLfloat v2[3], GLfloat v3[3], int depth) { if (depth == ) { glcolor3f(.5,.5,.5); glbegin(gl_triangles); glvertex3fv(v); glvertex3fv(v2); glvertex3fv(v3); glend(); else { GLfloat v2[3], v23[3], v3[3]; for (int i = ; i < 3; i++) { v2[i] = (v[i]+v2[i])/2.; v23[i] = (v2[i]+v3[i])/2.; v3[i] = (v3[i]+v[i])/2.; Normalize(v2); Normalize(v23); Normalize(v3); Subdivide(v, v2, v3, depth ); Subdivide(v2, v23, v2, depth ); Subdivide(v3, v3, v23, depth ); Subdivide(v2, v23, v3, depth );

Fixed Camera location So far => Change Camera location Single object => Multiple objects

Examples of multiple objects

3D Geometry Pipeline M object M view Model Space (Object Space) World Space M project Eye Space (View Space) y = M M M M object x image project view M image Canonical View Space Screen Space (2D) Image Space (pixels) Raster Space

3D Geometry Pipeline Model Transformation View Transformation Model Space (Object Space) World Space Eye Space (View Space) Screen Space (2D) Image Space (pixels) Raster Space

3D Geometry Pipeline Model View Transformation Model Space (Object Space) Projection Eye Space (View Space) View port Transformation Screen Space (2D) Image Space (pixels) Raster Space

3D Geometry Pipeline glmatrixmode(gl_modelview) glloadidentity(); glrotate( ); Model View Transformation Model Space (Object Space) glmatrixmode(gl_projection) glloadidentity(); glfrustum( ); Projection View port Transformation Eye Space (View Space) glviewport( ); Screen Space (2D) Image Space (pixels) Raster Space

Cube.cpp

Cube.cpp Event Driven Programming Window management library GLUT / FLTK Events: key strokes, mouse clicks Event handlers: mouse(), display(), reshape()

Cube.cpp int main(int argc, char** argv) { glutinit(&argc, argv); glutinitdisplaymode (GLUT_SINGLE GLUT_RGB); glutinitwindowsize (5, 5); glutinitwindowposition (, ); glutcreatewindow (argv[]); init (); glutdisplayfunc(display); glutreshapefunc(reshape); glutkeyboardfunc(keyboard); glutmainloop(); return ; void keyboard(unsigned char key, int x, int y) { switch (key) { case 27: //correspond to ESC exit(); break;

Cube.cpp int main(int argc, char** argv) { glutinit(&argc, argv); glutinitdisplaymode (GLUT_SINGLE GLUT_RGB); glutinitwindowsize (5, 5); glutinitwindowposition (, ); glutcreatewindow (argv[]); init (); glutdisplayfunc(display); glutreshapefunc(reshape); glutkeyboardfunc(keyboard); glutmainloop(); return ; void reshape (int w, int h) { glviewport(,, w, h); glmatrixmode(gl_projection); glloadidentity(); glfrustum(.,.,.,.,.5, 2.);

Cube.cpp void display(void) { glclear(gl_color_buffer_bit); glcolor3f(.,.,.); glmatrixmode(gl_modelview); glloadidentity(); /* clear the matrix */ /* viewing transformation */ glulookat(.,., 5.,.,.,.,.,.,.); glscalef(., 2.,.); /* modeling transformation */ glutwirecube(.); glflush(); int main(int argc, char** argv) { glutinit(&argc, argv); glutinitdisplaymode (GLUT_SINGLE GLUT_RGB); glutinitwindowsize (5, 5); glutinitwindowposition (, ); glutcreatewindow (argv[]); init (); glutdisplayfunc(display); glutreshapefunc(reshape); glutkeyboardfunc(keyboard); glutmainloop(); return ;

Modeling Transformation gltranslatef(float x, float y, float z) glrotatef(float angle, float x, float y, float z) glscalef(float x, float y, float z) glscalef(2.,.5,.)

General Modeling Transform glloadidentify() glloadmatrixf(float *M) glmultimatrixf(float *M) double M[4][4]; M[2][] corresponds to??? M[]

Matrix Chain glmatrixmode(gl_modelview); glloadidentity(); glmultmatrixf(n); /* apply transformation N */ glmultmatrixf(m); /* apply transformation M */ glmultmatrixf(l); /* apply transformation L */ glbegin(gl_points); glvertex3f(v); /* draw transformed vertex v */ glend(); /* which is (N*(M*(L*v))) */

Matrix Chain glmatrixmode(gl_modelview); glloadidentity(); glmultmatrixf(v); glmultmatrixf(r); glmultmatrixf(t); glbegin(gl_points); glvertex3f(v); glend(); glmatrixmode(gl_modelview); glloadidentity(); glulookat( ); glrotatef( ); gltranslatef( ); glbegin(gl_points); glvertex3f(v); glend();

glulookat glulookat( float eyex, float eyey, float eyez, float px, float py, float pz, float upx, float upy, float upz ) e p u e p e p z = e x e z e y e e e e z u z u x = e e e e e x z x z y =. Give eye location e 2. Give target position p 3. Give upward direction u = T T T e z y x M e e e v

glulookat

glfrustum glfrustum(double left, double right, double bottom, double top, double near, double far) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) ( ) + + + + = = > 2 2 2 nf f n n n f n f n f n b t b t b t l r l r l r P O canonical view M M M

gluperspective gluperspective(double fovy, double aspect, double znear, double zfar)

gluperspective

Orthographic Projection glortho(double left, double right, double bottom, double top, double near, double far);

Viewport Transformation glviewport(int x, int y, int width, int height); glfrustum(double left, double right, double bottom, double top, double near, double far) gluperspective(double fovy, double aspect, double znear, double zfar)

Revisit cube.cpp int main(int argc, char** argv) { glutinit(&argc, argv); glutinitdisplaymode (GLUT_SINGLE GLUT_RGB); glutinitwindowsize (5, 5); glutinitwindowposition (, ); glutcreatewindow (argv[]); init (); glutdisplayfunc(display); glutreshapefunc(reshape); glutkeyboardfunc(keyboard); glutmainloop(); return ; void display(void) { glclear(gl_color_buffer_bit); glcolor3f(.,.,.); glmatrixmode(gl_modelview); glloadidentity(); /* clear the matrix */ /* viewing transformation */ glulookat(.,., 5.,.,.,.,.,.,.); glscalef(., 2.,.); /* modeling transformation */ glutwirecube(.); glflush(); void reshape (int w, int h) { glviewport(,, w, h); glmatrixmode(gl_projection); glloadidentity(); glfrustum(.,.,.,.,.5, 2.);