Rotating child object in OpenGL c++OpenGL translation before and after a rotationWhat are the differences between a pointer variable and a reference variable in C++?How can I profile C++ code running on Linux?The Definitive C++ Book Guide and ListActivity restart on rotation AndroidWhat is the “-->” operator in C++?Rotate and translate object in local and global orientation using glmOpenGL Rotation Around a Point Using GLMMy 3d OpenGL object rotates around the world origin, not local-space origin. What am I doing wrong or misunderstanding?Rotate object towards 3D pointcursor orientation openGL c++

How do I run a game when my PCs have different approaches to combat?

What to do when you reach a conclusion and find out later on that someone else already did?

What exactly makes a General Products hull nearly indestructible?

Why are there not any MRI machines available in Interstellar?

Is there a way to shorten this while condition?

This message is flooding my syslog, how to find where it comes from?

How much damage does a magic stone cause when hurled from a sling?

If my business card says 〇〇さん, does that mean I'm referring to myself with an honourific?

What is the difference between $path and $PATH (lowercase versus uppercase) with zsh?

What does Kasparov mean here?

How to write a sincerely religious protagonist without preaching or affirming or judging their worldview?

How do campaign rallies gain candidates votes?

Area of parallelogram = Area of square. Shear transform

Where is this photo of a group of hikers taken? Is it really in the Ural?

401(k) investment after being fired. Do I own it?

Passing lines from the text file of a list of files to or as arguments

Should I leave my PhD after 3 years with a Masters?

kids pooling money for Lego League and taxes

How do professional electronic musicians/sound engineers combat listening fatigue?

Will LSST make a significant increase in the rate of astronomical event alerts?

High income, sudden windfall

Where to place an artificial gland in the human body?

Terence Tao - type books in other fields?

Are glider winch launches rarer in the USA than in the rest of the world? Why?



Rotating child object in OpenGL c++


OpenGL translation before and after a rotationWhat are the differences between a pointer variable and a reference variable in C++?How can I profile C++ code running on Linux?The Definitive C++ Book Guide and ListActivity restart on rotation AndroidWhat is the “-->” operator in C++?Rotate and translate object in local and global orientation using glmOpenGL Rotation Around a Point Using GLMMy 3d OpenGL object rotates around the world origin, not local-space origin. What am I doing wrong or misunderstanding?Rotate object towards 3D pointcursor orientation openGL c++






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








3















I'm adding a robot with multiple DoG to my OpenGL application(later i want to implement inverse kinematics for this robot) and i need to move objects that are "connected" together.



So far i added 3 STL object into scene and it looks like this



There is base, joint1 and joint2.



Base is stationary, joint1 and joint2 are for now rotating around Z axis based on keyboard input, but they both just rotate around theirs origin point, which is fine for joint1, but for joint2 i need them to be connected and translate accordingly.



Here is the output after rotation.



For object positioning and rotating i'm using regular MVP matrix and glm.



joint1M = glm::translate(joint1M, glm::vec3(-50.0f, -10.4f, 0.0f));
joint1M = glm::rotate(joint1M, glm::radians(rotation), glm::vec3(0.0f, 1.0f, 0.0f));


joint2M = glm::translate(joint2M, glm::vec3(-50.0f, 2.85f, 0.0f));
joint2M = glm::rotate(joint2M, glm::radians(rotation), glm::vec3(0.0f, 1.0f, 0.0f));


Is there any way to create something like child-parent Unity relationship in OpenGL? Or should i somehow change the position of joint2 based on joint1 rotation?










share|improve this question



















  • 1





    I suggest you reading about scene graphs and hierarchical trees. In short it could help you build parent-child relationship. Whenever a parent changes on the scene its position children are transformed accordingly

    – Mateusz Stompór
    Mar 26 at 16:14






  • 1





    The question OpenGL translation before and after a rotation is about legacy OpenGL (fixed function pipeline matrix stack), but it shows the principle.

    – Rabbid76
    Mar 26 at 16:34


















3















I'm adding a robot with multiple DoG to my OpenGL application(later i want to implement inverse kinematics for this robot) and i need to move objects that are "connected" together.



So far i added 3 STL object into scene and it looks like this



There is base, joint1 and joint2.



Base is stationary, joint1 and joint2 are for now rotating around Z axis based on keyboard input, but they both just rotate around theirs origin point, which is fine for joint1, but for joint2 i need them to be connected and translate accordingly.



Here is the output after rotation.



For object positioning and rotating i'm using regular MVP matrix and glm.



joint1M = glm::translate(joint1M, glm::vec3(-50.0f, -10.4f, 0.0f));
joint1M = glm::rotate(joint1M, glm::radians(rotation), glm::vec3(0.0f, 1.0f, 0.0f));


