コード例 #1
0
AlphaState EightTurn::get_setpoint(AlphaState state){
  AlphaState setpoint;
  setpoint.pos.z = initial_state.pos.z;
  float aim_rot_z = 0;
  if(phase == 0){//first half of the eight turn
    setpoint.rot.x = EIGHT_ROLL_SETPOINT;
    aim_rot_z = add_angle(initial_state.rot.z,M_PI);
  }
  else if(phase == 1){
    setpoint.rot.x = EIGHT_ROLL_SETPOINT;
    aim_rot_z = add_angle(initial_state.rot.z,M_PI/3);
  }
  else if(phase == 2){//other side of the eight turn
    setpoint.rot.x = -EIGHT_ROLL_SETPOINT;
    aim_rot_z = add_angle(initial_state.rot.z,M_PI);
  }
  else if(phase == 3){
    setpoint.rot.x = -EIGHT_ROLL_SETPOINT;
    aim_rot_z = add_angle(initial_state.rot.z,-M_PI/6);
  }
  else{
    setpoint.rot.x = 0;
  }
  pid_reset = false;
  if(in_range(aim_rot_z,state.rot.z,angle_error_range) && phase < 4){
    phase++;
    if(phase == 2 || phase == 4)
      pid_reset = true;
  }

  return setpoint;
}
コード例 #2
0
ファイル: CHARMMParameters.cpp プロジェクト: apolitis/imp
Particles CHARMMParameters::create_angles(kernel::Particles bonds) const {
  IMP_OBJECT_LOG;
  kernel::Particles ps;
  BondMap particle_bonds;
  make_bond_map(bonds, particle_bonds);

  // Iterate over all bonds
  for (kernel::Particles::const_iterator bit1 = bonds.begin();
       bit1 != bonds.end(); ++bit1) {
    IMP::atom::Bond bd = IMP::atom::Bond(*bit1);
    kernel::Particle *p2 = bd.get_bonded(0).get_particle();
    kernel::Particle *p3 = bd.get_bonded(1).get_particle();

    // Extend along each adjoining p2 bond to get candidate p1-p2-p3 angles
    for (base::Vector<IMP::atom::Bond>::const_iterator bit2 =
             particle_bonds[p2].begin();
         bit2 != particle_bonds[p2].end(); ++bit2) {
      kernel::Particle *p1 = get_other_end_of_bond(p2, *bit2);
      // Avoid making angles where p1 == p3, and avoid double-counting
      if (p3 > p1) {
        add_angle(p1, p2, p3, ps);
      }
    }
    // Do the same for p2-p3-p4 angles
    for (base::Vector<IMP::atom::Bond>::const_iterator bit2 =
             particle_bonds[p3].begin();
         bit2 != particle_bonds[p3].end(); ++bit2) {
      kernel::Particle *p4 = get_other_end_of_bond(p3, *bit2);
      if (p4 < p2) {
        add_angle(p2, p3, p4, ps);
      }
    }
  }
  return ps;
}
コード例 #3
0
AlphaState RiseTurn::get_setpoint(AlphaState state){
 AlphaState setpoint;
 setpoint.rot.x = MAX_ROLL_SETPOINT;
 float aim_rot_z;
 if(phase==0){
   setpoint.pos.z = initial_state.pos.z;
   aim_rot_z = add_angle(initial_state.rot.z,M_PI);
 }
 else if(phase==1){
   setpoint.pos.z = initial_state.pos.z;
   aim_rot_z = add_angle(initial_state.rot.z,0);
 }
 else if(phase==2){
   setpoint.pos.z = initial_state.pos.z;
   aim_rot_z = add_angle(initial_state.rot.z,M_PI);
 }
 else if(phase==3){
   setpoint.pos.z = initial_state.pos.z;
   aim_rot_z = add_angle(initial_state.rot.z,0);
 }
 else{
   pid_throttle = true;
   setpoint.pos.z = initial_state.pos.z+6;
 }
 
 pid_reset = false;
 
 if(in_range(aim_rot_z,state.rot.z,angle_error_range) && phase < 4){
   phase++;
   
   if(phase==4){
     pid_reset = true;
     initial_state = state;
   }
   
 }
 


  return setpoint;
}
コード例 #4
0
ファイル: misc.c プロジェクト: arvidfm/fiend
void make_bullet_hit_flesh(int i,int power, int color)
{
	int amount,j;
	int x_add=0, y_add=0;
	
	amount = RANDOM(15,27);
	for(j=0;j<amount;j++)
	{

		x_add = RANDOM(-3,3);
		y_add = RANDOM(-3,3);
		make_new_particle("blood",missile_data[i].x+x_add, missile_data[i].y+y_add, add_angle(missile_data[i].angle,RANDOM(150,210) )
			,(float)(RANDOM(5,12))/10,0.001, RANDOM(40,60),2,color);

	}
	
}
コード例 #5
0
ファイル: input.c プロジェクト: slitvinov/BD_BOX
void parse_angle()
{
    INT ids[3];
    DOUBLE temp[2];
    STR typea;
    typea = strtok( NULL, " \t\n" );
    if( typea == NULL ) UNERR("Wrong line in " ANGLE_TAG " no name");

    parse_ints( ids, 3 );
    parse_doubles( temp, 2 );
    if( strtok( NULL, " \t\n" ) ) UNERR("Wrong line in " ANGLE_TAG " too many columns");
    if( strcmp( typea, "cosine") == 0 )
    {
        add_angle_cos( resolve_pos(ids[0]), resolve_pos(ids[1]),
                       resolve_pos(ids[2]), temp[0], temp[1] );
    }
    else
    {
        add_angle( resolve_pos(ids[0]), resolve_pos(ids[1]),
                   resolve_pos(ids[2]), temp[0], temp[1] );
    }
}
コード例 #6
0
ファイル: menu.cpp プロジェクト: limbahq/example-tomatoes
// Show a menu. Returns the action taken.
int show_menu(int menu_id) {
	// Initialize
	int action = 0;
	int menu_item = MENU_START;
	back_anim = 0.0f;
	bx_roll = RANDF(0,1);
	by_roll = RANDF(0,1);
	bx_roll_dir = RANDF(-0.001f,0.001f);
	by_roll_dir = RANDF(-0.001f,0.001f);
	mid_fade_amount = 0.0f;
	mid_fade_dir = 1;
	mid_state = 1;
	mid_state_wait = WAIT_BEFORE_FADE_IN * FADE_WAIT_FACTOR;
	memset(key, 0, sizeof(key));
	setting_key = false;
	key_to_set = NULL;
	whose_keys = 0;
	prev_key = 0;

	// Load the hiscores
	hiscore_1.load(get_hiscore_location(1));
	hiscore_2.load(get_hiscore_location(2));

	// Fade in
	fading = 1;
	fade_amount = 1.0f;

	SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);


	// Menu loop
	bool menu_loop = true;
	timer_count = 0;
	while(menu_loop) {
		// Handle events
		SDL_Event event;
		while(SDL_PollEvent(&event)) {
			switch(event.type) {
				case SDL_QUIT:		// Quit
					menu_loop = false;
					action = MENU_EXIT;
					break;

				case SDL_KEYDOWN:
					// Update the 'key' array
					if(setting_key == false)
						key[event.key.keysym.sym] = 1;
					// Set the key if it's not ESC, F12, F1
					else if(setting_key == true && event.key.keysym.sym != SDLK_ESCAPE && event.key.keysym.sym != SDLK_F12 && event.key.keysym.sym != SDLK_F1) {
						(*key_to_set) = event.key.keysym.sym;
						setting_key = false;
					}
					// ESC pressed -> cancel the key setting
					else if(setting_key == true && event.key.keysym.sym == SDLK_ESCAPE) {
						(*key_to_set) = prev_key;
						setting_key = false;
					}
					break;

				case SDL_KEYUP:
					// Update the 'key' array
					key[event.key.keysym.sym] = 0;
					break;
			}
		}

		while(timer_count > 0) {
			// Fade
			if(fading) {
				if(fading == 1) {
					// Fade in
					fade_amount -= 0.015f;
					if(fade_amount <= 0.0f) {
						fading = 0;
						fade_amount = 0.0f;
					}
				}
				else if(fading == 2) {
					// Fade out
					fade_amount += 0.015f;
					if(fade_amount >= 1.0f) {
						fading = 0;
						fade_amount = 1.0f;
						menu_loop = false;
					}
				}
			}

			// Take a screenshot?
			if(key[SDLK_F12])
				save_screenshot();

			// Handle the cursor movement
			if(key[SDLK_UP] || (key[SDLK_LEFT] && menu_item != MENU_MUSICVOL && menu_item != MENU_SOUNDVOL)) {
				play_sound(SND_MENU1, false);
				menu_item--;
				if(menu_id == MENU_ID_MAIN) {
					if(menu_item < MENU_START)
						menu_item = MENU_EXIT;
				}
				else if(menu_id == MENU_ID_START) {
					if(menu_item < MENU_SINGLEPLAY)
						menu_item = MENU_MULTIPLAY;
				}
				else if(menu_id == MENU_ID_OPTIONS) {
					if(menu_item < MENU_WHOSEKEYS)
						menu_item = MENU_CANCEL;
				}
			}

			if(key[SDLK_DOWN] || (key[SDLK_RIGHT] && menu_item != MENU_MUSICVOL && menu_item != MENU_SOUNDVOL)) {
				play_sound(SND_MENU1, false);
				menu_item++;
				if(menu_id == MENU_ID_MAIN) {
					if(menu_item > MENU_EXIT)
						menu_item = MENU_START;
				}
				else if(menu_id == MENU_ID_START) {
					if(menu_item > MENU_MULTIPLAY)
						menu_item = MENU_SINGLEPLAY;
				}
				else if(menu_id == MENU_ID_OPTIONS) {
					if(menu_item > MENU_CANCEL)
						menu_item = MENU_WHOSEKEYS;
				}
			}

			// Handle the ESC pressings
			if(key[SDLK_ESCAPE]) {
				play_sound(SND_MENU2, false);
				// In the main menu -> exit, otherwise return to the main menu
				if(menu_id == MENU_ID_MAIN) {
					action = MENU_EXIT;
					fading = 2;		// Fade out
				}
				if(menu_id == MENU_ID_START) {
					menu_id = MENU_ID_MAIN;
					menu_item = MENU_START;
				}
				if(menu_id == MENU_ID_OPTIONS) {
					menu_id = MENU_ID_MAIN;
					menu_item = MENU_OPTIONS;

					mid_fade_amount = 0.0f;
					mid_fade_dir = 1;
					mid_state = 1;
					mid_state_wait = WAIT_BEFORE_FADE_IN * FADE_WAIT_FACTOR;

					// Restore the settings
					load_config(get_config_location(), &config);
					Mix_Volume(-1,config.sound_vol);
					Mix_VolumeMusic(config.music_vol);
				}
			}

			// Handle the item selection
			if(key[SDLK_RETURN] || key[SDLK_KP_ENTER] || key[SDLK_SPACE]) {
				play_sound(SND_MENU2, false);
				switch(menu_item) {
					// MAIN MENU items
					case MENU_START:			// Start menu
						menu_id = MENU_ID_START;
						menu_item = MENU_SINGLEPLAY;
						break;
					case MENU_OPTIONS:			// Options menu
						menu_id = MENU_ID_OPTIONS;
						menu_item = MENU_WHOSEKEYS;
						break;
					case MENU_EXIT:				// Exit the game
						action = MENU_EXIT;
						fading = 2;				// Fade out
						break;

					// START MENU items
					case MENU_SINGLEPLAY:		// Start a single player game
						action = MENU_SINGLEPLAY;
						fading = 2;				// Fade out;
						break;
					case MENU_MULTIPLAY:		// Start a two player game
						action = MENU_MULTIPLAY;
						fading = 2;				// Fade out
						break;

					// OPTIONS MENU items
					case MENU_WHOSEKEYS:		// Toggle the player whose keys we're setting
						if(whose_keys == 0)
							whose_keys = 1;
						else if(whose_keys == 1)
							whose_keys = 0;
						break;
					case MENU_MOVSTYLE:			// Toggle the moving style
						if(config.moving_style[whose_keys] == 1)
							config.moving_style[whose_keys] = 2;
						else if(config.moving_style[whose_keys] == 2)
							config.moving_style[whose_keys] = 1;
						break;
					case MENU_KEYUP:			// Set the key up
						key_to_set = &(config.key_up[whose_keys]);
						setting_key = true;
						prev_key = config.key_up[whose_keys];
						config.key_up[whose_keys] = -1;
						break;

					case MENU_KEYDOWN:			// Set the key down
						key_to_set = &(config.key_down[whose_keys]);
						setting_key = true;
						prev_key = config.key_down[whose_keys];
						config.key_down[whose_keys] = -1;
						break;

					case MENU_KEYLEFT:			// Set the key left
						key_to_set = &(config.key_left[whose_keys]);
						setting_key = true;
						prev_key = config.key_left[whose_keys];
						config.key_left[whose_keys] = -1;
						break;

					case MENU_KEYRIGHT:			// Set the key right
						key_to_set = &(config.key_right[whose_keys]);
						setting_key = true;
						prev_key = config.key_right[whose_keys];
						config.key_right[whose_keys] = -1;
						break;

					case MENU_KEYBOMB:			// Set the key bomb
						key_to_set = &(config.key_shoot[whose_keys]);
						setting_key = true;
						prev_key = config.key_shoot[whose_keys];
						config.key_shoot[whose_keys] = -1;
						break;

					case MENU_KEYSPECIAL:		// Set the key special
						key_to_set = &(config.key_special[whose_keys]);
						setting_key = true;
						prev_key = config.key_special[whose_keys];
						config.key_special[whose_keys] = -1;
						break;

					case MENU_PERSPECTIVE:		// Toggle the perspective mode
						config.perspective_mode = !config.perspective_mode;
						break;

					case MENU_OK:				// Save the changes
						menu_id = MENU_ID_MAIN;
						menu_item = MENU_OPTIONS;

						mid_fade_amount = 0.0f;
						mid_fade_dir = 1;
						mid_state = 1;
						mid_state_wait = WAIT_BEFORE_FADE_IN * FADE_WAIT_FACTOR;

						save_config(get_config_location(true), &config);
						break;

					case MENU_CANCEL:			// Cancel the changes
						menu_id = MENU_ID_MAIN;
						menu_item = MENU_OPTIONS;

						mid_fade_amount = 0.0f;
						mid_fade_dir = 1;
						mid_state = 1;
						mid_state_wait = WAIT_BEFORE_FADE_IN * FADE_WAIT_FACTOR;

						// Restore the settings
						load_config(get_config_location(), &config);
						Mix_Volume(-1,config.sound_vol);
						Mix_VolumeMusic(config.music_vol);
				}
			}

			// Check the volume level sliders
			if(menu_item == MENU_MUSICVOL) {
				if(key[SDLK_LEFT]) {
					config.music_vol -= 10;
					if(config.music_vol < 0)
						config.music_vol = 0;
					// Update the volume levels
					Mix_VolumeMusic(config.music_vol);
				}
				if(key[SDLK_RIGHT]) {
					config.music_vol += 10;
					if(config.music_vol > 255)
						config.music_vol = 255;
					// Update the volume levels
					Mix_VolumeMusic(config.music_vol);
				}
			}
			if(menu_item == MENU_SOUNDVOL) {
				if(key[SDLK_LEFT]) {
					config.sound_vol -= 10;
					if(config.sound_vol < 0)
						config.sound_vol = 0;
					// Update the volume levels
					Mix_Volume(-1,config.sound_vol);
					play_sound(SND_MENU1, false);
				}
				if(key[SDLK_RIGHT]) {
					config.sound_vol += 10;
					if(config.sound_vol > 255)
						config.sound_vol = 255;
					// Update the volume levels
					Mix_Volume(-1,config.sound_vol);
					play_sound(SND_MENU1, false);
				}
			}


			// Clear the key array
			memset(key, 0, sizeof(key));

			// Animate the background
			back_anim = add_angle(back_anim, 2.0f);
			bx_roll += bx_roll_dir;
			if(bx_roll > 1.0f)
				bx_roll -= 1.0f;
			else if(bx_roll < 0.0f)
				bx_roll += 1.0f;

			by_roll += by_roll_dir;
			if(by_roll > 1.0f)
				by_roll -= 1.0f;
			else if(by_roll < 0.0f)
				by_roll += 1.0f;

			// Handle the hiscores/credits
			if(menu_id == MENU_ID_MAIN || menu_id == MENU_ID_START) {
				if(mid_state_wait > 0)
					mid_state_wait--;
				else if(mid_state_wait == 0) {
					// Fade either in or out
					if(mid_fade_dir == 1) {
						if(mid_fade_amount < 1.0f)
							mid_fade_amount += FADE_STEP;
						if(mid_fade_amount >= 1.0f) {
							// Wait a bit before fading out
							mid_fade_dir = 2;
							mid_state_wait = WAIT_BEFORE_FADE_OUT * FADE_WAIT_FACTOR;
						}
					}
					else if(mid_fade_dir == 2) {
						if(mid_fade_amount > 0.0f)
							mid_fade_amount -= FADE_STEP;
						if(mid_fade_amount <= 0.0f) {
							// Wait a bit before changing the state and fading in
							mid_fade_dir = 1;
							mid_state_wait = WAIT_BEFORE_FADE_IN * FADE_WAIT_FACTOR;
							mid_state++;
							if(mid_state > 3)
								mid_state = 1;
						}
					}
				}
			}

			timer_count--;
		}


		// Draw the menu
		draw_menu(menu_id, menu_item, -1, fade_amount, NULL);

		// Flush and swap the buffers
		glFlush();
		SDL_GL_SwapBuffers();

	}

	SDL_EnableKeyRepeat(0,0);
	return action;
}
コード例 #7
0
ファイル: misc.c プロジェクト: arvidfm/fiend
void update_shells(void)
{
	int i;
	int type;
	float temp_x, temp_y;

	for(i=0;i<MAX_SHELL_NUM;i++)
		if(shell_data[i].used)
		{
			type = shell_data[i].type;

			xyplus(shell_data[i].speed, shell_data[i].angle, &temp_x, &temp_y);
			
				
			/// The bouncing up and down
			if(shell_data[i].dir==0)
			{
				shell_data[i].z-=0.05;
				if(shell_data[i].z<0.5)
				{
					shell_data[i].z=0.5;
					shell_data[i].dir=1;
					shell_data[i].max_z-=0.2;
					
					if(shell_data[i].max_z<0)shell_data[i].max_z=0;
					
					if(shell_data[i].max_z>0.6)
						play_fiend_sound(particle_info[type].name,shell_data[i].x,shell_data[i].y, 1,0,100);

					
				}
			}

			if(shell_data[i].dir==1)
			{
				shell_data[i].z+=0.05;
				if(shell_data[i].z>shell_data[i].max_z)
				{
					shell_data[i].z=shell_data[i].max_z;
					shell_data[i].dir=0;
				}
			}
			
			//The speed
			shell_data[i].speed-=0.01;
			if(shell_data[i].speed<0)shell_data[i].speed=0;


			
			//The bouncing on walls and stuff
			shell_data[i].x+=temp_x;
			shell_data[i].y+=temp_y;

			if(shell_collides(shell_data[i].x, shell_data[i].y))
			{
				play_fiend_sound(particle_info[type].name,shell_data[i].x,shell_data[i].y, 1,0,100); 
				
				shell_data[i].x-=temp_x;
				shell_data[i].y-=temp_y;
				
				shell_data[i].angle=add_angle(shell_data[i].angle, 180);

			}
			
			
			//The life time
			shell_data[i].time--;
			if(shell_data[i].time<1)shell_data[i].used=0;
		}
	
}