Last active
March 9, 2025 03:40
-
-
Save Fighter19/83e1f1dac7878234af9ca40f67917360 to your computer and use it in GitHub Desktop.
Implement D3DXMatrixInverse using glm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <glm/glm.hpp> | |
#include <glm/gtc/matrix_transform.hpp> | |
static void ConvertGLMToD3DX (const glm::mat4x4 &glm, D3DXMATRIX &d3dx) | |
{ | |
d3dx._11 = glm[0][0]; | |
d3dx._12 = glm[1][0]; | |
d3dx._13 = glm[2][0]; | |
d3dx._14 = glm[3][0]; | |
d3dx._21 = glm[0][1]; | |
d3dx._22 = glm[1][1]; | |
d3dx._23 = glm[2][1]; | |
d3dx._24 = glm[3][1]; | |
d3dx._31 = glm[0][2]; | |
d3dx._32 = glm[1][2]; | |
d3dx._33 = glm[2][2]; | |
d3dx._34 = glm[3][2]; | |
d3dx._41 = glm[0][3]; | |
d3dx._42 = glm[1][3]; | |
d3dx._43 = glm[2][3]; | |
d3dx._44 = glm[3][3]; | |
} | |
static void ConvertD3DXToGLM (const D3DXMATRIX &d3dx, glm::mat4x4 &glm) | |
{ | |
glm[0][0] = d3dx._11; | |
glm[1][0] = d3dx._12; | |
glm[2][0] = d3dx._13; | |
glm[3][0] = d3dx._14; | |
glm[0][1] = d3dx._21; | |
glm[1][1] = d3dx._22; | |
glm[2][1] = d3dx._23; | |
glm[3][1] = d3dx._24; | |
glm[0][2] = d3dx._31; | |
glm[1][2] = d3dx._32; | |
glm[2][2] = d3dx._33; | |
glm[3][2] = d3dx._34; | |
glm[0][3] = d3dx._41; | |
glm[1][3] = d3dx._42; | |
glm[2][3] = d3dx._43; | |
glm[3][3] = d3dx._44; | |
} | |
D3DXMATRIX *WINAPI D3DXMatrixInverse(D3DXMATRIX *pOut, FLOAT *pDeterminant, CONST D3DXMATRIX *pM) | |
{ | |
glm::mat4x4 m; | |
ConvertD3DXToGLM(*pM, m); | |
if (pDeterminant) | |
*pDeterminant = glm::determinant(m); | |
glm::mat4x4 inv = glm::inverse(m); | |
ConvertGLMToD3DX(inv, *pOut); | |
return pOut; | |
} | |
D3DXMATRIX *WINAPI D3DXMatrixScaling(D3DXMATRIX *pOut, FLOAT sx, FLOAT sy, FLOAT sz) | |
{ | |
glm::mat4x4 m = glm::scale(glm::mat4x4(1.0f), glm::vec3(sx, sy, sz)); | |
ConvertGLMToD3DX(m, *pOut); | |
return pOut; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment