   Why use matrices in computer graphics?
  Is there any reason, other than past experiance, why matrices are still used in computer graphics?  Why not use quaternions exclusively?  AND WHY, WHY doesn''t graphics hardware (vertex shaders) support quaternion operations?  With such a limited number of constant registers, one would think that the first thing they would do is to make quaternions easier to use.  I know you can do the operations yourself, but it''s too slow...I want single instructions like with matrices.  When doing skeletal animation, you can store 4 times the number of bone rotations using quaternions rather than matrices, and a good system would be using quaternions anyways.  why should we have to convert them to matrices at all?My point is, matrix multiplication is a lot of operations (although many can be done in parallel), but quaternion rotations are much less expensive (and many things can be done in parallel also)So what gives?  IS there any reason why there is no hardware supoprt for quaternions? 
  Because matrices don''t just represent rotation, they also do scaling and translation as well. In fact they can do pretty much any kind of linear transformation - for example, the perspective view transform. ;  Well I know that...my point is that many times you dont care about scale/sheer and you just want to translate/rotate or even just rotate (skeletal animation).  with 1 rotation quaternion and 1 translation vector you can represent that.  if you had hardware support I believe it would be much quicker.Considering the most demanding use vertex shaders seems to always involve skeletal animation (generally with only rotation), why wouldn''t they add quaternion instructions.you could still use a matrix for projection.;  Perhaps hardware support for quaternions would be worthwhile, particularly when it comes to matrix skinning type techniques, but I suspect the key thing stopping it from happening is that a dual-function system - i.e. matrices and quaternions - would be slower and more difficult to create than a single-function system (i.e. just matrices).I''m not convinced that quaternions can''t be done on the GPU anyway - they''re just 4-component vectors, after all. Perhaps it would be possible to write shading functions to manipulate them? All you really need on the GPU is quaternion interpolation and transforming a vector by a quaternion... ;  Some of the quaterion maths are more complex than the matrix maths.  For instance, multiplication of a quaternion and a vector is actuallyq v q^(-1) where v is the quaternion [0, x, y, z], and quaternion multiplication is:qq´ = [ww´ - v · v´, v x v´ + wv´ +w´v]where quaternions are in the form [w, v] where v is (x, y, z).Note that this calculation (which must compute two quaternion multiplications) takes considerably more instructions to do in a vertex shader EVEN WITHOUT calculating the inverse of the quaternion (which is necessary for the transform, but is precalculated).Plus, you''ve passed in the inverse and the normal quaterion (2 vectors) and a third, probably, for translation (which gives you another vector), and you''re only sending one less vector (and you can actually get away with only sending a 4x3 matrix in as a transformation most of the time, if I remember correctly).Finally, quaternions can''t really be used in complex rotations like,  "translate -5 along x, rotate 40 degrees, and translate +20 along y", where a matrix carries all of this information intrinsically.I had looked at doing quaternions in vertex shaders, but I''ve decided that it''s faster to convert it into a matrix once per object than do more calculations per every vertex, to only save one vector constant.Josh ;  Josh makes good points about the current state of hardware, but I dont think they would be slower if they had the same support as matrices do.  when you rotate a vector with a matrix, you have to do 16 multiplications and a bunch of adds.  this can probably be done nicely in hardware using parallel ALU''s, but the same goes for multiplying quaternions in hardware.  only with a quaternion muliply, you do much less.  the only reason I can see that they aren''t used is because you have to do like 10 instructions, but that SHOULD be 1 instructions if the hardware supported them, so that''s only an excuse. ;  The real issue is composition.. yes you could store a quaternion... scale factors... shear factors, and translations (and for projective matricies... the projective coefficients), but if you add them up, there are just as many values to store as a general matrix. Matrix vector multiplcation is fairly cheap... and matricies provide a simple method for arbitrary composition of transformations... How would this be implemented in a hybrid quaternion+extra vector system? composition would become far less trivial than it is at present. In any case, I''m sure if you really need to, you could implement them directly in vertex shaders... I think the main purpose of vertex/pixel shaders is to get away from special case functionality (eg bump mapping, normal mapping, environment mappoing) with a single uniform and flexible method that can be made to support any of these features. Implementing quaternion support explicitly is a step backward IMHO. It goes against the principles that these more advanced graphics card features are trying to promote. ;  in my quite uninformed opinion it would be best to have them alongside: a quaternion for purely rotation, and a 4x4 matrix for the scale, sheer, translation and perspective. its only a 25% memory increase, and you wont be bothered by numerical drift nor things as gimble lock anymore, and besides interpolation would become much easier. multiplying these states would also become more expensive, but when implemented in hardware it would still be one streamlined instruction. ;quote:Original post by Pseudo  Josh makes good points about the current state of hardware, but I dont think they would be slower if they had the same support as matrices do.  when you rotate a vector with a matrix, you have to do 16 multiplications and a bunch of adds.  this can probably be done nicely in hardware using parallel ALU''s, but the same goes for multiplying quaternions in hardware.  only with a quaternion muliply, you do much less.  the only reason I can see that they aren''t used is because you have to do like 10 instructions, but that SHOULD be 1 instructions if the hardware supported them, so that''s only an excuse.   hw can not do more math at the same time. a rot(quat,vec) just does more math than a rot(matrix,vec). it has more multiplications, more additions, just write it out and count. so it will take more instructions.still, depending on your bottlenecks, the more instructions don''t hurt, while the storage-gain helps.yes, if you only need quaternions, only use them. if they fit your needs. but only then.i, for myself, never use(d) matrices actually. the only time i use them, is to set up some of the opengl ones. own matrix classes? i haven''t.   If that''s not the help you''re after then you''re going to have to explain the problem better than what you have. - joanusdmentiadavepermen.net ;  There is an article somewhere(I thought GameDev, but couldn''t find it) that shows that matrixes and quaternions are mathmatically equal in certain ways, and thus that a matrix can be used to replace a quaternion (since it hold the same information and more). If it was correct, then all you need to do is change your quaternion operations to work on matrices and you have hardware acceleration on everything. The only drawback is that you store a few extra numbers you might not need in some cases. 