Friday, May 10, 2013

HW10 - RT Added Features


My ray tracer supports shadows, subsampling, anti-aliasing, reflections, local lights, background images, quadratic surfaces, and surface transformations. If you download the code, when executing the appletviewer command add the flag

-J-Djava.security.policy=applet.policy

This accesses the file applet.policy, which allows the program to import background images.

The applet renders at 600x600 resolution. When subsampling is used the edges of shadows are extremely pixelated; you can turn subsampling off by clicking the top right button. You can select/deselect multiple surfaces by clicking on them. Once selected, you can use the keyboard to scale them. For the highest quality render, toggle the red/green buttons as in the image below.

Java Applet

___________________________________________________________________________________

Thursday, April 18, 2013

HW9 - Sphere Ray Tracer 1



I made a class called Canvas_RT to do all of my ray tracing for me. Shadows are implemented. To shade an object I keep a tbuffer rather than a zbuffer, which stores the time it took for the ray to hit the object, and I use Phong's reflectance algorithm. I determine if a shaded point P is in shadow with respect to light L by ray tracing from P outwards in the direction of L and checking if the ray hits any other spheres.

I added couple of basic helper methods to my Light and Material classes.

Applet

  • [ UP / DOWN ] - change rotation angle of white sphere
  • [ LEFT / RIGHT ] - select the next sphere (white)
  • [ space ] - reset all rotation angles to random
  • [ q w e a s d ] - change direction of light
  • [ - = ] - zoom out / in

Applet - Ray Tracer


EDIT: added subsampling for massive speedup and added anti-aliasing
  • [ 1 ] - show ray traced pixels (subsampling)
  • [ 2 ] - show anti-aliased pixels
  • [ 3 ] - toggle anti-aliasing
NEW Applet

___________________________________________________________________________________
HW9_Package.zip
HW9_szymczak.java
Canvas_RT.java

Wednesday, April 10, 2013

HW8 - Materials and Phong's Reflectance



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

Sunday, March 31, 2013

HW7 - Normal Shading


In my Geometry class, I added a Matrix normals and a method compute_normals to store and compute the normals at each vertex, respectively. I added a few helper methods in my Matrix class, namely add, subtract, and cross_product. Shading is all done within the HW7_szymczak.java file -- explained within the comments.

I explicitly typed the normals for spheres, rectangular prisms, and 2D shapes. In the applet, the difference in color (eg. between the sphere and klein bottle) is due to the polarity of the face directions and is dependent on how the parameterizations are defined; Notice how the inside of the klein bottle is shaded similarly to the sphere. This is easily rectified by multiplying the normals by -1 for the incongruously colored shapes. I left the applet uncorrected for visual effect.

The object of the game is to use the paddle to block the balls from passing below the bottom edge of the screen. The game is initially paused.

  • spacebar ] : pause/unpause the game
  • [ left/right ] : move the paddle
  • [ / ] : increase size of balls
  • [ . ] : decrease size of balls
Applet
If you make the balls really big (hold down '/'), then you may notice that the shading isn't perfectly smooth. Unshaded lines plague the shapes, creating a scratchy look. There is something wrong with my fillTriangle method; I must be neglecting to fill in a line of pixels (off by one error). This was not an issue in HW6 -- but I completely revamped the code and I have yet to find the problem. 
PROBLEM FIXED** XR (as defined in the class notes) gets truncated when you cast it as an int. So you have to shade pixels from XL to XR+1.
___________________________________________________________________________________
Package
HW7_szymczak.java
Geometry.java

Saturday, March 9, 2013

HW6 - Frame Buffers

I altered MISapplet to reinitialize values if the animation window changes size. In my java programs I store my own pixel values at a set resolution so I can stretch the animation window without breaking the code or increasing computation. I also store my own array because short of overriding computeImage, you can not nicely alter the pix[] array. To aid my computations I added the method set(int,int,int,int,int,int,int,int,Matrix) in Matrix.java to copy the contents from a part of one matrix into a part of another.


Fun With MISapplet 

  • spacebar ] : change exponent (toggle between bulb and brot)

MISapplet - Mandelbulb

This is my first MISapplet that animates the Mandelbulb and Mandelbrot set. It takes about 2 minutes to generate 600x600 resolution so instead I read the image from a file (URL) of precomputed values. Reading from the URL shouldn't take more than a couple seconds. If you are compiling and running directly from your computer, you may need to change java permissions to read from a URL. The zip download below includes a file called applet.policy that does this. When executing the appletviewer command, add the flag

-J-Djava.security.policy=applet.policy

The code lets you either read the image from a URL, read the image from a local txt file, or generate the image. The latter two are commented out. The txt files are available for download separately.



Backward Triangles

  • arrow keys ] : x,y rotation speed
  • wasd ]  : x,y in-place rotation speed
  • [ / ] : stop rotation
  • spacebar ] : reset screen

