Archived

This topic is now archived and is closed to further replies.

onnel

World to Object Space

Recommended Posts

I though I understood how to convert a coordinate in world space in to vector space, but my method doesn''t seem to be working. I''m doing the following:
/*
 * Takes a position in world coordinates and converts it to 
 * local object coordinates, and puts the result in ''objectPos''
 * Both rotation and translation are transformed
ConvertWorldToObjectPos(D3DXVECTOR3 *worldPos,D3DXVECTOR3 *objectPos)
{

  D3DXMATRIX transposedMatrix;
  D3DXMatrixTranspose(&transposedMatrix,&mRotPos);

  // Does the rotation
  D3DXVec3TransformCoord(bodyPos,worldPos,&transposedMatrix);

  // And now the translation
  D3DXVec3Subtract(bodyPos,bodyPos,&linPos);
}
 
Does anyone see any obvious problems with this? the translation works just fine, but when there is a rotation involved, I seem to start running in to problems. Onnel

Share this post


Link to post
Share on other sites
Well I thought that you were obviously correct, but now I'm not so sure. if i was going from local to world coordinates, it would make sense to use the inverse (since I'm basically rewinding to the "high" world state), but going "down" from world to an object state, it would seem to make sense to apply the same rotation that you applied to the object (since you're replicating its state).

Or am I missing something here?

Onnel

[edited by - onnel on October 1, 2002 3:53:27 PM]

Share this post


Link to post
Share on other sites
Can anyone lend a hand? I tried doing it without the transpose:

I.e, I simply rotated by the same matrix I am using for my object and then subtracting the translation offset for the object, but this didn''t work either.

I know I must just be missing something dumb. :-(

Onnel

Share this post


Link to post
Share on other sites

- To go from world space to object space you transform by the inverse of the *whole* of the world (to object) matrix.

- If the matrix is *orthogonal*, i.e. it contains ONLY rotations and translations with absolutely NO non-uniform scaling or skewing/shearing, the inverse of a matrix is the SAME as the transpose of that matrix which is why you can use a transpose in some circumstances.

- If the matrix DOES contain ANY scaling/skewing/shearing, you MUST use the true inverse.


--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com

Share this post


Link to post
Share on other sites
This means I should do BOTH my rotation and my translation before doing the transpose, correct? I assume I should do the rotation and then the transform?

Let me make sure what I'm trying to do is clear:

I have an mesh with all vertexes defined in local coords. I then have one transformation (actually a rotation matrix with a transformation added in) for the object to go from local to world coords (for example when I need to render).

Now, I need to be able to go in reverse (from world coords to local coords for the object) for collision testing against the vertexes of the object.

So I want to take the coordinates of the other object (which are in world space) and convert them into the local space of the object so I can easily test against it's vertices.

Does that make sense?

Onnel

[edited by - onnel on October 2, 2002 9:14:32 AM]

Share this post


Link to post
Share on other sites
You don''t need to do any transposing at all. If your matrix has only rotations but no translation or scaling then the inverse wil be the same as the transpose. You should still use the inverse though because that will always work. Also, if the translation is in a separate vector, you should translate first and then apply the matrix.

All of this only applies to world-to-local transformations.

Share this post


Link to post
Share on other sites
Making sure I did the translation FIRST and then using Inverse worked like a charm...

I''ll stick to Inverse from now on. Is there a case where you might want to use transpose over inverse?

Thanks!

Onnel

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
You can only use a transpose to invert when your matrix is orthogonal...

Where would you want to play with transposes... well I''ve never used them much (unless I''m playing with some kind formula, which is then applied to something, and this is a rare ocasion), but I think it needs to be stressed that transposes are better for playing with pure matix OPs and, normally, you''ll arrive to a point where you can totally bypass half of the operations and calculate the results directly without taking an undless amount of steps (afterall that''s why you solved them, right?).

Share this post


Link to post
Share on other sites