Jump to content
  • Advertisement
Sign in to follow this  

Applying matrix state changes

This topic is 3889 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have an object which has a matrix transform. And I have a gadget that is attached to the object. The object and gadget update their transforms seperately. But when the gadget updates, I need it to change the gadget transform so that it looks like it's attached to the object's transform. I thought this was pretty simple, but I'm having a lot of trouble. When the gadget is first created, I read and record the object's current matrix state: gadget.ObjectState = object.Transform; Each time the gadget updates, I do the following: gadget.Transform *= Inverse( gadget.ObjectState ); gadget.ObjectState = object.Transform; gadget.Transform *= gadget.ObjectState; Or in english: Remove the previous known transform of the object from the gadget transform; Record the new object transform; Multiply the new object transform into the gadget transform; It doesn't work. The gadget object just stretches and flips out. Can anyone help me understand where I've wandered off track?

Share this post

Link to post
Share on other sites
The proper transformation can be generated directly from the current state and the states of all parents whenever you need it. Ideally it should be calculated once and stored until invalidated. All the matrix operations involved with inverting the previous transformation and applying the new one is probably eroding your floating-point values rather quickly, which would cause stretching and other wackiness.

The transformation hierarchy can be updated recursively using something like this:
void updateTransform(Node* node, const Matrix& transform)
node->transform = transform * node->currentState;

updateTransform(node->child, node->transform);

Where the current state is the local space of the object relative to the parent space, and the transform is what's passed directly to the API as the world matrix. The multiplication order reverses for row vectors.

Share this post

Link to post
Share on other sites
The problem is that the child isn't always attached to the object. It's flying through the air on it's own, then comes in contact with an object and sticks to it like a parent. Even if I do keep a relative state of the child object, I need to convert the child's absolute world transform to a relative-to-parent transform when it attaches. That seems to be where I'm messing things up.

I thought I could just invert the parent's transform and multiply it into the child transform to get the relative state. Like this:

On attach:

child.RelativeState = child.Transform * Inverse( parent.Transform );

On child update:

child.Transform = child.RelativeState * parent.Transform;

Am I doing something wrong?

I appreciate your help.

Share this post

Link to post
Share on other sites
I found the problem. I was generating a random starting transform of the child object using a velocity vector:

Transform.GetForward() = Normalized( Velocity );
Transform.GetRight() = RandomCross( Transform.GetForward() );
Transform.GetUp() = Cross( Transform.GetForward(), Transform.GetRight() );
Transform.GetTranslation() = Position;

But I neglected to initialize the "unused" portions of a 4x4 matrix. Specifically, the last float on each row. There was no detectable problem until I tried multiplying it with another matrix - the parent.

Sorry, I guess I didn't even know what my problem was before I posted.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!