I got tired of copying-and-pasting my drawing code from one HW to the next so I created a Canvas class that does all of it for me. The pipeline is the same as for HW7.
- renderShape(Geometry shape) : splits each face into triangles and performs transform on vertices and normals.
- renderTriangle() : calculates area of the triangle, and renders accordingly by calling methods below
- vertexData() : calculates pixels, depth, and colors at A, B, C, and D. Vertex A is oriented on top; D-B in the middle; C on the bottom.
- fillTriangle(int[] vertex, double[] color, double depth) : parameters give data for the apex of the triangle (either A or C).
- interpolate(double fraction, double[] a, double[] b) : linearly interpolate fraction along the way between a and b.
- phong(double[] color) : Phong's color reflectance algorithm
- gamma(double[] color) : Gamma correction
I added a bunch of helper methods to my Matrix class -- operations on arrays. In the .java file they are grouped together.
- add, subtract, cmult, dot, normalize, copy, copyCol
I also added a Light class that simply stores data for a light and a Material class that stores the relevant values to mimic a material. Each Geometry object has a Material object as a class variable.
Applet
- [ arrow keys ] - rotation
- [ . / ] - zoom out and in
- [ space ] - pause rotation
| Click for Applet |
It's kind of boring but I didn't have time to create a fun game this week.
___________________________________________________________________________________
HW8_package.zip
HW8_szymczak.java
Canvas.java
Material.java
Light.java
Matrix.java
Geometry.java
No comments:
Post a Comment