2014-12-20 21:34:19 +01:00
|
|
|
#include <c3d/maths.h>
|
|
|
|
|
2015-07-23 22:21:49 +02:00
|
|
|
void Mtx_OrthoTilt(C3D_Mtx* mtx, float left, float right, float bottom, float top, float near, float far)
|
2014-12-20 21:34:19 +01:00
|
|
|
{
|
|
|
|
C3D_Mtx mp;
|
|
|
|
Mtx_Zeros(&mp);
|
|
|
|
|
|
|
|
// Build standard orthogonal projection matrix
|
|
|
|
mp.r[0].x = 2.0f / (right - left);
|
|
|
|
mp.r[0].w = (left + right) / (left - right);
|
|
|
|
mp.r[1].y = 2.0f / (top - bottom);
|
|
|
|
mp.r[1].w = (bottom + top) / (bottom - top);
|
2015-07-23 22:21:49 +02:00
|
|
|
mp.r[2].z = 2.0f / (near - far);
|
|
|
|
mp.r[2].w = (far + near) / (far - near);
|
2014-12-20 21:34:19 +01:00
|
|
|
mp.r[3].w = 1.0f;
|
|
|
|
|
|
|
|
// Fix depth range to [-1, 0]
|
2015-07-23 22:21:49 +02:00
|
|
|
C3D_Mtx mp2, mp3;
|
2014-12-20 21:34:19 +01:00
|
|
|
Mtx_Identity(&mp2);
|
|
|
|
mp2.r[2].z = 0.5;
|
|
|
|
mp2.r[2].w = -0.5;
|
2015-07-23 22:21:49 +02:00
|
|
|
Mtx_Multiply(&mp3, &mp2, &mp);
|
2014-12-20 21:34:19 +01:00
|
|
|
|
2015-07-23 22:21:49 +02:00
|
|
|
// Fix the 3DS screens' orientation by swapping the X and Y axis
|
|
|
|
Mtx_Identity(&mp2);
|
|
|
|
mp2.r[0].x = 0.0;
|
|
|
|
mp2.r[0].y = 1.0;
|
|
|
|
mp2.r[1].x = -1.0; // flipped
|
|
|
|
mp2.r[1].y = 0.0;
|
|
|
|
Mtx_Multiply(mtx, &mp2, &mp3);
|
2014-12-20 21:34:19 +01:00
|
|
|
}
|