Calculate roll from yaw and pitch?












0












$begingroup$


I came across an issue earlier today where I have created a look-at camera in 3D space, and applied yaw and pitch to it to rotate around the target properly. The problem is that introducing local pitch and yaw introduces global roll.



Yaw + Pitch + Yaw = Roll



I believe the way I manipulate the camera is important for the question and thus I will post some code in C# here.



I can convert most math back to code and since this problem is heavily math based I figured the math site was a better fit for my question.





When the user drags the mouse I use the X and Y coordinates to introduce yaw and pitch via the following method:



Vector3 lookat = Position - Target;
Vector3 right = Vector3.Normalize(Vector3.Cross(lookat, Up));
Vector3 up = Vector3.Normalize(Vector3.Cross(right, lookat));
Vector3 rotationx = right * yaw * lookat.Length();
Vector3 rotationy = up * pitch * lookat.Length();
Vector3 newPosition = Vector3.Normalize(Position + rotationx + rotationy) * Position.Length();
if (Vector3.Dot(up, newPosition) / (up.Length() * newPosition.Length()) < 0.98) {
Position = newPosition;
Up = up;
}


It is important to note the following statements:





  • Up is initially set to $(0, 0, 1)$ which is North in ECR.

  • The x and y coordinates of the mouse from the previous frame are subtracted from the current frame.


    • Then they are divided by $1000$ to represent $x = yaw$ and $y = pitch$.




Then, every frame I calculate the new View matrix by using the built in LookAtRH function supplied by DirectX.



View = Matrix.LookAtRH(Position, Target, Up);


Where the Target position is $(0, 0, 0)$.





I am wondering the following:




  • Is there a way to calculate roll from yaw and pitch?


    • If so, how can I use the calculated roll to negate the roll that just occurred?



  • Would ensuring the Up vector is always pointing North or South help prevent this issue?


    • If so, how do I get over the issue of singularity which causes my camera to just spin frantically around the poles simulating Gimbal lock?



  • Is there a way to remove the roll when assigning my View matrix?


    • From my understanding some matrix multiplication may help here?












share|cite|improve this question









$endgroup$








  • 1




    $begingroup$
    Are you completely certain that you don't want to learn to use quaternions? I know I get a headache remembering whether I want my axes to rotate with the object or not, and how that choice affects the order in which rotations should be applied, and which order corresponded to which choice. Quaternions are comparatively problem free once you get used to the arithmetic.
    $endgroup$
    – Arthur
    Dec 27 '18 at 0:26


















0












$begingroup$


I came across an issue earlier today where I have created a look-at camera in 3D space, and applied yaw and pitch to it to rotate around the target properly. The problem is that introducing local pitch and yaw introduces global roll.



Yaw + Pitch + Yaw = Roll



I believe the way I manipulate the camera is important for the question and thus I will post some code in C# here.



I can convert most math back to code and since this problem is heavily math based I figured the math site was a better fit for my question.





When the user drags the mouse I use the X and Y coordinates to introduce yaw and pitch via the following method:



Vector3 lookat = Position - Target;
Vector3 right = Vector3.Normalize(Vector3.Cross(lookat, Up));
Vector3 up = Vector3.Normalize(Vector3.Cross(right, lookat));
Vector3 rotationx = right * yaw * lookat.Length();
Vector3 rotationy = up * pitch * lookat.Length();
Vector3 newPosition = Vector3.Normalize(Position + rotationx + rotationy) * Position.Length();
if (Vector3.Dot(up, newPosition) / (up.Length() * newPosition.Length()) < 0.98) {
Position = newPosition;
Up = up;
}


It is important to note the following statements:





  • Up is initially set to $(0, 0, 1)$ which is North in ECR.

  • The x and y coordinates of the mouse from the previous frame are subtracted from the current frame.


    • Then they are divided by $1000$ to represent $x = yaw$ and $y = pitch$.




Then, every frame I calculate the new View matrix by using the built in LookAtRH function supplied by DirectX.



View = Matrix.LookAtRH(Position, Target, Up);


Where the Target position is $(0, 0, 0)$.





I am wondering the following:




  • Is there a way to calculate roll from yaw and pitch?


    • If so, how can I use the calculated roll to negate the roll that just occurred?



  • Would ensuring the Up vector is always pointing North or South help prevent this issue?


    • If so, how do I get over the issue of singularity which causes my camera to just spin frantically around the poles simulating Gimbal lock?



  • Is there a way to remove the roll when assigning my View matrix?


    • From my understanding some matrix multiplication may help here?












share|cite|improve this question









$endgroup$








  • 1




    $begingroup$
    Are you completely certain that you don't want to learn to use quaternions? I know I get a headache remembering whether I want my axes to rotate with the object or not, and how that choice affects the order in which rotations should be applied, and which order corresponded to which choice. Quaternions are comparatively problem free once you get used to the arithmetic.
    $endgroup$
    – Arthur
    Dec 27 '18 at 0:26
















0












0








0





$begingroup$


I came across an issue earlier today where I have created a look-at camera in 3D space, and applied yaw and pitch to it to rotate around the target properly. The problem is that introducing local pitch and yaw introduces global roll.



Yaw + Pitch + Yaw = Roll



I believe the way I manipulate the camera is important for the question and thus I will post some code in C# here.



I can convert most math back to code and since this problem is heavily math based I figured the math site was a better fit for my question.





When the user drags the mouse I use the X and Y coordinates to introduce yaw and pitch via the following method:



