Another retrospective change…

Yesterday evening (3 November 2009) I made some small retrospective changes to lessons 3, 4 and 5. If you first read those lessons before then, you may find the rest of this post useful, because the next lesson will build on the changed code. If you first read the lessons after 2 November 2009, you can ignore this post completely because the code you looked at already contained these changes.

It’s a pretty minor change; what happened was that while putting together lesson 6, in which I introduce keystroke handling, I realised that my drawScene functions have had two purposes since lesson 3; they both drew the scene and animated it. So, I’ve gone back and split out the animation part.

This means that from that lesson on, at the end of webGLStart, we arrange for a new function to be called every 15 milliseconds instead of drawScene:

    setInterval(tick, 15);

…and in tick, we call drawScene and a new function called animate:

  function tick()
  {
    drawScene();
    animate();
  }

These two functions are simply a new way of splitting up the work that used to all be done in drawScene: drawScene itself is reduced so that it simply draws the scene, and animate does the tracking of the time between calls and updates the triangle/pyramid/square/cube rotation angles.

A small change, but it makes the code neater, putting us in a better position for lesson 6.

By the way, lesson 6 is now code-complete and just needs me to write it up; you can see the WebGL page here if you have a compatible browser, or you can watch a video of it on YouTube. Once it’s loaded, use page up/page down to zoom in and out, use the cursor keys to make the box spin in different directions, and press the “F” key to change the kind of texture filtering used.

You can leave a response, or trackback from your own site.

Leave a Reply

Subscribe to RSS Feed Follow Learning WebGL on Twitter