glMultMatrix
I'm building a 3D math library and now I want to implement rotation. I've generated rotation matrix and I need to multiply it with current martix. I can achive that with glMultiMatrix, but the problem is that I don't want to multiply it with current OpenGL matrix, I want to multiply it with my own, custom matrix. That's I want to do: ....... (generate rotation matrix)...... customMultiMatrixf( fMatrix, fRoataionMatrix ); // this is what I need glLoadMatrixf( fMatrix ); I tried to recreate MultiMatrixf myself, but then some strange things happen when I try to rotate. Thanks in advice.
Please post your matrix multiplication code, so that we can take a look at it.
Edit: Just some advice: If you're only multiplying them by yourself, so that you can use glLoadMatrix afterwards, then glMultMatrix is probably alot faster than doing it yourself.
Edit: Just some advice: If you're only multiplying them by yourself, so that you can use glLoadMatrix afterwards, then glMultMatrix is probably alot faster than doing it yourself.
I tried to google it. It's no use.
Here's exe: http://kiput.webpark.pl/data/mlib.zip - it's pretty wierd.
My code for multiplication is, well... ordinary. :) I probably do it wrong, but here's the code: http://kiput.webpark.pl/data/mtrx.c
Sorry for not using links, but I don't know how to do it. :)
Here's exe: http://kiput.webpark.pl/data/mlib.zip - it's pretty wierd.
My code for multiplication is, well... ordinary. :) I probably do it wrong, but here's the code: http://kiput.webpark.pl/data/mtrx.c
Sorry for not using links, but I don't know how to do it. :)
Simply put, your code is a bit wrong. You are reading and writing to same array. You should be calculating in new array.
"Fixed" code:
"Fixed" code:
DECL void CALL mxMultiMatrix( GLfloat * fM, GLfloat * fSM ){ GLfloat temp[ 16 ]; temp[0] = fM[0]*fSM[0] + fM[4]*fSM[1] + fM[8] *fSM[2] + fM[12]*fSM[3]; temp[1] = fM[1]*fSM[0] + fM[5]*fSM[1] + fM[9] *fSM[2] + fM[13]*fSM[3]; temp[2] = fM[2]*fSM[0] + fM[6]*fSM[1] + fM[10]*fSM[2] + fM[14]*fSM[3]; temp[3] = fM[3]*fSM[0] + fM[7]*fSM[1] + fM[11]*fSM[2] + fM[15]*fSM[3]; temp[4] = fM[0]*fSM[4] + fM[4]*fSM[5] + fM[8] *fSM[6] + fM[12]*fSM[7]; temp[5] = fM[1]*fSM[4] + fM[5]*fSM[5] + fM[9] *fSM[6] + fM[13]*fSM[7]; temp[6] = fM[2]*fSM[4] + fM[6]*fSM[5] + fM[10]*fSM[6] + fM[14]*fSM[7]; temp[7] = fM[3]*fSM[4] + fM[7]*fSM[5] + fM[11]*fSM[6] + fM[15]*fSM[7]; temp[8] = fM[0]*fSM[8] + fM[4]*fSM[9] + fM[8] *fSM[10] + fM[12]*fSM[11]; temp[9] = fM[1]*fSM[8] + fM[5]*fSM[9] + fM[9] *fSM[10] + fM[13]*fSM[11]; temp[10] = fM[2]*fSM[8] + fM[6]*fSM[9] + fM[10]*fSM[10] + fM[14]*fSM[11]; temp[11] = fM[3]*fSM[8] + fM[7]*fSM[9] + fM[11]*fSM[10] + fM[15]*fSM[11]; temp[12] = fM[0]*fSM[12] + fM[4]*fSM[13] + fM[8] *fSM[14] + fM[12]*fSM[15]; temp[13] = fM[1]*fSM[12] + fM[5]*fSM[13] + fM[9] *fSM[14] + fM[13]*fSM[15]; temp[14] = fM[2]*fSM[12] + fM[6]*fSM[13] + fM[10]*fSM[14] + fM[14]*fSM[15]; temp[15] = fM[3]*fSM[12] + fM[7]*fSM[13] + fM[11]*fSM[14] + fM[15]*fSM[15]; for ( unsigned int i=0; i<16; ++i ) fM = temp;<br>}<br></pre><br><br>And <a href=http://www.j3d.org/matrix_faq/ >here</a> is link to a nice matrix FAQ.<br><br>edit: Bah… AP beat me to it.
You should never let your fears become the boundaries of your dreams.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement