Code:
void AngleNormalize(float* angle)
{
if (angle[0] > 89.0f && angle[0] <= 180.0f)
{
angle[0] = 89.0f;
}
if (angle[0] > 180.f)
{
angle[0] -= 360.f;
}
if (angle[0] < -89.0f)
{
angle[0] = -89.0f;
}
if (angle[1] > 180.f)
{
angle[1] -= 360.f;
}
if (angle[1] < -180.f)
{
angle[1] += 360.f;
}
if (angle[2] != 0.0f)
{
angle[2] = 0.0f;
}
}
void calcang(float *src, float *dst, float *angles)
{
random_device Random;
mt19937 RandomGen(Random());
uniform_real<float> RandomXdistrib(PitchMinPunch, PitchMaxPunch);
uniform_real<float> RandomYdistrib(YawMinPunch, YawMaxPunch);
float MyPunch[2];
Player.GetPunch(MyPunch);
float pitchreduction = RandomXdistrib(RandomGen);
float yawreduction = RandomYdistrib(RandomGen);
float delta[3] = { (src[0] - dst[0]), (src[1] - dst[1]), ((src[2] + Player.GetViewOrigin()) - dst[2]) };
float hyp = sqrt(delta[0] * delta[0] + delta[1] * delta[1]);
angles[0] = atanf(delta[2] / hyp) * 57.295779513082f - MyPunch[0] * pitchreduction;
angles[1] = atanf(delta[1] / delta[0]) * 57.295779513082f - MyPunch[1] * yawreduction;
angles[2] = 0.0f;
if (delta[0] >= 0.0)
{
angles[1] += 180.0f;
}
}
void SmoothAngleSet(float* dest, float* orig)
{
float SmoothAngles[3];
SmoothAngles[0] = dest[0] - orig[0];
SmoothAngles[1] = dest[1] - orig[1];
SmoothAngles[2] = 0.0f;
AngleNormalize(SmoothAngles);
SmoothAngles[0] = orig[0] + SmoothAngles[0] / 100.0f * smoothamount;
SmoothAngles[1] = orig[1] + SmoothAngles[1] / 100.0f * smoothamount;
SmoothAngles[2] = 0.0f;
AngleNormalize(SmoothAngles);
Player.SetAngles(SmoothAngles);
Sleep(1);
}
void VelocityComp(int PlayerNumber, float* EnemyPos)
{
float EnemyVelocity[3];
float MyVelocity[3];
EntityList.GetVelocity(PlayerNumber, EnemyVelocity);
Player.GetVelocity(MyVelocity);
EnemyPos[0] = EnemyPos[0] + (EnemyVelocity[0] / 100.f) * (40.f / smoothamount); //not sure why 40 works. I tried a lot of different values and 40 seems to scale perfectly
EnemyPos[1] = EnemyPos[1] + (EnemyVelocity[1] / 100.f) * (40.f / smoothamount);
EnemyPos[2] = EnemyPos[2] + (EnemyVelocity[2] / 100.f) * (40.f / smoothamount);
EnemyPos[0] = EnemyPos[0] - (MyVelocity[0] / 100.f) * (40.f / smoothamount);
EnemyPos[1] = EnemyPos[1] - (MyVelocity[1] / 100.f) * (40.f / smoothamount);
EnemyPos[2] = EnemyPos[2] - (MyVelocity[2] / 100.f) * (40.f / smoothamount);
}
I'm curious if it's possible to change the viewangels and the smooth to make this more like this ->>