当前位置: 首页>>代码示例>>C++>>正文


C++ world::get_height方法代码示例

本文整理汇总了C++中world::get_height方法的典型用法代码示例。如果您正苦于以下问题:C++ world::get_height方法的具体用法?C++ world::get_height怎么用?C++ world::get_height使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在world的用法示例。


在下文中一共展示了world::get_height方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: update

void unit_vehicle::update(int dt, world &w)
{
    if (hp <= 0)
        return;

    if (m_first_update)
    {
        m_first_update = false;

        if (!m_follow.expired())
        {
            auto f = m_follow.lock();
            vec3 diff = get_pos() - f->get_pos();
            if (diff.length() < m_params.formation_radius)
                m_formation_offset = f->get_rot().rotate_inv(diff);
            else
                m_formation_offset.set(0, 0, -15.0f);
        }

        m_ground = (get_pos().y - w.get_height(get_pos().x, get_pos().z)) < 5.0f;
        if (m_ground)
        {
            //ToDo: gear anim
        }
        else
        {
            if (m_params.speed_min > 0.01f)
                m_vel = get_rot().rotate(vec3::forward() * m_params.speed_cruise);
            m_dpos = vec3();
        }

        return;
    }

    float kdt = dt * 0.001f;

    vec3 target_dir;
    bool has_target = false;

    if (m_target.expired())
    {
        if (m_ai > ai_default && m_target_search != search_none)
        {
            const bool air = m_ai == ai_air_to_air || m_ai == ai_air_multirole,
            ground = m_ai == ai_air_to_ground || m_ai == ai_air_multirole;

            float min_dist = 10000.0f;
            for (int i = 0; i < w.get_planes_count() + w.get_units_count(); ++i)
            {
                object_ptr t;
                if (i < w.get_planes_count())
                {
                    auto p = w.get_plane(i);
                    if (is_ally(p, w))
                        continue;

                    t = p;
                }
                else
                {
                    if (m_target_search == search_player)
                        continue;

                    auto u = w.get_unit(i - w.get_planes_count());
                    if (is_ally(u))
                        continue;

                    t = u;
                }

                if (!t->is_targetable(air, ground))
                    continue;

                const float dist = (t->get_pos() - get_pos()).length();
                if(dist >= min_dist)
                    continue;

                m_target = t;
                min_dist = dist;
            }
        }
    }
    else
    {
        if (m_target.lock()->hp <= 0)
            m_target.reset();
    }

    bool not_path_not_follow = false;

    if (!m_path.empty())
    {
        has_target = true;
        target_dir = m_path.front() - get_pos();
        if (target_dir.length() < m_vel.length() * kdt * m_params.target_radius)
        {
            if (m_path_loop)
                m_path.push_back(m_path.front());
            m_path.pop_front();
            if (m_path.empty())
//.........这里部分代码省略.........
开发者ID:undefined-darkness,项目名称:open-horizon,代码行数:101,代码来源:units.cpp

示例2: update

void ai::update(const world &w, int dt)
{
    if (m_plane.expired())
        return;

    const float kdt = dt * 0.001f;

    auto p = m_plane.lock();

    vec3 next_pos = p->phys->pos + p->phys->vel * kdt;

    p->controls.mgun = false;
    p->controls.brake = 0.0f;

    if (m_state == state_pursuit)
    {
        if ((m_target.expired() || m_target.lock()->hp <= 0) && m_state != state_follow)
            m_state = state_wander;
    }

    //if (m_state != state_pursuit)
        find_best_target();

    if (!m_target.expired())
    {
        p->select_target(std::static_pointer_cast<object>(m_target.lock()));

        auto t = m_target.lock();
        auto target_pos = t->phys->pos + t->phys->vel * (dt * 0.001f);

        if (m_state == state_pursuit)
            go_to(target_pos - 20.0 * vec3::normalize(t->phys->vel), dt); //6 o'clock
        else
            go_to(target_pos, dt);
    }

    if (m_state == state_wander)
    {
        if (fabsf(p->get_pos().x) > 4096 || fabsf(p->get_pos().z) > 4096 ) //ToDo: set operation area
        {
            auto dir = p->get_dir();
            dir.y = 0;
            dir.normalize();

            if (stabilize_course(dir))
                p->controls.rot = nya_math::vec3(0.0, 1.0, 0.0);

            p->controls.throttle = 1.0;
        }
    }

    //evade ground
    const float minimal_height = 600.0f + w.get_height(next_pos.x, next_pos.z);
    if (next_pos.y < minimal_height && p->get_dir().y < 0.0f)
    {
        if (p->phys->get_speed_kmh() > 700.0f)
            p->controls.brake = 1.0f;

        p->controls.rot.x = vec3::up().dot(p->phys->rot.rotate(vec3::up())) < 0.0f ? 1.0f : -1.0f;
    }

    if (!p->targets.empty() && p->targets.front().locked)
    {
        p->controls.missile = !p->controls.missile;
        p->controls.mgun = true; //ToDo
    }
    else
        p->controls.missile = false;
}
开发者ID:Dracophoenix1,项目名称:open-horizon,代码行数:69,代码来源:ai.cpp


注:本文中的world::get_height方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。