#problem in creating a camera in opengl

5 messages · Page 1 of 1 (latest)

fleet egret
#
class Camera
{
   public:
    Camera() = default;
    glm::vec3 cameraPos = glm::vec3(0.0f, 0.0f, 0.0f);
    glm::vec3 cameraRot = glm::vec3(0.0f, 0.0f, 0.0f);
    float FOV = 100.0f;
    float zFAR = 100.0f;
    float zNEAR = 0.01f;
    float aspect = 1.0f;
    glm::mat4 projection;
    glm::mat4 view;

    void update()
    {
        glm::vec3 cameraFront;
        cameraFront.x = cos(glm::radians(cameraRot.x)) * cos(glm::radians(cameraRot.y));
        cameraFront.y = sin(glm::radians(cameraRot.x));
        cameraFront.z = cos(glm::radians(cameraRot.x)) * sin(glm::radians(cameraRot.y));
        cameraFront = glm::normalize(cameraFront);

        glm::vec3 worldUp = glm::vec3(0.0f, 1.0f, 0.0f);
        glm::mat4 rollMatrix = glm::rotate(glm::mat4(1.0f), cameraRot.z, cameraFront);
        glm::vec3 cameraUp = glm::normalize(glm::vec3(rollMatrix * glm::vec4(worldUp, 0.0f)));

        projection = glm::perspective(glm::radians(FOV), aspect, zNEAR, zFAR);
        view = glm::lookAt(cameraPos, cameraPos + cameraFront, cameraUp);
    }

    void update(int width, int height)
    {
        aspect = (float)width / (float)height;
        update();
    }

    void cameraMatrix(Shader& shader)
    {
        glm::mat4 camMatrix;

        camMatrix = projection * view;
        shader.bind();
        shader.setMat4("camMat", camMatrix);
        shader.unbind();
    }
};

any problem with this?
why my mesh disapeared when i multilple the gl_position with the camMat

small orchidBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

fleet egret
#
#version 330 core

layout(location = 0) in vec3 aPos;     
layout(location = 1) in vec3 aNormal;   
layout(location = 2) in vec3 aColor;
layout(location = 3) in vec2 aTexCoord;

out vec3 color;
uniform mat4 model;
uniform mat4 camMat;

void main(){
    gl_Position = camMat * model * vec4(aPos, 1.0f);
    color = aColor;
}

my vertex shader btw

patent berry
#

I think you should also apply radians to cameraRot.z in the rollMatrix multiplication.dont_know_man

fleet egret