C OMPUTER G RAPHICS Thursday

Similar documents
Transformation, Input and Interaction. Hanyang University

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

Order of Transformations

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

Precept 2 Aleksey Boyko February 18, 2011

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

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

CSC 470 Computer Graphics

Computer graphics MN1

Computer Graphics CS 543 Lecture 5 (Part 2) Implementing Transformations

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


Computer Graphics. Chapter 7 2D Geometric Transformations

Computer Graphics (CS 4731) Lecture 11: Implementing Transformations. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

Lecture 2 CISC440/640 Spring Department of Computer and Information Science

Introduction to OpenGL

GL_COLOR_BUFFER_BIT, GL_PROJECTION, GL_MODELVIEW

Lecture 4 of 41. Lab 1a: OpenGL Basics

Modeling Objects by Polygonal Approximations. Linear and Affine Transformations (Maps)

Computer graphics MN1

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

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

Lecture 3. Understanding of OPenGL programming

CS D Transformation. Junqiao Zhao 赵君峤

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

Graphics Programming

CS 4204 Computer Graphics

Computer Graphics (CS 4731) Lecture 11: Implementing Transformations. Prof Emmanuel Agu. Computer Science Dept. Worcester Polytechnic Institute (WPI)

12. Selection. - The objects selected are specified by hit records in the selection buffer. E.R. Bachmann & P.L. McDowell MV 4202 Page 1 of 13

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

Computer Graphics. OpenGL

Lectures OpenGL Introduction

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

20 GLuint objects; 36 Scale += 0.1; 37 break; 38 case GLUT_KEY_DOWN:

COMPUTER GRAPHICS LAB # 3

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

Computer Graphics Course 2005

Programming with OpenGL Part 3: Three Dimensions

Introduction to Computer Graphics with OpenGL/GLUT

CS 4204 Computer Graphics

OpenGL/GLUT Intro. Week 1, Fri Jan 12

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

Transformations. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

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

OpenGL refresher. Advanced Computer Graphics 2012

Computer Graphics Introduction to OpenGL

CMSC 425: Lecture 4 More about OpenGL and GLUT Tuesday, Feb 5, 2013

Drawing Primitives. OpenGL basics

Chapter 13 Selection and Feedback

Hierarchical Modeling: Tree of Transformations, Display Lists and Functions, Matrix and Attribute Stacks,

Lecture 2 2D transformations Introduction to OpenGL

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

Computer Graphics. Chapter 10 Three-Dimensional Viewing

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

Objectives. transformation. General Transformations. Affine Transformations. Notation. Pipeline Implementation. Introduce standard transformations

2. OpenGL -I. 2.1 What is OpenGL? Things OpenGL can do: -23-

Erik Anchondo cse 520 lab 4

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

Interaction Computer Graphics I Lecture 3

Lecture 5b. Transformation

Interaction. CSCI 420 Computer Graphics Lecture 3

Interaction. CSCI 480 Computer Graphics Lecture 3

yahoo.com

Computer Graphics. Bing-Yu Chen National Taiwan University

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

Computer Graphics. Transformations. CSC 470 Computer Graphics 1

