cmann1 / dustmod-issues

Dustmod issue tracker
0 stars 0 forks source link

`canvas::rotate` ignores `center_x/y` #70

Closed AlexMorson closed 2 years ago

AlexMorson commented 2 years ago

The following script should draw a square that rotates around its bottom-right corner, but it actually rotates around its center.

const float DEG2RAD = 3.141 / 180;
const float a = 1;
const float x = 100;
const float y = 100;

class script
{
    canvas@ canv;

    script() { @canv = create_canvas(false, 20, 0); }

    void step(int)
    {
        canv.rotate(a, x, y);

        // Expected behaviour is achieved with the following:
        // float c = cos(a * DEG2RAD);
        // float s = sin(a * DEG2RAD);
        // canv.multiply(c, -s, s, c, x * (1 - c) + y * s, y * (1 - c) - x * s);
    }

    void draw(float) { canv.draw_rectangle(-100, -100, 100, 100, 0, 0xFF000000); }
}

The same is true for canvas::rotate_left.