Skip to content

Conversation

@xezon
Copy link

@xezon xezon commented Jan 3, 2026

This change implements Matrix4x4::Inverse and Matrix3D::Get_inverse so that we do not need to use D3DXMatrixInverse for Matrix4x4 and Matrix3D anymore (there are 4 callers, verified to produce same result). Chat GPT was used to help implement the text book math.

Eliminates all unsafe C casts (that I was able to find) between D3DMATRIX, D3DXMATRIX and Matrix4x4, Matrix3D.

The following new helpers functions help converting between the matrices:

void To_D3DMATRIX(_D3DMATRIX& dxm, const Matrix3D& m);
_D3DMATRIX To_D3DMATRIX(const Matrix3D& m);
D3DXMATRIX To_D3DXMATRIX(const Matrix3D& m);

void To_D3DMATRIX(_D3DMATRIX& dxm, const Matrix4x4& m);
_D3DMATRIX To_D3DMATRIX(const Matrix4x4& m);
D3DXMATRIX To_D3DXMATRIX(const Matrix4x4& m);

void To_Matrix4x4(Matrix4x4& m, const _D3DMATRIX& dxm);
Matrix4x4 To_Matrix4x4(const _D3DMATRIX& dxm);

TODO

  • Replicate in Generals

…inverse and replace unsafe Matrix4x4 to D3DMATRIX casts with conversion functions that apply the required transpose
@xezon xezon added this to the Code foundation build up milestone Jan 3, 2026
@xezon xezon requested a review from bobtista January 3, 2026 13:51
@xezon xezon added Major Severity: Minor < Major < Critical < Blocker Refactor Edits the code with insignificant behavior changes, is never user facing Rendering Is Rendering related labels Jan 3, 2026
@xezon
Copy link
Author

xezon commented Jan 3, 2026

Generals will fail to compile until replicated.

@xezon xezon changed the title refactor(math): Implement Matrix4x4::Inverse, Matrix3D::Get_inverse and replace unsafe Matrix4x4 to D3DMATRIX casts with conversion functions that apply the required transpose refactor(math): Implement Matrix4x4::Inverse, Matrix3D::Get_Inverse and replace unsafe Matrix4x4 to D3DMATRIX casts with conversion functions that apply the required transpose Jan 3, 2026
* 03/01/2026 TheSuperHackers : Implemented with assistance of Chat GPT. *
*=============================================================================================*/
void Matrix3D::Get_Inverse(Matrix3D & inv) const
Matrix3D * Matrix3D::Get_Inverse(Matrix3D * out, float * detOut, const Matrix3D * m)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the benefit of having two Matrix3D outputs here (no longer using void)? The only difference I see is that if m is singular then out is unchanged while the function outputs NULL, otherwise the function outputs a pointer to out

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Major Severity: Minor < Major < Critical < Blocker Refactor Edits the code with insignificant behavior changes, is never user facing Rendering Is Rendering related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Properly implement transpose between Matrix4 and D3DMatrix

2 participants