   What is this object pointing at?
  I've created some rifle weapon objects, and I represent their position/orientation with a 4x4 matrix.  I allow the user to aim these rifles using the mouse.I need to be able to figure out what direction the rifle is pointing at any given time.  I was told that I could multiply the object's matrix by a unit vector along the z-axis (0.0, 0.0, 1.0), and that will give me a vector which tells me where the rifle is pointing.I tried that, but the x and y coordinates of the answer vector appear to be reversed (i.e. -1,-1,1 when the rifle is pointing at 1,1,1).Here is my matrix multiplication code--have I done something wrong?  Thanks in advance! //-----------------------------------------------------------------------------------//Multiply a 4x4 matrix by a 3-element vector//-----------------------------------------------------------------------------------void MatrixMultiplyVec3 (D3DXVECTOR3 *vOut, D3DXMATRIX *matIn, D3DXVECTOR3 *vIn){  vOut->x = matIn->_11 * vIn->x + matIn->_12 * vIn->y + matIn->_13 * vIn->z + matIn->_14;  vOut->y = matIn->_21 * vIn->x + matIn->_22 * vIn->y + matIn->_23 * vIn->z + matIn->_24;  vOut->z = matIn->_31 * vIn->x + matIn->_32 * vIn->y + matIn->_33 * vIn->z + matIn->_34;}//MatrixMultiplyVec3[edited by - Teric on April 5, 2004 12:57:16 PM]
  I''m not sure about your function, but you can use the D3DX math functions to do all the basic linear algebra stuff.  It''ll do it fast, because they''re tuned to use SIMD CPU instructions. I like pie. ;  Somebody slap me if I''m missing something, but I can''t find a D3DX function that multiplies a matrix by a vector.  Could someone point me in the right direction?Thanks in advance! ;  Ok, I figured out what I was doing wrong.  I had my matrix math flipped the wrong way.  Here''s my new code: //-----------------------------------------------------------------------------------//Multiply a 4x4 matrix by a 3-element vector//-----------------------------------------------------------------------------------void MatrixMultiplyVec3 (D3DXVECTOR3 *vOut, D3DXMATRIX *matIn, D3DXVECTOR3 *vIn){  float x, y, z;  x = vIn->x;  y = vIn->y;  z = vIn->z;  vOut->x = x * matIn->_11 + y * matIn->_21 + z * matIn->_31;  vOut->y = x * matIn->_12 + y * matIn->_22 + z * matIn->_32;  vOut->z = x * matIn->_13 + y * matIn->_23 + z * matIn->_33;}//MatrixMultiplyVec3That worked like a charm. 