opengl-tutorials/ogl

Tutorial 4 projection issues

Closed this issue · 1 comments

I'm afraid my results for tutorial 4 are providing a box, but not a very cubic box:

Screen Shot 2022-11-13 at 1 29 55 AM

I'm using the same matrix transformations as the tutorial, except with my screen width and hight instead of 4 and 3. Using 4 and 3 doesn't make a difference however.

glm::mat4 generate_MVP() {
    glm::mat4 Projection = glm::perspective(glm::radians(45.0f), float(SCREEN_WIDTH/SCREEN_HEIGHT), 0.1f, 100.0f);
    // Or, for an ortho camera :
    //glm::mat4 Projection = glm::ortho(-10.0f,10.0f,-10.0f,10.0f,0.0f,100.0f); // In world coordinates
    
    // Camera matrix
    glm::mat4 View       = glm::lookAt(
                                glm::vec3(4,3,-3), // Camera is at (4,3,3), in World Space
                                glm::vec3(0,0,0), // and looks at the origin
                                glm::vec3(0,1,0)  // Head is up (set to 0,-1,0 to look upside-down)
                           );
    // Model matrix : an identity matrix (model will be at the origin)
    glm::mat4 Model      = glm::mat4(1.0f);

    // Our ModelViewProjection : multiplication of our 3 matrices
    return Projection * View * Model; // Remember, matrix multiplication is the other way around
}

I fixed it. I just had to typecast my integers before dividing.


glm::mat4 generate_multimatrix() {
    glm::mat4 Projection = glm::perspective(glm::radians(45.0f), float(SCREEN_WIDTH)/float(SCREEN_HEIGHT), 0.1f, 100.0f);
    // Or, for an ortho camera :
    //glm::mat4 Projection = glm::ortho(-10.0f,10.0f,-10.0f,10.0f,0.0f,100.0f); // In world coordinates
    
    // Camera matrix
    glm::mat4 View       = glm::lookAt(
                                glm::vec3(4,3,3), // Camera is at (4,3,3), in World Space
                                glm::vec3(0,0,0), // and looks at the origin
                                glm::vec3(0,1,0)  // Head is up (set to 0,-1,0 to look upside-down)
                           );
    // Model matrix : an identity matrix (model will be at the origin)
    glm::mat4 Model      = glm::mat4(1.0f);
    printf("Completed generate_multimatrix\n");

    // Our ModelViewProjection : multiplication of our 3 matrices
    return Projection * View * Model; // Remember, matrix multiplication is the other way around
}

Screen Shot 2022-11-13 at 9 36 32 PM