Selection in 3D Graphics Environments
Christine Albert and Lindsey Press

This week, we began the development process by creating a 3D cube in OpenGL. Below you will see samples of our first working code and an example of what the code should output. We focused specifically on familiarizing ourselves with the new aspects of OpenGL, as well as writing the inital code. In order to create a 3-Dimensional cube, we initialized these global variables:

const GLfloat FOV = 50.0;

const GLfloat FAR = 10.0;

const GLfloat NEAR = 0.1;

const GLfloat aspect = SCREEN_SIZE.x/SCREEN_SIZE.y;

Then, we set the projeciton matrix and the camera matrix so that we could view the object on the screen:

glm::mat4 projection = glm::perspective(FOV, SCREEN_SIZE.x/SCREEN_SIZE.y, NEAR, FAR);

glm::mat4 camera = glm::lookAt(EYE, glm::vec3(0,0,0), glm::vec3(0,1,0));

Although trivial, getting this step correct and fully understanding it is key to the future of our research. We hit a few road blocks with uncooperative software but are now back in full swing. Below is a picture of the cube.

3D Cube!




The following week, we made manual setting changes to the code. To get the projection working, we inserted the following code:

glm::mat4 projection(0.0);

projection[0] = glm::vec4(d/aspect, 0, 0, 0);

projection[1] = glm::vec4(0, d, 0, 0);

projection[2] = glm::vec4(0, 0, ((FAR+NEAR)/(NEAR-FAR)), -1);

projection[3] = glm::vec4(0, 0, ((2*FAR*NEAR)/(NEAR-FAR)), 0);

A bug with the program was eventually determined to be that the program takes radians when using tangent and initially we were using degrees, and once that was changed to be radians the code worked properly and the box appeared as before.


Resources:

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