OpenGL: Setup 3D World

Similar documents
Surface Graphics. 200 polys 1,000 polys 15,000 polys. an empty foot. - a mesh of spline patches:

CSE 690: GPGPU. Lecture 2: Understanding the Fabric - Intro to Graphics. Klaus Mueller Stony Brook University Computer Science Department

COMP 175 COMPUTER GRAPHICS. Lecture 07: Scene Graph. COMP 175: Computer Graphics March 10, Remco Chang 07 Scene Graph

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

Two possible ways to specify transformations. Each part of the object is transformed independently relative to the origin

Transformation Pipeline

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

CS 591B Lecture 9: The OpenGL Rendering Pipeline

Using GLU/GLUT Objects

Precept 2 Aleksey Boyko February 18, 2011

Modeling with Transformations

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

Scene Graphs. CS4620/5620: Lecture 7. Announcements. HW 1 out. PA 1 will be out on Wed

Interacting with a 3D World

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

Transforms 1 Christian Miller CS Fall 2011

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

Introduction to OpenGL

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

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

C OMPUTER G RAPHICS Thursday

Modeling Objects. Modeling. Symbol-Instance Table. Instance Transformation. Each appearance of the object in the model is an instance

Graphics and Visualization

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

Assignment #6 2D Vector Field Visualization Arrow Plot and LIC

CSC 470 Computer Graphics

CSCI E-74. Simulation and Gaming

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

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

Computer Graphics Hands-on

CS380: Computer Graphics 2D Imaging and Transformation. Sung-Eui Yoon ( 윤성의 ) Course URL:

Advanced Computer Graphics (CS & SE )

Computer Graphics Geometric Transformations

OpenGL Tutorial. Ceng 477 Introduction to Computer Graphics

OpenGL Transformations

6.837 Introduction to Computer Graphics Assignment 5: OpenGL and Solid Textures Due Wednesday October 22, 2003 at 11:59pm

Computer Graphics. Chapter 7 2D Geometric Transformations

CS4202: Test. 1. Write the letter corresponding to the library name next to the statement or statements that describe library.

Hierarchical Modeling. University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell

OpenGL. Toolkits.

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

Computer Graphics. Prof. Feng Liu. Fall /21/2016

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

GRAFIKA KOMPUTER. ~ M. Ali Fauzi

part 3 Martin Samuelčík Room I4

Graphics Pipeline & APIs

Visualizing Molecular Dynamics

CS 4204 Computer Graphics

Introduction to OpenGL Transformations, Viewing and Lighting. Ali Bigdelou

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

Computer Graphics. Chapter 10 Three-Dimensional Viewing

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

EECE 478. Learning Objectives. Learning Objectives. Rasterization & Scenes. Rasterization. Compositing

蔡侑庭 (Yu-Ting Tsai) National Chiao Tung University, Taiwan. Prof. Wen-Chieh Lin s CG Slides OpenGL 2.1 Specification

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

GL_MODELVIEW transformation

Hierarchical Modeling

CIS 636 Interactive Computer Graphics CIS 736 Computer Graphics Spring 2011

Prof. Feng Liu. Fall /19/2016

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

Graphics Pipeline & APIs

Better Interactive Programs

Display Lists in OpenGL

Cheating: In case of cheating, all parts involved (source(s) and receiver(s)) get zero.

Fachhochschule Regensburg, Germany, February 15, 2017

Where We Are: Static Models

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

Hierarchical Modeling and scene graphs

Graphics Programming

Hierarchical Modeling and Scene Graphs

Rendering Pipeline and Coordinates Transforms

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

Hierarchical Modeling and Scene Graphs

Transformations IV. Week 3, Wed Jan 20

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

Hierarchical Modelling

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

Outline. Introduction Surface of Revolution Hierarchical Modeling Blinn-Phong Shader Custom Shader(s)

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

SE313: Computer Graphics and Visual Programming. Computer Graphics Notes Gazihan Alankus, Fall 2011

HIERARCHICAL TRANSFORMATIONS A Practical Introduction

Lecture 4 of 41. Lab 1a: OpenGL Basics

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

CSC 240 Computer Graphics. Fall 2015 Smith College

Rasterization Overview

Hierarchical Modeling II. Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

Graphical Objects and Scene Graphs

Lecture 2 2D transformations Introduction to OpenGL

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

Due: Thursday, February 6 th, 11:59 pm TA: Mason Remy

Introduction to OpenGL

TIEA311 Tietokonegrafiikan perusteet kevät 2018

