Пример #1
0
void menu::adjust_viewport_to_selection()
{
	if(click_selects_)
		return;
	//adjust_position(selected_);
	adjust_position(selected_ * item_height_);
}
Пример #2
0
/**
 * \brief Center the camera on the second player.
 * \param elapsed_time Elapsed time since the last call.
 */
void
ptb::shared_camera::set_second_player( bear::universe::time_type elapsed_time )
{
  if ( m_second_player != NULL )
    adjust_position( m_second_player.hot_spot(), elapsed_time );
  else if ( m_first_player != NULL )
    set_first_player( elapsed_time );
  else
    m_placement = do_nothing;
} // shared_camera::set_second_player()
Пример #3
0
/**
 * \brief Do one step in the progression of the item.
 * \param elapsed_time Elapsed time since the last call.
 */
void bear::camera_on_object::progress_fit_items
( bear::universe::time_type elapsed_time )
{
  unsigned int nb_objects(0);
  bear::universe::position_type top_left(get_center_of_mass());
  bear::universe::position_type bottom_right(get_center_of_mass());

  handle_list::const_iterator it;
  handle_list remaining_objects;

  for ( it = m_objects.begin(); it != m_objects.end(); ++it )
    if ( (*it).get() != NULL )
      {
        if ( (*it)->get_left() < top_left.x )
          top_left.x = (*it)->get_left();

        if ( (*it)->get_right() > bottom_right.x )
          bottom_right.x = (*it)->get_right();

        if ( (*it)->get_top() > top_left.y )
          top_left.y = (*it)->get_top();

        if ( (*it)->get_bottom() < bottom_right.y )
          bottom_right.y = (*it)->get_bottom();

        ++nb_objects;
        remaining_objects.push_back(*it);
      }

  std::swap(m_objects, remaining_objects);

  if ( nb_objects != 0 )
    {
      universe::position_type center((top_left + bottom_right) /2);
      adjust_position( center , elapsed_time );

      universe::size_type r_init = get_default_size().x / get_default_size().y;
      universe::coordinate_type w(bottom_right.x - top_left.x + 200);
      universe::coordinate_type h(top_left.y  - bottom_right.y + 200*r_init);

      if ( w > h*r_init )
        set_wanted_size(universe::size_box_type(w, w/r_init));
      else
        set_wanted_size(universe::size_box_type(h*r_init, h));
    }
} // camera_on_object::progress_fit_items()
Пример #4
0
/**
 * \brief Do one step in the progression of the item.
 * \param elapsed_time Elapsed time since the last call.
 */
void bear::camera_on_object::progress_center
( bear::universe::time_type elapsed_time )
{
  bear::universe::position_type center(0, 0);
  unsigned int nb_objects(0);

  handle_list::const_iterator it;
  handle_list remaining_objects;

  for ( it = m_objects.begin(); it != m_objects.end(); ++it )
    if ( (*it).get() != NULL )
      {
        center += (*it)->get_center_of_mass();
        ++nb_objects;
        remaining_objects.push_back(*it);
      }

  std::swap(m_objects, remaining_objects);

  if ( nb_objects != 0 )
    adjust_position( center / nb_objects , elapsed_time );
} // camera_on_object::progress()
Пример #5
0
/**
 * \brief Center the camera between the two players.
 * \param elapsed_time Elapsed time since the last call.
 */
void ptb::shared_camera::set_shared( bear::universe::time_type elapsed_time )
{
  if ( m_first_player != NULL )
    {
      if ( m_second_player != NULL )
        {
          bear::universe::position_type center1;
          bear::universe::position_type center2;

          center1 = m_first_player.hot_spot();
          center2 = m_second_player.hot_spot();

          adjust_position( (center1 + center2) / 2, elapsed_time );
        }
      else
        set_first_player( elapsed_time );
    }
  else if ( m_second_player != NULL )
    set_second_player( elapsed_time );
  else
    m_placement = do_nothing;
} // shared_camera::set_shared()
/**
 * \brief Set the position and the angle of the arrow.
 * \param glob The level globals in which we load the media.
 * \param visible_area The visible part of the level.
 */
