mercredi 2 septembre 2020

Why is my quad becoming large while looking up and small when looking down?

I'm having bit of an issue with rendering a quad onto the screen.

I am rendering a quad at these coordinates : 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f };

And then translating it to another position using glm::translate and I set that as the model matrix. I set the uniform view matrix to the view matrix of the camera (after removing the rotation component) and I set the uniform projection matrix to the camera's projection matrix.

Only thing is that when I look a little up, the square looks like it's really close to the player and when I look down it goes really far. Is it something to do with the view or projection matrix? How do I get around it?` I'm trying to make a particle system like the one from thin matrix' tutorial

My camera code is identical to the camera class on learnopengl.com I would be very thankful if anyone could help me out

Here is the particle class code :

ParticleRenderer::ParticleRenderer()
        {
            m_ParticleShader.CreateShaderProgramFromFile("Shaders/ParticleVert.glsl", "Shaders/ParticleFrag.glsl");
            m_ParticleShader.CompileShaders();
        }

        void ParticleRenderer::RenderParticle(const Particle& particle, FPSCamera* camera)
        {
            GLuint indices[6] = { 0,1,2,1,2,3 };
            GLfloat vertices[] = { 
                0.0f, 1.0f, 1.0f,
                0.0f, 0.0f, 1.0f,
                1.0f, 1.0f, 1.0f,
                1.0f, 0.0f, 1.0f };

            GLClasses::VertexBuffer VBO(GL_ARRAY_BUFFER);
            GLClasses::VertexArray VAO;
            GLClasses::IndexBuffer IBO;
            VAO.Bind();
            VBO.Bind();
            IBO.Bind();
            VBO.VertexAttribPointer(0, 3, GL_FLOAT, 0, sizeof(GLfloat) * 3, 0);
            VBO.BufferData(sizeof(vertices), vertices, GL_STATIC_DRAW);
            IBO.BufferData(sizeof(indices), indices, GL_STATIC_DRAW);
            VAO.Unbind();

            glm::mat4 view_matrix = camera->GetViewMatrix();
            view_matrix[0][0] = 1.0f;
            view_matrix[0][1] = 0.0f;
            view_matrix[0][2] = 0.0f;
            view_matrix[1][0] = 0.0f;
            view_matrix[1][1] = 1.0f;
            view_matrix[1][2] = 0.0f;
            view_matrix[2][0] = 0.0f;
            view_matrix[2][1] = 0.0f;
            view_matrix[2][2] = 1.0f;

            glm::mat4 proj_matrix = camera->GetProjectionMatrix();
            glm::mat4 model_matrix = glm::translate(glm::mat4(1.0f), glm::vec3(particle.p_Position));

            m_ParticleShader.Use();
            m_ParticleShader.SetMatrix4("u_ViewMatrix", view_matrix);
            m_ParticleShader.SetMatrix4("u_ProjectionMatrix", proj_matrix); 
            m_ParticleShader.SetMatrix4("u_ModelMatrix", model_matrix);
            VAO.Bind();
            DebugGLFunction(glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0));
            VAO.Unbind();
        }

The position is constant. It does not change over time.

Shaders :

Vertex Shader :

#version 330 core

layout (location = 0) in vec3 a_Position;

uniform mat4 u_ModelMatrix;
uniform mat4 u_ViewMatrix;
uniform mat4 u_ProjectionMatrix;

void main()
{
    gl_Position = u_ProjectionMatrix * u_ViewMatrix * u_ModelMatrix * vec4(a_Position, 1.0f);
}     

Fragment Shader :

#version 330 core

out vec4 o_Color;

void main()
{
    o_Color = vec4(1.0f, 1.0f, 1.0f, 1.0f);
}

Images : https://i.imgur.com/YCtrESS.png https://i.imgur.com/Iv9XhJs.jpeg

Camera code : H File : https://pastebin.com/6HqeZb2S

CPP File : https://pastebin.com/m0nAqUVb

Aucun commentaire:

Enregistrer un commentaire