# Conversions between coordinate systems

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

## Recommended Posts

I'm currently writing a xsi-parser wich is quite a pain in the ass since it's a very flexible format. The problem I've got at the moment is that in the file, the coordinate system can be specified setting the following parameters (http://www.iro.umontreal.ca/~roys/softimage_xsi/files/docs/html/script/XSIfile/xsi33.htm):
handRotation int Specifies the coordinate system:
0 = left-handed (D3D, PlayStation)
1 = right-handed (SOFTIMAGE|3D, Nintendo)
uAxis int Orientation of the U axis for texture coordinates:
0 = right (all)
1 = left
vAxis int Orientation of the V axis for texture coordinates:
0 = down (D3D, Nintendo, PlayStation)
1 = up (SOFTIMAGE|3D)
xAxis int Orientation of the X axis:
0 = right (all)
1 = left
2 = up
3 = down
4 = in
5 = out
yAxis int Orientation of the Y axis:
0 = right
1 = left
2 = up (SOFTIMAGE|3D, D3D, Nintendo)
3 = down (PlayStation)
4 = in
5 = out
zAxis int Orientation of the Z axis:
0 = right
1 = left
2 = up
3 = down
4 = in (D3D, PlayStation)
5 = out (SOFTIMAGE|3D, Nintendo)


I'd like to convert the vertices to my coordinate space (x-axis, going from left to right, y-axis going bottom to up, z - axis going from back to front, right handed system). The different direction vectors expressed in my space are: 0 = [1,0,0] 1 = [-1,0,0] 2 = [0,1,0] 3 = [0,-1,0] 4 = [0,0,-1] 5 = [0,0,1] I build the matrix from the file information. Ex: xAxis = 0 [1,0,0] yAxis = 2 [0,1,0] zAxis = 4 [0,0,-1] I then inverse the matrix to get the matrix that converts from their space to mine. Is this correct? What about the left/right-handed flag, isn't a coordinate system left or right handed on it's own? (Maybe this flag is just an easy way to determine if I need to flip the polygon winding or not). Further more I've got problems with their rotations (this is quite xsi specific I guess). They represents rotation as 3 angles like(http://www.iro.umontreal.ca/~roys/softimage_xsi/files/docs/html/script/XSIfile/xsi68.htm#1207067):
scalX, scalY, scalZ float Scaling vector.
rotX, rotY, rotZ float Rotation vector.
transX, transY, transZ float Translation vector.


How do I create a transform in my space that represents the transform above? Translation and scaling shouldn't cause any problems, but what about rotations? Isn't the order of the applied axis rotations important? Anyone know what order xsi use? Are the rotations clockwise / counter clockwise? Help please! :) I'm lost in translation..

##### Share on other sites
The standard matrix that flips between left and right handed system is the one you wrote:
1 0  00 1  00 0 -1
Its inverse looks the same. Multiply your vertices with this (basically change sign on the z-component) to toggle between left and right handed coordinates. You also have to convert your transformations in the same way.

The angle representation is called Euler Angles. Do a search on that for more information. The order of rotations are essential and XSI probably change the order depending on what it does. You have to find a flag for this somewhere. To build a complete transformation using 3 angles you could just multiply 3 rotation matrices together RotX(anglex) * RotY(angley) * RotZ(anglez) (using correct order of course). This is not the most efficient way, but easy.

##### Share on other sites
Yes that one was easy, but I've seen files with rotations like this:

xAxis = 0 [1,0,0]
yAxis = 4 [0,0,-1]
zAxis = 2 [0,1,0]

Then the matrix that takes you from that repsentation to mine should be the inverse of the above, right?

I know how to create a rotation matrix from euler angles, the problem is that you can create it in ALOT (48) of diffrent ways:

+X+Y+Z+X+Y-Z+X-Y+Z+X-Y-Z-X+Y+Z-X+Y-Z-X-Y+Z-X-Y-Z+X+Z+Y+X+Z-Y+X-Z+Y+X-Z-Y-X+Z+Y-X+Z-Y-X-Z+Y-X-Z-Y+Y+X+Z+Y+X-Z+Y-X+Z+Y-X-Z-Y+X+Z-Y+X-Z-Y-X+Z-Y-X-Z+Y+Z+X+Y+Z-X+Y-Z+X+Y-Z-X-Y+Z+X-Y+Z-X-Y-Z+X-Y-Z-X+Z+X+Y+Z+X-Y+Z-X+Y+Z-X-Y-Z+X+Y-Z+X-Y-Z-X+Y-Z-X-Y+Z+Y+X+Z+Y-X+Z-Y+X+Z-Y-X-Z+Y+X-Z+Y-X-Z-Y+X-Z-Y-X

Where the +/- represents clockwise or counter clockwise order (either defined as looking along the rotation axis or towards it).

Usually you decide upon an order and stick with it. As long as your euler=>matrix and matrix=>euler uses the same order you're fine (I got stuck with the order that lightwave used, back in 1995 or so, don't even remember the order now :).

But since the rotations aren't applied in my space but rather in the space defined above, my rotation functions and order aren't going to work, right?

##### Share on other sites
Are you saying that this is the base matrix they use, and that all transformations are applied using that base matrix? That's a bit odd, I've never seen it before. =)

But okay, here's a short explanation in linear algebra form.

The base f (XSI's base) is represented, in the standard base e, by the transform matrix T (the matrix you gave an example of):
f = eT

If X is a vertex in base e, and Y is the same vertex in base f, the relationship is:
eX = fY = /replacing f with the above/ = eTY

So each vertex Y on base f is converted to base e by applying T.

In your case, Y is a transformed vertex.
Y = AV
where A is the rotation matrix from euler angles and V is the original vertex. That comes to:
eX = eT(AV) = e(TA)V

So, build A using euler formulas. Multiply T with A and you have your transform matrix that converts any vertex in its original form to the standard base including rotation.

Depending on whether XSI use row or column vectors you may have to transpose the base matrix. If you use row vectors you have to do everything in the opposite order of what I explained (ie. X = VAT)

Euler
There are actually 12 different combinations. Every combination of axis but never the same axis twice.
XYZ	YZX	ZXYXZY	YXZ	ZYXXYX	YXY	ZXZXZX	YZY	ZYZ
To rotate in a negative direction doesn't make any sense. Pi can be added to the angle instead. But if you suspect that XSI does rotate in the "wrong" direction you would have 72 combinations to try. =)
Whatever they do, you must of course use their order. I know that 3DSMAX switch the order when doing animations for instance. Each anim key can have a different order to prevent gimbal lock.