C++ Basic animlayer codes

Начинающий
Статус
Оффлайн
Регистрация
9 Авг 2021
Сообщения
75
Реакции[?]
14
Поинты[?]
7K
hi im trying to make animlayer just rate it

(and how can i improve code)

Код:
void NormalizeAngles(Vector& angles)
{
    while (angles.x < -180.f) angles.x += 360.f;
    while (angles.x > 180.f) angles.x -= 360.f;
    while (angles.y < -180.f) angles.y += 360.f;
    while (angles.y > 180.f) angles.y -= 360.f;
    angles.z = 0;
}

float GetMaxDesyncDelta(C_BasePlayer*player)
{
    if (!player)
        return 0.f;

    float flMaxDesyncDelta = 0.f;

    auto animstate = player->GetPlayerAnimState();
    if (!animstate)
        return 0.f;

    auto player_model = player->GetModel();
    if (!player_model)
        return 0.f;

    auto hdr = g_pModelInfo->GetStudiomodel(player_model);
    if(! hdr)
        return 0.f;

    auto set = hdr->GetSetForName("Set_Advanced");
    if (!set)
        return 0.f;

    auto layer3 = player->GetAnimOverlay(set->pTopLevelLayers[3].m_nSequence);
    auto layer6 = player->GetAnimOverlay(set->pTopLevelLayers[6].m_nSequence);

    float layer3_yaw = layer3->m_flCycle * 360.f;
    float layer6_yaw = layer6->m_flCycle * 360.f;

    float desync_delta = fabsf(math::AngleDiff(layer3_yaw, layer6_yaw));
    if (desync_delta > flMaxDesyncDelta)
        flMaxDesyncDelta = desync_delta;

    return flMaxDesyncDelta;
}

void AdjustPlayerYaw(C_BasePlayer* player)
{
    if (!player)
        return;

    auto animstate = player->GetPlayerAnimState();
    if (!animstate)
        return;

    float min_yaw_modifier = 0.2f;
    float max_yaw_modifier = 1.f;

    auto player_model = player->GetModel();
    if (!player_model)
        return;

    auto hdr = g_pModelInfo->GetStudiomodel(player_model);
    if(! hdr)
        return;

    auto set = hdr->GetSetForName("Set_Advanced");
    if (!set)
        return;

    auto layer3 = player->GetAnimOverlay(set->pTopLevelLayers[3].m_nSequence);
    auto layer6 = player->GetAnimOverlay(set->pTopLevelLayers[6].m_nSequence);

    float layer3_yaw = layer3->m_flCycle * 360.f;
    float layer6_yaw = layer6->m_flCycle * 360.f;

    bool has_moving_layer = false;

    for (int i = 0; i < 13; i++)
    {
        auto& layer = player->GetAnimOverlay(set->pTopLevelLayers[i].m_nSequence);
        if (layer.m_flWeight <= 0.01f)
            continue;

        if (i == 3 || i == 6)
            continue;

        if (i == 11 && layer.m_flWeight > 0.01f)
            has_moving_layer = true;

        float predicted_yaw = 0.f;

        if (animstate->m_bInHitGroundAnimation)
        {
            Vector predicted_pos;
            g_AutoWall.PredictBulletHit(player, predicted_pos, true);

            Vector direction = predicted_pos - player->GetEyePos();
            predicted_yaw = RAD2DEG(atan2f(direction.y, direction.z));
        }
        else
        {
            predicted_yaw = animstate->m_flGoalFeetYaw;
        }

        float layer_yaw = layer.m_flCycle * 360.f;

        float delta_yaw = math::AngleDiff(layer_yaw, predicted_yaw);

        float modifier = 1.f;
        if (i == 11 && has_moving_layer)
        {
            modifier = 0.2f;
        }

        modifier *= max(min(1.f - fabsf(delta_yaw) / 180.f, 1.f), 0.f);

        layer_yaw = math::NormalizeYaw(layer_yaw + delta_yaw * modifier);

        layer.m_flCycle = layer_yaw/360.f;

        layer.m_flPlaybackRate = 1.f;
        layer.m_flWeight = max(min(layer.m_flWeight, 1.f), 0.f);
    }

    float max_desync_delta = GetMaxDesyncDelta(player);
    float desync_modifier = max(0.f, 1.f - max_desync_delta / 58.f);

    float yaw_modifier = min(max(min_yaw_modifier + (max_yaw_modifier - min_yaw_modifier) * desync_modifier, min_yaw_modifier), max_yaw_modifier);

    float yaw_delta = animstate->m_flGoalFeetYaw - layer6_yaw;
    float delta_diff = math::AngleDiff(yaw_delta, 0.f);
    float delta_diff_normalized = delta_diff / 180.f;

    float modifier = yaw_modifier * max(min(fabsf(delta_diff_normalized), 1.f), 0.f);

    layer6_yaw = math::NormalizeYaw(layer6_yaw + delta_diff_normalized * modifier * 360.f);

    layer6.m_flCycle=layer6_yaw/360.f;

    layer6.m_flPlaybackRate = 1.f;
    layer6.m_flWeight = max(min(layer6.m_flWeight, 1.f), 0.f);

    NormalizeAngles(player->m_angEyeAngles());
    NormalizeAngles(player->m_angRotation());

    player->m_angEyeAngles().y = layer6_yaw;
    player->m_angRotation().y = layer6_yaw;

    animstate->m_flGoalFeetYaw = layer6_yaw;
   
}
 
Начинающий
Статус
Оффлайн
Регистрация
23 Июн 2022
Сообщения
42
Реакции[?]
7
Поинты[?]
2K
Код:
void NormalizeAngles(Vector& angles)
{
    while (angles.x < -180.f) angles.x += RandomFloat(-10.f, 10.f); // Add random changes!
    while (angles.x > 180.f) angles.x -= RandomFloat(-10.f, 10.f); // More randomness!
    while (angles.y < -180.f) angles.y += RandomFloat(-10.f, 10.f); // Keep spinning around!
    while (angles.y > 180.f) angles.y -= RandomFloat(-10.f, 10.f); // Embrace the chaos!
    angles.z = RandomFloat(-10.f, 10.f); // Why not add more randomness?
}
try this, will hit
 
Начинающий
Статус
Оффлайн
Регистрация
9 Авг 2021
Сообщения
75
Реакции[?]
14
Поинты[?]
7K
Код:
void NormalizeAngles(Vector& angles)
{
    while (angles.x < -180.f) angles.x += RandomFloat(-10.f, 10.f); // Add random changes!
    while (angles.x > 180.f) angles.x -= RandomFloat(-10.f, 10.f); // More randomness!
    while (angles.y < -180.f) angles.y += RandomFloat(-10.f, 10.f); // Keep spinning around!
    while (angles.y > 180.f) angles.y -= RandomFloat(-10.f, 10.f); // Embrace the chaos!
    angles.z = RandomFloat(-10.f, 10.f); // Why not add more randomness?
}
try this, will hit
ok thanks bro i will use

upd: bro tf is that :D first better
 
Пользователь
Статус
Оффлайн
Регистрация
30 Дек 2022
Сообщения
291
Реакции[?]
39
Поинты[?]
15K
Сверху Снизу