5
\$\begingroup\$

This is related to rendering creating a model, view, projection matrix for opengl. While matrix are fairly standard there's a lot of talk about using quaternions for rotations but why would u go from quaternions to matrix and back to matrix?

Quaternions might be faster but if you have to switch to matrix and back again doesn't that overhead eat into using just matrix only?

Is the typical workflow for using quaternions with matrix is to let the quaternion handle the rotation then create a 4x4 matrix from that rotation to concat with translation/ scale matrix in the model->view->projection matrix stack?

Does converting quaternion to matrix cause a lot of overhead?

\$\endgroup\$
0

1 Answer 1

2
\$\begingroup\$

The best paper out there for performance comparison is from geometrictools according to the paper you need 12 multiplication and 12 addition to convert a quaternion to a matrix, but this is hardly a deciding factor.. you need to look at the bigger picture

Quaternions are great for interpolation because they are numerically more stable than matrices when dealing with interpolations because less operations are involved. This is especially important for skeletal animation. Other than than you can use a matrix for everything including rotations. But if you insist on using quaternions (which is fine btw) the scenario I can imagine you are talking about is that you can separately keep track of scaling vec3, translation vec3 and a quaternion in that you need to build a matrix from and sent it to the GPU, in this case you need to do this for every object every frame it moves. I hardly think this would be a bottleneck unless you profile and it proved to be the problem.

A deciding factor for using matrix vs quaternion for rotation is what your engine is supposed to do, matrices can be more than enough if no precise skeletal animation is involved. Quaternions have the advantage of less memory but unless you are dealing with limited memory (eg. consoles) this is not a problem.

I would hardly optimize unless it is proven to be a bottleneck or I am struggling to get every bit of performance. So the answer it depends on the scale of the game and where the bottleneck is. Read the paper I linked to get a detailed comparison. After all you can hide your transformation in a class and change the implementation if it proves to be troublesome.

\$\endgroup\$
3
  • \$\begingroup\$ this is a well detailed answer, I am in a limited memory situation [mobile] which also comes with power constraints as well because of battery. Dealing with less data [quats] vs [mat] does seem to be a win in that regard but it's the fact that I haven't seen any papers really diving into quats being able to hold scaling. I've seen dual quaternions which can do rotation and translation but that would still leave something that i'd need to dive into matrices to handle. also this article: gameprogrammer.com/4-fixed.html has a way to speed up matrix multiplication for rendering. \$\endgroup\$
    – sean
    Jul 22, 2015 at 13:49
  • \$\begingroup\$ @sean I've added the paper link into my answer. Regarding scaling quaternions can't hold scale, as I explained you need to keep track of separate vector and build and a matrix before sending it to the GPU (I don't know of other solutions.) As for the article you linked, it's doing fixed point arithmetic which I doubt has anything to do with modern GPUs. \$\endgroup\$
    – concept3d
    Jul 22, 2015 at 14:09
  • \$\begingroup\$ it's towards the end of the article where they skipped the 4th column multiplication and addition to save a few cycles. I will have to go with this as it stands right now. \$\endgroup\$
    – sean
    Jul 22, 2015 at 14:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .