d3dx9: Use float functions in D3DXQuaternionRotationMatrix().

This commit is contained in:
Rico Schüller 2012-09-27 12:14:23 +02:00 committed by Alexandre Julliard
parent e921953374
commit 9a281e5dd2
1 changed files with 47 additions and 44 deletions

View File

@ -1370,57 +1370,60 @@ D3DXQUATERNION * WINAPI D3DXQuaternionRotationAxis(D3DXQUATERNION *out, const D3
return out; return out;
} }
D3DXQUATERNION* WINAPI D3DXQuaternionRotationMatrix(D3DXQUATERNION *pout, CONST D3DXMATRIX *pm) D3DXQUATERNION * WINAPI D3DXQuaternionRotationMatrix(D3DXQUATERNION *out, const D3DXMATRIX *m)
{ {
int i, maxi; FLOAT s, trace;
FLOAT maxdiag, S, trace;
TRACE("(%p, %p)\n", pout, pm); TRACE("out %p, m %p\n", out, m);
trace = pm->u.m[0][0] + pm->u.m[1][1] + pm->u.m[2][2] + 1.0f; trace = m->u.m[0][0] + m->u.m[1][1] + m->u.m[2][2] + 1.0f;
if ( trace > 1.0f) if (trace > 1.0f)
{ {
pout->x = ( pm->u.m[1][2] - pm->u.m[2][1] ) / ( 2.0f * sqrt(trace) ); s = 2.0f * sqrtf(trace);
pout->y = ( pm->u.m[2][0] - pm->u.m[0][2] ) / ( 2.0f * sqrt(trace) ); out->x = (m->u.m[1][2] - m->u.m[2][1]) / s;
pout->z = ( pm->u.m[0][1] - pm->u.m[1][0] ) / ( 2.0f * sqrt(trace) ); out->y = (m->u.m[2][0] - m->u.m[0][2]) / s;
pout->w = sqrt(trace) / 2.0f; out->z = (m->u.m[0][1] - m->u.m[1][0]) / s;
return pout; out->w = 0.25f * s;
}
maxi = 0;
maxdiag = pm->u.m[0][0];
for (i=1; i<3; i++)
{
if ( pm->u.m[i][i] > maxdiag )
{
maxi = i;
maxdiag = pm->u.m[i][i];
}
} }
switch( maxi ) else
{ {
case 0: int i, maxi = 0;
S = 2.0f * sqrt(1.0f + pm->u.m[0][0] - pm->u.m[1][1] - pm->u.m[2][2]);
pout->x = 0.25f * S; for (i = 1; i < 3; i++)
pout->y = ( pm->u.m[0][1] + pm->u.m[1][0] ) / S; {
pout->z = ( pm->u.m[0][2] + pm->u.m[2][0] ) / S; if (m->u.m[i][i] > m->u.m[maxi][maxi])
pout->w = ( pm->u.m[1][2] - pm->u.m[2][1] ) / S; maxi = i;
break; }
case 1:
S = 2.0f * sqrt(1.0f + pm->u.m[1][1] - pm->u.m[0][0] - pm->u.m[2][2]); switch (maxi)
pout->x = ( pm->u.m[0][1] + pm->u.m[1][0] ) / S; {
pout->y = 0.25f * S; case 0:
pout->z = ( pm->u.m[1][2] + pm->u.m[2][1] ) / S; s = 2.0f * sqrtf(1.0f + m->u.m[0][0] - m->u.m[1][1] - m->u.m[2][2]);
pout->w = ( pm->u.m[2][0] - pm->u.m[0][2] ) / S; out->x = 0.25f * s;
break; out->y = (m->u.m[0][1] + m->u.m[1][0]) / s;
case 2: out->z = (m->u.m[0][2] + m->u.m[2][0]) / s;
S = 2.0f * sqrt(1.0f + pm->u.m[2][2] - pm->u.m[0][0] - pm->u.m[1][1]); out->w = (m->u.m[1][2] - m->u.m[2][1]) / s;
pout->x = ( pm->u.m[0][2] + pm->u.m[2][0] ) / S; break;
pout->y = ( pm->u.m[1][2] + pm->u.m[2][1] ) / S;
pout->z = 0.25f * S; case 1:
pout->w = ( pm->u.m[0][1] - pm->u.m[1][0] ) / S; s = 2.0f * sqrtf(1.0f + m->u.m[1][1] - m->u.m[0][0] - m->u.m[2][2]);
break; out->x = (m->u.m[0][1] + m->u.m[1][0]) / s;
out->y = 0.25f * s;
out->z = (m->u.m[1][2] + m->u.m[2][1]) / s;
out->w = (m->u.m[2][0] - m->u.m[0][2]) / s;
break;
case 2:
s = 2.0f * sqrtf(1.0f + m->u.m[2][2] - m->u.m[0][0] - m->u.m[1][1]);
out->x = (m->u.m[0][2] + m->u.m[2][0]) / s;
out->y = (m->u.m[1][2] + m->u.m[2][1]) / s;
out->z = 0.25f * s;
out->w = (m->u.m[0][1] - m->u.m[1][0]) / s;
break;
}
} }
return pout;
return out;
} }
D3DXQUATERNION * WINAPI D3DXQuaternionRotationYawPitchRoll(D3DXQUATERNION *out, FLOAT yaw, FLOAT pitch, FLOAT roll) D3DXQUATERNION * WINAPI D3DXQuaternionRotationYawPitchRoll(D3DXQUATERNION *out, FLOAT yaw, FLOAT pitch, FLOAT roll)