Hey, I am writing a 3d engine with glide(who isn't :-)and I need to multiply to matrixs together, because I read that this is the way you combine two matrixs. However, my code is in big trouble. Using my small understanding of matrix math, I wrote this function:

struct matrix { float x1;float y1;float z1;float w1;

float x2;float y2;float z2;float w2;

float x3;float y3;float z3;float w3;

float x4;float y4;float z4;float w4;};matrix matrixmulti(matrix a,matrix b)//Multiply Matrix

{

matrix returnv;

returnv.x1=(a.x1*b.x1)+(a.y1*b.x2)+(a.z1*b.x3)+(a.w1*b.x4);

returnv.x2=(a.x2*b.x1)+(a.y2*b.x2)+(a.z2*b.x3)+(a.w2*b.x4);

returnv.x3=(a.x3*b.x1)+(a.y3*b.x2)+(a.z3*b.x3)+(a.w3*b.x4);

//

returnv.y1=(a.x1*b.y1)+(a.y1*b.y2)+(a.z1*b.y3)+(a.w1*b.x4);

returnv.y2=(a.x2*b.y1)+(a.y2*b.y2)+(a.z2*b.y3)+(a.w2*b.x4);

returnv.y3=(a.x3*b.y1)+(a.y3*b.y2)+(a.z3*b.y3)+(a.w3*b.x4);

//

returnv.z1=(a.x1*b.z1)+(a.y1*b.z2)+(a.z1*b.z3)+(a.w1*b.x4);

returnv.z2=(a.x2*b.z1)+(a.y2*b.z2)+(a.z2*b.z3)+(a.w2*b.x4);

returnv.z3=(a.x3*b.z1)+(a.y3*b.z2)+(a.z3*b.z3)+(a.w3*b.x4);

//

returnv.w1=(a.x1*b.z1)+(a.y1*b.z2)+(a.z1*b.z3)+(a.w1*b.x4);

returnv.w2=(a.x2*b.z1)+(a.y2*b.z2)+(a.z2*b.z3)+(a.w2*b.x4);

returnv.w3=(a.x3*b.z1)+(a.y3*b.z2)+(a.z3*b.z3)+(a.w3*b.x4);

return returnv;

}

I tried roating these two:

matrix Org={50,0,0,500,

0,50,0,500,

0,0,50,100,

0,0,0,1};

matrix roat={50,0,0,500,

0,50,0,500,

0,0,50,100,

but the matrix that came out, was NOT the combination of the two! What do I do? Have I got a bug? Did I goof in my matrix function?

maybe that's the same as your code, but I use the non unrolled version of matrix multiply..

since I store my matrices as an array of 16 floats I do a different addressing.. however, passing the pointer to your first matrix element should work.

this code actually performs a 4x4 matrix multiply, where c = a * b.

maybe it helps you to get startet.

nils

--- code begins here -------

void matrix_mul( float *c, float *a, float *b )

{

int i,j,k;

for ( i=0; i<16; i++) c[i]=0;

for ( i=0; i<4; i++ )

for ( j=0; j<4; j++ )

for ( k=0; k<4; k++ )

c[i+4*j] += a[i+4*k] * b[k+4*j];

}