OpenGL Loading In Multiple Models

  • meiyee
    Likes 0

    Problem Description

    Sorry for so many questions!

     

    I have finished the skybox tutorial, and I am now wondering how to load in multiple models, and not have them affected by the camera object – this is surely done by changing the model matrix or something, but I’m not entirely sure how to implement in. Essentially, I have a main model that I want to be affected by the keyboard input, but these two other models I am loading in are to be static and unmoveable. How do I do this?

     

    At the moment, this is the code within my while loop, discluding the clear colour set-up, etc. I want the planet and the probe to be immoveable. 

    shader.Use();

            

            glm::mat4 view = camera.GetViewMatrix( );

            glUniformMatrix4fv( glGetUniformLocation( shader.Program, "projection" ), 1, GL_FALSE, glm::value_ptr(projection));

            glUniformMatrix4fv( glGetUniformLocation( shader.Program, "view" ), 1, GL_FALSE, glm::value_ptr(view));

            

            glm::mat4 model;

            model = glm::translate( model, glm::vec3( 0.0f, 0.0f, -5.0f ) ); //start slightly below origin

            //model = glm::translate( model, glm::vec3( 0.0f, (GLfloat)glfwGetTime() * 0.75f, 0.0f ) ); // moves itself up slowly

            //model = glm::rotate( model, (GLfloat)glfwGetTime() * -0.5f, glm::vec3(0.0f, 1.0f, 0.0f) ); // spins

            glUniformMatrix4fv( glGetUniformLocation( shader.Program, "model" ), 1, GL_FALSE, glm::value_ptr(model));

            ship.Draw(shader);

     

     

            model = glm::translate(model, glm::vec3(-5.0f, 10.0f, -10.0f ));

            model = glm::scale(model, glm::vec3(0.2f, 0.2f, 0.2f));

            glUniformMatrix4fv(glGetUniformLocation(shader.Program, "model"), 1, GL_FALSE, glm::value_ptr(model));

            probe.Draw(shader);

            

            model = glm::translate(model, glm::vec3(105.0f, 10.0f, -5.0f ));

            model = glm::scale(model, glm::vec3(1.5f, 1.5f, 1.5f));

            glUniformMatrix4fv(glGetUniformLocation(shader.Program, "model"), 1, GL_FALSE, glm::value_ptr(model));

            planet.Draw(shader);

           

            glDepthFunc(GL_LEQUAL);

            skyboxShader.Use();

            view = glm::mat4(glm::mat3(camera.GetViewMatrix()));

            glUniformMatrix4fv(glGetUniformLocation(skyboxShader.Program, "view"), 1, GL_FALSE, glm::value_ptr(view));

            glUniformMatrix4fv(glGetUniformLocation(skyboxShader.Program, "projection"), 1, GL_FALSE, glm::value_ptr(projection));

            

            glBindVertexArray(sbVAO);

            glBindTexture(GL_TEXTURE_CUBE_MAP, skyboxTex);

            glDrawArrays(GL_TRIANGLES, 0, 36);

            glBindVertexArray(0);

            glDepthFunc(GL_LESS);

            

            

            

            glfwSwapBuffers(window);

     

    Thanks in advance.

  • Sonar Systems admin
    Likes 0

    Load in the objects and display them before the transformations, the ones that shouldn’t move.

  • meiyee
    Likes 0

    So I tried that and they still move along with my main model. I also do need to perform some transformations on them. Surely I need to define a new model matrix or something? But how do I do that?

  • Sonar Systems admin
    Likes 0

    Are you using the same model matrix for everything?

Login to reply