Hi,
I''m trying to convert my file format (kept in a left handed coordinate system) to render in opengl''s right handed coordiante system, where left hand Coordinate system defined as x, y, z where they point right, up and into the screen and right handed coordinate system defined as x,y, z where they point right, up and away from the screen respectively.
Now technically could i multipy all z values by -1 and rotate by the negative amount? Suppose i have some transformations in my file and i want to convert this transformation from left hand to right hand. I dont think scaling it by [1 1 -1] and negating the z translation component works. does anybody know how to convert this properly. I think i''ve seen it on the forums before but the search isn''t working. Thanks for any help.

# Conversion between left and right handed coordinate systems

Started by WesTam, Oct 31 2002 07:19 AM

6 replies to this topic

###
#2
Anonymous Poster_Anonymous Poster_*
Guests - Reputation:

Posted 31 October 2002 - 09:32 AM

Does this make any sence:

Let P be a point.

Let W be a transformation in left handed coordnate system.

Let S be a transformation that converts Point P from left to right coordinate systems.

Thus S = | 1 0 0 0 |

| 0 1 0 0 |

| 0 0 -1 0 |

| 0 0 0 1 |

So (P*W) *S = transformed point in right handed coordinate system.

since mutliplicative associativity holds between nxm matricies:

(P*W)*S = P (W*S)

So The product of W and S is W with the thrid column negated. Thus to transform from a transformation from left to right handed coordinate systems we can just negate it''s thrid column.

Is this correct?

Let P be a point.

Let W be a transformation in left handed coordnate system.

Let S be a transformation that converts Point P from left to right coordinate systems.

Thus S = | 1 0 0 0 |

| 0 1 0 0 |

| 0 0 -1 0 |

| 0 0 0 1 |

So (P*W) *S = transformed point in right handed coordinate system.

since mutliplicative associativity holds between nxm matricies:

(P*W)*S = P (W*S)

So The product of W and S is W with the thrid column negated. Thus to transform from a transformation from left to right handed coordinate systems we can just negate it''s thrid column.

Is this correct?

###
#3
Members - Reputation: **126**

Posted 31 October 2002 - 09:33 AM

Does this make any sence:

Let P be a point.

Let W be a transformation in left handed coordnate system.

Let S be a transformation that converts Point P from left to right coordinate systems.

So (P*W) *S = transformed point in right handed coordinate system.

since mutliplicative associativity holds between nxm matricies:

(P*W)*S = P (W*S)

So The product of W and S is W with the thrid column negated. Thus to transform from a transformation from left to right handed coordinate systems we can just negate it's thrid column.

Is this correct?

[edited by - _walrus on October 31, 2002 4:34:32 PM]

[edited by - _walrus on October 31, 2002 4:35:19 PM]

[edited by - _walrus on October 31, 2002 4:35:44 PM]

Let P be a point.

Let W be a transformation in left handed coordnate system.

Let S be a transformation that converts Point P from left to right coordinate systems.

Thus S =

| 1 0 0 0 |

| 0 1 0 0 |

| 0 0 -1 0 |

| 0 0 0 1 |

So (P*W) *S = transformed point in right handed coordinate system.

since mutliplicative associativity holds between nxm matricies:

(P*W)*S = P (W*S)

So The product of W and S is W with the thrid column negated. Thus to transform from a transformation from left to right handed coordinate systems we can just negate it's thrid column.

Is this correct?

[edited by - _walrus on October 31, 2002 4:34:32 PM]

[edited by - _walrus on October 31, 2002 4:35:19 PM]

[edited by - _walrus on October 31, 2002 4:35:44 PM]

###
#4
Members - Reputation: **122**

Posted 01 November 2002 - 03:42 AM

Yep, that's correct. Just flip the sign of the third column (for column-major matrices; the third row for row-major matrices) and don't forget to change the winding of your triangles to counter-clockwise (or simply flip the culling mode).

[edited by - Asgard on November 1, 2002 10:43:35 AM]

[edited by - Asgard on November 1, 2002 10:43:35 AM]

###
#5
Members - Reputation: **126**

Posted 01 November 2002 - 07:18 AM

Great thanks Asgard,

The above method (scaling the thrid column) works on translations, but what about rotation components of the transformation? Rotating about the Z axis is the same for both coordinate system, but the rotations about the y and x axis are negated in the two systems. Will scaling the thrid column address this?

The above method (scaling the thrid column) works on translations, but what about rotation components of the transformation? Rotating about the Z axis is the same for both coordinate system, but the rotations about the y and x axis are negated in the two systems. Will scaling the thrid column address this?

###
#6
Members - Reputation: **122**

Posted 01 November 2002 - 09:21 AM