Using GLU/GLUT Objects. GLU/GLUT Objects. glucylinder() glutwirecone() GLU/GLUT provides very simple object primitives

Graphics Hardware and OpenGL

Luiz Fernando Martha André Pereira

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

CSCI 4620/8626. The 2D Viewing Pipeline

Computer graphics MN1

Computer graphics 2: Graduate seminar in computational aesthetics

Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

Transcription:

CT4510: Computer Graphics OpenGL: Setup 3D World BOCHANG MOON

Prerequisite for 3D World Understanding on basic mathematical background, transformations, and spaces Pixels, raster image, ector, matrix, Model, viewing, and projection transformations Object, world, eye, canonical view, and screen space

3D Model Definition of a model (or object) in 3D ertex Normal (optional) Q. Why do we need to use the vertex normal? Texture coordinates (optional) Face (usually triangles) etc. File format for 3D models You can make your own format only for your program. Common formats 3DS, MAX, ply (Stanford graphics lab), obj (Wavefront), etc. Simple formats ply and obj are quite simple formats In this course, we will use obj format as this can be used in most rendering engines.

Example:.obj File Format Artists (or you) can design 3D models in some modeling tools (e.g., blender). Out of scope Most modeling tools allow us to store the models in.obj format. For your homework,.obj files will be given.

Example:.obj File Format teapot.obj (toy example) - 3644 vertices - 6320 faces

Example:.obj File Format #: comment line v x y z w ertex coordinates in model space w: optional (default = 1) vt u v Texture coordinates (0 <= u, v <= 1) vn x y z Normal direction f v1 v2 v3 v1: index in the vertex list (integer) Q. why do they use the vertex index instead of coordinates?

Example:.obj File Format f v1 v2 v3 v1: index in the vertex list (integer) f v1/vt1 v2/vt2 v3/vt3 vt: texture coordinate (index) f v1/vt1/vn1 v2/vt2/vn2 v3/vt3/vn3 vn: normal (index) f v1//vn1 v2//vn2 v3//vn3 Need empty slash to avoid ambiguity

Loading.obj Model Read.obj files from your disk Build a vertex list from each model (optional) Create normal and texture coordinate lists Build a face list In our example, we will use triangles. A very simple.obj loader will be given for your assignments. ModelLoader.h & ModelLoader.cpp

Draw Triangles For each triangle in a model glbegin(gl_triangles) For each vertex in a triangle glertex3d(x, y, z) (optionally) glnormal3d(nx, ny, nz) gltexcoord2d(u, v) glend() // related to shading // related to texture mapping

OpenGL Display List Display list: a set of OpenGL commands that have been stored for later execution Once the list is compiled (one time), it can be re-used multiple times. ery efficient for static models

Example of OpenGL Display List g_teapotid = glgenlists(1) // create a list and store the ID to the variable glnewlist(g_teapotid, GL_COMPILE) // Define the set of commands glbegin(gl_triangles) For each vertex in a triangle glertex3d(x, y, z) (optionally) glnormal3d(nx, ny, nz) gltexcoord2d(u, v) glend() glendlist() // related to shading // related to texture mapping Draw some models with IDs glcalllist(g_teapotid)

Result Image Title bar Teapot model A set of triangles

OpenGL Matrix Mode glmatrixmodel(mode) mode: specify which matrix stack is the target that we want to modify GL_PROJECTION GL_MODEL_IEW GL_TEXTURE (not used now) Stack? An abstract data structure that can contain multiple elements LIFO: Last In First Out Interfaces Push: insert a new element into the stack Pop: delete an element from the stack The top element can be modified. top top Push() stack stack

Sequence of Spaces and Transformations Object space Eye (camera) space Screen space Modeling transformation iewing transformation Projection Transformation iewport Transformation World space Canonical view volume (normalized device coordinates)

OpenGL Matrix Mode glmatrixmodel(mode) mode: specify which matrix stack is the target that we want to modify GL_PROJECTION GL_MODEL_IEW GL_TEXTURE (not used now) GL_PROJECTION Related to the projection transformation GL_MODEL_IEW Related to the modeling and viewing transformation Should call this function first before applying a transformation

OpenGL Matrix Mode void reshape(int w, int h) gliewport(0, 0, w, h); // viewport transformation is specified. glmatrixmode(gl_projection); // specify our target stack glloadidentity(); // set the current matrix as the identity gluperspective(fov, aspect, near, far); // change the current matrix with the perspective transformation matrix stack (projection)

