通常情况下,3-D 图形应用程序使用两种卡笛尔坐标系:左手系和右手系。在这两种坐标系下,X 轴的正向指向右方,Y 轴正向指向上方。你可以这样记忆 Z 轴的正向:无论是左手系还是右手系,将你的手指沿 X 轴的正向伸展开,然后向 Y 轴的正向弯曲,这样你的大拇指所指的方向就是 Z 轴的正向。下面的插图就显示了这两个坐标系。
Typically 3-D graphics applications use two types of Cartesian coordinate systems: left-handed and right-handed. In both coordinate systems, the positive x-axis points to the right, and the positive y-axis points up. You can remember which direction the positive z-axis points by pointing the fingers of either your left or right hand in the positive x-direction and curling them into the positive y-direction. The direction your thumb points, either toward or away from you, is the direction that the positive z-axis points for that coordinate system. The following illustration shows these two coordinate systems.
Direct3D 使用的是左手坐标系。如果你正在移植基于右手系的应用程序时,你必须对传给 Direct3D 的数据做两方面的修改:
Microsoft® Direct3D® uses a left-handed coordinate system. If you are porting an application that is based on a right-handed coordinate system, you must make two changes to the data passed to Direct3D.
颠倒三角形顶点的顺序,这样系统可以从正面沿顺时针的方向去遍历他们。换句话说就是,如果原顶点的顺序为v0、v1、v2,那么将他们传递给 Direct3D 时就应该以这样的顺序v0、v2、v1。
Flip the order of triangle vertices so that the system traverses them clockwise from the front. In other words, if the vertices are v0, v1, v2, pass them to Direct3D as v0, v2, v1.
用观察矩阵对世界空间中 Z 轴上的值求反。为了达到这个目的,将观察矩阵中的 D3DMATRIX 结构中的_31、_32、_33 和 _34 成员的符号取反。
Use the view matrix to scale world space by -1 in the z-direction. To do this, flip the sign of the _31, _32, _33, and _34 member of the D3DMATRIX structure that you use for your view matrix.
要得到右手系世界空间的效果,要使用 D3DXMatrixPerspectiveRH 和 D3DXMatrixOrthoRH 函数来定义投影矩阵的转换。但是,要小心使用对应的 D3DXMatrixLookAtRH 函数,反转背景裁剪的顺序,以及立方体贴图的位置。
To obtain what amounts to a right-handed world, use the D3DXMatrixPerspectiveRH and D3DXMatrixOrthoRH functions to define the projection transform. However, be careful to use the corresponding D3DXMatrixLookAtRH function, reverse the backface-culling order, and lay out the cube maps accordingly.
虽然左手系和右手系都是很常用的系统,但是也有很多其他种类的坐标系用于 3-D 软件。比如说,对于3-D 建模应用程序而言,Y 轴指向或背向观察者的坐标系就并不罕见。在这种情况下,右手系就定义为任意轴的正向均指向观察者。而左手系就定义为任意轴的正向均背向观察者。如果你正在移植 Z 轴指向上的左手系建模应用程序,你就必须将所有的顶点数据做上述的处理。
Although left-handed and right-handed coordinates are the most common systems, there is a variety of other coordinate systems used in 3-D software. For example, it is not unusual for 3-D modeling applications to use a coordinate system in which the y-axis points toward or away from the viewer, and the z-axis points up. In this case, right-handedness is defined as any positive axis (x, y, or z) pointing toward the viewer. Left-handedness is defined as any positive axis (x, y, or z) pointing away from the viewer. If you are porting a left-handed modeling application where the z-axis points up, you must do a rotation on all the vertex data in addition to the previous steps.
对 3-D 坐标系中定义的对象最基本的操作就是变换、旋转和缩放。你可以将基本变换进行组合,以此来创建出新的变换矩阵。更多细节请查看 3-D 变换。
The essential operations performed on objects defined in a 3-D coordinate system are translation, rotation, and scaling. You can combine these basic transformations to create a transform matrix. For details, see 3-D Transformations.
当你在组合这些操作的时候,矩阵的运算顺序是不可交换的,不同相乘顺序会导致不同的变换效果,这点很重要。
When you combine these operations, the results are not commutative - the order in which you multiply matrices is important.