How to use Analogue Sticks (joystick) output values to rotate an object using transform matrix?












-2














Given that analog stick outputs values



float xaxisval = controller->left_stick_x_axis(); //-1 is left, 1 is right
float yaxisval = controller->left_stick_y_axis(); //-1 is up, 1 is down


Values go from 0 to 1 with which can be used for sensitivity.



I'm moving the character in the direction of the joystick in a 3D environment the same way you would in a game like Diablo. I'm adding and retracting these values from X and Z position to move him. But the character is always facing the same dierection.
How can I use these values and convert them into degrees?



xaxisval += controller->left_stick_x_axis() /100;
yaxisval += controller->left_stick_y_axis() /100;
distAdjust.SetTranslation(Vector4(xaxisval, 0, yaxisval));

rotateAdjust.RotationX(rotateDegrees);

player_->set_transform(player_transform *distAdjust *rotateAdjust)


Problem I have is the movement only works with fixed rotation, if I rotate the object then it moves into a different direction.










share|improve this question
























  • Are you trying to calculate an angle from your x/y axis values? If so, then atan2 from <math.h> can do that. Check out the example at cplusplus.com/reference/cmath/atan2
    – Blaze
    Nov 23 '18 at 14:57












  • Please be more specific about what kind of movement you want. I assume this is 2D?
    – Nico Schertler
    Nov 23 '18 at 15:00










  • @Nico No, this is a lovked perspective game, 3D environment where I want to move the player character around like you would in diablo. Using just the joystick.
    – reverse coding guru
    Nov 23 '18 at 15:04










  • So, that would mean - the horizontal axis of the joystick makes your character rotate around its vertical axis and the vertical axis of the joystick makes your player move forward/backward?
    – Nico Schertler
    Nov 23 '18 at 15:07
















-2














Given that analog stick outputs values



float xaxisval = controller->left_stick_x_axis(); //-1 is left, 1 is right
float yaxisval = controller->left_stick_y_axis(); //-1 is up, 1 is down


Values go from 0 to 1 with which can be used for sensitivity.



I'm moving the character in the direction of the joystick in a 3D environment the same way you would in a game like Diablo. I'm adding and retracting these values from X and Z position to move him. But the character is always facing the same dierection.
How can I use these values and convert them into degrees?



xaxisval += controller->left_stick_x_axis() /100;
yaxisval += controller->left_stick_y_axis() /100;
distAdjust.SetTranslation(Vector4(xaxisval, 0, yaxisval));

rotateAdjust.RotationX(rotateDegrees);

player_->set_transform(player_transform *distAdjust *rotateAdjust)


Problem I have is the movement only works with fixed rotation, if I rotate the object then it moves into a different direction.










share|improve this question
























  • Are you trying to calculate an angle from your x/y axis values? If so, then atan2 from <math.h> can do that. Check out the example at cplusplus.com/reference/cmath/atan2
    – Blaze
    Nov 23 '18 at 14:57












  • Please be more specific about what kind of movement you want. I assume this is 2D?
    – Nico Schertler
    Nov 23 '18 at 15:00










  • @Nico No, this is a lovked perspective game, 3D environment where I want to move the player character around like you would in diablo. Using just the joystick.
    – reverse coding guru
    Nov 23 '18 at 15:04










  • So, that would mean - the horizontal axis of the joystick makes your character rotate around its vertical axis and the vertical axis of the joystick makes your player move forward/backward?
    – Nico Schertler
    Nov 23 '18 at 15:07














-2












-2








-2







Given that analog stick outputs values



float xaxisval = controller->left_stick_x_axis(); //-1 is left, 1 is right
float yaxisval = controller->left_stick_y_axis(); //-1 is up, 1 is down


Values go from 0 to 1 with which can be used for sensitivity.



I'm moving the character in the direction of the joystick in a 3D environment the same way you would in a game like Diablo. I'm adding and retracting these values from X and Z position to move him. But the character is always facing the same dierection.
How can I use these values and convert them into degrees?



