Is there a function to get Column of Quaternion like in CryEngine?


When I use Quaternion as orientation, I get the Column 0 for the right vector, Column 1 for the forward vector. And here is how I get them:

    AZ::Vector3 GetColumn0(const AZ::Quaternion &quat)
return AZ::Vector3(
2.0f * (quat.GetX() * quat.GetX() + quat.GetW() * quat.GetW()) - 1.0f,
2.0f * (quat.GetY() * quat.GetX() + quat.GetZ() * quat.GetW()),
2.0f * (quat.GetZ() * quat.GetX() - quat.GetY() * quat.GetW())
AZ::Vector3 GetColumn1(const AZ::Quaternion &quat)
return AZ::Vector3(
2.0f * (quat.GetX() * quat.GetY() - quat.GetZ() * quat.GetW()),
2.0f * (quat.GetY() * quat.GetY() + quat.GetW() * quat.GetW()) - 1.0f,
2.0f * (quat.GetZ() * quat.GetY() - quat.GetX() * quat.GetW())

But I want to use the function of Lumberyard framework to get the column instead of write the function myself.

Does anyone know if there is a function to get Column of Quaternion in C++?

They don’t have that function but you could create a matrix from the quaternion and then access its columns. AZ::Transform has a CreateFromQuaternion function.

Column 0 & Column 1 is what CryEngine use for right vector & forward vector of a rotation Quaternion. Should not do that, it’s confusing.

Here is what to do to get right vector & forward vector:

     Quaternion cameraRot; //Rotation of camera
Vector3 camForward = cameraRot * Vector3.forward;
Vector3 camRight = cameraRot * Vector3.right;

Thanks to Bunny83 at Unity community.