joint2M = glm::translate(joint2M, glm::vec3(-50.0f, 2.85f, 0.0f));
joint2M = glm::rotate(joint2M, glm::radians(rotation), glm::vec3(0.0f, 1.0f, 0.0f));


Is there any way to create something like child-parent Unity relationship in OpenGL? Or should i somehow change the position of joint2 based on joint1 rotation?










share|improve this question



















  • 1





    I suggest you reading about scene graphs and hierarchical trees. In short it could help you build parent-child relationship. Whenever a parent changes on the scene its position children are transformed accordingly

    – Mateusz Stompór
    Mar 26 at 16:14






  • 1





    The question OpenGL translation before and after a rotation is about legacy OpenGL (fixed function pipeline matrix stack), but it shows the principle.

    – Rabbid76
    Mar 26 at 16:34














3












3








3








I'm adding a robot with multiple DoG to my OpenGL application(later i want to implement inverse kinematics for this robot) and i need to move objects that are "connected" together.



So far i added 3 STL object into scene and it looks like this



There is base, joint1 and joint2.



Base is stationary, joint1 and joint2 are for now rotating around Z axis based on keyboard input, but they both just rotate around theirs origin point, which is fine for joint1, but for joint2 i need them to be connected and translate accordingly.



Here is the output after rotation.



For object positioning and rotating i'm using regular MVP matrix and glm.



joint1M = glm::translate(joint1M, glm::vec3(-50.0f, -10.4f, 0.0f));
joint1M = glm::rotate(joint1M, glm::radians(rotation), glm::vec3(0.0f, 1.0f, 0.0f));


joint2M = glm::translate(joint2M, glm::vec3(-50.0f, 2.85f, 0.0f));
joint2M = glm::rotate(joint2M, glm::radians(rotation), glm::vec3(0.0f, 1.0f, 0.0f));


Is there any way to create something like child-parent Unity relationship in OpenGL? Or should i somehow change the position of joint2 based on joint1 rotation?










share|improve this question
















I'm adding a robot with multiple DoG to my OpenGL application(later i want to implement inverse kinematics for this robot) and i need to move objects that are "connected" together.



So far i added 3 STL object into scene and it looks like this



There is base, joint1 and joint2.



Base is stationary, joint1 and joint2 are for now rotating around Z axis based on keyboard input, but they both just rotate around theirs origin point, which is fine for joint1, but for joint2 i need them to be connected and translate accordingly.



Here is the output after rotation.



For object positioning and rotating i'm using regular MVP matrix and glm.



joint1M = glm::translate(joint1M, glm::vec3(-50.0f, -10.4f, 0.0f));
joint1M = glm::rotate(joint1M, glm::radians(rotation), glm::vec3(0.0f, 1.0f, 0.0f));


joint2M = glm::translate(joint2M, glm::vec3(-50.0f, 2.85f, 0.0f));
joint2M = glm::rotate(joint2M, glm::radians(rotation), glm::vec3(0.0f, 1.0f, 0.0f));


Is there any way to create something like child-parent Unity relationship in OpenGL? Or should i somehow change the position of joint2 based on joint1 rotation?







c++ opengl rotation glm-math robot






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 26 at 16:25









genpfault

43.2k9 gold badges57 silver badges102 bronze badges




43.2k9 gold badges57 silver badges102 bronze badges










asked Mar 26 at 16:10









merethmereth

13614 bronze badges




13614 bronze badges







  • 1





    I suggest you reading about scene graphs and hierarchical trees. In short it could help you build parent-child relationship. Whenever a parent changes on the scene its position children are transformed accordingly

    – Mateusz Stompór
    Mar 26 at 16:14






  • 1





    The question OpenGL translation before and after a rotation is about legacy OpenGL (fixed function pipeline matrix stack), but it shows the principle.

    – Rabbid76
    Mar 26 at 16:34













  • 1





    I suggest you reading about scene graphs and hierarchical trees. In short it could help you build parent-child relationship. Whenever a parent changes on the scene its position children are transformed accordingly

    – Mateusz Stompór
    Mar 26 at 16:14






  • 1





    The question OpenGL translation before and after a rotation is about legacy OpenGL (fixed function pipeline matrix stack), but it shows the principle.

    – Rabbid76
    Mar 26 at 16:34








1




1





I suggest you reading about scene graphs and hierarchical trees. In short it could help you build parent-child relationship. Whenever a parent changes on the scene its position children are transformed accordingly

– Mateusz Stompór
Mar 26 at 16:14





