R = 10 w = 2 for s in -w .. w for t to 361 x = (R + s * cos ( 0.5 * t)) * cos (t) y = (R + s * cos ( 0.5 * t)) * sin (t) z = s * sin ( 0.5 * t) moveto x, y, z end end surface 361, w * 2 + 1
Next I wanted to do a Klein bottle. This was more challenging because the parametric equation is rather large and you need to be careful how you compute it else it will never finish. A trouble I ran into was that at first my Klein bottle was all twisted up. I was about to give up on it I stumbled upon the solution: StepV needs to twice stepU.
stepU = 5 stepV = 10 for u in 0,stepU..(180) cu = cos(u) su = sin(u) for v in 0,stepV..(360) cv = cos(v) sv = sin(v) x = (-2//15) * cu * (3 * cv - 30 * su + 90 * cu ^ 4 * su - 60 * cu ^ 6 * su + 5 * cu * cv * su) A = 3 * (cos v) - 3 * cu ^ 2 * cv - 48 * cu ^ 4 * cv + 48 * cu ^ 6 * cv - 60 * su + 5 * cu * cv * su B = -5 * cu ^ 3 * cv * su - 80 * cu^5 * cv * su + 80 * cu ^ 7 * cv * su y = (-1//15) * su * (A + B) z = (2//15) * (3 + 5 * cu * su) * sv moveto x, y, z end end surface (180 / stepU) + 1, (360 / stepV) + 1
I thing I noticed is that the parenthesis in cos(v) does not do what I would expect. Instead you have to do this: (cos u). This is part of the reason I pulled out the cos and sin evaluations into their own variables.
And finally a “Bagel” Klein just for fun:


]]>r = 3 step = 5 for v in 0, step.. 360 sv = sin(v) sdv = sin(2 * v) for t in 0, step..360 cht = cos (t // 2) sht = sin (t // 2) ct = cos(t) st = sin(t) a = (r + cht * sv - sht * sdv) x = a * ct y = a * st z = sht * sv + cht * sdv moveto x, y, z end end surface 360 / step + 1, 360 / step + 1
Once I decided what scene I was going to make I searched the internet for some suitable models. I found some good ones and also made a couple of my own. After figuring out the texture mapping, I spend some some time positioning my objects just right. Most of this assignment was similar to what we had already done in class so I didn’t think too much out of the box.
Hurdles:
My most significant hurdle was the texture mapping. In particular the lander, which I found on the internet, was composed of multiple materials. The only way I could figure how combine the materials into one texture file was use the ‘Export UV Layout Option’. This created a texture map that outlined the edges of model which I thought looked OK so I just left it like that. After that I was stumped for a while because my texture was not showing up, and I was convinced I was exporting from Blender incorrectly. It turned out that the ObjUtilities::Read code was expecting a // delimiter but blender was only using a single / for me for some reason.
Picture:
]]>
I started off the project by converting the magnet pseudocode into a c++ class. I used a class instead of a struct for no real reason other than that I like classes better and I knew that there is little difference between them. I then worked on adding an OnDraw method to this magnet class so the magnets could draw themselves. Finally I set up the mouse click and drag events to correctly interact with the magnets. This required converted a point from the screen space to a point in world space.
Hurdles:
I think the most challenging aspect of this lab was the click events because you had to figure out the conversion function. Also the requirement of having only one vertex array object tripped me up for a while until I realized how that could be done. Of course I also had some errors when copying the pseudocode and that took me some time to find them all.
Pictures:
It is hard to capture the simulation in pictures. Here is my attempt:
]]>
One issue I had was that I was getting weird distortions around the edges of my bumps. This turned to be because I was printing the float value of the colors to my PPM file and gimp interprets 3.03984e-005 as 3. Additionally, testing the code to make sure it was correct was a challenge.
Thought Processes:
I started off by creating the Image class uses the specs. Next I wrote three loops to generate bumps, calculate energies, and then map these energies to colors. For my mapping I wanted to create a wave like pattern. To (sort of) do this I used the absolute value of a sine function of period 1 and then passed that to a linear interpolation function so I could change colors from blue to cyan. Since I didn’t normalize by using the max value I could have gotten away with 2 loops, but I kept it at three for cleanliness.
Here is the result with one bump:

Then with 250 bumps:
]]>]]>
]]>
]]>
This is a game about blocks and a man. There are 16 levels of fun. Can you beat them all?
http://www.twodee.org/teaching/honors304-503/2012C/homework/adr4/
By the way… There is an explosively exciting block for those who stick to it.
]]>
A Game of Growth:
Good things will happen if you collect spheres.
Bad things will happen if you collect squares.
Amazing things will happen if you collect speedy orange orbs.
http://www.twodee.org/teaching/honors304-503/2012C/homework/adr/
]]>
]]>