Ejemplo n.º 1
0
static int _generate_detail_alpha(pyGLTexture* self, GLint level, float* result) {
    float dropoff_start, dropoff_stop, detail_max, detail_min;
    if (!_get_float(self->m_textureKey, "detail_fade_start", dropoff_start))
        return -1;
    if (!_get_float(self->m_textureKey, "detail_fade_stop", dropoff_stop))
        return -1;
    if (!_get_float(self->m_textureKey, "detail_opacity_start", detail_max))
        return -1;
    if (!_get_float(self->m_textureKey, "detail_opacity_stop", detail_min))
        return -1;

    dropoff_start /= 100.f;
    dropoff_start *= _get_num_levels(self);
    dropoff_stop /= 100.f;
    dropoff_stop *= _get_num_levels(self);
    detail_max /= 100.f;
    detail_min /= 100.f;

    float alpha = (level - dropoff_start) * (detail_min - detail_max) / (dropoff_stop - dropoff_start) + detail_max;
    if (detail_min < detail_max)
        *result = std::min(detail_max, std::max(detail_min, alpha));
    else
        *result = std::min(detail_min, std::max(detail_max, alpha));
    return 0;
}
Ejemplo n.º 2
0
static int _define_station(lua_State *L, SpaceStationType &station)
{
	station.id = s_currentStationFile;

	LUA_DEBUG_START(L);
	_get_string(L, "model", station.modelName);
	_get_int(L, "num_docking_ports", station.numDockingPorts);
	_get_bool(L, "dock_one_at_a_time", station.dockOneAtATimePlease, false);
	_get_float(L, "angular_velocity", station.angVel, 0.f);
	_get_float(L, "parking_distance", station.parkingDistance, 5000.f);
	_get_float(L, "parking_gap_size", station.parkingGapSize, 2000.f);
	_get_stage_durations(L, "dock_anim_stage_duration", station.numDockingStages, &station.dockAnimStageDuration);
	_get_stage_durations(L, "undock_anim_stage_duration", station.numUndockStages, &station.undockAnimStageDuration);
	_get_int(L, "ship_launch_stage", station.shipLaunchStage);
	station.dockAnimFunction = _set_global_function(L, "ship_dock_anim", station.id.c_str());
	station.approachWaypointsFunction = _set_global_function(L, "ship_approach_waypoints", station.id.c_str());
	LUA_DEBUG_END(L, 0);

	assert(!station.modelName.empty());
	assert(!station.dockAnimFunction.empty());
	assert(!station.approachWaypointsFunction.empty());
	station.model = Pi::FindModel(station.modelName);
	return 0;
}
int main(){

	int t;
	int max_int;
	max_int = 100;

	printf("float random\n");
	t = 1;
	while (t <= MANY_TIMES){
		printf("%f \n", _get_float());
		t = t + 1;
	}

	printf("int random\n");
	t = 1;
	while (t <= MANY_TIMES){
		printf("%d \n", _get_int_random_number(&max_int));		
		t = t + 1;
	}

	return 0;
}
Ejemplo n.º 4
0
void general_rotation(protein_t *ind_new, const input_parameters_t *in_para)
{
    float angle_radians, rate;
    int num_residue_choose;
    int what_rotation;
    int max_kind_of_rotation = 4;

    rate = _get_float();
    num_residue_choose = 0;

    if (rate < in_para->individual_mutation_rate)
    {
        for (int number_rotations = 1; number_rotations <= in_para->how_many_rotations; number_rotations++)
        {
            //Choose a residue
            num_residue_choose = get_choose_residue(&ind_new->p_topol->numres);
            //Obtaing kind of rotation
            what_rotation = _get_int_random_number(&max_kind_of_rotation);
            //Appling the rotation
            switch(what_rotation)
            {
                case 0:
                        angle_radians = _get_float_random_interval(&in_para->min_angle_mutation_psi,
                        &in_para->max_angle_mutation_psi);
                        rotation_psi(ind_new, &num_residue_choose, &angle_radians);
                        break;
                case 1:
                        angle_radians = _get_float_random_interval(&in_para->min_angle_mutation_phi,
                        &in_para->max_angle_mutation_phi);
                        rotation_phi(ind_new, &num_residue_choose, &angle_radians);
                        break;
                case 2:
                        //Obtaing a random degree angule
                        angle_radians = _get_float_random_interval(&in_para->min_angle_mutation_omega,
                        &in_para->max_angle_mutation_omega);
                        rotation_omega(ind_new, &num_residue_choose, &angle_radians);
                        break;
                case 3:
                        int chi = 0;
                        int max_chi = -1;
                        char *res_name;
                        res_name = Malloc(char, 4);
                        get_res_name_from_res_num(res_name, &num_residue_choose,
                            ind_new->p_atoms, &ind_new->p_topol->numatom);
                        max_chi = get_number_chi(res_name);

                        switch(max_chi)
                        {
                            case 1:
                                    chi = 1;
                                    break;
                            case 0:
                                    chi = _get_int_random_number(&max_chi);
                                    break;
                            default:
                                    break;
                        }
                        free(res_name);
                        break;
                default:
                        break;
            }
        }
    }
}