Sundukovskiy Aleksey
CSE167
Final Project
--------------------------------------Homer Simpson eating donuts.-------------------------
 	In this final project I created a Homer Simpson game. Using openGL I was able to 
construct a Homer Simpson head using glutSolidSphere. I stretched the sphere using glScalef 
function in the y and z directions. To color the sphere I used a phong lighting model 
provided by OpenGl which gives Homer's head specular highlights. The material properties 
are specified such that his head is yellow in color as is in the real cartoon.The function 
in which takes care of rendering the Homer head is called myDrawCosineSurface. To add 
detail to the head I gave Homer a few features such as eyelids, eyes, pupils, hair (both on 
top of the head and above his ears), and obviously ears. The crucial part of the game is 
that Homer open his mouth to swallow donuts flying across the playing field. Unfortunately 
I couldn't use glutSolidSphere, but instead I had to build, scale, color and animate two 
half-spheres where the top half-sphere overlaps the bottom half-sphere to give a realistic 
impression of opening and closing of a mouth. To draw the half spheres I used spherical 
coordinates and to rotate the two spheres in the opposite directions about the the Z axis.
For the mouth I specified different material properties than for the head because the 
mouth in the cartoon character is somewhat darker than the head. I placed the mouth in a 
way such it seems as if the two objects (head and mouth) are merged. However the are not 
really merged and therefore when the mouth is open one can see the sphere used to build 
the head is visible through the mouth. To give an illusion to the user that indeed Homer 
has a mouth I created a black sphere which carefully placed inside Homer's mouth such 
that the yellow head itself is no longer visible. 
 	To give the user something to aim for as the mouth closes and opens I gave homer a 
bright red tongue which is placed just outside the red sphere right after I scaled it in the 
z direction to give the tongue a flat appearance. Next I created Homer's eyes using to white 
spheres. Then I gave Homer a nose which I placed at an angle for added realism (also using a
 sphere). Then I gave Homer pupils which are simply two tiny black spheres placed in front 
of Homer's eyes.
 	Next I created Homer's ears using glutSolidTorus commands. Only I made the inner 
radius of the torus small enough so that there is no hole in the ear. Just as before I used 
glMaterialf/v properties to give the tori which I placed on the opposite sides of Homer's 
head .
 	The final step in creating Homer's head was to give him hair. Above each ear I 
placed a symbolic M in such a way as to give illusion that it curves around Homer's head. 
To create the hair I placed points using glVerte3f function and then I connected the points 
using GL_LINE_STRIP.
 	For the hair on top of his head I created an algorithm which calculates how to 
place the points around his head in a roughly circular manner. To connect the points I 
again used the GL_LINE_STRIP.
 	To make the lines smooth and thick I used some of the commands specified by 
instructor Buss in his connect dots program within the initRendering function. One such 
command was glLineWidth(6) to make the lines thick.
	 Once I was done with Homer's head I created the ability to animate Homer's head by 
pressing Y to make his head go up and Shift+Y to make it go down and z to make Homer go in 
the positive Z direction (that is towards the user if the user is looking at the head 
sideways) and to make it go in the negative Z direction the user presses Z + Shift.
 	I also gave Homer Simpson, as well the donut, which he has to catch shadows which 
follow them across the screen. To achieve this I redraw both the head and the donut with a 
second call to the functions that draw them passing a flag which will tell the algorithm to 
scale the image in the Y direction by 0 affectively creating the projection image of the 
object. The shadow is projected onto a rectangular plane drawn in drawScene function. To 
avoid Z fighting the shadow image is rendered just a tiny distance above the plane. 
 	To make the game interesting I render the donut in different places on the screen 
both on the z and y axis. To achieve this random rendering I used rand() function. To make 
the donut appear on the negative Z axis I make the direction negative if it's less or equal 
to a certain range. To make the donut look more realistic I created a donut which has one 
color for the creme on the top and the dough on the bottom by drawing two tori in almost 
exactly the same place except one is place a tiny bit higher above the other.The donut 
disappers if it reaches the end of the palying field. Then a new donut is rendered at the 
start of the playing field and each time it is redrawn it gets closer to Homer on the X axis.
 	To make the game more interesting I also loaded two texture maps which have the 
pictures of the actual cartoon in one texture Homer is praising donuts and in the other 
Homer is having a heart attack. To load the images I used instructor Buss's initFour 
function to create the bindings to the loaded images (additionally I also use 
RgbImage.cpp). I also use instructor's loadTextureFromFile to load the textures.I rebind 
the textures and display them on top of the plane mentioned above with the help of 
glTextCoord2f() commands. The Heartattack Homer is displayed only if the homer doesn't 
catch the donut on the tongue .The program checks where Homer is in relation to the donut
 because the information where Homer and the donut are at any given point are globally 
available and if the donut is close to Homer's tongue the normal texture map stays. However 
if the absolute value ( I used fabs for this) of the difference of the position where Homer 
is and where the Donut is, is  greater than some set value which still keeps the game fun 
the Heartattack Homer will be displayed and the also a sound byte "Doh!" will sound.To play 
the clip sndPlaySound("Homer.wav", SND_ASYNC || SND_LOOP); and also need the following 
includes #include "glext.h" #include . The sound file must be a wav file.