# 4.1.6 Set the View and Projection Matrices

## Create View and Projection matrix&#x20;

in the main function after initShader()

```cpp
    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

{% embed url="<https://thedarkroom.com/focal-length/?srsltid=AfmBOoreT7CqtVIyukj9r6wjea9uqLVNQxq-IcatABGedbXopSbQCahZ>" %}

<figure><img src="https://3464970502-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3JUKGJZ67JX02QZdPhsy%2Fuploads%2FReGwwo0Pr8l3ov9UNqVe%2FCheltenham2014-023-968.webp?alt=media&#x26;token=e81f7ac7-a64f-4e1a-b088-fcf1b9111a18" alt=""><figcaption></figcaption></figure>

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.

```cpp
    while (!glfwWindowShouldClose(window))
    {
        glfwPollEvents();

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

        // !!!! example of calling a Node::draw(), you can also call a Mesh::draw()
        scene->draw(matModelRoot, matView, matProj);
        
        glfwSwapBuffers(window);
    }
```

## Result

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

<figure><img src="https://3464970502-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F3JUKGJZ67JX02QZdPhsy%2Fuploads%2FyCXkBc3JwMVWuv6IPGUD%2Fimage.png?alt=media&#x26;token=f75c4e59-929e-49ab-b20b-11974ad644a9" alt=""><figcaption></figcaption></figure>
