WebGL Programming Guide Reading Notes-fourth chapter

Source: Internet
Author: User

First, preface

Today continue to the fourth chapter of the study content, began to learn the complex transformation of knowledge.

Second, the text

Example1: Composite Transformations

In the book, the author encapsulates a set of matrix objects for transformations: Matrix4 objects. It contains the following methods:

  1. Matrix4. setidentity (): Instantiate Matrix4 as the unit matrix
  2. Matrix4 . settranslate (x, Y, z): Sets the Matrix4 instance to the translation transformation matrix, the x-axis translation distance is x, the y-axis translation distance is Y, and the z-axis translation distance is Z;
  3. Matrix4. Setscale (x, Y, z): Sets the Matrix4 instance to a scaled transformation matrix with a scaling factor of x, Y, Z;
  4. Matrix4. setRotate (ANGLE,X,Y,Z): Sets the Matrix4 instance to the rotation transformation matrix, the angle is angle, the axis of rotation is (x, y, z);
  5. Matrix4. Translate (x, Y, z): Multiplies the Matrix4 instance itself by a translation transformation matrix;
  6. Matrix4. rototate (angle,x,y,z): Multiply the Matrix4 instance itself by a rotation transformation matrix;
  7. < Span style= "font-size:14pt" >matrix4. Scale (x, Y, z): < Span style= "COLOR: #000000" >
  8. < Span style= "font-size:14pt" > < Span style= "font-size:16px" >matrix4. set (m): < Span style= "font-size:14pt" > < Span style= "font-size:16px" > Matrix4 set to M;
  9. < Span style= "font-size:14pt" > < Span style= "font-size:16px" > < Span style= "COLOR: #ff0000" > matrix4.elements : The typed array contains the matrix elements of the Matrix4 instance;
var New Matrix4 (); Modelmatrix.setrotate (ANGLE,0,0,1); Modelmatrix.translate (Tx,  0,0);.....GL.UNIFORMMATRIX4FV (U_modelmatrix,false, modelmatrix.elements);

Example2: Animation

&NBSP; requ Estanimationframe (func): Requests that the browser callback the function func at some point in the future to complete the redraw. We should start the request again at the end of the callback function.

var tick = function () {    = animate (Currentangle);  // Update the rotation angle    Draw (GL, N, Currentangle, Modelmatrix, U_modelmatrix);   // Draw the triangle    // Request that the browser calls tick };tick ();

Since the time the browser executes tick () is not controllable, we need to make the triangle rotate at a constant speed, then we need to control the time:

var g_last = date.now (); function animate (angle) {  //  Calculate the elapsed time  var now = date.now ();   var elapsed = now- g_last;   = Now ;   // Update The current rotation angle (adjusted by the elapsed time)  var 1000.0)  ;   return  the ;}

Third, end

The fifth chapter continues to be updated in Sunday.

WebGL Programming Guide Reading Notes-fourth chapter

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.