```
/*
* @brief returns a value between 0 and 360 degrees
* @author Killerswin2
* @param angle float angle in degrees to be AxisClamped
* @return float clampedAxis
* @see Rotator::clampAxis for sqf cmd
*/
float clampAxisInternal(float angle)
{
angle = std::fmod(angle, 360);
if (angle < 0)
{
angle = angle + 360.0f;
}
return angle;
}
/*
* @brief returns a value between -180 and 180 degrees
* @author Killerswin2
* @param angle float angle in degrees to be normalized
* @return float normalized angle
* @see Rotator::normalizeAxis for sqf cmd
*/
float normalizeAxisInternal(float angle)
{
// make sure angle is with in (0,360)
angle = clampAxisInternal(angle);
if (angle > 180.0f)
{
angle = angle - 360.0f; // in the range of -180,180 normalized
}
return angle;
}
/*
* @brief clamps an angle in degrees between min angle and max angle.
* @author Killerswin2
* @param angle float current angle measurement
* @param minAngle float min allowed angle to clamp to
* @param maxAngle float max allowed angle to clamp to
* @return float normalized angle
* @see Rotator::clampAngle for sqf cmd
* @warning coterminal angles are handled, 400 -> 40
*/
float clampAngleInternal(float angle, float minAngle, float maxAngle)
{
float deltaAngle = clampAxisInternal(maxAngle - minAngle);
float centerAngle = clampAxisInternal(minAngle + deltaAngle);
float centerDisplacement = normalizeAxisInternal(angle - centerAngle);
// clamp values here
if (centerDisplacement > deltaAngle)
{
return normalizeAxisInternal(centerAngle + deltaAngle);
}
else if (centerDisplacement < -deltaAngle)
{
return normalizeAxisInternal(centerAngle - deltaAngle);
}
return normalizeAxisInternal(angle);
}
/*
* @brief clamps all components of a vec3 between 0 and 360
* @author Killerswin2
* @param x float x component
* @param y float y component
* @param z float z component
* @return vec3 clamped vec3
* @see Rotator::clamp for sqf cmd
*/
vector3 clampInternal(float x, float y, float z)
{
return vector3{clampAxisInternal(x), clampAxisInternal(y), clampAxisInternal(z)};
}
```