OpenGL Matrix Mode void reshape(int w, int h) gliewport(0, 0, w, h); // viewport transformation is specified. glmatrixmode(gl_projection); glloadidentity(); // specify our target stack // set the current matrix as the identity Alternatively, We can explicitly construct the projection matrix double matrix[16] = { } glmultmatrixd(matrix); // multiply the current matrix with the specified matrix stack (projection)

OpenGL Matrix Mode void reshape(int w, int h) gliewport(0, 0, w, h); // viewport transformation is specified. glmatrixmode(gl_projection); // specify our target stack glloadidentity(); // set the current matrix as the identity gluperspective(fov, aspect, near, far); // change the current matrix with the perspective transformation matrix glmatrixmode(gl_modeliew); glloadidentity(); stack (projection)

OpenGL Matrix void display() glclear(gl_color_buffer_bit GL_DEPTH_BUFFER_BIT) setcamera() // specify the viewing transformation (change the current matrix) e.g., glulookat() or explicitly build the matrix

OpenGL Matrix For each model glpushmatrix(); // push down the current matrix, and insert a new element it to the stack (the new matrix will be equal to the current matrix - duplicated) glloadidentity(); // initialize the current matrix push I

OpenGL Matrix For each model (continued ) // specify modeling transformation matrix e.g., MM = TT, MM = RRRR, and etc. e.g., call predefined functions (gltranslated( ), glrotated( )) or explicitly build the matrix and multiply it e.g., gltranslated( ) // build the specified translation matrix and multiply it to the current matrix // draw primitives e.g., glcalllist(id) // use the display list // pop the modeling transformation why? glpopmatrix() I M1 pop

OpenGL Matrix Scenarios Each model has different modeling transformations The matrix stack (with different modeling matrix) should be built before drawing the primitives of each model M1 M2 M3

Object vs Camera Transformation input output Use modeling transformation Translate the object along x direction (this can be separately applied to each object) Use viewing transformation Translate our camera along x direction (this moves the coordinate system all objects will be transformed)

Hierarchical Transformation Two ways of achieving this transformation: 1. Apply different transformation to each part Translate the body Translate the head Rotate and translate the arm 2. Utilize relative transformation Some parts can depend on others Specify each object s transformation relative to its parent body head arm Scene graph

Hierarchical Transformation 2. Utilize relative transformation Translate the body and its descendants Translate the head and its descendant Rotate the arm body head arm Scene graph

Hierarchical Transformation 2. Utilize relative transformation // apply a transformation to the body and its descendants gltranslated( ) // draw body gltranslated( ) // draw head // apply a transformation to the arm glrotated(..) // draw arm body head arm Scene graph

Hierarchical Transformation 2. Utilize relative transformation // apply a transformation to the body and its descendants gltranslated( ) // draw body gltranslated( ) // draw head // apply a transformation to the arm glrotated(..) // draw arm T1 T1T2 T1T2R

Hierarchical Transformation 2. Utilize relative transformation Translate the body and its descendants Translate the head and its descendants Rotate the left arm Rotate the right arm? body head Left arm Right arm

Hierarchical Transformation 2. Utilize relative transformation // apply a transformation to the body and its descendants gltranslated( ) // draw body gltranslated( ) // draw head // apply a transformation to the left arm glrotated(..) // draw left arm // apply a transformation to the right arm glrotated(..) // draw right arm? T1 T1T2 T1T2R1 T1T2R1R2

Hierarchical Transformation 2. Utilize relative transformation // apply a transformation to the body and its descendants gltranslated( ) // draw body gltranslated( ) // draw head // apply a transformation to the left arm glrotated(..) // draw left arm // apply a transformation to the right arm glrotated(..) // draw right arm? ERROR: the left arm is not a parent of the right arm T1 T1T2 T1T2R1 T1T2R1R2

Hierarchical Transformation Body Head Left arm Right arm T1 T1T2 T1T2R1 T1T2R1R2 Right arm T1T2R2

Hierarchical Transformation 2. Utilize relative transformation // apply a transformation to the body and its descendants gltranslated( ) // draw body gltranslated( ) // draw head // Store the current matrix! glpushmatrix() T1T2 T1T2 T1T2

Hierarchical Transformation // Store the current matrix! glpushmatrix() // apply a transformation to the left arm glrotated(..) // draw left arm // Pop the top of the stack glpopmatrix() T1T2 T1T2 T1T2R1 T1T2 T1T2

Hierarchical Transformation // Store the current matrix! glpushmatrix() // apply a transformation to the left arm glrotated(..) // draw left arm // Pop the top of the stack glpopmatrix() // apply a transformation to the right arm glrotated(..) // draw right arm T1T2R1 T1T2 T1T2 T1T2R2