MISapplet - Triangulation

If a triangle is facing forwards I fill it in. If one is facing backwards I only draw the edges.


___________________________________________________________________________________

Wednesday, March 6, 2013

HW 5 - Geometrical Hierarchicy


  • arrow keys ] : x,y translation
  • / ]  : toggle rotation
  • click ] : add a new layer to the tree
  • space ] : reset screen
Applet


I have a lot of added methods so here is the documentation for Matrix, Transform, and Geometry objects.


___________________________________________________________________________________
HW5 Package
HW5_szymczak.java
Matrix.java
Transform.java
Geometry.java

Monday, February 25, 2013

HW 4 - 3D Objects


  • [ arrow keys ] : x,y translation
  • [ .  / ]  : zoom in / out
  • [ z x ] : rotate
  • [ space ] : reset

Java Applet



My Geometry class has methods for the construction of a prism, cylinder, super sphere, super torus, regular polygon, circle, boy surface, seashell, nautilus, cross-cap, Dini's surface, Enneper's surface, Klein bottle, Mobius strip, random hills, roman surface, and 2d mesh. I assume we will learn how to fix the shading and drawing order issue next class.

I'm currently using a Java hack to define anonymous functions. I have a class called Function that lets you define a method to return a double array. This allows the user to generate any paramaterized surface using my Geometry class. I'm probably going to get rid of its explicit use in Geometry.java code because it generates a million class files upon compiling, but before I change anything I'm going to wait and see how we are supposed to shade our objects.

___________________________________________________________________________________
Download HW4.zip
Download HW4_Szymczak.java
Download Geometry.java

Wednesday, February 20, 2013

HW 3 - Matrix Transform


The controls for the applet are the following:

Applet
            • q, w, e : translate (+) x, y, z
            • a, s, d : translate (-) x, y, z
            • i, o, p : scale (+) x, y, z
            • j, k, l : scale (-) x, y, z
            • 1, 2 : rotation velocity (+/-) x
            • 3, 4 : rotation velocity (+/-) y
            • 5, 6 : rotation velocity (+/-) z
            • [space] : reset to identity

I made my own classes instead of implementing the interface IMatrix. First I have a class Matrix that simply defines a general matrix and has methods to perform operations.

class Matrix 

Variables:
    • double[][] mat
    • int nrows, ncols
Methods:
    • void set(int i, int j, double val) : set value of index i,j (HW)
    • double get(int i, int j) : get value of index i,j (HW)
    • int getn() : number of rows
    • int getm() : number of columns
    • double[][] getmat() : matrix ad 2d array
Static Operations:
    • void prettyPrint(Matrix m) : prints out matrix nicely
    • Matrix eye(int n) : returns nxn identity matrix (HW)
    • Matrix mult(double c, Matrix M) : scalar product of matrix
    • Matrix mult(Matrix ... M) : chain multiplication left to right (HW)
    • Matrix copy(Matrix M) : copy
    • Matrix transpose(Matrix M) : transpose

I also have a class called Transform. This defines the 4x4 Matrix TRS to perform transformations on points. There are two modes: separate=true,false. If separate=false, then only TRS is sequentially updated. If separate is true, then T, R, S, the translation, rotation, and scale matrices, are sequentially updated independently. Then TRS is calculated as the multiplication [T][R][S].

class Transform

Variables:
    • Matrix TRS, T, R, S
    • boolean separate, compressed
Methods:
    • void prettyPrint(): prints TRS, T, R, S nicely
    • void compressTRS() : calculate TRS by multiplying [T][R][S]
    • <> get<>() : retrieve one of the variables
    • void set<>(...) : set one of the matrix variables
    • void rotateZYX() : perform x, then y, then z rotation.
    • Matrix tM, rM, rxM, ryM, rzM, sM(...) : primitive matrices
    • double getTRS(int i, int j) (HW)
    • void setTRS(int i, int j, double val) (HW)
    • void reset() : identity (HW)
    • void translate(double x, double y, double z) (HW)
    • void rotate<>(double rad) (HW)
    • Matrix apply(Matrix src)
    • void apply(Matrix src, Matrix dst)  (HW)


___________________________________________________________________________________
Download HW3.zip
Download Matrix.java
Download Transform.java

Wednesday, February 13, 2013

HW2 - Simple Applet



I figured I'd kill two birds with one stone and make something for class and for Valentine's Day. The applet only works in Safari for me.
  • 'c' : change colors
  • '=' : speed up time
  • '-' : slow down time
  • '1' : toggle movement type
  • [arrow keys] : movement

Click For Valentines Day Applet


___________________________________________________________________________________
Valentine.java

Saturday, February 2, 2013

HW 1 - Introductory Essay





___________________________________________________________________________________