Selection in 3D Graphics Environments
Christine Albert and Lindsey Press

After discovering how to correctly create, translate, and scale our cube in OpenGL, this week we duplicated this code to create three additional cubes in different locations of different sizes. To change the location, we changed the translation coordinates and to change the size we changed the scale coordinates. Having the ability to create multiple cubes is essential to our research becasue the selection of objects is more difficult in highly populated screens. Our next goal will be to turn the individual model calls into a model array which can be looped through so that we can exponentially increase the amount of traffic on the screen. Here is the code for our four cubes:

// set the "model" uniform in the vertex shader

//cube1

glm::mat4 model1(1.0);

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

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

//cube 2

glm::mat4 model2(1.0);

model2 = glm::translate(glm::mat4(), glm::vec3(2, 2, 0));

model2 = model2*glm::scale(glm::mat4(), glm::vec3(1, 1, 1));

//cube3

glm::mat4 model3(1.0);

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

model3 = model3*glm::scale(glm::mat4(), glm::vec3(3, 3, 1));

//cube4

glm::mat4 model4(1.0);

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

model4 = model4*glm::scale(glm::mat4(), glm::vec3(2, 2, 1));

// bind the VAO (the triangle)

glBindVertexArray(gVAO);

// draw the VAO

//cube1

gProgram->setUniform("model", model1);

glDrawArrays(GL_TRIANGLES, 0, 6 * 2 * 3);

//cube2

gProgram->setUniform("model", model2);

glDrawArrays(GL_TRIANGLES, 0, 6 * 2 * 3);

//cube3

gProgram->setUniform("model", model3);

glDrawArrays(GL_TRIANGLES, 0, 6 * 2 * 3);

//cube4

gProgram->setUniform("model", model4);

glDrawArrays(GL_TRIANGLES, 0, 6 * 2 * 3);

// unbind the VAO and the program

glBindVertexArray(0);

gProgram->stopUsing();

// swap the display buffers (displays what was just drawn)

glfwSwapBuffers();

}

The resulting graphics scene is:

Four Cubes



Resources:

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