TheCherno / Sparky

Cross-Platform High Performance 2D/3D game engine for people like me who like to write code.
Apache License 2.0
1.1k stars 222 forks source link

Mat4 Multiplication Bug #6

Closed TheCherno closed 9 years ago

TheCherno commented 9 years ago

Mat4 multiplication doesn't work correctly. Change to:


    mat4& mat4::multiply(const mat4& other)
    {
        float data[16];
        for (int y = 0; y < 4; y++)
        {
            for (int x = 0; x < 4; x++)
            {
                float sum = 0.0f;
                for (int e = 0; e < 4; e++)
                {
                    sum += elements[x + e * 4] * other.elements[e + y * 4];
                }
                data[x + y * 4] = sum;
            }
        }

        memcpy(elements, data, 16 * 4);

        return *this;
    }
TheCherno commented 9 years ago

Fixed in Ep. 10.