Skip to content

Conversation

@bobtista
Copy link

@bobtista bobtista commented Nov 13, 2025

Summary

Replaces all C-style casts between Matrix4x4/Matrix3D and D3DXMATRIX/D3DMATRIX with proper conversion functions that handle the row-major/column-major transpose.

Before:

DX8CALL(SetTransform(transform, (D3DMATRIX*)&m));

After:

D3DXMATRIX d3dMat = Build_D3DXMATRIX(m);
DX8CALL(SetTransform(transform, &d3dMat));

@bobtista bobtista force-pushed the bobtista/fix-matrix4-d3d-transpose branch from 518ebd4 to fa2fff2 Compare November 13, 2025 17:13
@bobtista bobtista force-pushed the bobtista/fix-matrix4-d3d-transpose branch 2 times, most recently from 9a7854f to de78d22 Compare December 3, 2025 20:51
@bobtista bobtista changed the title refactor(dx8): Replace unsafe Matrix4/D3DMATRIX casts with explicit conversions refactor(dx8): Replace unsafe Matrix4x4/D3DMATRIX casts with proper transpose conversion Dec 3, 2025
@bobtista bobtista force-pushed the bobtista/fix-matrix4-d3d-transpose branch 4 times, most recently from 780bdee to 93986cd Compare December 3, 2025 21:36
@bobtista bobtista force-pushed the bobtista/fix-matrix4-d3d-transpose branch from 93986cd to 2a0b73e Compare December 3, 2025 21:38
@bobtista bobtista marked this pull request as ready for review December 3, 2025 21:53
Copy link

@xezon xezon left a comment

Choose a reason for hiding this comment

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

Goes into the right direction but it still looks like there are quirks.

Did you test the code paths? Is the math still correct?

DX8Wrapper::_Get_DX8_Transform(D3DTS_VIEW, curView);
D3DXMatrixInverse(&inv, &det, (D3DXMATRIX*)&curView);
D3DXMATRIX d3dCurView = Build_D3DXMATRIX(curView);
D3DXMatrixInverse(&inv, &det, &d3dCurView);
Copy link

Choose a reason for hiding this comment

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

Was this inverse meant to be a transpose or does it really want to do the inverse here on a D3DXMATRIX that is in DX coordinates?

DX8CALL(GetTransform(transform,(D3DMATRIX*)&m));
D3DXMATRIX d3dMat;
DX8CALL(GetTransform(transform,&d3dMat));
Build_Matrix4(m, (D3DMATRIX&)d3dMat);
Copy link

Choose a reason for hiding this comment

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

There still is a reinterpret cast here.

float det;

Matrix4x4 curView;
DX8Wrapper::_Get_DX8_Transform(D3DTS_VIEW, curView);
Copy link

Choose a reason for hiding this comment

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

Maybe add another function to get D3DXMATRIX here instead of doing this conversion?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Properly implement transpose between Matrix4 and D3DMatrix

2 participants