private void UpdateLightDir() { XMMatrix mInvView = m_mView.Inverse(); mInvView.M41 = 0; mInvView.M42 = 0; mInvView.M43 = 0; XMMatrix mLastRotInv = m_mRotSnapshot.Inverse(); XMMatrix mRot = m_ArcBall.GetRotationMatrix(); m_mRotSnapshot = mRot; // Accumulate the delta of the arcball's rotation in view space. // Note that per-frame delta rotations could be problematic over long periods of time. m_mRot *= m_mView * mLastRotInv * mRot * mInvView; // Since we're accumulating delta rotations, we need to orthonormalize // the matrix to prevent eventual matrix skew XMVector pXBasis = XMVector.FromFloat(m_mRot.M11, m_mRot.M12, m_mRot.M13, 0); XMVector pYBasis = XMVector.FromFloat(m_mRot.M21, m_mRot.M22, m_mRot.M23, 0); XMVector pZBasis = XMVector.FromFloat(m_mRot.M31, m_mRot.M32, m_mRot.M33, 0); pXBasis = XMVector3.Normalize(pXBasis); pYBasis = XMVector3.Cross(pZBasis, pXBasis); pYBasis = XMVector3.Normalize(pYBasis); pZBasis = XMVector3.Cross(pXBasis, pYBasis); pXBasis.W = m_mRot.M14; pYBasis.W = m_mRot.M24; pZBasis.W = m_mRot.M34; XMVector pWBasis = XMVector.FromFloat(m_mRot.M41, m_mRot.M42, m_mRot.M43, m_mRot.M44); m_mRot = new XMMatrix(pXBasis, pYBasis, pZBasis, pWBasis); // Transform the default direction vector by the light's rotation matrix m_vCurrentDir = XMVector3.TransformNormal(m_vDefaultDir, m_mRot); }