Transformation, perspective projection, and LookAT in WebGL vs.OpenGL

Slides:



Advertisements
Similar presentations
Computer Graphics - Viewing -
Advertisements

Computer Graphics 2D & 3D Transformation.
02/17/05CISC640/440 OpenGL Tutorial1 OpenGL Tutorial CISC 640/440 Computer Graphics TA: Qi Li/Mani Thomas
MAT 594CM S2010Fundamentals of Spatial ComputingAngus Forbes Overview Goals of the course: 1. to introduce real-time 3D graphics programming with openGL.
Based on slides created by Edward Angel
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Computer Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
OpenGL and WebGL Drawing Functions CSCI 440 Day Five.
OpenGL (II). How to Draw a 3-D object on Screen?
3D Rendering with JOGL Introduction to Java OpenGL Graphic Library By Ricardo Veguilla
3D Transformation. In 3D, we have x, y, and z. We will continue use column vectors:. Homogenous systems:. 3D Transformation glVertex3f(x, y,z);
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 OpenGL Basics A Graphics Standard ©Mel Slater, Anthony Steed
Basic OpenGL Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Wednesday, September 10, 2003.
A Really (too) Short Introduction to OpenGL Peter Rautek.
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.
TWO DIMENSIONAL GEOMETRIC TRANSFORMATIONS CA 302 Computer Graphics and Visual Programming Aydın Öztürk
Homogeneous Form, Introduction to 3-D Graphics Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, October 20,
Interactive Computer Graphics CS 418 – Spring 2015 Mesh Rendering, Transformation, Camera Viewing and Projection in OpenGL TA: Zhicheng Yan Sushma S Kini.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Graphics CSCI 343, Fall 2015 Lecture 2 Introduction to HTML, JavaScript and WebGL.
Stages of Vertex Transformation To specify viewing, modeling, and projection transformations, you construct a 4 × 4 matrix M, which is then multiplied.
Computer Graphics I, Fall 2010 Computer Viewing.
16/5/ :47 UML Computer Graphics Conceptual Model Application Model Application Program Graphics System Output Devices Input Devices API Function.
OpenGL: Introduction Yanci Zhang Game Programming Practice.
Chapters 5 2 March Classical & Computer Viewing Same elements –objects –viewer –projectors –projection plane.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
1 Graphics CSCI 343, Fall 2015 Lecture 3 Introduction to WebGL.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Classical Viewing Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Part One - Parallel Projection textbook
OpenGL API 2D Graphic Primitives Angel Angel: Interactive Computer Graphics5E © Addison-Wesley
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Programming with OpenGL Part 4: Color and Attributes Isaac Gang University.
1 Perception, Illusion and VR HNRS 299, Spring 2008 Lecture 15 Creating 3D Models.
1 E. Angel and D. Shreiner: Interactive Computer Graphics 6E © Addison-Wesley 2012 Computer Viewing Isaac Gang University of Mary Hardin-Baylor.
Geometric Transformations Ceng 477 Introduction to Computer Graphics Computer Engineering METU.
Computer Graphics I, Fall Programming with OpenGL Part 2: Complete Programs.
Computer Graphics Lecture 34. OpenGL Programming II Taqdees A. Siddiqi
OpenGL Programming Guide Chapter 2 Korea Univ. Graphics Labs. Ji Jun Yong Korea Univ. Graphics Labs. Ji Jun Yong.
Interactive Computer Graphics CS 418 – Fall 2017
Interactive Computer Graphics CS 418 – Fall 2017 Indexed Meshes Transformations Background Imagery:
Viewing.
Computer Viewing.
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.
Graphics CSCI 343, Fall 2017 Lecture 13 More on WebGL
Isaac Gang University of Mary Hardin-Baylor
Introduction to OpenGL
Programming with OpenGL Part 2: Complete Programs
OpenGL API 2D Graphic Primitives
CSC461: Lecture 19 Computer Viewing
Programming with OpenGL Part 2: Complete Programs
OpenGL (Open Graphics Library) Mr. B.A.Swamy Assistant Professor Dept of CSE.
Lab 3 Geometric Drawing Lab 3 Geometric Drawing.
Objectives OpenGL drawing primitives and attributes
Programming with OpenGL Part 2: Complete Programs
Introduction to Computer Graphics with WebGL
CSC4820/6820 Computer Graphics Algorithms Ying Zhu Georgia State University Transformations.
Introduction to Computer Graphics with WebGL
Introduction to Computer Graphics with WebGL
Projection in 3-D Glenn G. Chappell
Drawing in the plane 455.
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
Introduction to Computer Graphics with WebGL
Geometric Objects and Transformations (II)
University of New Mexico
Programming with OpenGL Part 2: Complete Programs
Computer Graphics Computer Viewing
Computer Viewing Ed Angel Professor Emeritus of Computer Science
Introduction to OpenGL
Programming with OpenGL Part 2: Complete Programs
CS 352: Computer Graphics Chapter 5: Viewing.
Presentation transcript:

Transformation, perspective projection, and LookAT in WebGL vs.OpenGL Ming Ouhyoung, September 2018