void ptb::player_arrows_layer::player_data::adjust_arrow
( bear::engine::level_globals& glob,
  const bear::universe::rectangle_type& visible_area )
{
  m_visible = false;

  if ( (m_player != NULL) && !m_player.is_a_marionette() )
    {
      const bear::universe::position_type center =
        m_player.get_center_of_mass();

      if( ( center.x < visible_area.left() ) ||
          ( center.x > visible_area.left() + visible_area.size().x ) ||
          ( center.y < visible_area.bottom() ) ||
          ( center.y > visible_area.bottom() + visible_area.size().y ) )
        {
          adjust_position( visible_area );
          adjust_angle( visible_area );
          adjust_distance(glob, visible_area );

          m_visible = true;
        }
    }
} // player_arrows_layer::player_data::adjust_arrow()
Пример #7
0
void menu::adjust_viewport_to_selection()
{
	if(click_selects_)
		return;
	adjust_position(selected_);
}
Пример #8
0
bool placement_finder<DetectorT>::find_point_placement(double label_x,
                                                       double label_y,
                                                       double angle)
{
    find_line_breaks();

    double rad = M_PI * angle/180.0;
    double cosa = std::cos(rad);
    double sina = std::sin(rad);

    double x, y;
    std::auto_ptr<text_path> current_placement(new text_path(label_x, label_y));

    adjust_position(current_placement.get());

    // presets for first line
    unsigned int line_number = 0;
    unsigned int index_to_wrap_at = line_breaks_[0];
    double line_width = line_sizes_[0].first;
    double line_height = line_sizes_[0].second;

    /* IMPORTANT NOTE:
       x and y are relative to the center of the text
       coordinate system:
       x: grows from left to right
       y: grows from bottom to top (opposite of normal computer graphics)
    */

    // set for upper left corner of text envelope for the first line, bottom left of first character
    y = string_height_ / 2.0 - line_height;
    // RTL text is converted to a mirrored representation in get_string_info()
    // so we have to fix line break order here
    if (info_.get_rtl()) y = -y;

    // adjust for desired justification
    if (jalign_ == J_LEFT)
        x = -(string_width_ / 2.0);
    else if (jalign_ == J_RIGHT)
        x = (string_width_ / 2.0) - line_width;
    else /* J_MIDDLE */
        x = -(line_width / 2.0);

    // save each character rendering position and build envelope as go thru loop
    std::queue< box2d<double> > c_envelopes;

    for (unsigned i = 0; i < info_.num_characters(); i++)
    {
        char_info const& ci = info_.at(i);

        double cwidth = ci.width + ci.format->character_spacing;

        if (i == index_to_wrap_at)
        {
            index_to_wrap_at = line_breaks_[++line_number];
            line_width = line_sizes_[line_number].first;
            line_height= line_sizes_[line_number].second;

            if (info_.get_rtl())
            {
                y += line_height;
            } else
            {
                y -= line_height;  // move position down to line start
            }

            // reset to begining of line position
            if (jalign_ == J_LEFT)
                x = -(string_width_ / 2.0);
            else if (jalign_ == J_RIGHT)
                x = (string_width_ / 2.0) - line_width;
            else
                x = -(line_width / 2.0);
            continue;
        }
        else
        {
            // place the character relative to the center of the string envelope
            double dx = x * cosa - y*sina;
            double dy = x * sina + y*cosa;

            current_placement->add_node(&ci, dx, dy, rad);

            // compute the Bounding Box for each character and test for:
            // overlap, minimum distance or edge avoidance - exit if condition occurs
            box2d<double> e;
            /*x axis: left to right, y axis: top to bottom (negative values higher)*/
            e.init(current_placement->center.x + dx,                    // Bottom Left
                   current_placement->center.y - dy - ci.ymin,          // ymin usually <0
                   current_placement->center.x + dx + ci.width,         // Top Right
                   current_placement->center.y - dy - ci.ymax);

            // if there is an overlap with existing envelopes, then exit - no placement

            if (!detector_.extent().intersects(e) ||
                (!p.allow_overlap &&
                 !detector_.has_point_placement(e, pi.get_actual_minimum_distance())))
            {
                return false;
            }

            // if avoid_edges test dimensions contains e
            if (p.avoid_edges && !dimensions_.contains(e))
            {
                return false;
            }

            if (p.minimum_padding > 0)
            {
                double min_pad = pi.get_actual_minimum_padding();
                box2d<double> epad(e.minx()-min_pad,
                                   e.miny()-min_pad,
                                   e.maxx()+min_pad,
                                   e.maxy()+min_pad);
                if (!dimensions_.contains(epad))
                {
                    return false;
                }
            }


            c_envelopes.push(e);  // add character's envelope to temp storage
        }
        x += cwidth;  // move position to next character
    }

    // check the placement of any additional envelopes
    if (!p.allow_overlap && !additional_boxes_.empty())
    {
        BOOST_FOREACH(box2d<double> const& box, additional_boxes_)
        {
            box2d<double> pt(box.minx() + current_placement->center.x,
                             box.miny() + current_placement->center.y,
                             box.maxx() + current_placement->center.x,
                             box.maxy() + current_placement->center.y);

            // abort the whole placement if the additional envelopes can't be placed.
            if (!detector_.has_point_placement(pt, p.minimum_distance)) return false;

            c_envelopes.push(pt);
        }
/*
 * The task 'VehicleTask' updates the current velocity of the vehicle
 */
void VehicleTask(void* pdata)
{ 
  INT8U err, err_tmr_1, err_tmr_start, err_sem;  
  void* msg;
  INT8U* throttle; 
  INT8S acceleration;  /* Value between 40 and -20 (4.0 m/s^2 and -2.0 m/s^2) */
  INT8S retardation;   /* Value between 20 and -10 (2.0 m/s^2 and -1.0 m/s^2) */
  INT16U position = 0; /* Value between 0 and 20000 (0.0 m and 2000.0 m)  */
  INT16S wind_factor;   /* Value between -10 and 20 (2.0 m/s^2 and -1.0 m/s^2) */

  Sem_VehicleTask = OSSemCreate(0);
  //OSSemPend(Sem_VehicleTask,0,&err_sem);

  printf("Vehicle task created!\n");
   
  
    SWTimer_VehicleTask = OSTmrCreate(0, VEHICLE_PERIOD, OS_TMR_OPT_PERIODIC, Tmr_Callback_Vehicle_Task, (void *)0,"S/W Timer 2",&err_tmr_1);
    if(err_tmr_1 == OS_ERR_NONE){
        if(DEBUG)
        printf("Timer for VECHICLE TASK is created\n"); 
        
        OSTmrStart(SWTimer_VehicleTask, &err_tmr_start);
        
        if(err_tmr_start == OS_ERR_NONE){
            if(DEBUG)
            printf("Timer started in VEHICLE TASK \n");
        }
        else {
            printf("Problem starting timer in VEHICLE TASK \n");
        }       
      }
      else {
      printf("Error while creating Vehicle task timer \n");     
     
      if(err_tmr_1 == OS_ERR_TMR_INVALID_DLY)
      printf(" Delay INVALID : VEHICLE TASK\n");
      
      }

  while(1)
    {
        // Wait for user inputs
        OSSemPend(Sem_SwitchIO_IP , 0, &err_sem);
        OSSemPend(Sem_ButtonIO_IP, 0, &err_sem);
        
        if((brake_pedal == on) && (CUR_VELOCITY > 0)){
            CUR_VELOCITY = CUR_VELOCITY - 10;
            
           // if(CUR_VELOCITY < -200)         // Max value for velocity
            //CUR_VELOCITY = -200; 
            
            if(DEBUG_IO)
            printf("********** Brake brake_pedal : %d ********** \n", CUR_VELOCITY);
        }
        
      err = OSMboxPost(Mbox_Velocity, (void *) &CUR_VELOCITY);
      
      if(DEBUG)
      printf("Vehicle task Posted MBoxPost_Velocity \n");

        if(DEBUG)
        printf("SEM ACCESS VEHICLE TASK\n\n");
        
        OSSemPend(Sem_VehicleTask,0,&err_sem);
        
      /* Non-blocking read of mailbox: 
       - message in mailbox: update throttle
       - no message:         use old throttle
      */
      if(DEBUG)
      printf("Vehicle task waiting for MBoxPost_Throttle for 1 unit time \n");
      
      msg = OSMboxPend(Mbox_Throttle, 1, &err); 
      if (err == OS_NO_ERR) 
         throttle = (INT8U*) msg;

      if(DEBUG)
      printf("Vehicle task GOT MBoxPost_Throttle \n");
      
      /* Retardation : Factor of Terrain and Wind Resistance */
      if (CUR_VELOCITY > 0)
         wind_factor = CUR_VELOCITY * CUR_VELOCITY / 10000 + 1;
      else 
         wind_factor = (-1) * CUR_VELOCITY * CUR_VELOCITY / 10000 + 1;
         
      if (position < 4000) 
         retardation = wind_factor; // even ground
      else if (position < 8000)
          retardation = wind_factor + 15; // traveling uphill
        else if (position < 12000)
            retardation = wind_factor + 25; // traveling steep uphill
          else if (position < 16000)
              retardation = wind_factor; // even ground
            else if (position < 20000)
                retardation = wind_factor - 10; //traveling downhill
              else
                  retardation = wind_factor - 5 ; // traveling steep downhill
                  
      acceleration = *throttle / 2 - retardation;     
      position = adjust_position(position, CUR_VELOCITY, acceleration, 300); 
      CUR_VELOCITY = adjust_velocity(CUR_VELOCITY, acceleration, brake_pedal, 300); 
      printf("Position: %dm\n", position / 10);
      printf("Velocity: %4.1fm/s\n", CUR_VELOCITY /10.0);
      printf("Throttle: %dV Time : %d \n\n", *throttle / 10, (int) (alt_timestamp() / (alt_timestamp_freq()/1000)));
      alt_timestamp_start();
     /* 
      INT32U stk_size;
  err = OSTaskStkChk(16, &stk_data);
      stk_size = stk_data.OSUsed;
      printf("Stack Used OverLoadDetection : %d \n", stk_size);
      
      err = OSTaskStkChk(14, &stk_data);
      stk_size = stk_data.OSUsed;
      printf("Stack Used DYNAMIV_UTI : %d \n", stk_size);
      
      err = OSTaskStkChk(12, &stk_data);
      stk_size = stk_data.OSUsed;
      printf("Stack Used CONTROLTASK: %d \n", stk_size);
      
      err = OSTaskStkChk(10, &stk_data);
      stk_size = stk_data.OSUsed;
      printf("Stack Used VehicleTask: %d \n", stk_size);
      
      err = OSTaskStkChk(8, &stk_data);
      stk_size = stk_data.OSUsed;
      printf("Stack Used SwitchIO: %d \n", stk_size);
      
      err = OSTaskStkChk(7, &stk_data);
      stk_size = stk_data.OSUsed;
      printf("Stack Used ButtonIO: %d \n", stk_size);
      
      err = OSTaskStkChk(6, &stk_data);
      stk_size = stk_data.OSUsed;
      printf("Stack Used WatchDog: %d \n", stk_size);
      
      err = OSTaskStkChk(5, &stk_data);
      stk_size = stk_data.OSUsed;
      printf("Stack Used Start Task: %d \n", stk_size);
*/
      show_velocity_on_sevenseg((INT8S) (CUR_VELOCITY / 10));
      show_active_signals();
      show_position(position);
      
     // OSSemPend(Sem_VehicleTask,0,&err_sem);
    }
} 
Пример #10
0
/**
 * Updates Tux's position taking into account gravity, friction, tree 
 * collisions, etc.  This is the main physics function.
 */
void
update_player_pos(float timestep)
{
    ppogl::Vec3d surf_nml;   // normal vector of terrain
    ppogl::Vec3d tmp_vel;
    float speed;
    float paddling_factor; 
    ppogl::Vec3d local_force;
    float flap_factor;
    pp::Plane surf_plane;
    float dist_from_surface;

    if(timestep > 2.0*EPS){
		for(int i=0; i<GameMgr::getInstance().numPlayers; i++){
			solve_ode_system(players[i], timestep);
		}
    }
	
	for(int i=0; i<GameMgr::getInstance().numPlayers; i++){
		Player& plyr=players[i];
		
		tmp_vel = plyr.vel;
	
		//Set position, orientation, generate particles
    	surf_plane = get_local_course_plane( plyr.pos );
    	surf_nml = surf_plane.nml;
		dist_from_surface = surf_plane.distance( plyr.pos );
		adjust_velocity( &plyr.vel, surf_plane );
		adjust_position( &plyr.pos, surf_plane, dist_from_surface );

		speed = tmp_vel.normalize();

		set_tux_pos( plyr, plyr.pos );
		adjust_orientation( plyr, timestep, plyr.vel, 
				dist_from_surface, surf_nml );

    	flap_factor = 0;

		if(plyr.control.is_paddling){
			double factor;
			factor = (GameMgr::getInstance().time - plyr.control.paddle_time) / PADDLING_DURATION;
			if(plyr.airborne){
	    		paddling_factor = 0;
	    		flap_factor = factor;
			}else{
	   			paddling_factor = factor;
	    		flap_factor = 0;
			}
    	}else{
			paddling_factor = 0.0;
    	}

		// calculate force in Tux's local coordinate system
    	local_force = plyr.orientation.conjugate().rotate(plyr.net_force);

    	if(plyr.control.jumping){
			flap_factor = (GameMgr::getInstance().time - plyr.control.jump_start_time) / JUMP_FORCE_DURATION;
    	} 

		tux[i].adjustJoints( plyr.control.turn_animation, plyr.control.is_braking,
		       	paddling_factor, speed, local_force, flap_factor );
	}
}