Skip to main content

Posts

Showing posts from 2019

Animating objects with WebGL

Making the square rotate Let's start by making the square rotate. The first thing we'll need is a variable in which to track the current rotation of the square: var squareRotation = 0.0 ; Now we need to update the  drawScene()  function to apply the current rotation to the square when drawing it. After translating to the initial drawing position for the square, we apply the rotation like this: mat4 . rotate ( modelViewMatrix , // destination matrix modelViewMatrix , // matrix to rotate squareRotation , // amount to rotate in radians [ 0 , 0 , 1 ] ) ; // axis to rotate around This rotates the modelViewMatrix by the current value of  squareRotation , around the Z axis. To actually animate, we need to add code that changes the value of  squareRotation  over time. We can do that by creating a new variable to track the time at which we last animated (let's call it  then ), then adding the followi...

Privacy Policy

Privacy Policy Effective date: October 01, 2019 Matrix Writer ("us", "we", or "our") operates the Matrix Writer mobile application (hereinafter referred to as the "Service"). This page informs you of our policies regarding the collection, use, and disclosure of personal data when you use our Service and the choices you have associated with that data. The Privacy Policy for Matrix Writer has been created with the help of TermsFeed . We use your data to provide and improve the Service. By using the Service, you agree to the collection and use of information in accordance with this policy. Unless otherwise defined in this Privacy Policy, the terms used in this Privacy Policy have the same meanings as in our Terms and Conditions. Definitions Service Service is the Matrix Writer mobile application operated by Matrix Writer Personal Data Personal Data means data about a living individual who can be identified from those data (or from those and other in...

Matrix math for the web

Matrices can be used to represent transformations of objects in space, and are an important tool to use in visualizations on the Web. This article explores how to create matrices and use them with  CSS3 transforms  and the  matrix3d  transform type. While this article uses CSS3 for the ease of explanations, matrices are a core concept used by many different technologies including WebGL and shaders. This article is also available as an  MDN content kit . The live examples use a collection of  utility functions  availabile under a global object named "MDN". What is a transformation matrix? There are many types of matrices, but the ones we are interested in are the 3D transformation matrices. These matrices consist of a set of 16 values arranged in a 4x4 grid. In JavaScript, it is easy to represent a matrix as an array. The typical starting point is to show the identity matrix. When this matrix is multiplied against another point or matrix then the result...

Advanced animations

In the last chapter we made some  basic animations  and got to know ways to get things moving. In this part we will have a closer look at the motion itself and are going to add some physics to make our animations more advanced. Drawing a ball Section We are going to use a ball for our animation studies, so let's first draw that ball onto the canvas. The following code will set us up. < canvas id = " canvas " width = " 600 " height = " 300 " > </ canvas > As usual, we need a drawing context first. To draw the ball, we will create a  ball  object which contains properties and a  draw()  method to paint it on the canvas. var canvas = document . getElementById ( 'canvas' ) ; var ctx = canvas . getContext ( '2d' ) ; var ball = { x : 100 , y : 100 , radius : 25 , color : 'blue' , draw : function ( ) { ctx . beginPath ( ) ; ctx . arc ( this . x , this . y , this . radius , 0 , ...