Esempio n. 1
0
        inline UniDirection dirToUni(Direction dir_)
        {
            int x = dir_x(dir_);
            int y = dir_y(dir_);

                 if(x == -1 || y == -1) return UniDirection::UP_LEFT;
            else if(x ==  1 || y == -1) return UniDirection::UP_RIGHT;
            else if(x == -1 || y ==  1) return UniDirection::DOWN_LEFT;
            else if(x ==  1 || y ==  1) return UniDirection::DOWN_RIGHT;
            else if(x ==  0 || y == -1) return UniDirection::UP;
            else if(x ==  0 || y ==  1) return UniDirection::DOWN;
            else if(x == -1 || y ==  0) return UniDirection::LEFT;
            else if(x ==  1 || y ==  0) return UniDirection::RIGHT;
            else return UniDirection::NONE;   
        }
Esempio n. 2
0
int trace_line_interpolate(point_t end_point) {
    int x_diff;
    int y_diff;
    int xy_bal;

    x_diff = end_point.x - current_point.x;
    y_diff = end_point.y - current_point.y;

    dir_x(x_diff);
    dir_y(y_diff);

    x_diff = abs(end_point.x - current_point.x);
    y_diff = abs(end_point.y - current_point.y);

    xy_bal = x_diff - y_diff;

    while(current_point.x != end_point.x
            || current_point.y != end_point.y) {
        if(xy_bal > 0) {
            step_x();

            xy_bal -= y_diff;
        } else if(xy_bal < 0) {
            step_y();

            xy_bal += x_diff;
        } else {
            step_xy();

            xy_bal -= y_diff;
            xy_bal += x_diff;
        }

        if(steps > x_diff + y_diff) {
            printf("Ran too long!\n");
            break;
        }
    }
}
Esempio n. 3
0
 inline ck::Vector2i direction(UniDirection udir_)
 {
     Direction dir = uniToDir(udir_);
     return ck::Vector2i(dir_x(dir), dir_y(dir));
 }
Esempio n. 4
0
 inline ck::Vector2i direction(Direction dir)
 {
     return ck::Vector2i(dir_x(dir), dir_y(dir));
 }