Fix some broken 3D math

This commit is contained in:
fincs 2015-07-23 22:21:49 +02:00
parent d4971ddca5
commit 21452fe6ee
2 changed files with 13 additions and 12 deletions

View File

@ -1,11 +1,7 @@
#include <c3d/maths.h>
void Mtx_OrthoTilt(C3D_Mtx* mtx, float top, float bottom, float left, float right, float near, float far)
void Mtx_OrthoTilt(C3D_Mtx* mtx, float left, float right, float bottom, float top, float near, float far)
{
// Notes:
// The 3DS screens are sideways and so are the top/bottom/left/right parameters
// that the caller passed. Hence why the parameter names are swapped in the implementation.
C3D_Mtx mp;
Mtx_Zeros(&mp);
@ -14,17 +10,22 @@ void Mtx_OrthoTilt(C3D_Mtx* mtx, float top, float bottom, float left, float righ
mp.r[0].w = (left + right) / (left - right);
mp.r[1].y = 2.0f / (top - bottom);
mp.r[1].w = (bottom + top) / (bottom - top);
mp.r[2].z = 2.0f / (far - near);
mp.r[2].w = (near + far) / (near - far);
mp.r[2].z = 2.0f / (near - far);
mp.r[2].w = (far + near) / (far - near);
mp.r[3].w = 1.0f;
// Fix depth range to [-1, 0]
C3D_Mtx mp2;
C3D_Mtx mp2, mp3;
Mtx_Identity(&mp2);
mp2.r[2].z = 0.5;
mp2.r[2].w = -0.5;
Mtx_Multiply(mtx, &mp2, &mp);
Mtx_Multiply(&mp3, &mp2, &mp);
// Rotate the matrix one quarter of a turn CCW in order to fix the 3DS screens' orientation
Mtx_RotateZ(mtx, M_TAU/4, true);
// 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);
}

View File

@ -9,6 +9,6 @@ void Mtx_Translate(C3D_Mtx* mtx, float x, float y, float z)
tm.r[1].w = y;
tm.r[2].w = z;
Mtx_Multiply(&om, &tm, mtx);
Mtx_Multiply(&om, mtx, &tm);
Mtx_Copy(mtx, &om);
}