UE4 is using left-handed coordinate system which is clockwise when viewing from the top. However the data we use is sampled in right-handed system which is counter-clockwise when viewing from the top. If we use the data directly in UE4, we gets a lying down viewport. So we have to convert the coordinate into left-handed coordinate system at first.

We have already known that $Coordinate;in;Screen;Space = Projection Matrix \times View Matrix \times Model Matrix \times Coordinate;in;Local;Space$. The coordinate conversion happens in World Space that we can get from $Model Matrix \times Coordinate;in;Local;Space$. The only thing we need to do is modifying the Model Matrix that is equal to $Translation \times Rotation \times Scale$. But we cannot simplely multipy an extra rotation matrix on the left or right side because it will break the construction order of model matrix. So We have to transfer each component of model matrix respectively.

For example, we need to convert a position $(x, y, z)$ to $(-z, x, y)$, the new position is $x’ = y, y’ = z, z’ = -x$. We can get translation component from model matrix directly then shift the three axes.

1
2
auto translation = modelMatrix[3]
auto newTrans = glm::vec3(translation.y, translation.z, -translation.x)

For rotation, we can convert the rotation matrix without scale into quaternion and shift the three axes as before in quaternion then convert it back to rotation matrix. It is easier to do based on glm library than constructing a rotation matrix.

1
2
auto newQuat = glm::quat(oldQuat.W, oldQuat.Y, oldQuat.Z, -oldQuat.X);
auto rotMat = glm::mat3_cast(newQuat);

For scale, I haven’t tried it yet but it would be similar.


For any problems about this article, feel free to rise an issue to me. Issue
If this article is usful for you, welcome to follow my github. Follow @gcmiao

Go back Home