Advertisement

Help with Quaternion rotation (6DOF)

Started by February 28, 2016 04:56 PM
46 comments, last by SBD 8 years, 5 months ago

Pretty much. I don't think there is much in it, performance-wise. And transformations shouldn't ever really be a performance bottleneck in a scene graph.

There are some storage advantages, which is why I tend to use quaternions for skeletal animation. Also quaternion 'slerp' is really a lot easier than the matching operation for matrices...

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]


quaternions for skeletal animation. Also quaternion 'slerp'

Ah! see, that's a different kettle of fish entirely!

yes, without a doubt, quat slerp for skeletons, and thus quats for skeletons (or convert back and forth). blender uses quats. the keyframed animation controller in dx9 probably does as well internally for the tween.

but slerp seems to be the only time quats are the obvious goto choice. and there's no slerp in flight sims.

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

Advertisement

there's no slerp in flight sims.

I have a whole bunch in my chase camera controller and spaceflight AI smile.png

Not that that's a valid reason to encode all your rotations that way, but it certainly works fine.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]


I have a whole bunch in my chase camera controller and spaceflight AI

come on man! fancy chase cam angles don't count! <g> well - you know what i mean....

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

hey guys sorry for the late reply here is my code for 6dof


glm::quat quatx = glm::angleAxis((rotation.x),right);

  up = quatx * up;
  forward = quatx * forward;

  glm::quat quaty = glm::angleAxis((rotation.y),up);

  forward = quaty * forward;
  right = quaty * right;


  glm::quat quatz = glm::angleAxis((rotation.z),forward);

  up = quatz * up;
  right * quatz * right;


  up = glm::cross(right,forward);
  right = glm::cross(forward,up);
  forward = forward;


  up = glm::normalize(up);
  right = glm::normalize(right);
  forward = glm::normalize(forward);

  currentrotation = quatz * quaty * quatx * currentrotation;

 

Also i was gonna say i use slerp for changing the ai ships rotation


I have a whole bunch in my chase camera controller and spaceflight AI

come on man! fancy chase cam angles don't count! <g> well - you know what i mean....

Not to belabor the point, but to add to what swiftcoder is pointing out, SLERP is certainly not the only benefit of Quaternion rotation representation. In skeletal animation systems, aside from the obvious usefulness for interpolation as mentioned above, the size benefit cannot be undersold. In large AAA animation-heavy games, the memory/storage savings are significant.

Quats are also a very useful representation for rotations for transmission over a network, as they are very compact and can be reduced to 3 floats and re-built on the receiving end. And not to harp on the spaceflight example, but I will also echo that you (can) use them all over the place in doing AI.

All that having been said, it's totally correct and fine to use matrices if that's what you're comfortable with. But the instances where Quaternions provide a measurable benefit are not limited to solely SLERPing rotations.

Advertisement


the size benefit cannot be undersold

I just want to be very precise that I don't use them in scene transforms for the size benefit. I typically store position (vector3), orientation (quaternion), derived local space transform (4x4 matrix), and derived world space transform (another 4x4 matrix). All are handy to have around, and I don't ever have enough nodes in play for the size to be a problem.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]


the size benefit cannot be undersold

I just want to be very precise that I don't use them in scene transforms for the size benefit. I typically store position (vector3), orientation (quaternion), derived local space transform (4x4 matrix), and derived world space transform (another 4x4 matrix). All are handy to have around, and I don't ever have enough nodes in play for the size to be a problem.

Yeah, I was a bit imprecise in my wording there. Specifically, when storing animation data it's a huge savings. Obviously, if you're space-constrained with runtime node representation it can help there too, but the big kahuna is keyframe data.

I also don't use them exclusively, such as in the obvious places like final rendering transform where a matrix is the necessary output. Like you, I have also used rig-instance joint matrices for runtime animation calculations, even in the aforementioned animation-data-heavy projects.

This topic is closed to new replies.

Advertisement