Sign in to follow this  
akaitora

World to Local Space

Recommended Posts

So I have 2 Objects. ObjectA and ObjectB. I would like to convert ObjectB's position/orientation relative to ObjectA.
I have seen others use the transpose of ObjectA's world matrix to convert other objects into its local space. How does this work?

Share this post


Link to post
Share on other sites
[font="arial, verdana, tahoma, sans-serif"][size="2"][quote name='akaitora' timestamp='1313593823' post='4850352']
So I have 2 Objects. ObjectA and ObjectB. I would like to convert ObjectB's position/orientation relative to ObjectA.
I have seen others use the transpose of ObjectA's world matrix to convert other objects into its local space. How does this work?
[/quote]
Not at all (at least not in general). You need the inverse matrix instead.

A world matrix defines how to transform a vector given in local space to yield in the same vector but w.r.t. the global space. When using column vectors, this looks like[/size][/font]
[b]p[/b][sub]W[/sub] := [b]W[/b] * [b]p[/b]
The inverse matrix hence defines how a vector given in global space is to be transformed to yield in the same vector but w.r.t. the local.space, because of
[b][b]W[/b][sup]-1[/sup] * p[/b][sub]W[/sub] = [b][b]W[/b][sup]-1[/sup] * ([/b] [b]W[/b] * [b]p[/b][b] ) [/b]= [b]p[/b][b]
[/b]
If [b]W[/b][sub]A[/sub] is the world matrix of object A, and similarly [b]W[/b][sub]B[/sub] is the world matrix of object B, then
[b]W[/b][sub]B[/sub] * [ 0 0 0 1 ][sup]t[/sup]
gives you the local origin of B w.r.t. the global space. Further then
[b][b]W[/b][sub]A[/sub][sup]-1[/sup] * [/b][b]W[/b][sub]B[/sub] * [ 0 0 0 1 ][sup]t[/sup]
gives you the local origin of B w.r.t. the local space of A. In general,
[b]M[/b] := [b][b]W[/b][sub][/sub][sup]-1[/sup] * [/b][b]W[/b][sub]B[/sub]
transforms any vector given in local space of B into the local space of A.

Only in the special case that [b]W[/b] is a pure rotation (i.e. ortho-normal) matrix you have the correspondence
[b]W[/b][sup]-1[/sup] == [b]W[/b][sup]t[/sup]

Share this post


Link to post
Share on other sites
Thanks haegarr! So if I want to move Object B into the local space of Object A, then I should do the following...

[size="2"][color="#1c2837"]vecObjectBLocalSpacePosition = ObjectB.GetPosition() * ObjectA.GetWorldMatrixInverse();[/color][/size]
[size="2"][color="#1c2837"]
[/color][/size]
[size="2"][color="#1c2837"]That would give me Object B's local space position realtive to Object A if Object A were centered at the origin correct? Thanks![/color][/size]

Share this post


Link to post
Share on other sites
[quote name='akaitora' timestamp='1313679060' post='4850788']
[size="2"][color="#1c2837"]That would give me Object B's local space position realtive to Object A if Object A were centered at the origin correct? Thanks![/color][/size]
[/quote]

That will depend how you math library is set up. Normally I'd expect to see :

[size="2"][color="#1c2837"][source]vecObjectBLocalSpacePosition = ObjectA.GetWorldMatrixInverse() * ObjectB.GetPosition();[/source][/color][/size]

but that is down to your library i guess. There are quite few libraries where vec * matrix is not the same as matrix * vec. Definitely one you'd need to check with your lib ;)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this