Skip to main content
gamedev.net
🔒 Locked

Coordinate system conversion

Started by JakeM Jan 6, 2007 at 1:01 PM 4 replies 800+ views
Original Post
JakeM
JakeM
Is there a generic way to convert one 3D coordinate system to another using matrices? I would like to go from a right-handed system (OpenGL) to a 3dsmax-like system:

x+ right     y+ left
y+ up    ->  z+ up
z+ out       x+ in

1 0 0 0
0 1 0 0  ->   ???
0 0 1 0
0 0 0 1
TheAdmiral
TheAdmiral
It sounds like you're looking for the following indirect permutation matrix:
0   0  -1   0-1  0   0   00   1   0   00   0   0   1

Admiral
Ring3 Circus - Diary of a programmer, journal of a hacker.
JakeM
JakeM
Thanks, but how did you come up with that matrix?

Assuming I know the coordinate systems I want to go from->to, how do I create such a matrix?
Zipster
Zipster
There's a clever little trick you can use to come up with these permutation matrices. In the source system, let x correspond to the first column, y correspond to the second column, and z correspond to the third column, and let x/y/z in the destination system correspond to the rows. We see that x+ is "right" in the source system. What is "right" is the destination system? If y+ is left, then y- is right. So we're going from x+ -> y-, which is a -1 in the first column, second row. For "up", we go from y+ -> z+, so that's a +1 in the second column, third row. For "out", we go from z+ -> x-, so that's a -1 in the third column, first row. Basically, you figure out the orientations for x+/y+/z+ in the source system (which happen to be "right", "up", and "out", but could have just as easily been "right", "down", "in" for an arbitrary system), and match those up in the destination system. This will tell you which rows and columns have +1/-1.
hplus0603
hplus0603
Note that, depending on whether you use row vectors, or column vectors, the words "column" and "row" may need to be interchanged in Zipster's explanation. For more information, see my article on matrix representations.
enum Bool { True, False, FileNotFound };
JakeM
JakeM
Thanks for the explanation! I see the pattern now.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.