⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ivp_actuator.cxx

📁 hl2 source code. Do not use it illegal.
💻 CXX
📖 第 1 页 / 共 3 页
字号:
    hull_man_0->update_lazy_synapse(anchor_0, t_now, new_delta_hull);
    hull_man_1->update_lazy_synapse(anchor_1, t_now, new_delta_hull);
}


IVP_Actuator_Check_Dist::~IVP_Actuator_Check_Dist(){
    fire_check_dist_is_going_to_be_deleted_event();
    for (int i=0;i<2;i++){
	IVP_Hull_Manager *hull_man = anchors[i].real_object->get_hull_manager();
	hull_man->remove_synapse( &anchors[i] );
    }
}

IVP_Anchor_Check_Dist::~IVP_Anchor_Check_Dist(){
}

void IVP_Anchor_Check_Dist::hull_manager_is_going_to_be_deleted_event(IVP_Hull_Manager *){
    delete l_actuator_check_dist;	// no P_DELETE ad this call deletes this also
}

///////////// FORCE ////////////////

IVP_Actuator_Force::IVP_Actuator_Force(IVP_Environment *env, IVP_Template_Force *templ
                                    ) : IVP_Actuator_Two_Point(	env,templ,	IVP_ACTUATOR_TYPE_FORCE )
{
    this->force = templ->force;
    this->push_first_object = templ->push_first_object;
    this->push_second_object = templ->push_second_object;
}

IVP_Actuator_Force_Active::IVP_Actuator_Force_Active(IVP_Environment *env,IVP_Template_Force *templ
				       ) : IVP_Actuator_Force(env,templ)
{
    this->active_float_force = templ->active_float_force;
    if(this->active_float_force){
	this->active_float_force->add_dependency(this);
	active_float_changed(active_float_force);
    }
    
}

void IVP_Actuator_Force::set_force(IVP_DOUBLE nforce){
    if (nforce == force) return;
    force = nforce;
    this->ensure_actuator_in_simulation();
}


void IVP_Actuator_Force_Active::active_float_changed(IVP_U_Active_Float *af)
{
    if (af == this->active_float_force){
	this->set_force(af->get_float_value());
    }
}


IVP_Actuator_Force::~IVP_Actuator_Force()
{
    ;
}

IVP_Actuator_Force_Active::~IVP_Actuator_Force_Active()
{
    // clean up active_values ...
    if (this->active_float_force){
	this->active_float_force->remove_dependency(this);
    };
}


IVP_DOUBLE IVP_Actuator_Extra::get_force()
{
    return info.active_float_force->give_double_value();
}

///////////// EXTRA ////////////////

IVP_Actuator_Extra::IVP_Actuator_Extra(IVP_Environment *env,
				     IVP_Template_Extra *templ
                                    ) : IVP_Actuator_Two_Point(
					env,templ,IVP_ACTUATOR_TYPE_ETC )
{
    this->info=templ->info;

    if(this->info.active_float_force)	info.active_float_force->add_dependency(this);
    if(this->info.active_float_bomb)	info.active_float_bomb->add_dependency(this);

    if(this->info.mod_fc_height)	info.mod_fc_height->add_dependency(this);
    if(this->info.mod_fc_target_height)	info.mod_fc_target_height->add_dependency(this);
    if(this->info.mod_fc_dist)	info.mod_fc_dist->add_dependency(this);
    if(this->info.mod_fc_speed)	info.mod_fc_speed->add_dependency(this);
    
    // floating camera

    this->current_float_cam_pos.set(0.0f, -100.0f, 0.0f); // start position
    this->current_look_point.set_to_zero(); // start position
    this->current_vals_are_set = IVP_FALSE; // flag for first time
    ensure_actuator_in_simulation();
}

IVP_U_Point *IVP_Actuator_Extra::get_float_cam_props(IVP_DOUBLE *fc_height_out, IVP_DOUBLE *fc_target_height_out, IVP_DOUBLE *fc_dist_out, IVP_DOUBLE *fc_speed_out)
{
    // returns current IVP_FLOAT cam position
    *fc_height_out = info.mod_fc_height->give_double_value();
    *fc_target_height_out = info.mod_fc_target_height->give_double_value();
    *fc_dist_out = info.mod_fc_dist->give_double_value();
    *fc_speed_out = info.mod_fc_speed->give_double_value();

    return &this->current_float_cam_pos;
}

