Rotating an objects axis

Started by
11 comments, last by AndyTX 18 years, 4 months ago
Quote:Original post by jyk
My argument is that using quaternions rather than matrices should be an informed decision, based on a thorough understanding of the relative advantages and disadvantages of the degree evidenced in your post.

I agree with that completely :) I'd venture that there's a sizable portion of people that don't understand rotation matrices, but I'm willing to believe that the proportion is higher for quaternions.

Quote:Original post by Trienco
Not faster, but getting the axis and angle and building a new rotation from the interpolated angle is still simple and intuitive.

Sure, but for any advantage of rotation matrices, I could make the same argument: converting a quaternion to a matrix is simple and fast. Thus I still count interpolation as one of the primary advantages of quaternions.

Quote:Original post by Trienco
But seeing how many cross products are happening all over the place with quaternions...

Quaternion multiplation (composed rotation) is effectively four dot products with a few negations (depending on your internal representation). No cross products necessary...

Quote:Original post by Trienco
I wouldn't say much. 18 mults, 9 adds, 1 sin, 1 cos vs. 1 div, 3 mults, 1 sin, 1 cos.. if the compiler makes good use of SSE instructions the difference should be just a few ops.

Incidentally the formula for building a rotation matrix around an arbitrary axis is exactly the formula for converting a quaternion to a rotation matrix.

Quote:Original post by Trienco
Ignore hardware skinning, because with a variable number of bones per vertex it is pretty messy.

Unrelated, but not with Sh (http://libsh.org) ;)

Anyways I'm not opposed to converting quaternions to matrix form very early in the process - for example at each transform hierarchy node (in a scene graph) to compose a local affine transformation. That way you can keep the interpolation and composition advantages where they help, and pay a rather negligable cost (only need to convert to matrix form on update AND can be done lazily wrt the scene node).

Moreover take the performance advantages/disadvantages with a grain of sal; as I mentioned I've yet to see these operations bottleneck a modern computer.

To summarize, I totally agree that you could get away without ever touching quaternions. However one has to admit that they make some things similar and perform at least as well as matrices. Because the conversion process is simple though, you can get the best of both worlds in almost all cases :)
Advertisement
Quote:Original post by AndyTX
Thus I still count interpolation as one of the primary advantages of quaternions.


Though after doing the whole skeletal animation things with quaternions and comparing it to how I would do it without them the advantage is nice, but far from crucial.

I'll be going even further off topic here. A common thing seems to be to multiply a vertex with two matrices, then weigh the results and sum them up. Everybody knows that interpolating the matrices would screw them up, but not so many realize that it is still mathematically exactly the same. So the same square root used to renormalize a quaternion after interpolating it could be used to stretch the resulting vector to its original length. The result should be same: path is fine, velocity is wrong. Only angles close to 180° would be a problem. Hence I somewhere posted that quats should be more robust. Spherical interpolation is already involving a good bit of trig, so the extra cross and dot products for the vector based interpolation look a bit more harmless.

If you know you will be doing a lot per frame that's faster with quats and only convert once that would be the best case. Else wrapping your head around quats would have no benefit except for having learned something new.

Quote:
Quaternion multiplation (composed rotation) is effectively four dot products with a few negations (depending on your internal representation). No cross products necessary...


Because it's not showing when you "spell it out" for the function. It's already mixed in and where all the negations are coming from.

Quote:Incidentally the formula for building a rotation matrix around an arbitrary axis is exactly the formula for converting a quaternion to a rotation matrix.


True, but in the same way rotating a vector around a quaternion ends up as exactly the same as converting to a matrix and using that (meaning you don't use the existing quat multiplication, but write them as one). The difference above is more about finding the axis in the first place, though there should be a more efficient way than calculating the transformed vector for both and do the cross product. Skimming over the formula to extract the axis directly from a matrix doesn't look so tempting. Might be missing a shortcut though. Risky and lame trick would be to so save some work by always rotating (1,0,0) and praying that it doesn't happen to lie on the axis (or repeat for (0,1,0) and compare results, but here it starts to become really pointless.

Quote:Unrelated, but not with Sh (http://libsh.org) ;)


Might have to have a look at that. But with different numbers per vertex in a single batch I can't see a technical solution that doesn't involve the newest cards with real loops and branching.

Though in that case, quaternions would at least allow to store more bones in the registers. Some extra code to decide if they should be converted or not and which shader to use based on the number of bones/registers shouldn't hurt too much.

The main reason I'm sticking with them for now is this whole "but what if I want really complex skeletons, better be prepared for everything"-feeling. That and having to store inverse bind pose, relative transformation to parent and final transformation used on vertices. Storing multiple positions for vertices AND losing the option to interpolate quats/matrices instead of transformation results sounds like it's worth some overly bloated bone structs.
f@dzhttp://festini.device-zero.de
Quote:Original post by Trienco
Though after doing the whole skeletal animation things with quaternions and comparing it to how I would do it without them the advantage is nice, but far from crucial.

I agree - both methods can be employed in almost all cases with good results. They really aren't *that* different. The only point that I disagree on is that we should summarily dismiss quaternions as a graphics tool. We've agreed that they do some things better, and I see no reason to eliminate them as potentially the best tool for some jobs.

Quote:Original post by Trienco
Else wrapping your head around quats would have no benefit except for having learned something new.

I can't speak to this personally since I don't find quaternions very hard to understand at all (I suppose being in Math does help ;). That said, they're still perfectly usable even if you don't understand them. In my current scene graph engine, one could change a single typedef to make all quaternions 3x3 matrices and everything would still work. The constructors and operators are all identical, only the internals differ.

Quote:Original post by Trienco
Because it's not showing when you "spell it out" for the function. It's already mixed in and where all the negations are coming from.

My point was that they quaternion multiplation can be accelerated with SIMD (if required) just like vector operations. I was only responding to your initial comment to the contrary.

Quote:Original post by Trienco
True, but in the same way rotating a vector around a quaternion ends up as exactly the same as converting to a matrix and using that (meaning you don't use the existing quat multiplication, but write them as one).

Again, I was merely pointing out that quaternions are not disadvantaged in this case.

Quote:Original post by Trienco
Might have to have a look at that. But with different numbers per vertex in a single batch I can't see a technical solution that doesn't involve the newest cards with real loops and branching.

Sure, but there are a few answers to that: one, the newest SM3.0 cards do loops and branching quickly enough to be useful in the general case. If you don't have that support though, you can write a single shader in Sh and have it generate whatever combinations you need (this extends to things like combining your animation shaders with surface and light shaders as well).

Quote:Original post by Trienco
Storing multiple positions for vertices AND losing the option to interpolate quats/matrices instead of transformation results sounds like it's worth some overly bloated bone structs.

Sure, that sounds completely reasonable to me. However I think there are also completely reasonable situations to use quaternions in. Moreover you often don't have to make the choice to use one OR the other - a mix is often possible.

This topic is closed to new replies.

Advertisement