CSCI E-74. Simulation and Gaming

Similar documents
Computer Graphics. Chapter 7 2D Geometric Transformations

CS 591B Lecture 9: The OpenGL Rendering Pipeline

CSCI E-74. Simulation and Gaming

CS 4204 Computer Graphics

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

Affine Transformations in 3D

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

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

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

Transformations. CSCI 420 Computer Graphics Lecture 4

Transformation Pipeline

GL_MODELVIEW transformation

3D Transformation. In 3D, we have x, y, and z. We will continue use column vectors:. Homogenous systems:. x y z. x y z. glvertex3f(x, y,z);

C OMPUTER G RAPHICS Thursday

CSC 470 Computer Graphics

OpenGL Tutorial. Ceng 477 Introduction to Computer Graphics

CSCI E-74. Simulation and Gaming

Lecture 5b. Transformation

Introduction to OpenGL Transformations, Viewing and Lighting. Ali Bigdelou

Transformation, Input and Interaction. Hanyang University

Transformations. CSCI 420 Computer Graphics Lecture 5

Transformations. OpenGL Transformations. 4x4 Model-view Matrix (this lecture) OpenGL Transformation Matrices. 4x4 Projection Matrix (next lecture)

This library uses only GL functions but contains code for creating common objects and simplifying viewing.

Computer Graphics Lighting

Computer Graphics Lighting. Why Do We Care About Lighting?

OpenGL Transformations

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

Lecture 4: Transformations and Matrices. CSE Computer Graphics (Fall 2010)

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

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

Order of Transformations

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

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

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

Computer Graphics. Chapter 10 Three-Dimensional Viewing

Lecture 6 Sections 4.3, 4.6, 4.7. Wed, Sep 9, 2009

CS354 Computer Graphics Viewing and Modeling

Computer Graphics (Basic OpenGL)

Modeling with Transformations

Translation. 3D Transformations. Rotation about z axis. Scaling. CS 4620 Lecture 8. 3 Cornell CS4620 Fall 2009!Lecture 8

OpenGL: Setup 3D World

OpenGL. Toolkits.

Graphics Programming

Luiz Fernando Martha André Pereira

Computer graphics MN1

CS452/552; EE465/505. Transformations

Mobile Application Programming: Android. OpenGL ES 3D

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

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

This lecture. Introduction to VRT. Hardware. Implementation levels. Scene-Graph libraries. Computer Graphic libraries

Introduction to Computer Graphics with WebGL

Reading. Hierarchical Modeling. Symbols and instances. Required: Angel, sections , 9.8. Optional:

Introduction to VRT. Interactive Graphical Systems HT2007. Lars Pettersson. Interactive Graphical Systems

