get one'd
-
Автор темы
- #1
C++:
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;
}
}
float Math::NormalizeYaw(float value)
{
while (value > 180)
value -= 360.f;
while (value < -180)
value += 360.f;
return value;
}
void Math::VectorAngles(const Vector&vecForward, Vector&vecAngles)
{
Vector vecView;
if (vecForward[1] == 0.f && vecForward[0] == 0.f)
{
vecView[0] = 0.f;
vecView[1] = 0.f;
}
else
{
vecView[1] = atan2(vecForward[1], vecForward[0]) * 180.f / M_PI;
if (vecView[1] < 0.f)
vecView[1] += 360;
vecView[2] = sqrt(vecForward[0] * vecForward[0] + vecForward[1] * vecForward[1]);
vecView[0] = atan2(vecForward[2], vecView[2]) * 180.f / M_PI;
}
vecAngles[0] = -vecView[0];
vecAngles[1] = vecView[1];
vecAngles[2] = 0.f;
}
Последнее редактирование: