DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Multiply Two Matrices

07.17.2007
| 4139 views |
  • submit to reddit
        // Multiply two matrices

/*!
* Multiplies a matrix by a second one (m = m * n).
*/
void lib3ds_matrix_mult(Lib3dsMatrix m, Lib3dsMatrix n) {
    Lib3dsMatrix tmp;
    int i, j, k;
    float ab;

    memcpy(tmp, m, sizeof(Lib3dsMatrix));
    for (j = 0; j < 4; j++) {
        for (i = 0; i < 4; i++) {
            ab = 0.0f;
            for (k = 0; k < 4; k++)
                ab += tmp[k][i] * n[j][k];
            m[j][i] = ab;
        }
    }
}