IVP_Actuator_Extra::~IVP_Actuator_Extra()
{
     if (info.mod_fc_height) info.mod_fc_height->remove_dependency(this);
     if (info.mod_fc_target_height) info.mod_fc_target_height->remove_dependency(this);
     if (info.mod_fc_dist) info.mod_fc_dist->remove_dependency(this);
     if (info.mod_fc_speed) info.mod_fc_speed->remove_dependency(this);

     if (info.active_float_force) info.active_float_force->remove_dependency(this);
     if (info.active_float_bomb) info.active_float_bomb->remove_dependency(this);
     
    // @@@
}



///////////// ROT MOT ////////////////

IVP_Actuator_Rot_Mot::IVP_Actuator_Rot_Mot(IVP_Environment *env,
				     IVP_Template_Rot_Mot *templ
                                    ) : IVP_Actuator_Two_Point(
					env,templ,IVP_ACTUATOR_TYPE_ROT_MOT )
{
    this->max_rotation_speed = templ->max_rotation_speed;
    this->power = templ->power;
    this->max_torque = templ->max_torque;
    this->rot_speed_out = 0;
    this->active_float_rotation_speed_out = templ->active_float_rotation_speed_out;
    if (active_float_rotation_speed_out) active_float_rotation_speed_out->add_reference();
    // rotation motor
    
    IVP_Real_Object *obj0 = get_actuator_anchor(0)->l_anchor_object;
    IVP_Real_Object *obj1 = get_actuator_anchor(1)->l_anchor_object;
    if ( obj0->get_original_core() != obj1->get_original_core()){
	printf("Rot Mot Actuation has to be fixed on one object\n");
    }

    axis_in_core_coord_system.subtract(&get_actuator_anchor(1)->core_pos,&get_actuator_anchor(0)->core_pos);
    axis_in_core_coord_system.normize();
}


IVP_Actuator_Rot_Mot_Active::IVP_Actuator_Rot_Mot_Active(IVP_Environment *env,  IVP_Template_Rot_Mot *templ
							 ) : IVP_Actuator_Rot_Mot( env,templ )
{
    active_float_max_rotation_speed = templ->active_float_max_rotation_speed;
    active_float_power = templ->active_float_power;
    active_float_max_torque = templ->active_float_max_torque;

    
    if (active_float_max_rotation_speed){
	active_float_max_rotation_speed->add_dependency(this);
	set_max_rotation_speed( active_float_max_rotation_speed->get_float_value());
    }
    if (active_float_power){
	active_float_power->add_dependency(this);
	set_power( active_float_power->get_float_value());
    }
    if (active_float_max_torque){
	active_float_max_torque->add_dependency(this);
	set_max_torque( active_float_max_torque->get_float_value());
    }
}

void IVP_Actuator_Rot_Mot::set_max_rotation_speed( IVP_DOUBLE val){
    if (val == max_rotation_speed) return;
    max_rotation_speed = val;
    ensure_actuator_in_simulation();
}

void IVP_Actuator_Rot_Mot::set_power(IVP_DOUBLE val){
    if (val == power) return;
    power = val;
    ensure_actuator_in_simulation();
}

void IVP_Actuator_Rot_Mot::set_max_torque(IVP_DOUBLE val){
    if (val == max_torque) return;
    max_torque = val;
    ensure_actuator_in_simulation();
}

void IVP_Actuator_Rot_Mot_Active::active_float_changed(IVP_U_Active_Float *af){
    if (af == active_float_max_rotation_speed)	set_max_rotation_speed( active_float_max_rotation_speed->get_float_value());
    if (af == active_float_power)               set_power( active_float_power->get_float_value());
    if (af == active_float_max_torque)	        set_max_torque( active_float_max_torque->get_float_value());
}

IVP_Actuator_Rot_Mot_Active::~IVP_Actuator_Rot_Mot_Active(){
    if (active_float_max_rotation_speed) active_float_max_rotation_speed->remove_dependency(this);
    if (active_float_power) active_float_power->remove_dependency(this);
    if (active_float_max_torque) active_float_max_torque->remove_dependency(this);
}


IVP_Actuator_Rot_Mot::~IVP_Actuator_Rot_Mot()
{
    if (active_float_rotation_speed_out) active_float_rotation_speed_out->remove_reference();
}

