Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8692097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:15:06+00:00 2026-06-13T00:15:06+00:00

Right now I’m rotating an object, lets call it ‘mainBody’ but attached to the

  • 0

Right now I’m rotating an object, lets call it ‘mainBody’ but attached to the mainBody are several attachments and when I rotate my mainBody they are supposed to rotate along as well, but right now they don’t. I’m not using a parent/child system. The main body has an array of it’s attachments and draws them in the mainBody draw function.

The glPopMatrix() from the main body is done after the equipment items are drawn.

I know I managed to do this in the past with pushMatrix(); and popMatrix(); But now it doesn’t seem to work.

I’m using c++, opengl, and glm.

Here is some code that shows you what I have right now:

{

    setupStartModelMatrix(); //<---- Has glPushMatrix();
    setupModelviewMatrix();  //<--- has all the gml stuff
    drawMainBody();

    }

    if(mNumberOfEquipementOwned != 0)

    {
        for(int i = 0; i < mNumberOfEquipementOwned; i++)
        {
            //obj is retrieved with a function 
            obj->render();
        }
    }

    setupEndModelMatrix();  // <--- Has glPopMatrix(); 
}

And the glm code

void GameObject::setupModelviewMatrix()
{
    glm::mat4 Projection = glm::perspective(45.0f, 4.0f / 3.0f, 0.1f, 100.f);

    glm::mat4 Model = glm::scale( glm::mat4(1.0f), glm::vec3(1.0f)); 
    glm::mat4 ViewTranslate = glm::translate( glm::mat4(1.0f), glm::vec3(mPosition.x, mPosition.y, mPosition.z)); 
    glm::mat4 ViewRotateX = glm::rotate( ViewTranslate, mRotation.x, glm::vec3(1.0f, 0.0f, 0.0f));
    glm::mat4 ViewRotateY = glm::rotate( ViewRotateX, mRotation.y, glm::vec3(0.0f, 1.0f, 0.0f));
    glm::mat4 View = glm::rotate( ViewRotateY, mRotation.z, glm::vec3(0.0f, 0.0f, 1.0f)); 

    glm::mat4 MVP = View * Model;

    glUniformMatrix4fv( 0, 1, GL_FALSE, glm::value_ptr(MVP)); 

    glLoadMatrixf(glm::value_ptr(MVP));
}

And the draw equipement code

void Gun::render()
{
    glPushMatrix();
    setupModelviewMatrix();
    mMesh->render();
    glPopMatrix();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T00:15:07+00:00Added an answer on June 13, 2026 at 12:15 am

    Because of Tim I noticed my matrix wasn’t passed trough too the others. When I finally understood what he was saying it’s a easy fix so 100% of the props go to him.

    Now the code for anyone who might need it.

    {
        glm::mat4 startingModel(1.0);
    
        setupStartModelMatrix();
        startingModel = continuedModelvieuwMatrix(startingModel);
        drawMainBody();
        }
    
        if(mNumberOfEquipementOwned != 0)
        {
            for(int i = 0; i < mNumberOfEquipementOwned; i++)
            {
                //obj is retrieved with a function 
                obj->render(startingModel);
            }
        }
    
        setupEndModelMatrix();  // <--- Has glPopMatrix(); 
    }
    

    And the glm code

    glm::mat4 GameObject::continuedModelvieuwMatrix(glm::mat4 startingModel)
    {
        glm::mat4 Model = glm::scale( glm::mat4(1.0f), glm::vec3(1.0f)); 
        glm::mat4 ViewTranslate = glm::translate( startingModel, glm::vec3(mPosition.x, mPosition.y, mPosition.z)); 
        glm::mat4 ViewRotateX = glm::rotate( ViewTranslate, mRotation.x, glm::vec3(1.0f, 0.0f, 0.0f));
        glm::mat4 ViewRotateY = glm::rotate( ViewRotateX, mRotation.y, glm::vec3(0.0f, 1.0f, 0.0f));
        glm::mat4 View = glm::rotate( ViewRotateY, mRotation.z, glm::vec3(0.0f, 0.0f, 1.0f)); 
    
        glm::mat4 MVP = View * Model;
    
        glUniformMatrix4fv( 0, 1, GL_FALSE, glm::value_ptr(MVP)); 
    
        glLoadMatrixf(glm::value_ptr(MVP));
    
        return MVP;
    }
    
    void GameObject::setupStartModelMatrix()
    {
        glMatrixMode(GL_MODELVIEW);
        glLoadIdentity();
    }
    

    And the draw equipement code

    void Gun::render(glm::mat4 startingModel)
    {
        glm::math4 tempModel;
        tempModel = continuedModelvieuwMatrix(startingModel);
        mMesh->render();
    }
    

    And thats about it.
    I’m not 100% sure if this code works as I had to fix it for my self in a different way because of my object construction but this should at least give a good head start for anyone with the same problem.

    Also no glPopMatrix() or glPushMatrix() is required to make this work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Right now I'm using OleDbDataAdapter objDataReader = new OleDbDataAdapter(); objDataReader.SelectCommand = myCommand; objDataReader.Fill(myDataTable); But
Right now, I have two Eclipse projects - they both use Maven 2 for
Right now I have an upload field while uploads files to the server. The
Right now, I have: RewriteRule ^([^/\.]+)?$ index.php?id=$1 [L] to match any username at the
Right now when I run this it keeps clicking on the same button every
Right now, I've just some code which fetches the picture from the URL directly.
Right now I have a script that will get the last five files in
Right now, the label for my Activity has the name of the current Activity.
Right now I have 3 tables: User, Roles, and User_Roles for the many-to-many association.
Right now I have a function, in a class that is used to listen

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.