Assignment 4: Projected Cube Solution

$30.00

Description

In this assignment, you’ll explore different types of projection. Please download ‘ProjectedCube.cpp’ and the associated shader files from ‘Assignment 4’ section of the course module page.

Now when you run the program, you’ll find the front face of a cube centered at origin aligned with the principal axes. You can switch between orthographic (default) and perspective views by pressing ‘o’ from the keyboard. It will toggle the boolean variable ‘orthographic’. As the front face of the cube is drawn near the front plane, you won’t see much difference between the two modes at this stage. Now, as you press ‘s’ button from the keyboard, you’ll see the wire-frame model of the cube. ‘s’ button toggles the boolean variable ‘show_line’ by switching between ‘glPolygonMode (GL_FRONT_AND_BACK, GL_FILL)’ and glPolygonMode (GL_FRONT_AND_BACK, GL_LINE)’. Now, toggling between orthographic and perspective projection will be more meaningful. You’ll find that the back face of the cube looks much smaller in perspective mode. Now, if you press ‘c’ from the keyboard, you’ll find that the cube looks similar in both orthographic and perspective modes when wire-frame model is displayed. ‘c’ button switches between ‘glEnable(GL_CULL_FACE)’ and ‘glDisable(GL_CULL_FACE)’ by toggling the boolean variable ‘cull_face’. So when enabled in wire-frame model, any thing behind the front face won’t be visible and both views will be the same. The following picture clarifies what happens when you toggle ‘o’, ‘s’ and ‘c’ buttons from the keyboard.

lu1584vzgpa4 tmp 262b3fd85219d677

orthographic = true;

show_line = true;

cull_face = false;

orthographic = false;

show_line = true;

cull_face = false;

orthographic = true;

show_line = true;

cull_face = true;

orthographic = false;

show_line = true;

cull_face = true;

Figure 1: Interaction between different keyboard buttons and the corresponding outputs.

Now, if you look at the function ‘keyboard (unsigned char key, int x, int y)’, you’ll find there are different cases: ‘i’, ‘d’, ‘t’, ‘1’, ‘2’ and ‘3’. These cases have not yet implemented. You’ve to implement different views when those keyboard buttons will be pressed. Here ‘i’ stands for ‘isometric’ view, ‘d’ for ‘dimetric’ view and ‘t’ for ‘trimetric’ view. As you already know, these are different types of orthographic (axonometric) projection. Similarly,’1’, ‘2’ and ‘3’ stand for ‘one point’, ‘two point’ and ‘three point’ perspective view respectively

Let’s take a look at different types of orthographic (axonometric) projection first. In axonometric projection, an object is aligned along the principal axes. Different types of axonometric projections depend on the camera/ eye direction ‘n (nx, ny, nz)’ with respect to the principal axes x, y and z. In an isometric view, the components of the eye

vector are equal to each other. Hence the view plane makes equal interception along the principal axes and the angles between the projections of the principal axes are equal. Similarly, in ‘dimetric’ view, any two components of the eye vector are equal to each other. In ‘trimetric’ view, each component of the eye vector needs to be different. So there can be a number of outputs in dimetric and trimetric projections.

(a)

(b)

(c)

lu1584vzgpa4 tmp d189d75fe58c940a

Figure 2: (a) An isometric, (b) a dimetric and (c) a trimetric view of a cube.

Now let’s turn to different types of perspective projections. Let’s start with one point perspective. The default perspective mode of the cube in the program already shows its one point perspective view. In one point perspective view, the sides of the cube will converge along one principal axis. In two point perspective, the convergence will take place along any two of the principal axes. Hence any two components of the eye vector should be non-zero. Similarly, in three point perspective, convergence will happen along all three principal axes.

lu1584vzgpa4 tmp 68612bfbfd130e58

(a) (b)

Figure 3: A (a) two point and (b) three point perspective view.

Now, you’ve to fill the different cases in ‘keyboard’ function so that pressing different buttons can produce the corresponding projected views as discussed above.

Submission: Submit the assignment in a zipped file via canvas. Name the file as Firstname_Lastname_4.zip (your first name and last name). Deadline is Wednesday, February 22, 11:59 pm. No late submission will be accepted.

This assignment carries a weightage of 10% of this course.