D3DFVF_XYZ和D3DFVF_XYZRHW的区别

D3DFVF_XYZ和D3DFVF_XYZRHW有什么区别?以前好像没有仔细思考过,只是见到Beginning DirectX9中如是说:The RHW value, which stands for Reciprocal of Homogeneous W[1], tells Direct3D that the vertices that are being used are already in screen coordinates. This value is normally used in fog and clipping calculations and should be set to 1.0.

    今天,做了个实验得知,在顶点结构体中没有RHW时,Direct3D将执行视、投影、世界等变换以及进行光线计算,之后你才能在窗口中得到你所绘制的物体。当顶点结构体中有RHW时,就像上面那段英文所述,告知Direct3D使用的顶点已经在屏幕坐标系中了,不再执行视图、投影、世界等变换和光线计算,因为D3DFVF_XYZRHW标志告诉它顶点已经经过了这些处理,并直接将顶点进行光栅操作,任何用SetTransform进行的转换都对其无效。不过这时的原点就在客户区的左上角了,其中x向右为正,y向下为正,而z的意义已经变为z-buffer的象素深度。

 

    值得注意的是,D3DFVF_XYZRHW和D3DFVF_XYZ、D3DFVF_NORMAL不能共存,因为后两个标志与前一个矛盾。在使用这种顶点时,系统需要顶点的位置已经经过变换了,也就是说x、y必须在屏幕坐标系中,z必须是z-buffer中的象素深度,取值范围:0.0-1.0,离观察者最近的地方为0.0,观察范围内最远可见的地方为1.0。(不过我测试的时候似乎z值不起作用。)


If you use D3DFVF_XYZ, then your vertex format needs to have 3 floats in it, for x, y and z. Those are used to define a vertex position in 3D space.If you use D3DFVF_XYZRHW, then your vertex format needs to have 4 floats in it, for x, y, z and rhw. X and Y are used to define a vertex position in 2D space, Z is ignored (I think, it may be used for fog and such, but I don't recall just now - I always set it to 0.0f), and rhw is the Reciprocal of Homogenous W - which is basically 1 / the depth of the vertex.

Usually, you use D3DFVF_XYZRHW for doing 2D, and D3DFVF_XYZ any other time. However, a lot of people just use D3DFVF_XYZ, and use an orthoganal projection matrix to make it seem 2D.

你可能感兴趣的:(区别)