assignment 0

Graphics Intro

Finished Project

Including rotate, translate, scale, brighter, darker, keyboard input, and animation.

Start up

Scaled (any edge)

Rotated (any corner)

Scaled while rotated

Translated, rotated, scaled

Brighter (press 'b')

Darker (press 'd')

Animate: press 'a' (square rotates. Will run until termination.)

My Thoughts

The last time I programmed in c++ was in 2015 in csci 1113. To create this graphics project I had to first remember and get the hang of c++, and am still doing so. The code was a bit intimidating the first time I looked at it. I had to spend a good amount of time getting a sense of what the variables were and what the functions do. Prof Guy showed us how to import part of a ppm, and finishing the rest wasn't too hard.

I implemented translate, and scale first. Translate was pretty much already done for us. Initially scale was hard because I didn't realize I had g_clicked_x and g_clicked_y, which are key. I think I discovered them when I was doing the normalization calculations for figuring out which edge the user clicked and dragged. After I saw the clicked variables, scale was easy to get working by trial and error.

Rotate was the hardest, mostly because I haven't done transformations since high school. Editing updateVerticies() was ok. I remembered the basic x'=x*cos(t)-y*sin(t) and y'=x*sin(t)+y*cos(t). I had to re figure out how rotating about a point other than the origin worked, x'=x_0+(x-x_0)*cos(t)-(y-y_0)*sin(t) and y'=y_0+(x-x_0)*sin(t)+(y-y_0)*cos(t).

Figuring out how to "undo" a series of transformations was most challenging. Thanks for the piazza help. I scale first, stored in vars c & d. Then I rotate by using -g_angle and translate and store the result in x & y, which are normalized. I use arctan to figure out the dragged angle, which isn't perfect because, depending on quadrant, the angle needs to be adjusted by -π. My code works, but isn't as robust as it could be (line 257). I'm not sure how to make it robust.

I created the picture. It's supposed to be a person trapped in a box.

Click here for zip file. Mac OS. run.sh will compile my code. square is my exe.

Check in

Square compiled and is moved to the right from default location.