# Oh no, not this topic again: LH vs. RH.

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

## Recommended Posts

So I'm porting my game over from XNA (RH) to SharpDX (LH or RH, LH traditionally)  and have finally arrived to the last phase: the terrain. Once this is done porting finally be behind me!

And here is where LH or RH really causes major changes. For terrain I needed to do a ton of adjustment, even having to transpose the terrain only for physics.

In the past I did not mind switching from RH to LH. I had to use different matrices and swap the Z in position and normals at mesh load and things where pretty much done.

But recently I noticed that logically LH does not not make that much sense. Everything from applying a 2D grid on top of the 3D world to mapping mathematical matrices to world positions to drawing mini maps is a lot more intuitive using RH. Especially mapping of matrices. In programming you often have an (x, y) matrix that is represented as y rows of x columns. This maps intuitively to right handed. You need to put element (0, 0) at you coordinate system's origin and map Y to Z (assuming your world is not centered; even if it is, just subtract an offset).

LH on the other hand is more difficult to map. Especially since you often need to transform things from one space into another in your head.

Are there any good reasons to use LH other than DirectX has traditionally used it and it may make integrating things from DirectX easier?

I'm really torn between the two. But if I switch back to RH it must be done now.

##### Share on other sites

Switch to RH now.  Ultimately it's just a matrix multiply, so the final vertex transform is identical in both: SomeLeftHandedMatrix * Position or SomeRightHandedMatrix * Position.  It's far more important that you're consistent in your own code.

A write-up of the historical reasons for D3D choosing LH is here: http://www.alexstjohn.com/WP/2013/07/22/the-evolution-of-direct3d/ - summary: it was purely an arbitrary decision and based on a purely personal preference rather than for any technical or other reasons.

##### Share on other sites

There's nothing in modern (programmable) DirectX/OpenGL that incentivizes you to use one over the other, apart from the libraries you're using (D3DX, XNAMath and DirectXMath all provide LH and RH functions, while GLM unfortunately only provides RH ones).

Also, slightly unrelated but always interesting: http://programmers.stackexchange.com/a/88776

##### Share on other sites

the final vertex transform is identical in both: SomeLeftHandedMatrix * Position or SomeRightHandedMatrix * Position.

Actually, that's not correct. As commonly implemented, it would be Position * SomeLeftHandedMatrix and SomeRightHandedMatrix * Position.

##### Share on other sites

Doesnt't that depend on row-major vs column-major and not LH vs RH?

##### Share on other sites

There's nothing in modern (programmable) DirectX/OpenGL that incentivizes you to use one over the other, apart from the libraries you're using (D3DX, XNAMath and DirectXMath all provide LH and RH functions, while GLM unfortunately only provides RH ones).

Also, slightly unrelated but always interesting: http://programmers.stackexchange.com/a/88776

Yes, as I said, the changes were simple. But now with the physics engine, adapting to LH is incredibly hard.

Mapping data structures to 3D space will eventually boil down to familiarity.

RH seems much more intuitive and familiar. The one thing I might have problems is having to do some conversion when adding depth based thing or whatever from DirectX world.

the final vertex transform is identical in both: SomeLeftHandedMatrix * Position or SomeRightHandedMatrix * Position.

Actually, that's not correct. As commonly implemented, it would be Position * SomeLeftHandedMatrix and SomeRightHandedMatrix * Position.

I've never done that.

I always have world = (bone) * (matrix_from_model_to_physics) * w

and then the v * p matrix.

I never needed to swap any orders when going from LH to RH.

Edited by DwarvesH

##### Share on other sites

There's nothing in modern (programmable) DirectX/OpenGL that incentivizes you to use one over the other, apart from the libraries you're using (D3DX, XNAMath and DirectXMath all provide LH and RH functions, while GLM unfortunately only provides RH ones).

Also, slightly unrelated but always interesting: http://programmers.stackexchange.com/a/88776

Yes, as I said, the changes were simple. But now with the physics engine, adapting to LH is incredibly hard.

Mapping data structures to 3D space will eventually boil down to familiarity.

RH seems much more intuitive and familiar. The one thing I might have problems is having to do some conversion when adding depth based thing or whatever from DirectX world.

the final vertex transform is identical in both: SomeLeftHandedMatrix * Position or SomeRightHandedMatrix * Position.

Actually, that's not correct. As commonly implemented, it would be Position * SomeLeftHandedMatrix and SomeRightHandedMatrix * Position.

I've never done that.

I always have world = (bone) * (matrix_from_model_to_physics) * w

and then the v * p matrix.

I never needed to swap any orders when going from LH to RH.

I think the key part of what Buckeye said is " as commonly implemented". but no, you should not need to swap matrix multiplication order for handedness, only for majorness, as Mona2000 mentioned. The only real place that handedness matters is in the projection transform, or how our mapping of the 3D vector space is converted to 2D.

Edited by Burnt_Fyr

##### Share on other sites

I think the key part of what Buckeye said is " as commonly implemented". but no, you should not need to swap matrix multiplication order for handedness, only for majorness, as Mona2000 mentioned. The only real place that handedness matters is in the projection transform, or how our mapping of the 3D vector space is converted to 2D.

Not even majorness matters. What determines whether the vector goes on the left or the right hand side of the matrix depends on whether you use row or column vectors and nothing else. A column vector cannot go anywhere but on the right hand side, and a row vector cannot go anywhere but on the left hand side of a multiplication with a matrix, and majorness or handedness are irrelevant.

Edited by Brother Bob

##### Share on other sites

Yeah, but HLSL, GLSL and most (all?) math libs used by games don't have the concept of row or column vectors.

##### Share on other sites

The only real place that handedness matters is in the projection transform, or how our mapping of the 3D vector space is converted to 2D.

Sure, that is one key place that matters. But it is so easy and trivial to fix that it does not matter at all. You either have it right or wrong, and fixing it takes literally seconds.

Here are some things that change from LH to RH that do matter:

2. Mesh generations. I generate both some meshes and relative mesh placement procedurally. This code does not multiply everything by a forward vector so all Z placement is wrong after a change.

3. Mesh processing. I have custom code meant to fix the horrible and broken tangent export feature in most 3D modeling programs that results in seams. Maybe needs fixing, maybe doesn't.

4. The entire process of mapping my pretty big maps (64 square kilometers and growing) to the 3D world. Questions like "if I am at this character coordinate what is the logical coordinate, what cells does it map into, what neighbors is ahead of me and which one is behind, how best to circle cone map the area, etc." The simplest case is answering the question where does cell (0, 0) go. And does the next one go? This all change very slightly and subtly. At the very least you want to update your mapping that you present to the human being and that must be in a familiar map coordinate system, or risk questions like "why is 0 at the bottom".

5. Character controller. That code is 300 KiB and changing from LH to RH changes my move direction and mouse camera movement. I know where to look so I can fix it now relatively fast, but the first time I went from RH to LH that was very annoying to fix.

6. Terrain physics. This one I just can't get right in LH. Third party physics engine.

7. And many more.

So I would say that going from LH to RH is 2-4 weeks of work, that's why I weight the decision carefully.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 14
• 30
• 9
• 16
• 22