phase 4:
2d transformations
cs40 assignment 4 web page
overview
In this lab I implemented a 2d transformation library and started creating a hierarchical graphics pipeline.
transformations
Transformations are pretty easy to do, if you know some basic matrix algebra. It seemed like the best and only way to do this was to use the final concatenated transformation matrix to map theoretical points to image points. Also, that makes things really nice because then you can work in whatever units you want, regardless of the final image size. We were restricted to the unit line, unit circle, and unit square. Of course after transforming a unit square, you get some arbitrary quadrilateral (usually a parallelogram, still), so it ends up getting drawn with the fillPolygon() routine. The circle is a bit trickier, as you end up with an angled ellipse, but since I already have support for filled angled ellipses, it wasn't so tricky after all (you can describe the resultant angled ellipse by looking at the points on the x and y axes that define the unit circles semimajor and semiminor axes...)
viewing pipeline
It seemed to make the most sense to me to have the graphics pipeline exist if I was going to have a view transformation matrix, so I went ahead and did that. It is hierarchical and seems to work. The view parameters are established by a Camera structure which is defined by its center point in world space ('focus'), its width in world space ('zoom'), and its final row and column image output, plus an angle of its window in world space ('tilt'). The spinning and shrinking effects of the julia set above are all done by changing camera parameters (the julia set itself is actually shearing, but its kind of hard to tell that)
patterns and gradients
I wanted patterns and gradients to work the way you'd think they would, that is, say, as you rotate a square with a gradient on it, you want it to map the same relative to the square, not to the screen, so I used an inverse transformation matrix to do just that. That's largely how I got the spinning julia set to work right. Below you can see a gradient which 'stays put' as well.
antialiasing
I got a really basic form of line and polygon-edge antialiasing working by using the error term in bresenham's algorithm and some ad-hoc reasoning. This sort of works for ellipses too but only in a rather broken and undesirable way. I'm really hoping to get it to work for angled ellipses, because then my unit circles and unit squares could all be antialiased, which would be sweet. Below are some before/after comparisons.
spaceships
I had to go with the tie interceptor for this one. It is actually a hierarchical model, where I have the body and a wing, and then the wing is inserted twice with an inverse scale (reflection). There it is flying across the Hubble deep field...
And there they are trying not to crash into the sun. Again, this is done hierarchically where the world scene has the sun (a circle) and two tie-fighter instances (this one animates, so if it isn't animating for you reload your browser...)