Quote:
Originally Posted by SilverRazzer <3
Code:
#define PI 3.14159265f
#define RADTODEG(radian) ((180.0f / PI) * (radian))
// ...
FLOAT CalculatePitch(INT dwIndex)
{
FLOAT AngelX = p_Player->pGlobal[dwIndex]->ViewX - p_Local->PosX;
FLOAT AngelY = p_Player->pGlobal[dwIndex]->ViewY - p_Local->PosY;
FLOAT AngelZ = p_Player->pGlobal[dwIndex]->ViewZ - p_Local->PosZ;
FLOAT PitchCorrection = 0;
return float( -1 * (atan( (AngelY + PitchCorrection) / sqrt( AngelX * AngelX + AngelZ * AngelZ )) * 180 / M_PI ) );
}
|
Das crasht, wenn AngelX und AngelZ null sind. Ein Check mit std::isnormal hilft (das gibt true zurück, wenn der gegebene Wert keiner der folgenden ist: infinity, -infinity, NaN, null oder in die Kategorie subnormal fällt.
Der Header dafür ist <cmath>.
Anbei - unkommentiert, aber auf Fragen antworte ich - mein Header aimbot_math.hpp
Code:
#pragma once
#include <type_traits>
#include <utility>
#include <cmath>
namespace aimbot
{
namespace coordinates
{
namespace spherical
{
template <typename Arithmetic>
typename std::enable_if<std::is_arithmetic<Arithmetic>::value, Arithmetic>::type
radius(Arithmetic x, Arithmetic y, Arithmetic z)
{
return std::sqrt((x * x) + (y * y) + (z * z));
}
template <typename Arithmetic>
typename std::enable_if<std::is_arithmetic<Arithmetic>::value, Arithmetic>::type
inclination(Arithmetic z, Arithmetic radius)
{
if (std::isnormal(radius))
return std::acos(z / radius);
return Arithmetic{};
}
template <typename Arithmetic>
typename std::enable_if<std::is_arithmetic<Arithmetic>::value, Arithmetic>::type
inclination(Arithmetic x, Arithmetic y, Arithmetic z)
{
return inclination(z, radius(x, y, z));
}
template <typename Arithmetic>
typename std::enable_if<std::is_arithmetic<Arithmetic>::value, Arithmetic>::type
azimuth(Arithmetic x, Arithmetic y)
{
return std::atan2(y, x);
}
}
namespace cartesian
{
template <typename Arithmetic>
typename std::enable_if<std::is_arithmetic<Arithmetic>::value, Arithmetic>::type
x(Arithmetic radius, Arithmetic inclination, Arithmetic azimuth)
{
return radius * std::sin(inclination) * std::cos(azimuth);
}
template <typename Arithmetic>
typename std::enable_if<std::is_arithmetic<Arithmetic>::value, Arithmetic>::type
y(Arithmetic radius, Arithmetic inclination, Arithmetic azimuth)
{
return radius * std::sin(inclination) * std::sin(azimuth);
}
template <typename Arithmetic>
typename std::enable_if<std::is_arithmetic<Arithmetic>::value, Arithmetic>::type
z(Arithmetic radius, Arithmetic inclination)
{
return radius * std::cos(inclination);
}
}
}
}