Vector3 lookat = Position - Target;
Vector3 right = Vector3.Normalize(Vector3.Cross(lookat, Up));
Vector3 up = Vector3.Normalize(Vector3.Cross(right, lookat));
Vector3 rotationx = right * yaw * lookat.Length();
Vector3 rotationy = up * pitch * lookat.Length();
Vector3 newPosition = Vector3.Normalize(Position + rotationx + rotationy) * Position.Length();
if (Vector3.Dot(up, newPosition) / (up.Length() * newPosition.Length()) < 0.98) {
Position = newPosition;
Up = up;
}


It is important to note the following statements:





  • Up is initially set to $(0, 0, 1)$ which is North in ECR.

  • The x and y coordinates of the mouse from the previous frame are subtracted from the current frame.


    • Then they are divided by $1000$ to represent $x = yaw$ and $y = pitch$.




Then, every frame I calculate the new View matrix by using the built in LookAtRH function supplied by DirectX.



View = Matrix.LookAtRH(Position, Target, Up);


Where the Target position is $(0, 0, 0)$.





I am wondering the following:




  • Is there a way to calculate roll from yaw and pitch?


    • If so, how can I use the calculated roll to negate the roll that just occurred?



  • Would ensuring the Up vector is always pointing North or South help prevent this issue?


    • If so, how do I get over the issue of singularity which causes my camera to just spin frantically around the poles simulating Gimbal lock?



  • Is there a way to remove the roll when assigning my View matrix?


    • From my understanding some matrix multiplication may help here?












share|cite|improve this question









$endgroup$




I came across an issue earlier today where I have created a look-at camera in 3D space, and applied yaw and pitch to it to rotate around the target properly. The problem is that introducing local pitch and yaw introduces global roll.



Yaw + Pitch + Yaw = Roll



I believe the way I manipulate the camera is important for the question and thus I will post some code in C# here.



I can convert most math back to code and since this problem is heavily math based I figured the math site was a better fit for my question.





When the user drags the mouse I use the X and Y coordinates to introduce yaw and pitch via the following method:



Vector3 lookat = Position - Target;
Vector3 right = Vector3.Normalize(Vector3.Cross(lookat, Up));
Vector3 up = Vector3.Normalize(Vector3.Cross(right, lookat));
Vector3 rotationx = right * yaw * lookat.Length();
Vector3 rotationy = up * pitch * lookat.Length();
Vector3 newPosition = Vector3.Normalize(Position + rotationx + rotationy) * Position.Length();
if (Vector3.Dot(up, newPosition) / (up.Length() * newPosition.Length()) < 0.98) {
Position = newPosition;
Up = up;
}


It is important to note the following statements:





  • Up is initially set to $(0, 0, 1)$ which is North in ECR.

  • The x and y coordinates of the mouse from the previous frame are subtracted from the current frame.


    • Then they are divided by $1000$ to represent $x = yaw$ and $y = pitch$.




Then, every frame I calculate the new View matrix by using the built in LookAtRH function supplied by DirectX.



View = Matrix.LookAtRH(Position, Target, Up);


Where the Target position is $(0, 0, 0)$.





I am wondering the following:




  • Is there a way to calculate roll from yaw and pitch?


    • If so, how can I use the calculated roll to negate the roll that just occurred?



  • Would ensuring the Up vector is always pointing North or South help prevent this issue?


    • If so, how do I get over the issue of singularity which causes my camera to just spin frantically around the poles simulating Gimbal lock?



  • Is there a way to remove the roll when assigning my View matrix?


    • From my understanding some matrix multiplication may help here?









matrices vectors rotations






share|cite|improve this question













share|cite|improve this question











share|cite|improve this question




share|cite|improve this question










asked Dec 26 '18 at 23:06









PerpetualJPerpetualJ

1747




1747








  • 1




    $begingroup$
    Are you completely certain that you don't want to learn to use quaternions? I know I get a headache remembering whether I want my axes to rotate with the object or not, and how that choice affects the order in which rotations should be applied, and which order corresponded to which choice. Quaternions are comparatively problem free once you get used to the arithmetic.
    $endgroup$
    – Arthur
    Dec 27 '18 at 0:26
















  • 1




    $begingroup$
    Are you completely certain that you don't want to learn to use quaternions? I know I get a headache remembering whether I want my axes to rotate with the object or not, and how that choice affects the order in which rotations should be applied, and which order corresponded to which choice. Quaternions are comparatively problem free once you get used to the arithmetic.
    $endgroup$
    – Arthur
    Dec 27 '18 at 0:26










1




1




$begingroup$
Are you completely certain that you don't want to learn to use quaternions? I know I get a headache remembering whether I want my axes to rotate with the object or not, and how that choice affects the order in which rotations should be applied, and which order corresponded to which choice. Quaternions are comparatively problem free once you get used to the arithmetic.
$endgroup$
– Arthur
Dec 27 '18 at 0:26






$begingroup$
Are you completely certain that you don't want to learn to use quaternions? I know I get a headache remembering whether I want my axes to rotate with the object or not, and how that choice affects the order in which rotations should be applied, and which order corresponded to which choice. Quaternions are comparatively problem free once you get used to the arithmetic.
$endgroup$
– Arthur
Dec 27 '18 at 0:26












0






active

oldest

votes











Your Answer





StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
});
});
}, "mathjax-editing");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "69"
};
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
},
noCode: true, onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3053415%2fcalculate-roll-from-yaw-and-pitch%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Mathematics Stack Exchange!


  • 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.


Use MathJax to format equations. MathJax reference.


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%2fmath.stackexchange.com%2fquestions%2f3053415%2fcalculate-roll-from-yaw-and-pitch%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

Bressuire

Cabo Verde

Gyllenstierna