私がどこの光線方向を得るために画面上をクリックする点を変換しようとしていますをクリックします。結局、これはある種の交差点に使用されます。私は今、奇妙な結果を生み出しているようで、私はなぜそれがわからないのですか?ワールド座標(DX11、C++)の画面上でクリックする場所の光線の方向を取得するには
projectionMatrix = XMLoadFloat4x4(this->projectionMatrix);
viewMatrix = XMLoadFloat4x4(this->viewMatrix);
pointX = ((2.0f * (float)mouseX)/(float)screenWidth) - 1.0f;
pointY = (((2.0f * (float)mouseY)/(float)screenHeight) - 1.0f) * -1.0f;
pointX = pointX/XMVectorGetX(projectionMatrix.r[0]);
pointY = pointY/XMVectorGetY(projectionMatrix.r[1]);
inverseViewMatrix = XMMatrixInverse(nullptr, viewMatrix);
direction =
XMVectorSet((pointX * XMVectorGetX(inverseViewMatrix.r[0])) + (pointY * XMVectorGetX(inverseViewMatrix.r[1])) + XMVectorGetX(inverseViewMatrix.r[2]),
(pointX * XMVectorGetY(inverseViewMatrix.r[0])) + (pointY * XMVectorGetY(inverseViewMatrix.r[1])) + XMVectorGetY(inverseViewMatrix.r[2]),
(pointX * XMVectorGetZ(inverseViewMatrix.r[0])) + (pointY * XMVectorGetZ(inverseViewMatrix.r[1])) + XMVectorGetZ(inverseViewMatrix.r[2]), 0.0f);
これは、いくつかの角度で大丈夫動作しているようですが、それは特定のポイントに達すると、それは回転を停止し、「予想外」の結果を生成します。多分、この問題は私が直面することのできない方向性であるため、Z値に問題がありますか?
ビデオの例では、カメラを方向(世界のY軸を中心に回転するだけ)で見て、方向はマウスの動きに基づいています。ご覧のとおり、1つの領域でうまくいくように見えますが、ある点に達すると、後ろに移動してマウスの動きを止めるようになります。
https://i.gyazo.com/c0e1cd6bc5c36a7a488ba81928061104.mp4
誰もがこれを引き起こしているものを知っていますか?
編集:解決、問題は、問題は私に0〜180度の自由を与えたACOSを使用して、私のカメラの回転だっ0-360