xaxisval += controller->left_stick_x_axis() /100;
yaxisval += controller->left_stick_y_axis() /100;
distAdjust.SetTranslation(Vector4(xaxisval, 0, yaxisval));

rotateAdjust.RotationX(rotateDegrees);

player_->set_transform(player_transform *distAdjust *rotateAdjust)


Problem I have is the movement only works with fixed rotation, if I rotate the object then it moves into a different direction.










share|improve this question















Given that analog stick outputs values



float xaxisval = controller->left_stick_x_axis(); //-1 is left, 1 is right
float yaxisval = controller->left_stick_y_axis(); //-1 is up, 1 is down


Values go from 0 to 1 with which can be used for sensitivity.



I'm moving the character in the direction of the joystick in a 3D environment the same way you would in a game like Diablo. I'm adding and retracting these values from X and Z position to move him. But the character is always facing the same dierection.
How can I use these values and convert them into degrees?



xaxisval += controller->left_stick_x_axis() /100;
yaxisval += controller->left_stick_y_axis() /100;
distAdjust.SetTranslation(Vector4(xaxisval, 0, yaxisval));

rotateAdjust.RotationX(rotateDegrees);

player_->set_transform(player_transform *distAdjust *rotateAdjust)


Problem I have is the movement only works with fixed rotation, if I rotate the object then it moves into a different direction.







c++ visual-studio-2017






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 15:54

























asked Nov 23 '18 at 14:53









reverse coding guru

82




82












  • Are you trying to calculate an angle from your x/y axis values? If so, then atan2 from <math.h> can do that. Check out the example at cplusplus.com/reference/cmath/atan2
    – Blaze
    Nov 23 '18 at 14:57












  • Please be more specific about what kind of movement you want. I assume this is 2D?
    – Nico Schertler
    Nov 23 '18 at 15:00










  • @Nico No, this is a lovked perspective game, 3D environment where I want to move the player character around like you would in diablo. Using just the joystick.
    – reverse coding guru
    Nov 23 '18 at 15:04










  • So, that would mean - the horizontal axis of the joystick makes your character rotate around its vertical axis and the vertical axis of the joystick makes your player move forward/backward?
    – Nico Schertler
    Nov 23 '18 at 15:07


















  • Are you trying to calculate an angle from your x/y axis values? If so, then atan2 from <math.h> can do that. Check out the example at cplusplus.com/reference/cmath/atan2
    – Blaze
    Nov 23 '18 at 14:57












  • Please be more specific about what kind of movement you want. I assume this is 2D?
    – Nico Schertler
    Nov 23 '18 at 15:00










  • @Nico No, this is a lovked perspective game, 3D environment where I want to move the player character around like you would in diablo. Using just the joystick.
    – reverse coding guru
    Nov 23 '18 at 15:04










  • So, that would mean - the horizontal axis of the joystick makes your character rotate around its vertical axis and the vertical axis of the joystick makes your player move forward/backward?
    – Nico Schertler
    Nov 23 '18 at 15:07
















Are you trying to calculate an angle from your x/y axis values? If so, then atan2 from <math.h> can do that. Check out the example at cplusplus.com/reference/cmath/atan2
– Blaze
Nov 23 '18 at 14:57






Are you trying to calculate an angle from your x/y axis values? If so, then atan2 from <math.h> can do that. Check out the example at cplusplus.com/reference/cmath/atan2
– Blaze
Nov 23 '18 at 14:57














Please be more specific about what kind of movement you want. I assume this is 2D?
– Nico Schertler
Nov 23 '18 at 15:00




Please be more specific about what kind of movement you want. I assume this is 2D?
– Nico Schertler
Nov 23 '18 at 15:00












@Nico No, this is a lovked perspective game, 3D environment where I want to move the player character around like you would in diablo. Using just the joystick.
– reverse coding guru
Nov 23 '18 at 15:04




@Nico No, this is a lovked perspective game, 3D environment where I want to move the player character around like you would in diablo. Using just the joystick.
– reverse coding guru
Nov 23 '18 at 15:04












