-
Notifications
You must be signed in to change notification settings - Fork 512
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Keyboard and mouse uses inconsistent coordinate systems, resulting in incorrect movement #447
Comments
Standard modern math notation uses row-major matrices, column vectors, post-multiplication, and right-handed coordinates. OpenGL uses column-major matrices, column vectors, post-multiplication, and right-handed viewing coordinates, where -Z is 'forward'. DirectXMath (the underlying library used by SimpleMath) uses row-major matrices, row vectors, pre-multiplication, and left-handed viewing coordinates consistent with classic "DirectX" math setup. In this case +Z is 'forward' into the screen.
SimpleMath uses row-major matrices, row vectors, pre-multiplication, and right-handed viewing coordinates consistent with XNA Game Studio. And just to be fun, the HLSL compiler default is to use column-major layout, but you can opt into row-major. You may find this blog post helpful to read. With that out of the way, the keyboard & mouse tutorial lesson uses a "WASD" style control scheme for the XY plane, and Spacebar/X for the Z movement. Traditionally "E" and "Q" in the WASD scheme are used for rotation or look left/right, so don't really follow how you implemented your controls. |
I understand the difference between row major and column major (although pre and post multiplication was a new one). |
Are you using the 'orbit style' or the 'free camera' style? |
I'm using the free camera. |
From your description, it sounds like you have different keyboard controls than the tutorial which is:
What code are you actually using? |
Yeah so I had remapped the controls to be WASD but the issue still applies with the original code. Here's a gif with the exact same controls as the tutorial (and your reply by extension). I mov |
SimpleMath uses "right-handed" coordinate systems which is why +Z is 'into' the scene. That is also why in the tutorial I was using When I'm using the "not orbit" style camera, Page Up pulls you in 'closer' and Page Down makes you 'further' as I would expect. Of course, that is 'relative' to the view location because it's intended to be an "FPS" style camera. I did notice in the Orbit style, it would make sense to use |
Apologies but I think you misremembered it. Left-handed coordinate systems have +Z going forward (into the scene) and Right-handed means -Z is forward (into the scene). SimpleMath defines a Forward constant as Regardless, the main issue is that in the non orbit style of movement in the tutorial, if you look down, pressing forward (either |
I just tried out the test apps I used for the tutorial which are on GitHub and the behavior is as I described it. I wonder if there is some difference in the code in the markdown and the code in the test app? Right on the +Z/-Z. Dealing with both handedness can be confusing for sure. |
So you’re saying that in your test app, you look down, then press Page Up,
and you don’t move backwards?
Next time I’m on my computer I can check it out too. Bizarre
…On Fri, Aug 16, 2024 at 3:27 PM Chuck Walbourn ***@***.***> wrote:
I just tried out the test apps I used for the tutorial which are on GitHub
<https://github.com/walbourn/directxtk-tutorials> and the behavior is as
I described it. I wonder if there is some difference in the code in the
markdown and the code in the test app?
Right on the +Z/-Z. Dealing with both handedness can be confusing for sure.
—
Reply to this email directly, view it on GitHub
<#447 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABQG6QP6GBNROWQR4UDMFHLZRZODZAVCNFSM6AAAAABHASUZYKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEOJUGE4DOMZSHE>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Ah, I see now. Let me do some digging. |
If you follow the keyboard and mouse tutorial and implement a basic first person camera, the movement is incorrect.
In this provided GIF, you can see that as i'm looking down while pressing E to move up (locally), it begins to move be down (locally). And when I press W to move forward (locally) it moves me backwards (locally).
I narrowed it down to the trigonometry calculations used to create the lookAt vector. It appears to assume that forward is +Z. This is inconsistent with the quaternion transform function used to rotate the input vector, which follows SimpleMaths convention of forward being -Z.
Looks like that tutorial needs the trig calculations rewritten and unfortunately i'm not mathy enough to know what needs to be changed and submit a pull request for it.
The text was updated successfully, but these errors were encountered: