Graphics CSCI 343, Fall 2017 Lecture 13 More on WebGL

Slides:



Advertisements
Similar presentations
Transforming graphs of functions
Advertisements

Animation and Input CSCI Day Six. Animation Basic Steps to Draw Something: var vertices = [ … ]; var BufferId = gl.CreateBuffer(); gl.bindBuffer.
Geometric Transformations
Course Website: Computer Graphics 3: 2D Transformations.
Michael Robertson Yuta Takayama. WebGL is OpenGL on a web browser. OpenGL is a low-level 3D graphics API Basically, WebGL is a 3D graphics API that generates.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Basic Graphics Concepts Day One CSCI 440. Terminology object - the thing being modeled image - view of object(s) on the screen frame buffer - memory that.
Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Emeritus of Computer Science University of New Mexico.
Programming with OpenGL Part 2: Complete Programs Ed Angel Professor of Emeritus of Computer Science University of New Mexico.
Computer Graphics World, View and Projection Matrices CO2409 Computer Graphics Week 8.
Homogeneous Form, Introduction to 3-D Graphics Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 20,
1 Graphics CSCI 343, Fall 2015 Lecture 4 More on WebGL.
1 Graphics CSCI 343, Fall 2015 Lecture 2 Introduction to HTML, JavaScript and WebGL.
1 Perception and VR MONT 104S, Fall 2008 Lecture 21 More Graphics for VR.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Perception, Illusion and VR HNRS 299, Spring 2008 Lecture 18 Multiple Transformations.
1 Building Models Ed Angel Professor Emeritus of Computer Science University of New Mexico Angel and Shreiner: Interactive Computer Graphics 7E © Addison-Wesley.
User Input and Animation. For Further Reading Angel 7 th Ed: –Chapter 3: Input and Animation. –Chapter 4: Rotation and other transformation. Beginning.
1 Graphics CSCI 343, Fall 2015 Lecture 6 Viewing, Animation, User Interface.
Computer Graphics I, Fall 2010 OpenGL Transformations.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 OpenGL Transformations.
1 Graphics CSCI 343, Fall 2015 Lecture 21 Lighting and Shading III.
1 Graphics CSCI 343, Fall 2015 Lecture 5 Color in WebGL.
1 Graphics CSCI 343, Fall 2015 Lecture 3 Introduction to WebGL.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Transformations Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
Vertex Buffer Objects and Shader Attributes. For Further Reading Angel 7 th Ed: –Most parts of Chapter 2. Beginning WebGL: –Chapter 1: vertex Buffer Objects,
Graphics CSCI 343, Fall 2015 Lecture 16 Viewing I
1 Graphics CSCI 343, Fall 2015 Lecture 18 Viewing III--More Projection.
1 Graphics CSCI 343, Fall 2015 Lecture 25 Texture Mapping.
Computer Graphics Matrices
Honours Graphics 2008 Session 2. Today’s focus Vectors, matrices and associated math Transformations and concatenation 3D space.
1 OpenGL Transformations. 2 Objectives Learn how to carry out transformations in OpenGL ­Rotation ­Translation ­Scaling Introduce OpenGL matrix modes.
Computer Graphics I, Fall 2010 Transformations.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
OpenGL Matrices and Transformations Angel, Chapter 3 slides from AW, Red Book, etc. CSCI 6360/4360.
Introduction to Computer Graphics
Interactive Computer Graphics CS 418 – Fall 2017
Interactive Computer Graphics CS 418 – Fall 2017 Indexed Meshes Transformations Background Imagery:
School of Computer Science
OpenGL Transformations
Camera Position (5.6) we specify the position and orientation of the camera to determine what will be seen. use gluLookAt (eye x, y, z, at x, y, z, up.
Computer Graphics CC416 Week 15 3D Graphics.
2D Transformations with Matrices
and an introduction to matrices
Computer Graphics OpenGL Transformations
Introduction to Computer Graphics with WebGL
Modeling 101 For the moment assume that all geometry consists of points, lines and faces Line: A segment between two endpoints Face: A planar area bounded.
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
OpenGL Transformations
Introduction to Computer Graphics with WebGL
Programming with OpenGL Part 2: Complete Programs
Introduction to Computer Graphics with WebGL
CSC4820/6820 Computer Graphics Algorithms Ying Zhu Georgia State University Transformations.
Transformation, perspective projection, and LookAT in WebGL vs.OpenGL
Transformations 3 University of British Columbia
Building Models Ed Angel Professor Emeritus of Computer Science
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Building Models Ed Angel Professor Emeritus of Computer Science
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Computer Graphics Transformations
Presentation transcript:

Graphics CSCI 343, Fall 2017 Lecture 13 More on WebGL

Concatenation of Transformations Suppose you want to: Scale an object Rotate the object Translate the object For each vertex, we apply a series of transformations: P1 = SP P2 = RP1 = RSP P3 = TP2 = TRSP For efficiency, we create a new matrix, M = TRS. Each new point can be computed directly as P3 = MP Note: Matrix multiplication is not commutative. Order Matters!

Example Transformations: Double the height Rotate by 90 deg clockwise about the Z axis Translate horizontally by

Transformations in WebGL Ways to perform transformations: Create your own “current transformation matrix” (ctm): Compute transformation in advance. Enter matrix into an array (in column major order). OR Use the transformation functions provided in MV.js 1. Multiply the ctm by each transformation matrix in reverse order. In both cases A and B, next: Pass the ctm to the vertex shader. Draw object. In the vertex shader, multiply each vertex by the ctm.

Precomputing a matrix Example: Scale by 2 in both the x and y directions, then translate vertically by 0.2. P1 P1 Not drawn to scale P3 P2 P3 P2 M =

Representing a matrix in WebGL A matrix is stored as a 16 element array in column major order. The flatten( ) function in MV.js converts to column major order.

Example Code //Scale by 2.0 in x and y directions and //Move up 0.2 units in y direction mvMatrix = mat4(2.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.2, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0); gl.uniformMatrix4fv(modelView, false, flatten(mvMatrix) ); gl.drawArrays(gl.LINE_LOOP, 0, 3);

Drawing in 3D Drawing in 3D is the same as 2D, but we use 3D points. Example: //Vertices of a cube var vertices = [ vec3( -0.5, -0.5, 0.5 ), vec3( -0.5, 0.5, 0.5 ), vec3( 0.5, 0.5, 0.5 ), vec3( 0.5, -0.5, 0.5 ), vec3( -0.5, -0.5, -0.5 ), vec3( -0.5, 0.5, -0.5 ), vec3( 0.5, 0.5, -0.5 ), vec3( 0.5, -0.5, -0.5 ) ];

Hidden Surface Removal If you don't use a mechanism to remove hidden surfaces, then the last surface drawn will be the one that's seen, even if it is behind other surfaces. To remove hidden surfaces: In init( ): gl.enable(gl.DEPTH_TEST); In render( ): gl.clear( gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);

colorCube( ) function function colorCube() { //quad takes 4 parameters indicating which vertices //to use to make a square quad( 1, 0, 3, 2 ); quad( 2, 3, 7, 6 ); quad( 3, 0, 4, 7 ); quad( 6, 5, 1, 2 ); quad( 4, 5, 6, 7 ); quad( 5, 4, 0, 1 ); }

quad( ) function quad(a, b, c, d) { //Specify vertex array and color array here … //order to use with gl.TRIANGLES var indices = [ a, b, c, a, c, d ]; for ( var i = 0; i < indices.length; ++i ) { points.push( vertices[indices[i]] ); colors.push( vertexColors[indices[i]] ); //for solid colors use: //colors.push(vertexColors[a]); }