right/up/forward vectors
This commit is contained in:
parent
14523a8f5c
commit
97ffe2efb5
2 changed files with 31 additions and 0 deletions
|
@ -38,6 +38,21 @@ DirectX::XMFLOAT4X4 Transform::GetWorldMatrixInverseTranspose()
|
|||
return worldMatrixInverseTranspose;
|
||||
}
|
||||
|
||||
DirectX::XMFLOAT3 Transform::GetRight()
|
||||
{
|
||||
return right;
|
||||
}
|
||||
|
||||
DirectX::XMFLOAT3 Transform::GetUp()
|
||||
{
|
||||
return up;
|
||||
}
|
||||
|
||||
DirectX::XMFLOAT3 Transform::GetForward()
|
||||
{
|
||||
return forward;
|
||||
}
|
||||
|
||||
// XMVECTOR & XMStoreFloat compiles down to something faster than position += x,y,z because it happens all at once
|
||||
|
||||
void Transform::SetPosition(float _x, float _y, float _z)
|
||||
|
@ -52,6 +67,7 @@ void Transform::SetRotation(float _pitch, float _yaw, float _roll)
|
|||
XMVECTOR newRotation = XMVectorSet(_pitch, _yaw, _roll, 0);
|
||||
XMStoreFloat3(&eulerAngles, newRotation);
|
||||
worldMatrixChanged = true;
|
||||
UpdateDirections();
|
||||
}
|
||||
|
||||
void Transform::SetScale(float _x, float _y, float _z)
|
||||
|
@ -84,6 +100,7 @@ void Transform::Rotate(float _pitch, float _yaw, float _roll)
|
|||
XMVECTOR offset = XMVectorSet(_pitch, _yaw, _roll, 0);
|
||||
XMStoreFloat3(&eulerAngles, newRotation + offset);
|
||||
worldMatrixChanged = true;
|
||||
UpdateDirections();
|
||||
}
|
||||
|
||||
void Transform::Scale(float _x, float _y, float _z)
|
||||
|
@ -103,3 +120,10 @@ void Transform::UpdateWorldMatrix()
|
|||
XMStoreFloat4x4(&worldMatrix, matrixScale * matrixRotation * matrixPosition);
|
||||
XMStoreFloat4x4(&worldMatrixInverseTranspose, XMMatrixInverse(0, XMMatrixTranspose(XMLoadFloat4x4(&worldMatrix))));
|
||||
}
|
||||
|
||||
void Transform::UpdateDirections()
|
||||
{
|
||||
XMStoreFloat3(&right, XMVector3Rotate(XMVectorSet(1, 0, 0, 0), XMQuaternionRotationRollPitchYaw(eulerAngles.x, eulerAngles.y, eulerAngles.z)));
|
||||
XMStoreFloat3(&up, XMVector3Rotate(XMVectorSet(0, 1, 0, 0), XMQuaternionRotationRollPitchYaw(eulerAngles.x, eulerAngles.y, eulerAngles.z)));
|
||||
XMStoreFloat3(&forward, XMVector3Rotate(XMVectorSet(0, 0, 1, 0), XMQuaternionRotationRollPitchYaw(eulerAngles.x, eulerAngles.y, eulerAngles.z)));
|
||||
}
|
||||
|
|
|
@ -13,6 +13,9 @@ public:
|
|||
DirectX::XMFLOAT3 GetScale();
|
||||
DirectX::XMFLOAT4X4 GetWorldMatrix();
|
||||
DirectX::XMFLOAT4X4 GetWorldMatrixInverseTranspose();
|
||||
DirectX::XMFLOAT3 GetRight();
|
||||
DirectX::XMFLOAT3 GetUp();
|
||||
DirectX::XMFLOAT3 GetForward();
|
||||
|
||||
void SetPosition(float _x, float _y, float _z);
|
||||
void SetRotation(float _pitch, float _yaw, float _roll);
|
||||
|
@ -30,6 +33,10 @@ private:
|
|||
DirectX::XMFLOAT4X4 worldMatrix;
|
||||
DirectX::XMFLOAT4X4 worldMatrixInverseTranspose;
|
||||
bool worldMatrixChanged;
|
||||
DirectX::XMFLOAT3 right;
|
||||
DirectX::XMFLOAT3 up;
|
||||
DirectX::XMFLOAT3 forward;
|
||||
|
||||
void UpdateWorldMatrix();
|
||||
void UpdateDirections();
|
||||
};
|
||||
|
|
Reference in a new issue