int main()
{
	int hour, minute;
	
	printf("Hour: ");
	scanf("%d", &hour);

	printf("Minute: ");
	scanf("%d", &minute);

	if (hour < 0 || hour > 12) {
		printf("invalid hour (0-12) : %d\n", hour);
		return 0;
	}
		
	if (minute < 0 || minute > 60) {
		printf("invalid minute (0-60) : %d\n", minute);
		return 0;
	}

	printf("Angle between %d hour and %d minutes = %3.1f degrees \n", 
			hour, minute, find_angle(hour, minute));

	return 0;
}
コード例 #2
0
ファイル: car.cpp プロジェクト: Arlenka/Rock-n-Roll-Race
void Car::Calculate_angles()
{
	for( int i = 1; i < coords.size(); ++i ) {
		coords[i - 1].angle = find_angle( coords[i].x - coords[i - 1].x, coords[i].y - coords[i - 1].y );
		if( coords[i].y - coords[i - 1].y < 0 ) {
			coords[i - 1].help_angle = PI;
		}
	}
	coords[coords.size() - 1].angle = coords[coords.size() - 2].angle;
	coords[coords.size() - 1].help_angle = coords[coords.size() - 2].help_angle;
}
コード例 #3
0
ファイル: enemy.cpp プロジェクト: ADSgames/Gunner2.0
void enemy::update(){

  //if(random(1,1000)==1)create_mine(x,y);

  //angle_radians=find_angle(x+100,y+30,player_x+15,player_y+20);

  if(health<=0){
    game_world -> delete_enemy(this);
    game_world -> create_item( RICOCHET, x, y);

  }

  if( direction == LEFT)
    x -= 5;
  if( direction == RIGHT)
    x += 5;

  if( x > SCREEN_W-200){
    direction = HOVER;
    movement_timer++;
    if( movement_timer > 120){
      direction = LEFT;
      movement_timer = 0;
    }
  }

  if( x < 25){
    direction = HOVER;
    movement_timer++;
    if( movement_timer > 120){
      direction = RIGHT;
      movement_timer = 0;
    }
  }

  if( fire_rate < fire_timer){
    game_world -> create_projectile( x + 100, y + 30, HELICOPTER,
                                    find_angle( x + 100, y + 30, game_world -> get_character_x() + 30,
                                               game_world -> get_character_y() + 15),5,false,5,5);
    fire_timer = 0;
  }

  hurt_timer--;
  fire_timer++;


  for( unsigned int i = 0; i < game_world -> get_projectiles() -> size(); i++){
    if( collision(x,
                  x + width,
                  game_world -> get_projectiles() -> at(i) -> get_x(),
                  game_world -> get_projectiles() -> at(i) -> get_x() + game_world -> get_projectiles() -> at(i) -> get_width(),
                  y,
                  y + height,
                  game_world -> get_projectiles() -> at(i) -> get_y(),
                  game_world -> get_projectiles() -> at(i) -> get_y() + game_world -> get_projectiles() -> at(i) -> get_height()
                  )
        && game_world -> get_projectiles() -> at(i) -> get_owner()){
      health -= 5;
      hurt_timer = 3;
      game_world -> delete_projectile(game_world -> get_projectiles() -> at(i));

    }
  }

  /*if( health < 1){
    if( helicopter_killcount < 15){
      if(random( 1, 15 - helicopter_killcount) == 1){
        create_box( x, y, 0);
      }
    }
    else if( random( 1, 2) == 1)
      create_box( x - 76, y, 0);

    if( random( 1, 2) == 1)
      create_box( x, y, 3);

    if( helicopter_killcount < 20){
      if(random( 1, 20 - helicopter_killcount) == 1){
        create_box( x, y, 2);
      }
    }
    else
      create_box( x - 76, y, 2);

    create_box( x + 76, y, 1);

    health = 100;
    if( helicopter_killcount < 10)
      create_helicopter(1);
    if( helicopter_killcount > 9)
      create_helicopter( random( 1, 2));

    helicopter_killcount++;
  }*/
}
コード例 #4
-1
ファイル: canny.cpp プロジェクト: hone/school
ImageRAII canny( IplImage * image, std::pair< int, int > thresh, double sigma )
{
	const char * WINDOW_NAME = "Basic Canny Edge Detector";

	ImageRAII grayscale( cvCreateImage( cvGetSize( image ), image->depth, 1 ) );
	ImageRAII destination( cvCreateImage( cvGetSize( image ), image->depth, grayscale.image->nChannels ) );
	ImageRAII gaussian( cvCreateImage( cvGetSize( image ), image->depth, grayscale.image->nChannels ) );
	ImageRAII gradient_x( cvCreateImage( cvGetSize( image ), image->depth, grayscale.image->nChannels ) );
	ImageRAII gradient_y( cvCreateImage( cvGetSize( image ), image->depth, grayscale.image->nChannels ) );
	ImageRAII gradient( cvCreateImage( cvGetSize( image ), image->depth, grayscale.image->nChannels ) );
	ImageRAII orientation( cvCreateImage( cvGetSize( image ), image->depth, grayscale.image->nChannels ) );

	// convert image to grayscale
	cvCvtColor( image, grayscale.image, CV_BGR2GRAY );

	// gaussian smoothing
	cvSmooth( grayscale.image, gaussian.image, CV_GAUSSIAN, GAUSSIAN_X, GAUSSIAN_Y, sigma );
	// find edge strength
	cvSobel( gaussian.image, gradient_x.image, 1, 0, 3 );
	cvSobel( gaussian.image, gradient_y.image, 0, 1, 3 );
	// find edge orientation
	CvSize image_size = cvGetSize( gaussian.image );

	for( int i = 0; i < image_size.width; i++ )
	{
		for( int j = 0; j < image_size.height; j++ )
		{
			double x = cvGet2D( gradient_x.image, j, i ).val[0];
			double y = cvGet2D( gradient_y.image, j, i ).val[0];
			float angle;

			if( x == 0 )
			{
				if( y == 0 )
					angle = 0;
				else
					angle = 90;
			}
			else
				angle = cvFastArctan( y, x );

			CvScalar g;
			CvScalar a;
		   	g.val[0] = cvSqrt( pow( x, 2 ) + pow( y, 2 ) );
			a.val[0] = find_angle( angle );

			cvSet2D( destination.image, j, i, g );
			cvSet2D( orientation.image, j, i, a );
		}
	}

	ImageRAII suppressed_image = nonMaxSup( destination.image, orientation.image );
	ImageRAII hysteresis_image = hysteresis( suppressed_image.image, orientation.image, thresh );

	cvNamedWindow( WINDOW_NAME );
	cvShowImage( WINDOW_NAME, destination.image );
	cvMoveWindow( WINDOW_NAME, image_size.width, 0 );

	return hysteresis_image;
}