void ext_model::update( double time )
{
    view::update(time);

    double const fms_calc_step = cfg().model_params.msys_step;
    if(pilot_impl_)
    {
        double dt = last_time_ ? time - *last_time_ : 0.;

#if 0
        if (!cg::eq_zero(dt))
        {
            geo_base_3 prev_pos = pilot_impl_->state().dyn_state.pos;
            if (dt > 0)
            {
                size_t steps = cg::floor(dt / fms_calc_step + fms_calc_step * .1);
                fms::pilot_simulation_ptr pilot_sim(pilot_impl_);
                for (size_t i = 0; i < steps; ++i)
                {
                    pilot_sim->update(fms_calc_step);
                }
            }

            point_3 offset = prev_pos(pilot_impl_->state().dyn_state.pos);

            double course = pilot_impl_->state().dyn_state.course;
            double roll = pilot_impl_->roll();

            cpr orien(course, polar_point_3(offset).pitch, roll);
            
            set_state(state_t(pilot_impl_->state(), orien.pitch, orien.roll, state_.version + 1), false);

            if (pilot_impl_->instrument() && pilot_impl_->instrument_ended())
            {
                fms::plan_t plan;
                if (get_plan().size() > 1)
                {
                    auto tmp_plan = fms::plan_t(get_plan().begin()+1, get_plan().end());
                    std::swap(plan, tmp_plan);
                }
                else if (pilot_impl_->instrument()->kind() == fms::INSTRUMENT_APPROACH && pilot_impl_->state().dyn_state.cfg != fms::CFG_GD)
                {
                    plan.push_back(fms::create_direction_instrument(boost::none, get_instruments_env())) ;
                }

                set_plan(plan);
            }
        }
#endif

    }

    last_time_ = time;
}
Example #2
0
void visual::update(double time)
{
    view::update(time);
    
    if (nodes_management::vis_node_info_ptr(root_)->is_visible() && aerotow_)
    {

        if (!tow_visual_object_)
        {

            std::string tow_type = "towbar"; // "towbar"  "tube"
            tow_visual_object_ = dynamic_cast<visual_system*>(sys_)->create_visual_object(tow_type) ;
            
            ts_ = boost::make_shared<tow_support>(*tow_visual_object_, tow_type);
        }


        aircraft::info_ptr towair;

        if (tow_visual_object_ && *tow_visual_object_)
        {
            geo_base_3 base = dynamic_cast<visual_system_props*>(sys_)->vis_props().base_point;
            
            nodes_management::node_info_ptr aerotow_root = aerotow_->root();
            
            quaternion atr_quat = aerotow_root->get_global_orien();

            point_3f offset = base(tow_point_node_->get_global_pos());
            geo_point_3 air_tow_pos = geo_base_3(aerotow_root->get_global_pos())(aerotow_root->get_global_orien().rotate_vector(point_3(aerotow_->tow_point_transform().translation())));
            point_3f offset2 = base(air_tow_pos);

            cg::polar_point_3f dir(offset2 - offset);
            cpr orien(dir.course, dir.pitch, 0);

            // cg::transform_4f tr(cg::as_translation(offset), rotation_3f(orien), cg::as_scale(point_3f(1., dir.range, 1.)));
            // (*tow_visual_object_)->node()->as_transform()->set_transform(tr);
            
            ts_->update(dir, offset);

            (*tow_visual_object_)->set_visible(true);
        }
    }
    else
    {
        if (tow_visual_object_ && *tow_visual_object_)
            (*tow_visual_object_)->set_visible(false);
    }
}