Jump to content

Y-Up to Z-Up Mat4


photo

Recommended Posts

Hello!

12 hours ago, tolga said:

Is there an easy way to convert Y-Up matrix to Z-Up matrix as Mat4?

To convert a Y-Up matrix to a Z-Up matrix, you should multiply the Y-Up matrix by a rotation matrix that rotates the coordinate system around the X-axis by -90 degrees (-π/2 radians). This rotation swaps the Y-axis and Z-axis, aligning the matrix with the Z-Up system.

You can implement the following C++ code:

new_mat = old_mat * rotateX(-90.0f); 

Here, rotateX(-90.0f) represents the rotation matrix around the X-axis by -90 degrees (-π/2 radians) in the counterclockwise direction. By multiplying old_mat with rotateX(-90.0f), you apply the rotation transformation to the existing matrix, effectively converting it from Y-Up to Z-Up.

Another approach to convert a Y-Up matrix to a Z-Up matrix is by using column swapping. This approach, which directly manipulates the columns of the matrix, offers potential performance advantages compared to the previous method of matrix multiplication.

By swapping the Y-axis column with the negated Z-axis column as shown in the example below, the desired transformation is achieved:

Mat4 t;
Vec3 y = t.getColumn3(1);
Vec3 z = t.getColumn3(2);
t.setColumn3(1, -z);
t.setColumn3(2, y);

This one may be faster because it avoids the computational overhead associated with matrix multiplication. Swapping the columns can be more efficient as it involves direct assignment and does not require extensive matrix calculations. However, the actual performance gains may depend on various factors, such as the size of the matrix and the optimizations implemented in the underlying library or framework.

Thanks!

Link to comment
×
×
  • Create New...