Christine Albert and Lindsey Press

Continuing on from last week's code improvements, we made many improvements to this week's code. The first thing that we did was adjust the lookat call from week 8 to contain variable parameters rather than set parameters. To do this, we added the following global variables:

const glm::vec3 AT(0.0, 0.0, 0.0);

const glm::vec3 UP(0.0, 1.0, 0.0);

Then, we set the camera matrix so that it uses the AT and UP parameters:

glm::mat4 camera = glm::lookAt(EYE, AT, UP);

We also worked on translating and scaling the cube so that it is located in a different position on the screen. In order to do this, we added "model" code into the Render method. Because our screen is 20 units high and 20 units wide, we were able to move the cube into the upper right corner by translating the cube 5 units to the right and 5 units up, since the camera is focused on the center of the screen. Scaling the cube determines it's size, so the units (.5, .5 ,1) will give us a relatively small cube. Below is the model code for translating and scaling the cube:

glm::mat4 model(1.0);

model = glm::translate(glm::mat4(), glm::vec3(5, 5, 0));

model = model*glm::scale(glm::mat4(), glm::vec3(.5, .5, 1));

Lastly, we edited the color of our cube to be multicolored. The way that we did this was by allowing the vertex shader to pass the fragment shader, which passes one RGB triplet to the object per vertex, causing a rainbow-like display on the cube. Below is the code for our vertex-shader and fragment-shader that led us to a multicolored cube:

Vertex Shader:

in vec3 vert;

out vec4 vertColor;

vertColor = vec4(vert, 1.0);

Fragment Shader:

in vec4 vertColor;

out vec4 finalColor;

finalColor = vertColor;

By doing these few steps, the resulting cube is:

Resources: http://www.ntu.edu.sg/home/ehchua/programming/opengl/cg_basicstheory.html