Libraries for Computer Graphics. Introduction to VRT. Scene-graph libraries. Libraries for computer graphics. Scene-graph libraries (cont.

Introduction to OpenGL

Computer Graphics Geometric Transformations

Fachhochschule Regensburg, Germany, February 15, 2017

CS 428: Fall Introduction to. Transformations in OpenGL + hierarchical modeling. Andrew Nealen, Rutgers, /21/2009 1

Introduction to OpenGL

CS D Transformation. Junqiao Zhao 赵君峤

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

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

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

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

Lecture 4 of 41. Lab 1a: OpenGL Basics

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

Computer Viewing Computer Graphics I, Fall 2008

GEOMETRIC OBJECTS AND TRANSFORMATIONS I

3D Viewing Episode 2

3D Mathematics. Co-ordinate systems, 3D primitives and affine transformations

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

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

Chapter 3: Modeling Transformation

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

GRAFIKA KOMPUTER. ~ M. Ali Fauzi

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

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

Display Lists. Conceptually similar to a graphics file. In client-server environment, display list is placed on server

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

Viewing and Modeling

Computer Graphics. OpenGL

CIS 636 Interactive Computer Graphics CIS 736 Computer Graphics Spring 2011

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

Prof. Feng Liu. Fall /19/2016

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

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

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

Computer Graphics. Bing-Yu Chen National Taiwan University

Meshing and Geometry

Basic Graphics Programming

6. Modelview Transformations

Building Models. Objectives. Introduce simple data structures for building polygonal models. OpenGL vertex arrays. Vertex lists Edge lists

Fundamental Types of Viewing

Using GLU/GLUT Objects

Lecture 4. Viewing, Projection and Viewport Transformations

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

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

Computer Graphics 7: Viewing in 3-D

Mobile Application Programming. OpenGL ES 3D

part 3 Martin Samuelčík Room I4

Transcription:

CSCI E-74 Virtual and Augmented Reality for Simulation and Gaming Fall term 2017 Gianluca De Novi, PhD Lesson 3 General Introduction to OpenGL APIs and TRS

Perspective Simulation Perspective simulation is achieved using the projection matrix GL_PROJECTION to map the 3D image into the 2D viewport (eye coordinates). x y z l, r b, t n, f x p = n x x e z p = nx e e ze y p = n y y e z p = ny e e ze = nx e ze = ny e ze x c y c z c w c = 2n r l 0 0 2n t b r + l r l 0 t + b t b 0 (f + n) 2fn f n f n 1 0 GL_PROJECTION matrix x e y e z e w e CSCI E-74 Virtual and Augmented Reality for Simulation and Gaming 2

Matrix Mode Specify which matrix is the current matrix void glmatrixmode(glenum mode); GL_MODELVIEW Applies subsequent matrix operations to the modelview matrix stack. GL_PROJECTION Applies subsequent matrix operations to the projection matrix stack. GL_TEXTURE GL_COLOR Applies subsequent matrix operations to the texture matrix stack. Applies subsequent matrix operations to the color matrix stack. CSCI E-74 Virtual and Augmented Reality for Simulation and Gaming 3

Identity Matrix Load Identity matrix void glloadidentity(); 1 0 0 1 1 0 0 1 CSCI E-74 Virtual and Augmented Reality for Simulation and Gaming 4

Load Generic Matrix Load Identity matrix void glloadmatrixd(const GLdouble * m); void glloadmatrixf(const GLfloat * m); Example float m[16]={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}; //example of identity matrix glloadmatrixf(m); 1 0 0 1 1 0 0 1 CSCI E-74 Virtual and Augmented Reality for Simulation and Gaming 5

Translation Matrix void gltranslatef(glfloat tx, GLfloat ty, GLfloat tz); void gltranslated(gldouble tx, GLdouble ty, GLdouble tz); tz ty y Translation Vector x 1 0 0 1 0 tx 0 ty 1 tz 0 1 tx z CSCI E-74 Virtual and Augmented Reality for Simulation and Gaming 6

Scale Matrix void glscalef(glfloat sx, GLfloat sy, GLfloat sz); void glscaled(gldouble sx, GLdouble sy, GLdouble sz); y sy sz Scale Vector x sx 0 0 sy sz 0 0 1 sx z CSCI E-74 Virtual and Augmented Reality for Simulation and Gaming 7

Rotation Matrix void glrotatef(glfloat angle, GLfloat rx, GLfloat ry, GLfloat rz); void glrotated(gldouble angle, GLdouble rx, GLdouble ry, GLdouble rz); y Combining rz ry Rotation Vector x Rotation around a generic vector matrix z rx CSCI E-74 Virtual and Augmented Reality for Simulation and Gaming 8

TRS Complex For a generic object void BuildObjMatrix() { glmatrixmode(gl_modelview); // select the modelview mode transformation of the entities glloadidentity(); // loads the identity matrix gltranslatef(obj.tx,obj.ty,obj.tz); // translate the object to the desired position glrotatef (obj.yaw,0.0f,1.0f,0.0f); // rotation around Y axis glrotatef (obj.pitch,1.0f,0.0f,0.0f); // rotation around X axis glrotatef (obj.roll,0.0f,0.0f,1.0f); // rotation around Z axis glscalef (obj.sx,obj.sy,obj.sz); // Scale object } For the Camera void BuildCameraMatrix() { } glmatrixmode(gl_modelview); // select the modelview mode transformation of the entities glloadidentity(); // loads the identity matrix glrotatef (-pov.yaw,0.0f,1.0f,0.0f); // rotation around Y axis glrotatef (-pov.pitch,1.0f,0.0f,0.0f); // rotation around X axis glrotatef (-pov.roll,0.0f,0.0f,1.0f); // rotation around Z axis gltranslatef(-pov.tx,-pov.ty,pov.tz); // translate the camera to the desired position For the camera, NO SCALE and OPPOSITE ORDER CSCI E-74 Virtual and Augmented Reality for Simulation and Gaming 9

TRS Complex void BuildObjMatrix( ) { glmatrixmode(gl_modelview); // select the modelview mode transformation of the entities glloadidentity(); // loads the identity matrix gltranslatef(obj.tx,obj.ty,obj.tz); // translate the object to the desired position glrotatef (obj.yaw,0.0f,1.0f,0.0f); // rotation around Y axis glrotatef (obj.pitch,1.0f,0.0f,0.0f); // rotation around X axis glrotatef (obj.roll,0.0f,0.0f,1.0f); // rotation around Z axis glscalef (obj.sx,obj.sy,obj.sz); // Scale object } x t y t z t 1 = S R r R p R y T x o y o z o1 Mo CSCI E-74 Virtual and Augmented Reality for Simulation and Gaming 10

TRS Complex void BuildCameraMatrix() { glmatrixmode(gl_modelview); // select the modelview mode transformation of the entities glloadidentity(); // loads the identity matrix glrotatef (-pov.yaw,0.0f,1.0f,0.0f); // rotation around Y axis glrotatef (-pov.pitch,1.0f,0.0f,0.0f); // rotation around X axis glrotatef (-pov.roll,0.0f,0.0f,1.0f); // rotation around Z axis gltranslatef(-pov.tx,-pov.ty,pov.tz); // translate the camera to the desired position } x p y p z p 1 = R y R p R r T Mc x t y t z t 1 CSCI E-74 Virtual and Augmented Reality for Simulation and Gaming 11

3DGE Workflow #define N_ENTITIES 100 int i; TEntity Entity[N_ENTITIES]; load entities somewhere do{ generate entities configuration somewhere BuildCameraMatrix(); for(i=0;i< N_ENTITIES;i++) { BuildObjMatrix(Entity[i]); } CleanFrameBuffer(); for(i=0;i< N_ENTITIES;i++) { DrawEntity(Entity[i]); } FlipBuffer(); Number or entities in our simulation Just a simple variable to use as counter Array of entities Simulation Loop Generates the geometry information Draws the final scene }While(CheckExitEvent()); CSCI E-74 Virtual and Augmented Reality for Simulation and Gaming 12

Triangle Quadrilateral Drawing glbegin(gl_triangles); glvertex3f(v1.x,v1.y,v1.z); glvertex3f(v2.x,v2.y,v2.z); glvertex3f(v3.x,v3.y,v3.z); glend(); glbegin(gl_quads); glvertex3f(v1.x,v1.y,v1.z); glvertex3f(v2.x,v2.y,v2.z); glvertex3f(v3.x,v3.y,v3.z); glvertex3f(v4.x,v4.y,v4.z); glend(); f=floating point single precision CSCI E-74 Virtual and Augmented Reality for Simulation and Gaming 13

Polygon glbegin(gl_polygon); glvertex3f(v1.x,v1.y,v1.z); glvertex3f(v2.x,v2.y,v2.z); glvertex3f(v3.x,v3.y,v3.z); glvertex3f(v4.x,v4.y,v4.z); glvertex3f(v5.x,v5.y,v5.z); glend(); CSCI E-74 Virtual and Augmented Reality for Simulation and Gaming 14

GL-LINES glcolor4f(1.0f,0.0f,0.0f,1.0f); glbegin(gl_triangle_trip); glvertex3f(v0.x,v0.y,v0.z); glvertex3f(v1.x,v1.y,v1.z); glvertex3f(v2.x,v2.y,v2.z); glvertex3f(v3.x,v3.y,v3.z); glvertex3f(v4.x,v4.y,v4.z); glvertex3f(v5.x,v5.y,v5.z); glvertex3f(v6.x,v6.y,v6.z); glend(); CSCI E-74 Virtual and Augmented Reality for Simulation and Gaming 15

Color glcolor4f(1.0f,0.0f,0.0f,1.0f); glbegin(gl_triangle); glvertex3f(v1.x,v1.y,v1.z); glvertex3f(v2.x,v2.y,v2.z); glvertex3f(v3.x,v3.y,v3.z); glend(); glcolor4f(0.0f,1.0f,0.0f,1.0f); glbegin(gl_quad); glvertex3f(v1.x,v1.y,v1.z); glvertex3f(v2.x,v2.y,v2.z); glvertex3f(v3.x,v3.y,v3.z); glvertex3f(v4.x,v4.y,v4.z); glend(); r R [0,1] g R 0,1 b R 0,1 a R 0,1 CSCI E-74 Virtual and Augmented Reality for Simulation and Gaming 16

Triangle Strip glbegin(gl_lines); glvertex3f(v0.x,v0.y,v0.z); glvertex3f(v1.x,v1.y,v1.z); glend(); v1 v0 CSCI E-74 Virtual and Augmented Reality for Simulation and Gaming 17

Triangle Strip Double precision glbegin(gl_line_strip); glvertex3d(v0.x,v0.y,v0.z); glvertex3d(v1.x,v1.y,v1.z); glvertex3d(v2.x,v2.y,v2.z); glvertex3d(v1.x,v1.y,v1.z); glend(); v3 v1 v0 v2 CSCI E-74 Virtual and Augmented Reality for Simulation and Gaming 18

Hidden faces P0 P1 P2 P3 P4 P5 I cannot see all the faces at the same time! CSCI E-74 Virtual and Augmented Reality for Simulation and Gaming 19

Polygon Normal Represent the length of V 1 and V 2 V 1 = V 1x, V 1y, V 1z = v1 x v0 x, v1 y v0 y, v1 z v0 z R 3 V 2 = V 2x, V 2y, V 2z = v2 x v0 x, v2 y v0 y, v2 z v0 z R 3 Represent the direction of V 1 and V 2 V 1 = V 1 = v1 x v0 x 2 + v1 y v0 y 2 + v1z v0 z 2 R V 2 = V 2 = v2 x v0 x 2 + v2 y v0 y 2 + v2z v0 z 2 R n V 1 = V 1 = v1 x v0 x V 1, v1 y v0 y V 1, v1 z v0 z V 1 R 3 v0 V 1 v1 V 2 = V 2 = v2 x v0 x V 1, v2 y v0 y V 1, v2 z v0 z V 1 R 3 V 2 n = V 1 V 2 = V 1 V 2 v2 CSCI E-74 Virtual and Augmented Reality for Simulation and Gaming 20

Scalar Product V 1 V 2 = V 1 V 2 cos θ V 1 θ V 2 V 1 V 2 = V 1x V 2x + V 1y V 2y + V 1z V 2z R 1 0-1 CSCI E-74 Virtual and Augmented Reality for Simulation and Gaming 21

Scalar Product V 1 V 2 = V 1 V 2 cos θ V 1 V 2 = V 1x V 2x + V 1y V 2y + V 1z V 2z R Polygon Polygon -1 if V 1 V 2 0 then draw primitive else discard CSCI E-74 Virtual and Augmented Reality for Simulation and Gaming 22

GL_CULL_FACE glenable(gl_cull_face); gldisable(gl_cull_face); Only 3 faces if V 1 V 2 0 then draw primitive else discard CSCI E-74 Virtual and Augmented Reality for Simulation and Gaming 23

Polygon Normals Specifies the normal versor glnormal3f(glfloat nx, Glfloat ny, Glfloat nz); Example glbegin(gl_polygon); glnormal3f(n.x, n.y, n.z); glvertex3f(v1.x, v1.y, v1.z); glvertex3f(v2.x, v2.y, v2.z); glvertex3f(v3.x, v3.y, v3.z); glend(); v2 v1 v2 CSCI E-74 Virtual and Augmented Reality for Simulation and Gaming 24