0
\$\begingroup\$

I am writing this functionality in DirectX to rotate cube using the mouse. Now the functionality is working perfectly fine when the cube is sitting straight, but mouse functionality is reversed when the cube is upside down, i.e. the rotation flips completely when rotated about X-axis by 180 degrees. Here is the code implementing the same.

XMMATRIX mProjection =
    DirectX::XMMatrixTranspose(
        DirectX::XMMatrixPerspectiveFovLH(DirectX::XM_PIDIV4, 2.2f, .1f, 10000.f));

XMStoreFloat4x4(&viewProj, XMMatrixMultiply(mProjection, mView));

DirectX::XMMATRIX scalingMatrix = DirectX::XMMatrixScaling(m_zoom, m_zoom, m_zoom);
//DirectX::XMMATRIX m_rotationMatrix = DirectX::XMMatrixRotationQuaternion(DirectX::XMLoadFloat4(&m_Rot));
DirectX::XMMATRIX m_rotationMatrixX = XMMatrixRotationX(m_radiansX);
m_rotationMatrix = m_rotationMatrixX * XMMatrixRotationY(m_radiansY);

DirectX::XMMATRIX translationMatrix = DirectX::XMMatrixTranslation(0, 0, 0);

//m_newWorld = scalingMatrix * m_rotationMatrix * translationMatrix;
m_newWorld = scalingMatrix * m_rotationMatrix * translationMatrix;

DirectX::XMMATRIX m_worldMatrix = m_newWorld;

//MatrixBuffer constWordMatrix;
constWordMatrix.mWVP = XMMatrixMultiply(XMLoadFloat4x4(&viewProj), m_worldMatrix);

I found this solution in one of the old posts, but not sure how will that translate to my current code. directX rotation of a 3d cube inconsistent

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$

This is perfectly normal behavior.

Imagine being in a inverted airplane. Left is right and up is down.

If you feel this is the incorrect behavior, multiply your inputs by the sign of the dot product of your orientation to ground.

\$\endgroup\$
2
  • \$\begingroup\$ do you know how can I do that in DirectX? \$\endgroup\$
    – technoid
    Feb 20, 2023 at 21:26
  • \$\begingroup\$ The dot product of the up vector * the left right input. \$\endgroup\$
    – user122973
    Feb 23, 2023 at 3:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .