Matrix Inverse

Started by
14 comments, last by ZMaster 20 years, 7 months ago
rodzilla, I think that matrices are better for the camera because they are easier to set/read than quaternions for the average programmer.
http://www.sjbaker.org/steve/omniv/matrices_can_be_your_friends.html
Advertisement
Here is another technique that I use for finding the inverse of a 4x4 matrix.
Note: the matrices used are the OpenGL Column major format

Step 1. Transpose the 3x3 rotation portion of the 4x4 matrix to get the inverse rotation
    MatrixInvRotate(mtxin, mtxout);

the MatrixInvRotate code is:
void MatrixInvRotate(glMatrix mtxin, glMatrix mtxout){  for(int i=0 ; i<3; i++) {    for(int j=0; j<3; j++) {      mtxout[j][i] = mtxin[i][j];    }  }}

Step 2. negate the translation vector portion of the 4x4 matrix and then rotate it using the newly constructed 3x3 rotation matrix
  msVec3 vTmp, vTmp2;  vTmp[0] = -mtxin[3][0];  vTmp[1] = -mtxin[3][1];  vTmp[2] = -mtxin[3][2];  VectorRotate(vTmp, mtxout, vTmp2);

The VectorRotate code is straight forward:
void VectorRotate (const msVec3 vin, const glMatrix mtx, msVec3 vout){	vout[0] = vin[0]*mtx[0][0] + vin[1]*mtx[1][0] + vin[2]*mtx[2][0];	vout[1] = vin[0]*mtx[0][1] + vin[1]*mtx[1][1] + vin[2]*mtx[2][1];	vout[2] = vin[0]*mtx[0][2] + vin[1]*mtx[1][2] + vin[2]*mtx[2][2];}

Step 3. put the new translation vector into the new 4x4 matrix
  mtxout[3][0] = vTmp2[0];  mtxout[3][1] = vTmp2[1];  mtxout[3][2] = vTmp2[2];

Step 4. do some house cleaning so that the matrix can be used with OpenGL
  mtxout[0][3] = mtxout[1][3] = mtxout[2][3] = 0.0f;  mtxout[3][3] = 1.0f;


You now have the inverse of the original 4x4 matrix.

I use inverse matrices for cameras, bone animation and skinning using bone weights, and object picking.

quote:
I use inverse matrices for cameras, bone animation and skinning using bone weights, and object picking.


Could you make a bit more details ?
For bone animation : is it for inverse kynematics ?
For skinning using bone weights : are you using vertex buffers ?

For bone animation the inverse matrix representing bone position and rotation is required for doing both forward and inverse kynematics. The inverse matrix of the bone position and rotation is also required for skinning because I store the vertices in object space rather than bone space since each vertex can be attached to more than one bone. Doing it this way makes for slightly simpler code that runs faster especially as a vertex program on a GPU(ie vertex shader).

For the skinning I support two rendering paths using the OpenGL API. If the card supports ARB vertex program then all the vertex attribute data (position vector, bone weights etc) is offloaded to the GPU and vertex blending is executed on the GPU and its very fast. If the graphics card has a fixed function pipeline then the vertex blending is done on the CPU so I don''t use vertex buffers.
quote:Original post by nfz
For bone animation the inverse matrix representing bone position and rotation is required for doing both forward and inverse kynematics.


What is forward kynematic ?

quote:Original post by nfz
The inverse matrix of the bone position and rotation is also required for skinning because I store the vertices in object space rather than bone space since each vertex can be attached to more than one bone.


Yeah, that''s a problem for me... Did you deeply study the subject, and is it the only solution you found ? Cause using this method, you should make vertex per vertex matrix computation that should be very heavy in thems of CPU work. You should at least make 2 matrix multiplication for EACH vertex, in my case this should kill my frame rate


quote: Doing it this way makes for slightly simpler code that runs faster especially as a vertex program on a GPU(ie vertex shader).

i''m afraid my english is a bit weak, so I didnt all understand :D, but I think this means the same I wrote before ???
Forward kinematics (FK) is the propagation of motion from the parent joint down the chain to all of its children. An example is if the parent rotates then all the children rotate with the parent. FK is the simple part of kinematics to solve and is used in most applications and games that support bone animation.

Inverse kinematics (IK) is the reverse, ie if the child joint moves it effects its parent and on up the chain. IK in real time is much harder to solve and code and is more computationaly expensive so you don''t see it used in games much.

There are a few different ways of performing vertex blending and no I wouldn''t say I have studied it in depth so the way I am doing it now may not be the most efficient but it works and gives decent frame rates on middle of the road pc hardware. My target frame rate is 40fps with 10 animated objects(machines and creatures) in the forground at a screen resolution of 1024x768 24bpp using a GF2 and 1Ghz Athlon. Each model is low poly having about 800 triangles and the scenery has about 1800 visible triangles so in total there are no more than 10000 triangles being pumped through. On my dev machine at work (Radeon 8500 128 meg and AthlonXP 1.63 Ghz) I get about 130fps (CPU vertex blending) with each model having 4 animation streams being blended at the same time at a resolution of 1280x1024 32 bpp. Using a vertex shader and a vertex array on the GPU, the FPS jumps to about 270. Todays hardware allows these techniques to be used so now I am learning to use them. A year and a half ago I wouldn''t have considered it.

The bone matrix calculations are done at the beginning of each frame but before vertex processing. But, yes, vertex blending is expensive in CPU time and its a balance you have to play between good animation and frame rates.

This topic is closed to new replies.

Advertisement