Time for action – simple animation
Open
ch5_SimpleAnimation.html
using your WebGL-enabled Internet browser of choice.Move the camera around and see how the objects (sphere and cone) move independently of each other (local transformations) and from the camera position (global transformation).
Move the camera around pressing the left mouse button and holding it while you drag the mouse.
You can also dolly the camera by clicking the left mouse button while pressing the Alt key and then dragging the mouse.
Now change the camera type to Tracking. If for any reason you lose your bearings, click on go home.
Let's examine the source code to see how we have implemented this example. Open
ch5_SimpleAnimation.html
using the source code editor of your choice.Take a look at the functions
startAnimation
,onFrame
, andanimate
. Which timing strategy are we using here?The global variables
pos_sphere
andpos_cone
contain the position of the sphere and the cone respectively. Scroll up to thedraw
function. Inside...