I suggest you reading about scene graphs and hierarchical trees. In short it could help you build parent-child relationship. Whenever a parent changes on the scene its position children are transformed accordingly

– Mateusz Stompór
Mar 26 at 16:14




1




1





The question OpenGL translation before and after a rotation is about legacy OpenGL (fixed function pipeline matrix stack), but it shows the principle.

– Rabbid76
Mar 26 at 16:34






The question OpenGL translation before and after a rotation is about legacy OpenGL (fixed function pipeline matrix stack), but it shows the principle.

– Rabbid76
Mar 26 at 16:34













1 Answer
1






active

oldest

votes


















2














Thanks to the comments and more googling i managed to get this working like this:



joint1 stays the same:



joint1M = glm::translate(joint1M, glm::vec3(-50.0f, -10.4f, 0.0f));
joint1M = glm::rotate(joint1M, glm::radians(rotation), glm::vec3(0.0f, 1.0f, 0.0f));


joint2 moves to the position of joint1, rotates, moves where it's supposed to be



joint2M = glm::translate(joint2M, glm::vec3(-50.0f, -10.4f, 0.0f));
joint2M = glm::rotate(joint2M, glm::radians(rotation), glm::vec3(0.0f, 1.0f, 0.0f));
joint2M = glm::translate(joint2M, glm::vec3(0.0f, 13.25f, 0.0f));





share|improve this answer






















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55361620%2frotating-child-object-in-opengl-c%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    Thanks to the comments and more googling i managed to get this working like this:



    joint1 stays the same:



    joint1M = glm::translate(joint1M, glm::vec3(-50.0f, -10.4f, 0.0f));
    joint1M = glm::rotate(joint1M, glm::radians(rotation), glm::vec3(0.0f, 1.0f, 0.0f));


    joint2 moves to the position of joint1, rotates, moves where it's supposed to be



    joint2M = glm::translate(joint2M, glm::vec3(-50.0f, -10.4f, 0.0f));
    joint2M = glm::rotate(joint2M, glm::radians(rotation), glm::vec3(0.0f, 1.0f, 0.0f));
    joint2M = glm::translate(joint2M, glm::vec3(0.0f, 13.25f, 0.0f));





    share|improve this answer



























      2














      Thanks to the comments and more googling i managed to get this working like this:



      joint1 stays the same:



      joint1M = glm::translate(joint1M, glm::vec3(-50.0f, -10.4f, 0.0f));
      joint1M = glm::rotate(joint1M, glm::radians(rotation), glm::vec3(0.0f, 1.0f, 0.0f));


      joint2 moves to the position of joint1, rotates, moves where it's supposed to be



      joint2M = glm::translate(joint2M, glm::vec3(-50.0f, -10.4f, 0.0f));
      joint2M = glm::rotate(joint2M, glm::radians(rotation), glm::vec3(0.0f, 1.0f, 0.0f));
      joint2M = glm::translate(joint2M, glm::vec3(0.0f, 13.25f, 0.0f));





      share|improve this answer

























        2












        2








        2







        Thanks to the comments and more googling i managed to get this working like this:



        joint1 stays the same:



        joint1M = glm::translate(joint1M, glm::vec3(-50.0f, -10.4f, 0.0f));
        joint1M = glm::rotate(joint1M, glm::radians(rotation), glm::vec3(0.0f, 1.0f, 0.0f));


        joint2 moves to the position of joint1, rotates, moves where it's supposed to be



        joint2M = glm::translate(joint2M, glm::vec3(-50.0f, -10.4f, 0.0f));
        joint2M = glm::rotate(joint2M, glm::radians(rotation), glm::vec3(0.0f, 1.0f, 0.0f));
        joint2M = glm::translate(joint2M, glm::vec3(0.0f, 13.25f, 0.0f));





        share|improve this answer













        Thanks to the comments and more googling i managed to get this working like this:



        joint1 stays the same:



        joint1M = glm::translate(joint1M, glm::vec3(-50.0f, -10.4f, 0.0f));
        joint1M = glm::rotate(joint1M, glm::radians(rotation), glm::vec3(0.0f, 1.0f, 0.0f));


        joint2 moves to the position of joint1, rotates, moves where it's supposed to be



        joint2M = glm::translate(joint2M, glm::vec3(-50.0f, -10.4f, 0.0f));
        joint2M = glm::rotate(joint2M, glm::radians(rotation), glm::vec3(0.0f, 1.0f, 0.0f));
        joint2M = glm::translate(joint2M, glm::vec3(0.0f, 13.25f, 0.0f));






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 26 at 17:22









        merethmereth

        13614 bronze badges




        13614 bronze badges


















            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55361620%2frotating-child-object-in-opengl-c%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript