/**
 * The function creates the quadratic spline curve
 *
 * @param c_points   control points
 * @param smoothness smoothness to achieve

 * @param curve      holds the smooth curve
 */
void CubicSpline::cubic_spline( const std::vector<Point>& c_points,
                                const float& smoothness,
                                std::vector<Point>* curve) const {
    if(is_smooth(c_points, smoothness)) {
        for(unsigned int i = 0, i_end = c_points.size(); i < i_end; ++i) {
            curve->push_back(c_points.at(i));
        }
    } else {
        std::vector<Point>* sub_points = new std::vector<Point>();

        sub_points->push_back(*c_points.begin());

        for(int i = 0, i_end = c_points.size() -1; i < i_end; ++i) {
            sub_points->push_back(c_points.at(i) * 1/2 + c_points.at(i+1) * 1/2);
            if(i < i_end - 1) {
                sub_points->push_back(c_points.at(i) * 1/8
                                      + c_points.at(i+1) * 6/8
                                      + c_points.at(i+2) * 1/8);
            }
        }

        sub_points->push_back(*(c_points.end()-1));

        cubic_spline(*sub_points, smoothness, curve);

        delete sub_points;
    }
}
예제 #2
0
/**
 * @brief Returns the value of a property of this movement.
 *
 * Accepted keys:
 * - speed
 * - angle
 * - max_distance
 * - ignore_obstacles
 * - smooth
 * - displayed_direction
 *
 * @param key key of the property to get
 * @return the corresponding value as a string
 */
const std::string StraightMovement::get_property(const std::string &key) {

  std::ostringstream oss;

  if (key == "speed") {
    oss << get_speed();
  }
  else if (key == "angle") {
    oss << get_angle();
  }
  else if (key == "max_distance") {
    oss << get_max_distance();
  }
  else if (key == "ignore_obstacles") {
    oss << are_obstacles_ignored();
  }
  else if (key == "smooth") {
    oss << is_smooth();
  }
  else if (key == "displayed_direction") {
    oss << get_displayed_direction4();
  }
  else {
    Debug::die(StringConcat() << "Unknown property of StraightMovement: '" << key << "'");
  }

  return oss.str();
}
예제 #3
0
/**
 * @brief Updates the y position of the entity if it wants to move.
 */
void StraightMovement::update_y() {

  if (is_smooth()) {
    update_smooth_y();
  }
  else {
    update_non_smooth_y();
  }
}