4.1.6 Set the View and Projection Matrices

in main.cpp

Create View and Projection matrix

in the main function after initShader()

    initShader( "shaders/colour.vert", "shaders/colour.frag");

    // you are expected to add lines similar to the two lines to create the view and projection matrix

    // set the eye at (0, 0, 5), looking at the centre of the world
    // try to change the eye position
    matView = glm::lookAt(glm::vec3(0, 0, 5), glm::vec3(0, 0, 0), glm::vec3(0, 1, 0)); 
    // set the Y field of view angle to 60 degrees, width/height ratio to 1.0, and a near plane of 3.5, far plane of 6.5
    // try to play with the FoV
    matProj = glm::perspective(glm::radians(60.0f), 1.0f, 3.5f, 6.5f);

Choosing FoVs

Source: https://www.thephotovideoguy.com/blog/focal-length-and-angle-of-view

Call draw() with view and projection matrix

in the main loop, revise the calling of scene->draw() to add the view and projection matrix.

If you have implemented the scene graph, you are going to call the draw() of a root Node object, otherwise you are going to call the draw() of a Mesh object.

Result

Note the change of the teapot compared to the previous orthographics projection.

Last updated