1 /* 4 C:\opencv\build\include. 6 C:\opencv\build\x86\vc10\lib

Introduction to OpenGL Transformations, Viewing and Lighting. Ali Bigdelou

RECITATION - 1. Ceng477 Fall

Computer graphics MN1

Introduction to OpenGL

Using OpenGL with CUDA

Basic Graphics Programming

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

OpenGL Transformations

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

BOUNCING BALL IMRAN IHSAN ASSISTANT PROFESSOR

Project Sketchpad. Ivan Sutherland (MIT 1963) established the basic interactive paradigm that characterizes interactive computer graphics:

Fall CSCI 420: Computer Graphics. 2.2 Transformations. Hao Li.

CSCI E-74. Simulation and Gaming

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

OpenGL Tutorial. Ceng 477 Introduction to Computer Graphics

Assignment 1. Simple Graphics program using OpenGL

VR-programming tools (procedural) More VRML later in this course! (declarative)

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

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

Questions HW1 Transform Q/A. Transform. Shaoting Zhang. May 11, 2008

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

Computer Graphics Primitive Attributes

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

Transformations. CSCI 420 Computer Graphics Lecture 4

3D Graphics Pipeline II Clipping. Instructor Stephen J. Guy

Programming using OpenGL: A first Introduction

CS 591B Lecture 9: The OpenGL Rendering Pipeline

Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

CS380: Computer Graphics Basic OpenGL Structure. Sung-Eui Yoon ( 윤성의 ) Course URL:

Matrix-Rechnung I ' z =... Universität Frankfurt

Transformation Pipeline

Lecture 3 Advanced Computer Graphics (CS & SE )

Programming with OpenGL Part 1: Background

Transcription:

C OMPUTER G RAPHICS 2017.04.27 Thursday Professor s original PPT http://calab.hanyang.ac.kr/ Courses Computer Graphics practice3.pdf TA s current PPT not uploaded yet

GRAPHICS PIPELINE What is Graphics Pipeline? the process to express a 3D image into 2D raster image also called rendering pipeline pixels arrayed in grid pattern VERTEX PROCESSING BLENDING RASTERIZING FRAGMENT PROCESSING 3D image 2D raster image PIPELINE

GRAPHICS PIPELINE VERTEX PROCESSING RASTERIZING FRAGMENT PROCESSING BLENDING Vertex Processing converts 3D image s 3D vertices into 2D vertices fit into screen needs multiple to get final 2D vertices from original 3D vertices

GRAPHICS PIPELINE VERTEX PROCESSING RASTERIZING FRAGMENT PROCESSING BLENDING Vertex Processing performed by multiplying vertex by matrices for efficient computation, 3D vertices start in homogeneous coordinate system

GRAPHICS PIPELINE VERTEX PROCESSING RASTERIZING FRAGMENT PROCESSING BLENDING Vertex Processing Q. Isn t it too much pressure to compute for 4~5 s per one vertex? A. Rendering time is barely affected by the number of transforming steps. Actually, it is much affected by the number of vertices.

MATRIX & OpenGL X Y = viewport perspective division projection modelview X 0 Y 0 Z 0 W 0 finally converted 2D vertex original 3D vertex (homogeneous)

MATRIX & OpenGL X Y = viewport perspective division projection modelview X 0 Y 0 Z 0 W 0 finally converted 2D vertex Matrix Handling OpenGL Functions void glmatrixmode (GLenum mode) choose which to operate GL_MODELVIEW: operate on modelview GL_PROJECTION: operate on projection GL_TEXTURE: operate on texture operates this part original 3D vertex (homogeneous)

MATRIX & OpenGL X Y = viewport perspective division projection modelview X 0 Y 0 Z 0 W 0 finally converted 2D vertex Matrix Handling OpenGL Functions void glmatrixmode (GLenum mode) choose which to operate GL_MODELVIEW: operate on modelview GL_PROJECTION: operate on projection GL_TEXTURE: operate on texture void glloadidentity () call identity as currently operating void glloadmatrixf (const GLfloat *M1) call M1 as currently operating void glmultmatirxf (const GLfloat *M2) multiply M2 to currently operating operates this part original 3D vertex (homogeneous)

MATRIX & OpenGL X Y = viewport perspective division projection modelview X 0 Y 0 Z 0 W 0 finally converted 2D vertex Matrix Handling OpenGL Functions void glmatrixmode (GLenum mode) choose which to operate GL_MODELVIEW: operate on modelview GL_PROJECTION: operate on projection GL_TEXTURE: operate on texture void glloadidentity () call identity as currently operating void glloadmatrixf (const GLfloat *M1) call M1 as currently operating void glmultmatirxf (const GLfloat *M2) multiply M2 to currently operating operates this part original 3D vertex (homogeneous) glloadidentity();

MATRIX & OpenGL X Y = viewport perspective division projection modelview X 0 Y 0 Z 0 W 0 finally converted 2D vertex Matrix Handling OpenGL Functions void glmatrixmode (GLenum mode) choose which to operate GL_MODELVIEW: operate on modelview GL_PROJECTION: operate on projection GL_TEXTURE: operate on texture void glloadidentity () call identity as currently operating void glloadmatrixf (const GLfloat *M1) call M1 as currently operating void glmultmatirxf (const GLfloat *M2) multiply M2 to currently operating operates this part original 3D vertex (homogeneous) float m[] = 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f ; glloadmatrixf(m); glmultimatrixf(m);

MATRIX & OpenGL X Y = viewport perspective division projection modelview X 0 Y 0 Z 0 W 0 finally converted 2D vertex Matrix Operating in OpenGL Programming operates this part original 3D vertex (homogeneous) glloadidentity(); glsomething1(); glsomething2();

MATRIX & OpenGL X Y = viewport perspective division projection modelview X 0 Y 0 Z 0 W 0 finally converted 2D vertex Matrix Operating in OpenGL Programming operates this part original 3D vertex (homogeneous) glloadidentity(); glsomething1(); glsomething2(); OpenGL command lines work between modelview and original 3D vertex in order. X Y = projection perspective viewport modelview identity something1 something2 X 0 Y 0 Z 0 W 0

OpenGL 1: TRANSFORMATION Main Transforming OpenGL Functions void gltranslatef (GLfloat dx, GLfloat dy, GLfloat dz) translate the crayon dx/dy/dz: translating dx/dy/dz by x/y/z axis void glscalef (GLfloat sx, GLfloat sy, GLfloat sz) scale the crayon sx/sy/sz: translating sx/sy/sz by x/y/z axis void glrotatef (GLfloat angle, GLfloat x, GLfloat y, GLfloat z) Rotating the crayon angle: rotating angle x/y/z: rotating axis (0.0 if not rotating, 1.0 if rotating) example: glrotatef (45, 0.0, 0.0, 1.0); rotating 45 by z-axis

OpenGL 1: TRANSFORMATION Two Ways to Draw at Proper Position on Paper DESK PAPER OR draw like this move crayon move paper

OpenGL 1: TRANSFORMATION Two Ways to Draw at Proper Position on Paper DESK PAPER OR draw like this move crayon move paper 1 moving crayon = translate rotate scale usual MCS to WCS idea X Y = projection perspective viewport modelview translation rotation scale X 0 Y 0 Z 0 W 0 2 moving paper = scale rotate translate usual opengl programming idea X Y = projection perspective viewport modelview scale rotation translation X 0 Y 0 Z 0 W 0

OpenGL 1: TRANSFORMATION Two Ways to Draw at Proper Position on Paper glloadidentity(); gltranslatef(0.707, 0.0, 0.0); glrotatef(45.0, 0.0, 0.0, 1.0); glutsolidcube(0.3); glloadidentity(); glrotatef(45.0, 0.0, 0.0, 1.0); gltranslatef(0.5, -0.5, 0.0); glutsolidcube(0.3); 1 moving crayon = translate rotate scale usual MCS to WCS idea X Y = projection perspective viewport modelview translation rotation scale X 0 Y 0 Z 0 W 0 2 moving paper = scale rotate translate usual opengl programming idea X Y = projection perspective viewport modelview scale rotation translation X 0 Y 0 Z 0 W 0

OpenGL 1: TRANSFORMATION EXAMPLE: Three Rectangles (differ by transforming order) void MyDisplay() glclear(gl_color_buffer_bit); glviewport(0, 0, 300, 300); // red rectangle glcolor3f(1.0, 0.0, 0.0); glloadidentity(); glutsolidcube(0.3); // green rectangle glcolor3f(0.0, 1.0, 0.0); glloadidentity(); glrotatef(45.0, 0.0, 0.0, 1.0); gltranslatef(0.6, 0.0, 0.0); glutsolidcube(0.3); // blue rectangle glcolor3f(0.0, 0.0, 1.0); glloadidentity(); gltranslatef(0.6, 0.0, 0.0); glrotatef(45.0, 0.0, 0.0, 1.0); glutsolidcube(0.3); int main(int argc, char** argv) glutinitdisplaymode(glut_rgba); glutinitwindowsize(300, 300); glutcreatewindow("opengl Sample Drawing"); glclearcolor(1.0, 1.0, 1.0, 1.0); glmatrixmode(gl_projection); glloadidentity(); glortho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0); glutdisplayfunc(mydisplay); glutmainloop(); return 0; glflush();

OpenGL 2: VIEWPORT SKIP!!

OpenGL 3: INTERACTION Interacting With Users (Callback Functions) OpenGL provides Callback Functions to let users interact with program Keyboard Callback: reacts when user pushes some keys Special Key Callback: reacts when user pushes special keys (like F1, F2 keys) Mouse Callback: reacts when user start to push mouse button Motion Callback: reacts when user drags the mouse and take off the finger Menu Callback: shows menu above the window Timer Callback: reacts at every specific time intervals EXAMPLE: Change Rectangle Size by Mouse Dragging

OpenGL 3: INTERACTION #include <gl/glut.h> GLint TopLeftX, TopLeftY, BottomRightX, BottomRightY; void MyDisplay() glviewport(0, 0, 300, 300); glclear(gl_color_buffer_bit); glcolor3f(0.5, 0.5, 0.5); glbegin(gl_polygon); glvertex3f(topleftx / 300.0, (300 - TopLeftY) / 300.0, 0.0); glvertex3f(topleftx / 300.0, (300 - BottomRightY) / 300.0, 0.0); glvertex3f(bottomrightx / 300.0, (300 - BottomRightY) / 300.0, 0.0); glvertex3f(bottomrightx / 300.0, (300 - TopLeftY) / 300.0, 0.0); glend(); glflush(); EXAMPLE: Changing Rectangle Size by Mouse Dragging void MyMouseClick(GLint Button, GLint State, GLint X, GLint Y) if(button == GLUT_LEFT_BUTTON && State == GLUT_DOWN) TopLeftX = X; TopLeftY = Y; void MyMouseMove(GLint X, GLint Y) BottomRightX = X; BottomRightY = Y; glutpostredisplay(); // marks the current window as needing to be redisplayed. int main(int argc, char** argv) glutinitwindowsize(300, 300); glutcreatewindow("opengl Drawing Example"); glclearcolor(1.0, 1.0, 1.0, 1.0); glmatrixmode(gl_projection); glloadidentity(); glortho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0); glutdisplayfunc(mydisplay); glutmousefunc(mymouseclick); glutmotionfunc(mymousemove); glutmainloop(); return 0;

OpenGL 3: INTERACTION Difference Between OpenGL s drawing field and Window v1x = TopLeftX / 300; v1y = (300 - TopLeftY) / 300; v2x = TopLeftX / 300; v2y = (300 - BottomRightY) / 300; v3x = BottomRightX / 300; v3y = (300 - BottomRightY) / 300; v4x = BottomRightX / 300; v4y = (300 - TopLeftY) / 300;

OpenGL 4: MATRIX STACKS Save Transformed Coordinate with Stacks void glpushmatrix () save current position in the stack no matter how many times you transform and transform coordinates, you can come back to this saved coordinate position void glpopmatrix () load the most currently saved position once loaded position is removed from the stack

OpenGL 4: MATRIX STACKS EXAMPLE 1: Solar System

OpenGL 4: MATRIX STACKS #include <gl/freeglut.h> #include <gl/glu.h> #include <gl/gl.h> EXAMPLE 1: Solar System static int Day = 0, Time = 0; void MyDisplay() glclear(gl_color_buffer_bit GL_DEPTH_BUFFER_BIT); glenable(gl_depth_test); glloadidentity(); gltranslatef(0.0, 0.0, -2.0); /***The earth***/ glpushmatrix(); // 지구의공전 glrotatef((float)day, 0.0, 1.0, 0.0); gltranslatef(0.7, 0.0, 0.0); // 지구의자전 glrotatef((float)time, 0.0, 1.0, 0.0); glcolor3f(0.5, 0.6, 0.7); glutsolidsphere(0.1, 30, 8); /***The moon***/ glpushmatrix(); // 달의공전 glrotatef((float)time, 0.0, 1.0, 0.0); gltranslatef(0.2, 0.0, 0.0); glcolor3f(0.9, 0.8, 0.2); glutsolidsphere(0.04, 30, 8); glpopmatrix(); glpopmatrix(); /***The sun***/ glcolor3f(1.0, 0.3, 0.4); glutsolidsphere(0.2, 30, 16); glutswapbuffers(); void MyTimer(int value) Day = (Day + 10) % 360; Time = (Time + 5) % 360; gluttimerfunc(100, MyTimer, 1); glutpostredisplay(); int main(int argc, char** argv) glutinit(&argc, argv); glutinitdisplaymode(glut_double GLUT_RGB GLUT_DEPTH); glutinitwindowsize(500, 500); glutcreatewindow("solar system"); glclearcolor(0.0, 0.0, 0.0, 0.0); glmatrixmode(gl_projection); glloadidentity(); glortho(-1.0, 1.0, -1.0, 1.0, -1.0, 3.0); glutdisplayfunc(mydisplay); gluttimerfunc(100, MyTimer, 1); glutmainloop(); return 0;

