DirectX11에서 위치 벡터와 직면 방향 (Y 축 주위로만 회전)에 대한 회전 각도로 3D 오브젝트가 있습니다. 그때 뭔가를 향하도록 객체를 회전하고 싶었3D 오브젝트와 포인트 사이의 각도 계산
D3DXVECTOR3 m_position;
float m_angle;
는 내가 직면있어 방향과는 두 개의 정규화 된 벡터의 내적을 사용하여 얼굴을 필요로하는 방향 사이의 각도를 찾아야 할 것입니다.
제가 문제가되는 것은 객체가 현재 직면하고있는 방향을 각도와 각도로 찾는 방법입니다. 내가 현재 가지고 것은 :
는D3DXVECTOR3 normDirection, normTarget;
D3DXVec3Normalize(&normDirection, ????);
D3DXVec3Normalize(&normTarget, &(m_position-target));
// I store the values in degrees because I prefer it
float angleToRotate = D3DXToDegree(acos(D3DXVec3Dot(&normDirection, &normTarget)));
사람은 나는 그것이 내가 가지고있는 값에서 직면하고있어 현재의 방향 벡터를 얻을, 또는 그것을 다시 작성해야 할 방법을 알고 있습니까 그래서 객체의 방향을 추적 벡터?
편집 : 'cos'을 'acos'로 변경했습니다. (user2802841의 도움을)
해결 방법 : 각도로 방향을 저장하는 경우
// assuming these are member variables
D3DXVECTOR3 m_position;
D3DXVECTOR3 m_rotation;
D3DXVECTOR3 m_direction;
// and these are local variables
D3DXVECTOR3 target; // passed in as a parameter
D3DXVECTOR3 targetNorm;
D3DXVECTOR3 upVector;
float angleToRotate;
// find the amount to rotate by
D3DXVec3Normalize(&targetNorm, &(target-m_position));
angleToRotate = D3DXToDegree(acos(D3DXVec3Dot(&targetNorm, &m_direction)));
// calculate the up vector between the two vectors
D3DXVec3Cross(&upVector, &m_direction, &targetNorm);
// switch the angle to negative if the up vector is going down
if(upVector.y < 0)
angleToRotate *= -1;
// add the rotation to the object's overall rotation
m_rotation.y += angleToRotate;
정확히 어떻게 회전 행렬로 벡터를 회전합니까? 내가 본 것에서는'D3DXVECTOR3 = D3DXVECTOR3 * D3DXMATRIX'을 할 수 없습니다. 그리고 예, 이제는 적어도 제 프로그램에서 0도 == (0, 0, 1)임을 깨달았습니다. – Edward
@Edward [D3DXVec3TransformCoord] (http://msdn.microsoft.com/en-us/library/windows/desktop/bb205522.aspx) – user2802841
고마워, 그게 내가 필요한거야. 그러나 또 다른 문제가 발생했습니다. 위치를 (5, 3, 0)으로 설정하고 대상 위치를 (7.5, 3, 2.5)로 설정하면 45도 각도로 올바르게 작동하지만 타겟을 7.5로 설정하면 각도가 여전히 45도입니다. , 3, -2.5). 회전 방향을 결정하는 방법이 있습니까? – Edward