void IVP_Actuator_Rot_Mot::do_simulation_controller(IVP_Event_Sim *es,IVP_U_Vector<IVP_Core> * /*core_list*/) {
    if (power == 0) return;	// don't wake up object
  
    IVP_Real_Object *obj = get_actuator_anchor(0)->l_anchor_object;
    IVP_Core *core = obj->get_core();
    IVP_Core *orig_core = obj->get_original_core();

    IVP_U_Float_Point *axis;
    IVP_U_Float_Point h;
    if (core == orig_core){
	axis = &axis_in_core_coord_system;
    }else{
	const IVP_U_Matrix *m_w_f_c0 = get_actuator_anchor(0)->l_anchor_object->get_core()->get_m_world_f_core_PSI();
	const IVP_U_Matrix *m_w_f_c1 = get_actuator_anchor(1)->l_anchor_object->get_core()->get_m_world_f_core_PSI();
	IVP_U_Point pos1_ws;
	m_w_f_c1->vmult4( &get_actuator_anchor(1)->core_pos, &pos1_ws);
	IVP_U_Float_Point pos1_cs0;
	m_w_f_c0->vimult4( &pos1_ws, &pos1_cs0);
	
	h.subtract(&pos1_cs0,&get_actuator_anchor(0)->core_pos);
	h.normize();
	axis = &h;
    }

    IVP_DOUBLE domega = core->get_rot_speed_cs(axis);

    if (power * domega < 0){	// power in opposite direction
	domega = 0.0f;
    }
    this->rot_speed_out = domega; // memorize for sound e.g.
    if (active_float_rotation_speed_out){
	active_float_rotation_speed_out->set_double(rot_speed_out);
    }
    
    if (domega < 0.0f) domega = -domega;
    if (domega > max_rotation_speed){
	IVP_IF(0){
	    printf("Rot Mot rot speed threshold reached!\n");
	}
	return;	// too fast
    }
    if (domega < 0.1f) domega = 0.1f;
    
    
    IVP_DOUBLE rot_inertia_i = core->get_rot_inertia_cs(axis);
    
    IVP_DOUBLE rot_force = power /( domega * rot_inertia_i );

    // clip force
    while(max_torque != 0.0f){
	if( rot_force > max_torque){
	    IVP_IF(0){
		printf("RM Force clipped to %g, was %g\n", max_torque, rot_force);
	    }
	    rot_force = max_torque;
	    break;
	}
	if( rot_force < -max_torque){
	    IVP_IF(0){
		printf("RM Force clipped to %g, was %g\n", -max_torque, rot_force);
	    }
	    rot_force = -max_torque;
	}
        break;
    }
    IVP_DOUBLE rot_imp = rot_force * es->delta_time;
    core->async_rot_push_core_multiple_cs(axis, rot_imp);
}

///////////////////////

///////////// TORQUE ////////////////

IVP_Actuator_Torque::IVP_Actuator_Torque(IVP_Environment *env,    IVP_Template_Torque *templ
                                    ) : IVP_Actuator_Two_Point(
					env,	templ,	IVP_ACTUATOR_TYPE_TORQUE )
{
    this->max_rotation_speed = templ->max_rotation_speed;
    this->rot_speed_out = 0.0f;
    this->active_float_rotation_speed_out = templ->active_float_rotation_speed_out;
    if (active_float_rotation_speed_out) active_float_rotation_speed_out->add_reference();

    IVP_Real_Object *obj0 = get_actuator_anchor(0)->l_anchor_object;
    IVP_Real_Object *obj1 = get_actuator_anchor(1)->l_anchor_object;
    if ( obj0->get_original_core() != obj1->get_original_core()){
		printf("Both Anchors of a Torque_Actuator must be attached to just one object.\n");
		CORE;
    }
    axis_in_core_coord_system.subtract(&get_actuator_anchor(1)->core_pos,&get_actuator_anchor(0)->core_pos);
    axis_in_core_coord_system.normize();
    this->torque = templ->torque;	
    if (torque){
	ensure_actuator_in_simulation();
    }
}


IVP_Actuator_Torque_Active::IVP_Actuator_Torque_Active(IVP_Environment *env,  IVP_Template_Torque *templ
							 ) : IVP_Actuator_Torque( env,templ )
{
    active_float_max_rotation_speed = templ->active_float_max_rotation_speed;
    
    if (active_float_max_rotation_speed){
		active_float_max_rotation_speed->add_dependency(this);
		set_max_rotation_speed( active_float_max_rotation_speed->get_float_value());
    }

    active_float_torque = templ->active_float_torque;
    if (active_float_torque){
		active_float_torque->add_dependency(this);
		set_torque( active_float_torque->get_float_value());
    }
}

void IVP_Actuator_Torque::set_max_rotation_speed( IVP_DOUBLE val){
    if (val == max_rotation_speed) return;
    max_rotation_speed = val;
    ensure_actuator_in_simulation();
}

void IVP_Actuator_Torque::set_torque( IVP_DOUBLE val){
    if (val == torque) return;
    torque = val;
    ensure_actuator_in_simulation();
}

void IVP_Actuator_Torque_Active::active_float_changed(IVP_U_Active_Float *af){
    if (af == active_float_max_rotation_speed)	set_max_rotation_speed( af->get_float_value());
    if (af == active_float_torque)	            set_torque( af->get_float_value());
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -