SQT or Matrix

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • SQT or Matrix

      Hey Guys,

      I have a question regarding some issues I have run into while building my engine, mainly working with matrices. My problem is that I have found that I want to be able to change things like scale, rotation and translation of my objects at run time, but I also want to be able to retrieve the scale and rotation at run time.

      For instance, I just got my animations going, so to test out something cool I was going to do a Paper Mario style turn where the sprite actually flipped to turn, the trouble is that I need to track the rotation of the sprite to do this. This is where things get hard with matrices, at least the math library I am using.

      If I desire to get the rotation of my matrix in euler angles (or even radians), I have to do some heavy calculations to get it right. Even harder, if I want to do the same retrieval for the scale from the matrix, I am heavily restricted as to under what conditions extracting a scale matrix is even possible.

      I have borrowed a book from a friend and it talks about how bone animation transforms are often represents using an SQT, which is a scalar, qauternion and transform vector used in conjunction with one another. This seems to be ideal, although the only thing I can see being an issue is that OpenGL works with matrices, so I would need to generate matrices from this SQT to actually transform the object.

      Does anyone have any experience or know wether using SQT's is common place, and what kind of pros and cons am I looking at (aside from OpenGL not natively using it)
      PC - Custom Built
      CPU: 3rd Gen. Intel i7 3770 3.4Ghz
      GPU: ATI Radeon HD 7959 3GB
      RAM: 16GB

      Laptop - Alienware M17x
      CPU: 3rd Gen. Intel i7 - Ivy Bridge
      GPU: NVIDIA GeForce GTX 660M - 2GB GDDR5
      RAM: 8GB Dual Channel DDR3 @ 1600mhz
    • Is this per object? If so, just store it in the transform component. Storing the global orientation and scale for an object is fairly common in games.

      -Rez
    • Yes I was storing the scale alongside of the 4x4 matrix, however I did end up trying the SQT format and it is working fine now, I was mainly wondering whether there are any cautions from using this format.
      PC - Custom Built
      CPU: 3rd Gen. Intel i7 3770 3.4Ghz
      GPU: ATI Radeon HD 7959 3GB
      RAM: 16GB

      Laptop - Alienware M17x
      CPU: 3rd Gen. Intel i7 - Ivy Bridge
      GPU: NVIDIA GeForce GTX 660M - 2GB GDDR5
      RAM: 8GB Dual Channel DDR3 @ 1600mhz
    • I've never used SQT myself, but someone like Mike might have more information. There's a conversion step that might be a bit slow, but again, I'm just guessing. Glad it works. :)

      -Rez
    • Hey mholley,

      I could be wrong about this, but I think it's pretty common to just store your translation, rotation, and scale in your transform object, as well as a matrix, and then just regenerate the matrix when you change the above. In this case your authoritative data is all easy to manipulate, but you cache the matrix so you're not recomputing it every update if nothing changes.

      Then basically when you make a change, you calculate your local matrix, grab your parent's matrix, multiply them together, and store that matrix on the transform as it's world transform. Then you iterate through all of the children on this object, and tell them to recalculate their matrices, which will in turn reference your newly updated world matrix.

      James

      The post was edited 1 time, last by rickvanprim ().

    • Yup - I agree with James on this one.
      Mr.Mike
      Author, Programmer, Brewer, Patriot
    • I actually want to update my answer, though it risks pre-mature optimization. When you change a local value, just mark the matrix on it and its children as invalid. Don't recalculate them until you actually try to access it when building up your draw list. This way if you do a bunch of changes to a variety of objects during one Update, you'll only recalculate everything once. Similarly, if it's off camera, you won't waste time recalculating :)

      James
    • Yeah I looked into that alot of guys refer to it as a "dirty" matrix, the retrieval function will check if the matrix is dirty, and recalculate it if so.
      PC - Custom Built
      CPU: 3rd Gen. Intel i7 3770 3.4Ghz
      GPU: ATI Radeon HD 7959 3GB
      RAM: 16GB

      Laptop - Alienware M17x
      CPU: 3rd Gen. Intel i7 - Ivy Bridge
      GPU: NVIDIA GeForce GTX 660M - 2GB GDDR5
      RAM: 8GB Dual Channel DDR3 @ 1600mhz