OpenGL 4: MATRIX STACKS EXAMPLE 2: Rotating Teapot with Mouse

OpenGL 4: MATRIX STACKS #include <gl/glut.h> bool bdrag = false; float g_fdistance = -300.0f; float g_fspinx = 0.0f; float g_fspiny = 0.0f; int ptlastmousepositx, ptlastmouseposity; int ptcurrentmousepositx, ptcurrentmouseposity; EXAMPLE 2: Rotating Teapot with Mouse (1/2) void ChangeSize(GLsizei width, GLsizei height) GLfloat faspect = (GLfloat)width/(GLfloat)height; GLfloat nrange = height/4.0; if(height == 0) height = 1; glviewport(0, 0, width, height); glmatrixmode(gl_projection); glloadidentity(); if (width <= height) glortho (-nrange, nrange, -nrange/faspect, nrange/faspect, -nrange*4.0f, nrange*4.0f); else glortho (-nrange*faspect, nrange*faspect, -nrange, nrange, -nrange*4.0f, nrange*4.0f); glloadidentity(); void MyMouseClick(GLint Button, GLint State, GLint X, GLint Y) if(button == GLUT_LEFT_BUTTON ) if (State == GLUT_DOWN) ptlastmousepositx = ptcurrentmousepositx = X; ptlastmouseposity = ptcurrentmouseposity = Y; bdrag = true; else if (State == GLUT_UP) bdrag = false;