To make things (functions) simple: WebGL is an Open ES 2.0 binding. OpenGL ES 2.0 (and modern OpenGL 3.2+) does not have some old OpenGL functions, everything must be done in shaders and or your own matrix libraries. Good thing is that there is plenty of matrix libraries available for WebGL, one of the best/fastest being glMatrix ( https://github.com/toji/gl-matrix ).

But where are glLoadIdentity,  glMultMatrix,  glTranslate, and glRotate, in OpenGL?

Library: glMatrix Javascript has evolved into a language capable of handling realtime 3D graphics, via WebGL, and computationally intensive tasks such as physics simulations. These types of applications demand high performance vector and matrix math, which is something that Javascript doesn't provide by default. glMatrix to the rescue!

glMatrix is designed to perform vector and matrix operations stupidly fast! By hand-tuning each function for maximum performance and encouraging efficient usage patterns through API conventions, glMatrix will help you get the most out of your browsers Javascript engine.

glMatrix API The glMatrix API can be made can be made available for use on a web page with a script element such as <script src="gl-matrix-min.js"></script>This assumes that gl-matrix-min.js is in the same directory as the web page.

saveTransform = mat4.clone(modelview); Each glMatrix class has a create() function which creates an array of the appropriate length and fills it with default values. For example, transform = mat4.create();sets transform to be a new Float32Array of length 16, initialized to represent the identity matrix. Similarly, vector = vec3.create();creates a Float32Array of length 3, filled with zeros. Each class also has a function clone(x) that creates a copy of its parameter x. For example: saveTransform = mat4.clone(modelview);

Translation, rotation To apply a translation by a vector [dx,dy,dz], we can say mat4.translate( modelview, modelview, [dx,dy,dz] ); // This is equivalent to calling glTranslatef(dx,dy,dz) in OpenGL.  To apply a scaling transformation with scale factors sx, sy, and sz, use mat4.scale( modelview, modelview, [sx,sy,sz] ); in OpenGL: glScalef(sx, sy, sz)

glMatrix for rotation: These function allow us to do all the basic modeling and viewing transformations that we need for 3D graphics. For rotation, glMatrix has four functions, including three for the common cases of rotation about the x, y, or z axis. The fourth rotation function specifies the axis of rotation as the line from (0,0,0) to a point (dx,dy,dz). This is equivalent to glRotatef(angle,dx,dy,dz). Unfortunately, the angle of rotation in these functions is specified in radians rather than in degrees: mat4.rotateX( modelview, modelview, radians ); mat4.rotateY( modelview, modelview, radians ); mat4.rotateZ( modelview, modelview, radians ); mat4.rotate( modelview, modelview, radians, [dx,dy,dz] );

mat4.rotate(out, a, rad, axis) Rotates a mat4 by the given angle around the given axis Parameters: Name Type Description out mat4 the receiving matrix a the matrix to rotate rad Number the angle to rotate the matrix by axis vec3 the axis to rotate around

mat4.scale(out, a, v) Parameters: Name Type Description out mat4 the receiving matrix a the matrix to scale v vec3 the vec3 to scale the matrix by

“lookAt" function The glMatrix library has a "lookAt" function to do the same thing: mat4.lookAt( modelview, [eyex,eyey,eyez], [refx,refy,refz], [upx,upy,upz] ); var modelview = mat4.create();//create mat4.identity( modelview ); //set to identity This function call is actually equivalent to the two OpenGL commands glLoadIdentity(); gluLookAt( eyex,eyey,eyez,refx,refy,refz,upx,upy,upz );

Perspective Projection mat4.ortho( projection, left, right, bottom, top, near, far ); mat4.frustum( projection, left, right, bottom, top, near, far ); mat4.perspective( projection, fovyInRadians, aspect, near, far ); As with the modelview transformation, you do not need to load projection with the identity before calling one of these functions, but you must create projection as a mat4 (or an array of length 16).

Other original WebGL functions: 1 gl.TRIANGLES To draw a series of separate triangles. gl.drawElements(gl.TRIANGLES, indices.length, gl.UNSIGNED_SHORT, 0); gl.TRIANGLE_STRIP To draw a series of connected triangles in strip fashion.

gl.POINTS To draw a series of points. gl.drawArrays(gl.POINTS, 0, 3); //draw three points. gl.LINES To draw a series of unconnected line segments (individual lines). gl.drawArrays(gl.LINES, 0, 2); //Every line needs two indices: starting point and end point: gl.LINE_STRIP To draw a series of connected line segments.

void gl.drawElements(mode, count, type, offset); gl.POINTS: Draws a single dot. gl.LINE_STRIP: Draws a straight line to the next vertex. gl.LINE_LOOP: Draws a straight line to the next vertex, and connects the last vertex back to the first. gl.LINES: Draws a line between a pair of vertices. gl.TRIANGLE_STRIP gl.TRIANGLE_FAN gl.TRIANGLES: Draws a triangle for a group of three vertices.

Example: gl.drawElements(gl.POINTS, 8, gl.UNSIGNED_BYTE, 0);

Define the element array const indexBuffer = gl.createBuffer(); gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, indexBuffer); // This array defines each face as two triangles, using the indices into the vertex array to specify each triangle's position. const indices = [ 0, 1, 2, 0, 2, 3, front 4, 5, 6, 4, 6, 7, back 8, 9, 10, 8, 10, 11, top 12, 13, 14, 12, 14, 15, bottom 16, 17, 18, 16, 18, 19, right 20, 21, 22, 20, 22, 23, left ]; // Now send the element array to GL

Other original WebGL functions: 2 gl.enable(gl.DEPTH_TEST); gl.depthFunc(gl.LEQUAL); gl.clearColor(0.5, 0.5, 0.5, 0.9); gl.clearDepth(1.0); gl.viewport(0.0, 0.0, canvas.width, canvas.height); gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);