Left- handedness coordinate
As is known to all, OpenGL uses a right-handed coordinate system, while Direct3D uses a left-handed coordinate system.
Other than the orientation of the z axis above, there are other differences in the left-hand coordinate system:
forward direction of rotation: In the left-hand system with left-hand rule discriminant, the positive direction is clockwise direction. In the right-hand system, the right-hand rule is used to determine the counterclockwise direction.
direction of cross product : In the right-hand coordinate system, the direction of the cross product is determined by right-hand rule, while in the left-handed coordinate system, the direction of the cross product is determined by the left-hand rule.
World Space coordinate system
World space is the objective area for defining physical worlds, and left hand and right hand just provide two different ways of describing space, but the same world is described. Sit on either hand
The conversion between the scales does not change the world in which it is described, and the real-world clocks are rotated clockwise, whether in the left-hand or right-handed system.
View coordinate system
Whether it is the left-hand or the right-hand system, the world coordinate system describes the same universal space, and you observe this objective world space, depending on the coordinate system you use, which is OpenGL and
Direct3D the most important difference. Let's take a look at the example below.
The camera settings are eyepos (0, 0, +), LookAt (0, 0, 0), Upvec (0, 1, 0), the positions of the red squares are (-3, 0, 0), the green squares are (3, 0, 0),
So why is OpenGL and Direct3D upside-down? Personally think is because the view coordinate system is left or right hand relations, in the Direct3D, the View space coordinate system is Hand,
Z-axis is viewdirection (lookat-eyeposition), when the camera in (0,0,15) to the origin of the point of view, it is really ( -3,0,0) a red block appears in (3,0,0)
To the right of the green square. In OpenGL, the view space coordinate system is right Hand, the z axis is actually-viewdirection, so the result is that the red squares appear on the left side of the green squares.
Thus, the left-right hand coordinate system is actually two worlds upside down.
conversion of the left-handedness coordinate system
As seen above, the left-hand coordinate system renders the 2D image results are not the same, around the upside, how to make the right-hand coordinate system to render the same 2D image, there are two ways.
method One : Invert all vertex x-coordinate and camera x-coordinates, and the left-hand coordinate system is actually the two coordinate system which is reversed.
method Two : Reverse the horizontal direction of the 2D image rendered with the right-hand coordinate system.
using the left-handed coordinate system in modern OpenGL
It is well known that only the right-handed coordinate system is used in OpenGL for fixed pipelines, and OpenGL does not provide an API for you to switch in the left-hand coordinate system. In the programmable pipeline OpenGL, there is less
Many restrictions, all vertex transform are controlled by you. In fact, it's no problem for you to pass the vertex and matrix of the left-hand coordinate system directly to OpenGL Shader, in vertex Shader
Using Mul (V, matrix) to transform vertices, you get the same results as Direct3D. Note that the same result as Direct3D, not the same result as the fixed pipeline OpenGL, in fact, as
As mentioned above, the left-hand coordinate system renders the result of the right-side reversal. The only difference is viewport Z, in OpenGL, the z-coordinate of the clipping space is [-1.1], while in Direct3D is [0, 1],
After viewport changes, either OpenGL or Direct3D, Z is [0, 1], OpenGL viewport changes are z= (z/w + 1)/2, and Direct3D is z= (z/w), which depth
Test is not affected, Depth test only compares relative position, but the value of Depth buffer is different. So you need to make some adjustments to the project matrix in order for them to write to depth buffer.
Values are the same. Specifically, if you want the OpenGL pipeline to accept the D3D project matrix, you'll need to multiply your
The equivalent of z = z * 2–1 the vertex z of project space, so the viewport transformation is consistent.
OpenGL: You don't know the coordinate system of the left-handedness