 答应我,别当冤种了好吗
https://github.com/wine-mirror/wine/blob/90103fa07e5c23c7500c7d33e538b0610bf3c27d/dlls/d3dx9_36/math.c#L1828
[C++] 纯文本查看 复制代码 #ifdef NONAMELESSUNION
# define D3DX_U(x) (x).u
#else
# define D3DX_U(x) (x)
#endif
static inline D3DXMATRIX* D3DXMatrixIdentity(D3DXMATRIX *pout)
{
if ( !pout ) return NULL;
D3DX_U(*pout).m[0][1] = 0.0f;
D3DX_U(*pout).m[0][2] = 0.0f;
D3DX_U(*pout).m[0][3] = 0.0f;
D3DX_U(*pout).m[1][0] = 0.0f;
D3DX_U(*pout).m[1][2] = 0.0f;
D3DX_U(*pout).m[1][3] = 0.0f;
D3DX_U(*pout).m[2][0] = 0.0f;
D3DX_U(*pout).m[2][1] = 0.0f;
D3DX_U(*pout).m[2][3] = 0.0f;
D3DX_U(*pout).m[3][0] = 0.0f;
D3DX_U(*pout).m[3][1] = 0.0f;
D3DX_U(*pout).m[3][2] = 0.0f;
D3DX_U(*pout).m[0][0] = 1.0f;
D3DX_U(*pout).m[1][1] = 1.0f;
D3DX_U(*pout).m[2][2] = 1.0f;
D3DX_U(*pout).m[3][3] = 1.0f;
return pout;
}
D3DXMATRIX* WINAPI D3DXMatrixMultiply(D3DXMATRIX *pout, const D3DXMATRIX *pm1, const D3DXMATRIX *pm2)
{
D3DXMATRIX out;
int i,j;
//TRACE("pout %p, pm1 %p, pm2 %p\n", pout, pm1, pm2);
for (i=0; i<4; i++)
{
for (j=0; j<4; j++)
{
out.m[i][j] = pm1->m[i][0] * pm2->m[0][j] + pm1->m[i][1] * pm2->m[1][j] + pm1->m[i][2] * pm2->m[2][j] + pm1->m[i][3] * pm2->m[3][j];
}
}
*pout = out;
return pout;
}
D3DXVECTOR3* WINAPI D3DXVec3TransformCoord(D3DXVECTOR3 *pout, const D3DXVECTOR3 *pv, const D3DXMATRIX *pm)
{
D3DXVECTOR3 out;
FLOAT norm;
//TRACE("pout %p, pv %p, pm %p\n", pout, pv, pm);
norm = pm->m[0][3] * pv->x + pm->m[1][3] * pv->y + pm->m[2][3] *pv->z + pm->m[3][3];
out.x = (pm->m[0][0] * pv->x + pm->m[1][0] * pv->y + pm->m[2][0] * pv->z + pm->m[3][0]) / norm;
out.y = (pm->m[0][1] * pv->x + pm->m[1][1] * pv->y + pm->m[2][1] * pv->z + pm->m[3][1]) / norm;
out.z = (pm->m[0][2] * pv->x + pm->m[1][2] * pv->y + pm->m[2][2] * pv->z + pm->m[3][2]) / norm;
*pout = out;
return pout;
}
D3DXVECTOR3* WINAPI D3DXVec3Project(D3DXVECTOR3 *pout, const D3DXVECTOR3 *pv, const D3DVIEWPORT9 *pviewport, const D3DXMATRIX *pprojection, const D3DXMATRIX *pview, const D3DXMATRIX *pworld)
{
D3DXMATRIX m;
//TRACE("pout %p, pv %p, pviewport %p, pprojection %p, pview %p, pworld %p\n", pout, pv, pviewport, pprojection, pview, pworld);
D3DXMatrixIdentity(&m);
if (pworld) D3DXMatrixMultiply(&m, &m, pworld);
if (pview) D3DXMatrixMultiply(&m, &m, pview);
if (pprojection) D3DXMatrixMultiply(&m, &m, pprojection);
D3DXVec3TransformCoord(pout, pv, &m);
if (pviewport)
{
pout->x = pviewport->X + ( 1.0f + pout->x ) * pviewport->Width / 2.0f;
pout->y = pviewport->Y + ( 1.0f - pout->y ) * pviewport->Height / 2.0f;
pout->z = pviewport->MinZ + pout->z * ( pviewport->MaxZ - pviewport->MinZ );
}
return pout;
} |