coder of the year
-
Автор темы
- #1
Код:
void Math::AngleVectors(const Vector &angles, Vector *forward, Vector *right, Vector *up)
{
auto SinCos = [](float flRadians, float* pflSine, float* pflCosine)
{
__asm
{
fld DWORD PTR[flRadians]
fsincos
mov edx, DWORD PTR[pflCosine]
mov eax, DWORD PTR[pflSine]
fstp DWORD PTR[edx]
fstp DWORD PTR[eax]
}
};
float sr, sp, sy, cr, cp, cy;
SinCos(DEG2RAD(angles[1]), &sy, &cy);
SinCos(DEG2RAD(angles[0]), &sp, &cp);
SinCos(DEG2RAD(angles[2]), &sr, &cr);
if (forward)
{
forward->x = cp * cy;
forward->y = cp * sy;
forward->z = -sp;
}
if (right)
{
right->x = (-1 * sr*sp*cy + -1 * cr*-sy);
right->y = (-1 * sr*sp*sy + -1 * cr*cy);
right->z = -1 * sr*cp;
}
if (up)
{
up->x = (cr*sp*cy + -sr * -sy);
up->y = (cr*sp*sy + -sr * cy);
up->z = cr * cp;
}
}