From 4D transform to x y and z rotation angles?

Started by
2 comments, last by thatguyfromthething 13 years, 4 months ago
I'm using a game engine which has nodes that have all its transforms as 4D matrices, but I need to figure out the real rotation that an object is in. I would ask on its forums but in the past I have met with resistance on this subject for some reason (I guess I am not leet enough because I want to use regular rotations and translations since those are the only operations I ever need to do).

There are methods in the 4D vector class to set the rotations about the various axes in radians but no way to get them directly.

What I have been doing so far is to just store the data for the items I want to work with and then when the controls or circumstances change just reset the angle of rotation to the new value.

The problem I have now is that I don't know the starting state of something when it gets to a certain point. I mount a weapon to a character's hand, but the only data I have about the bone I mount to is its transform.

I can set the transform of the gun to the inverse of the bone's but they don't quite line up. The issue is the marker has standard default rotations but the hand's rotations are obviously oriented to the other joints not to worldspace. I can adjust the marker on the weapon handle but this is extremely time consuming because I will have to do it for each weapon and I will have to painstakingly check and recheck the results to get it just right, reimporting over and over and over.

So it looks like I can get a 3D matrix for each axis, and I can set axis rotations and that seems to be about it.

I know from that I can figure out the rotations in terms of x y and z but I recall it was a convoluted process and I can't for the life of me find what it was, though I am sure I have done exactly this before.

Anyone out there know of any online example or quick step by step explanation? I really don't care how long it takes as it only will get calculated in situations that speed doesn't matter.

This is my thread. There are many threads like it, but this one is mine.

Advertisement
Quote:all its transforms as 4D matrices, but I need to figure out the real rotation that an object is in.

I assume you know that the top left 3x3 subblock of the 4x4 matrix is the rotation matrix?

Quote:set the rotations about the various axes in radians

You mean you want to convert a rotation matrix to Euler angles? This sort of thing can be done (you can just google "rotation matrix to Euler angles"), but my gut impulse is to say "you probably want to do something else."

Quote:I can set the transform of the gun to the inverse of the bone's but they don't quite line up. The issue is the marker has standard default rotations but the hand's rotations are obviously oriented to the other joints not to worldspace

If the real problem is to mount a gun on the player's hand, it sounds like this is the approach that's more likely to bear fruit. You're just leaving something out in your transform. Do you need to also include a translation from bone's joint to the bone's end? Or do you need to multiply the transform by those of the parent bones? I'm not clear on what the transformations you have are precisely, but one of those things seems likely to be your answer. If you can describe the transformations you get in some more detail we can probably help with this.
Quote:
I can set the transform of the gun to the inverse of the bone's but they don't quite line up. The issue is the marker has standard default rotations but the hand's rotations are obviously oriented to the other joints not to worldspace.

You're almost there with this solution.

I don't know what tools you have available, and the simple solution might be to just add another bone. I'm used to working with tools that let you place custom game nodes into the art. One such node is just a matrix. That matrix marker multiplied by the inverse of the bind-pose hand matrix will result in a relative transform that you'd export along side the bone id of the hand. You then center the gun on 0,0,0. Multiply the gun by the skinned hand transform multiplied by the exported marker transform to get it to stick right in place.
Quote:Original post by KulSeran

I don't know what tools you have available, and the simple solution might be to just add another bone. I'm used to working with tools that let you place custom game nodes into the art. One such node is just a matrix. That matrix marker multiplied by the inverse of the bind-pose hand matrix will result in a relative transform that you'd export along side the bone id of the hand. You then center the gun on 0,0,0. Multiply the gun by the skinned hand transform multiplied by the exported marker transform to get it to stick right in place.


I can put a locator into the skeleton but the problem here is I have to reimport all animations and meshes that use the skeleton. Unfortunately that is a painful process for animated characters.

Quote:Original post by Emergent
Quote:all its transforms as 4D matrices, but I need to figure out the real rotation that an object is in.

I assume you know that the top left 3x3 subblock of the 4x4 matrix is the rotation matrix?

Quote:set the rotations about the various axes in radians

You mean you want to convert a rotation matrix to Euler angles? This sort of thing can be done (you can just google "rotation matrix to Euler angles"), but my gut impulse is to say "you probably want to do something else."

Quote:I can set the transform of the gun to the inverse of the bone's but they don't quite line up. The issue is the marker has standard default rotations but the hand's rotations are obviously oriented to the other joints not to worldspace

If the real problem is to mount a gun on the player's hand, it sounds like this is the approach that's more likely to bear fruit. You're just leaving something out in your transform. Do you need to also include a translation from bone's joint to the bone's end? Or do you need to multiply the transform by those of the parent bones? I'm not clear on what the transformations you have are precisely, but one of those things seems likely to be your answer. If you can describe the transformations you get in some more detail we can probably help with this.


Well I am sketchy on how things work as I don't really use the transforms much (or really ever) and it's been a long time since I took a math class.

So if I get it right then each of the matrices I get are the definition of an axis and the other 3 numbers are the amount of the rotation?

So then the process I need to go through is to covert the matrix into unit matrix then the values will be in terms of the correct axes? So if in take the Inverse of the transform is that what I get?

This is my thread. There are many threads like it, but this one is mine.

This topic is closed to new replies.

Advertisement