-
Notifications
You must be signed in to change notification settings - Fork 143
refactor(math): Implement Matrix4x4::Inverse, Matrix3D::Get_Inverse and replace unsafe Matrix4x4 to D3DMATRIX casts with conversion functions that apply the required transpose #2052
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…inverse and replace unsafe Matrix4x4 to D3DMATRIX casts with conversion functions that apply the required transpose
|
Generals will fail to compile until replicated. |
Greptile OverviewGreptile SummaryImplemented custom matrix inversion for Key Changes
NotesThe implementation correctly handles the fundamental difference between the engine's column-major, column-vector convention and Direct3D's row-major convention by applying transpose operations during conversion. Confidence Score: 5/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant App as Application Code
participant M4 as Matrix4x4/Matrix3D
participant Conv as Conversion Functions
participant DX8 as DX8Wrapper
participant D3D as Direct3D API
Note over M4: Column-major storage<br/>Row[col][row]
Note over D3D: Row-major storage<br/>m[row][col]
App->>M4: Create/manipulate matrix
M4->>M4: Perform operations (e.g., Inverse)
alt Set Transform
App->>DX8: Set_Transform(transform, Matrix4x4)
DX8->>Conv: To_D3DMATRIX(Matrix4x4)
Note over Conv: Transposes during conversion<br/>dxm.m[i][j] = m[j][i]
Conv-->>DX8: D3DMATRIX
DX8->>DX8: Store in render_state
DX8->>DX8: _Set_DX8_Transform(D3DMATRIX)
DX8->>D3D: SetTransform(D3DMATRIX*)
end
alt Get Transform
App->>DX8: Get_Transform(transform, Matrix4x4&)
DX8->>DX8: Retrieve D3DMATRIX from cache
DX8->>Conv: To_Matrix4x4(D3DMATRIX)
Note over Conv: Transposes during conversion<br/>m[i][j] = dxm.m[j][i]
Conv-->>DX8: Matrix4x4
DX8-->>App: Matrix4x4
end
alt Shader Texture Transform
App->>DX8: _Get_DX8_Transform(D3DTS_VIEW, D3DXMATRIX&)
DX8->>D3D: GetTransform(D3DXMATRIX*)
D3D-->>DX8: D3DXMATRIX (row-major)
DX8-->>App: D3DXMATRIX
App->>App: D3DXMatrixInverse(&inv, &det, &curView)
App->>App: Matrix operations in D3DXMATRIX space
App->>DX8: _Set_DX8_Transform(D3DTS_TEXTURE0, D3DXMATRIX)
DX8->>D3D: SetTransform(D3DMATRIX*)
end
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3 files reviewed, 3 comments
GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/Shadow/W3DVolumetricShadow.cpp
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2 files reviewed, 2 comments
| * * | ||
| * HISTORY: * | ||
| * 8/7/98 GTH : Created. * | ||
| * 01/03/2026 TheSuperHackers : Implemented with assistance of Chat GPT. * |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the comment is appropriate. ChatGPT is a tool, not an author and attributing tools in code creates legal ambiguity without adding value. GPL already covers licensing and authorship should remain limited to human contributors. Perhaps, to address AI use, it should belong in the project policy not in code comments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok. Tweaked.
This change implements
Matrix4x4::InverseandMatrix3D::Get_inverseso that we do not need to useD3DXMatrixInverseforMatrix4x4andMatrix3Danymore (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,D3DXMATRIXandMatrix4x4,Matrix3D.The following new helpers functions help converting between the matrices:
TODO