I'm not sure if I understand your question correctly. Basically negating the third column negates the z coordinate of every vector you multiply with the matrix, which is exactly what is needed to convert a vector from left-handed to right-handed coordinates. It doesn't have anything to do with what kind of matrix that is.

Note that, if you have multiple matrices in your file format that might get concatenated somewhere (like a hierarchy with each node having its own matrix), then negating the third column in each of those matrices will not give the desired result (at least, if the number of concatenated matrices is even).

So in general, it's probably best to simply convert all the vertices in your file to right-handed coordinates by setting z' = -z for each vertex and not change any of your matrices. Another option would be to leave the vertices as they are and simply set a left-handed projection matrix when rendering with OpenGL.

[edited by - Asgard on November 1, 2002 4:22:09 PM]

Note that, if you have multiple matrices in your file format that might get concatenated somewhere (like a hierarchy with each node having its own matrix), then negating the third column in each of those matrices will not give the desired result (at least, if the number of concatenated matrices is even).

So in general, it's probably best to simply convert all the vertices in your file to right-handed coordinates by setting z' = -z for each vertex and not change any of your matrices. Another option would be to leave the vertices as they are and simply set a left-handed projection matrix when rendering with OpenGL.

[edited by - Asgard on November 1, 2002 4:22:09 PM]

###
#7
Members - Reputation: **126**

Posted 02 November 2002 - 06:46 AM

Hey, i guess what i mean can be best illustrated in an example:

suppose i have the following in my file (left handed system):

All points specified in between PUSH and POP will be affected by the TRANSFORMATION. We see that this transformation W will rotate the points 180 degrees about the y-axis.

Now we apply S to W to tranform to right handed coordinate system where S is

This product yeilds a tranformation in right handed coordinate system:

But is this correct? Since in the left handed system we are rotating points about the y-axis 180 degrees? This matrix does not rotate about y-axis 180 degrees.

Intuatively shouldn't we be rotating points about the y-axis at -180 degrees in the right handed system as follows:

in left handed system:

Since cos(-180) = cos(180) we have the same matrix. Therefore using S to convert from one coordinate system to the other when rotation are involved is not adiquate.

I suppose i could tranform all points to get to them to world cooridinates and then apply S to each point, but I would really like to preseve the notaion of localized spaces in my system by transforming local points to right hand system by multipling by S and by converting Transformation by ???(by some process or by multiplying by some Transformation R). Any ideas or comments would be very helpful. Or does anyone know of documentation or books that illustrate how to do this? And thanks Asgard for your help so far.

[edited by - _walrus on November 2, 2002 1:48:06 PM]

[edited by - _walrus on November 2, 2002 1:50:23 PM]

[edited by - _walrus on November 2, 2002 1:55:44 PM]

suppose i have the following in my file (left handed system):

PUSH

TRANSFORMATION W

| -1 0 0 0 |

| 0 1 0 0 |

| 0 0 -1 0 |

| 0 0 0 1 | //where this row holds the translation components

POINTS [ vertex data for some points ]

POP

All points specified in between PUSH and POP will be affected by the TRANSFORMATION. We see that this transformation W will rotate the points 180 degrees about the y-axis.

Now we apply S to W to tranform to right handed coordinate system where S is

| 1 0 0 0 |

| 0 1 0 0 |

| 0 0 -1 0 |

| 0 0 0 1 |

This product yeilds a tranformation in right handed coordinate system:

| -1 0 0 0 |

| 0 1 0 0 |

| 0 0 1 0 |

| 0 0 0 1 | //where this row holds the translation

But is this correct? Since in the left handed system we are rotating points about the y-axis 180 degrees? This matrix does not rotate about y-axis 180 degrees.

Intuatively shouldn't we be rotating points about the y-axis at -180 degrees in the right handed system as follows:

in left handed system:

| cos(180) 0 0 0 |

| 0 0 0 0 |

| 0 0 cos(180) 0 |

| 0 0 0 0 |

so the equivalent transform in right handed system would be :

| cos(-180) 0 0 0 |

| 0 0 0 0 |

| 0 0 cos(-180) 0 |

| 0 0 0 0 |

Since cos(-180) = cos(180) we have the same matrix. Therefore using S to convert from one coordinate system to the other when rotation are involved is not adiquate.

I suppose i could tranform all points to get to them to world cooridinates and then apply S to each point, but I would really like to preseve the notaion of localized spaces in my system by transforming local points to right hand system by multipling by S and by converting Transformation by ???(by some process or by multiplying by some Transformation R). Any ideas or comments would be very helpful. Or does anyone know of documentation or books that illustrate how to do this? And thanks Asgard for your help so far.

[edited by - _walrus on November 2, 2002 1:48:06 PM]

[edited by - _walrus on November 2, 2002 1:50:23 PM]

[edited by - _walrus on November 2, 2002 1:55:44 PM]