[no bug]multiplyWith1x4Matrix is really wrong

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
mitras1
Posts: 26
Joined: Mon Jan 29, 2024 8:02 am

[no bug]multiplyWith1x4Matrix is really wrong

Post by mitras1 »

Code: Select all

    core::matrix4 A = core::matrix4();

    A[0] = -125;
    A[1] = 25;
    A[2] = -5;
    A[3] = 1;

    A[4] = 0;
    A[5] = 0;
    A[6] = 0;
    A[7] = 1;

    A[8] = 75;
    A[9] = -10;
    A[10] = 1;
    A[11] = 0;

    A[12] = 0;
    A[13] = 0;
    A[14] = 1;
    A[15] = 0;

    core::matrix4 Ai = core::matrix4();

    if (A.getInverse(Ai))
    {
        f32 a[4] = {2, 2, 2, 1};
        Ai.multiplyWith1x4Matrix(a);
        printf("%f\n%f\n%f\n%f\n", a[0], a[1], a[2], a[3]);
    }
Expected output:

Code: Select all

0.1200
0.8000
1.0000
2.0000
Actual output:

Code: Select all

0.272000
0.728000
0.480000
2.880000
I've already checked getInverse and it works fine
CuteAlien
Admin
Posts: 9734
Joined: Mon Mar 06, 2006 2:25 pm
Location: Tübingen, Germany
Contact:

Re: multiplyWith1x4Matrix is really wrong

Post by CuteAlien »

Rows and columns in computer matrices tend to be different than in math (edit: or maybe depends on the library, I think Irrlicht was heavily influenced by Direct3d back then). As computer matrices tend to use row major instead of column major like the math guys. It's kinda meant to transform a 4 element vector by the matrix I guess. Which it does. If you use transposed matrix instead you get your result.

But maybe stupid name - I just realize someone managed to persuade me to add transformVec4 a few years ago because neither of us realized at that point that this function exists already and does the same.
IRC: #irrlicht on irc.libera.chat
Code snippet repository: https://github.com/mzeilfelder/irr-playground-micha
Free racer made with Irrlicht: http://www.irrgheist.com/hcraftsource.htm
Post Reply