Modeling

I have a model loaded successfully, but now I want to transform it. Suffice it to say that I know how transforms work and the various transformations that I can do with vectors and matrices, and simply apply them to the model matrix, which is then passed to the vertex shader through a homogeneous variable. But this is my problem:

My model is a class and I also have a scene class where the models are loaded and where all the graphics are merged. If I have a model matrix as a private variable in a Model like so:

class Model
{
public:
    Model();
    ~Model();

    // other functions here

    setPosition(vec3 pos);
    setRotation(vec3 axis, float angle);
    setScale(vec3 factor);

    // getters

    render(GLuint shaderProgram);
    update(GLuint shaderProgram);

private:
    mat4 pModelMatrix;
    vector<Mesh> pMeshes;
};

      

How reasonable is it for the model matrix to be inside the model class; or there should be only ONE model matrix, which is in the scene class, which is then passed uniformly to the vertex shader. My only concern about the latter is that if I do this, then all models will have the same transformations. So if I just want to move one model (which the player would have [yes, that's what is or is - debate!]), Then it would be wise to apply transformations to only one model and therefore to the model matrix. But then, what would the vertex shader say then? I'm still pretty new to OpenGL and it's a little tricky to understand the whole business of how OpenGL deals with transformations with multiple rendered models; I know they serve a purpose like what was described earlier,but is it difficult to implement many model matrices of many models, which are transmitted by only one single matrix.

What the update () function does is take a pModelMatrix and use the glUniform () material to pass the matrix to the vertex shader, which is then multiplied by all other matrices, etc. The reason I am putting glUniform () in the update () function is because during my program I want the position that my model was writing with setPosition (..) then finally update the model as necessary while the program is running,

The vector pMeshes, a long story, just holds all the meshes of the model together and another class loads the mesh with the mesh.

+3


source to share


1 answer


The model / world transform is specific to each mesh / model in your scene. As you mentioned, to convert each model independently, with the matrix for each is apt.



As far as the vertex shader is concerned, you can have the projection representation matrix in uniform and the model matrix in uniform shape, and convert the mesh vertices to clip space. Then, for the next model, just change the model matrix to this matrix matrix and repeat.

+3


source







All Articles