So, that would mean - the horizontal axis of the joystick makes your character rotate around its vertical axis and the vertical axis of the joystick makes your player move forward/backward?
– Nico Schertler
Nov 23 '18 at 15:07




So, that would mean - the horizontal axis of the joystick makes your character rotate around its vertical axis and the vertical axis of the joystick makes your player move forward/backward?
– Nico Schertler
Nov 23 '18 at 15:07












1 Answer
1






active

oldest

votes


















1














I don't know what your function "rotateAdjust.RotationX(rotateDegrees);" really do.



But, you should for every game cycle take the value from 0 to 1 from your joystick, then multiply it by a constant angle depending of your rotation speed.



const float Angle = 1.0f; // Or whatever you want. Set more to increase rotation speed.

...

// Game loop
while ( true )
{
...

float xSensitivity = controller->left_stick_x_axis(); // example 0.33f for that cycle

myGuy.xRotate(Angle * xSensitivity);

...
}


"Angle" is a constant and can be expressed in degree or radian depending of your rotation function.






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%2f53448856%2fhow-to-use-analogue-sticks-joystick-output-values-to-rotate-an-object-using-tr%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









    1














    I don't know what your function "rotateAdjust.RotationX(rotateDegrees);" really do.



    But, you should for every game cycle take the value from 0 to 1 from your joystick, then multiply it by a constant angle depending of your rotation speed.



    const float Angle = 1.0f; // Or whatever you want. Set more to increase rotation speed.

    ...

    // Game loop
    while ( true )
    {
    ...

    float xSensitivity = controller->left_stick_x_axis(); // example 0.33f for that cycle

    myGuy.xRotate(Angle * xSensitivity);

    ...
    }


    "Angle" is a constant and can be expressed in degree or radian depending of your rotation function.






    share|improve this answer




























      1














      I don't know what your function "rotateAdjust.RotationX(rotateDegrees);" really do.



      But, you should for every game cycle take the value from 0 to 1 from your joystick, then multiply it by a constant angle depending of your rotation speed.



      const float Angle = 1.0f; // Or whatever you want. Set more to increase rotation speed.

      ...

      // Game loop
      while ( true )
      {
      ...

      float xSensitivity = controller->left_stick_x_axis(); // example 0.33f for that cycle

      myGuy.xRotate(Angle * xSensitivity);

      ...
      }


      "Angle" is a constant and can be expressed in degree or radian depending of your rotation function.






      share|improve this answer


























        1












        1








        1






        I don't know what your function "rotateAdjust.RotationX(rotateDegrees);" really do.



        But, you should for every game cycle take the value from 0 to 1 from your joystick, then multiply it by a constant angle depending of your rotation speed.



        const float Angle = 1.0f; // Or whatever you want. Set more to increase rotation speed.

        ...

        // Game loop
        while ( true )
        {
        ...

        float xSensitivity = controller->left_stick_x_axis(); // example 0.33f for that cycle

        myGuy.xRotate(Angle * xSensitivity);

        ...
        }


        "Angle" is a constant and can be expressed in degree or radian depending of your rotation function.






        share|improve this answer














        I don't know what your function "rotateAdjust.RotationX(rotateDegrees);" really do.



        But, you should for every game cycle take the value from 0 to 1 from your joystick, then multiply it by a constant angle depending of your rotation speed.



        const float Angle = 1.0f; // Or whatever you want. Set more to increase rotation speed.

        ...

        // Game loop
        while ( true )
        {
        ...

        float xSensitivity = controller->left_stick_x_axis(); // example 0.33f for that cycle

        myGuy.xRotate(Angle * xSensitivity);

        ...
        }


        "Angle" is a constant and can be expressed in degree or radian depending of your rotation function.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 28 '18 at 11:43

























        answered Nov 23 '18 at 15:41









        Sébastien Bémelmans

        1251311




        1251311






























            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.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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%2f53448856%2fhow-to-use-analogue-sticks-joystick-output-values-to-rotate-an-object-using-tr%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

            A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

            Calculate evaluation metrics using cross_val_predict sklearn

            Insert data from modal to MySQL (multiple modal on website)