OpenGL 4: MATRIX STACKS void MyMouseMove(GLint X, GLint Y) ptcurrentmousepositx = X; ptcurrentmouseposity = Y; EXAMPLE 2: Rotating Teapot with Mouse (2/2) if( bdrag ) g_fspinx -= (ptcurrentmousepositx - ptlastmousepositx); g_fspiny -= (ptcurrentmouseposity - ptlastmouseposity); ptlastmousepositx = ptcurrentmousepositx; ptlastmouseposity = ptcurrentmouseposity; glutpostredisplay(); void RenderScene(void) glclear(gl_color_buffer_bit GL_DEPTH_BUFFER_BIT); glpushmatrix(); gltranslatef(0.0f, 0.0f, g_fdistance); glrotatef( -g_fspiny, 1.0f, 0.0f, 0.0f ); glrotatef( -g_fspinx, 0.0f, 1.0f, 0.0f ); glcolor3f(0.0f, 1.0f, 0.0f); glutwireteapot(100.0); glpopmatrix(); glutswapbuffers(); int main(int argc, char *argv[]) glutinit(&argc, argv); glutinitdisplaymode(glut_double GLUT_RGB GLUT_DEPTH); glutinitwindowsize(600, 600); glutcreatewindow( Rotate an object using mouse"); glutreshapefunc(changesize); glutmousefunc(mymouseclick); glutmotionfunc(mymousemove); glutdisplayfunc(renderscene); glutmainloop(); return 0;

PRACTICE ASSIGNMENT: Advanced Solar System What to do Create solar system with SUN, EARTH, MOON, MARS! SUN is yellow, and it stays firm EARTH is blue, and it revolves around SUN while it also self-rotates MOON is green, and it revolves around EARTH without self-rotation SUN, EARTH, MOON are almost implemented in practice3_2.cpp What you have to do 1: modify SUN, EARTH, MOON s color in pratice3_2.cpp What you have to do 2: add MARS to practice3_2.cpp MARS is red and it revolves around SUN while it also self-rotates MARS is as twice far from SUN as the EARTH is far from the SUN MARS has two times longer orbital period than EARTH MARS self-rotates twice faster than EARTH MARS has the same size with EARTH Submission Send e-mail to teddysiah@gmail.com attaching practice3_2.cpp only Due: not decided yet