More Hints for Program 3

by Mike Gleicher on September 18, 2015

I just did a sample solution for Programming Assignment 3. (I had tried it before, but used code from another project).

The idea was to see what it was like to make the program from scratch, like you would have to. Using just twgl.m4. As simple as possible, and as fast as possible. (for me it should be pretty fast, since I’ve done it before)

You can see this simple sample solution (the code is obfuscated – so don’t try to look at it – write your own). It’s less than 100 lines of code – including a decent amount of comments. It just draws a checkerboard and has the simplest possible UI. It does the project/orthographic switch (I didn’t know how to make a button easily, so I used a slider – set it to zero for orthographic).

Some thoughts from doing it myself:

  • Javascript allowing me to call functions with the wrong arguments is a hassle! Remember that m4 always wants you to pass a matrix and a point to transform. And that lookat takes 3 points. I kept getting the parameters to functions wrong. And then you get a weird error from m4 (if you’re lucky) – or a bogus value.
  • The checkerboard was the simplest object I could make. Well, I actually started by making a dot at the origin – because I knew that if I pointed the camera at it, it should show up on the center of the screen.
  • m4.lookat doesn’t do what I thought it did. Read the documentation.
  • Ugly sliders are easy. And they work for the assignment. If you want to get things done fast, they are OK.
  • I made the sliders in a loop – using document.writeln (which is a bad thing). But you can do exactly what was in the sliders tutorial instead.
  • I had written the gl matrix tutorial which reminded me about the multiplication order. You might want to review it so you don’t make the same mistake I did.
  • I didn’t know how to make a checkbox. So I used a slider with values 0/1. Later, I took the time to learn how to do a checkbox (similar, but different enough – you need a different event name). The point is: do something that you can get to work (for me, a slider) – then make it better afterwards. (I haven’t uploaded the new version with a checkbox yet).

Have fun doing it yourself! Do something cooler than mine! (well, mine gets some of the project points)

 

Print Friendly, PDF & Email

Previous post:

Next post: