Exemplo n.º 1
0
void tileray::advance (int num)
{
    last_dx = last_dy = 0;
    int ax = abs(deltax);
    int ay = abs(deltay);
    int anum = abs (num);
    for (int i = 0; i < anum; i++)
    {
        if (mostly_vertical ())
        { // mostly vertical line
            leftover += ax;
            if (leftover >= ay)
            {
                last_dx++;
                leftover -= ay;
            }
            last_dy++;
        }
        else
        { // mostly horizontal line
            leftover += ay;
            if (leftover >= ax)
            {
                last_dy++;
                leftover -= ax;
            }
            last_dx++;
        }
        steps++;
    }

    // offset calculated for 0-90 deg quadrant, we need to adjust if direction is other
    int sx[4] = { 1, -1, -1, 1 };
    int sy[4] = { 1, 1, -1, -1 };
    int quadr = (direction / 90) % 4;
    last_dx *= sx[quadr];
    last_dy *= sy[quadr];
    if (num < 0)
    {
        last_dx = -last_dx;
        last_dy = -last_dy;
    }
}
Exemplo n.º 2
0
bool tileray::end ()
{
    if (infinite)
        return true;
    return mostly_vertical()? steps >= abs(deltay) - 1 : steps >= abs(deltax) - 1;
}
Exemplo n.º 3
0
int tileray::ortho_dy (int od)
{
    int quadr = (direction / 90) % 4;
    od *= sx[quadr];
    return mostly_vertical()? 0 : od;
}
Exemplo n.º 4
0
int tileray::ortho_dx (int od)
{
    int quadr = (direction / 90) % 4;
    od *= -sy[quadr];
    return mostly_vertical()? od : 0;
}
Exemplo n.º 5
0
int tileray::ortho_dy (int od)
{
    return mostly_vertical()? 0 : od;
}
Exemplo n.º 6
0
int tileray::ortho_dx (int od)
{
    return mostly_vertical()? od : 0;
}