D3DFVF_XYZ和D3DFVF_XYZRHW有什么區(qū)別?以前好像沒有仔細思考過,只是見到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將執(zhí)行視、投影、世界等變換以及進行光線計算,之后你才能在窗口中得到你所繪制的物體。當頂點結構體中有RHW時,就像上面那段英文所述,告知Direct3D使用的頂點已經(jīng)在屏幕坐標系中了,不再執(zhí)行視圖、投影、世界等變換和光線計算,因為D3DFVF_XYZRHW標志告訴它頂點已經(jīng)經(jīng)過了這些處理,并直接將頂點進行光柵操作,任何用SetTransform進行的轉(zhuǎn)換都對其無效。不過這時的原點就在客戶區(qū)的左上角了,其中x向右為正,y向下為正,而z的意義已經(jīng)變?yōu)閦-buffer的象素深度。
值得注意的是,D3DFVF_XYZRHW和D3DFVF_XYZ、D3DFVF_NORMAL不能共存,因為后兩個標志與前一個矛盾。在使用這種頂點時,系統(tǒng)需要頂點的位置已經(jīng)經(jīng)過變換了,也就是說x、y必須在屏幕坐標系中,z必須是z-buffer中的象素深度,取值范圍:0.0-1.0,離觀察者最近的地方為0.0,觀察范圍內(nèi)最遠可見的地方為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.
_______________________
[1] RHW表示投影空間中頂點所在的齊次點(x,y,z,w)(homogeneous point)的w坐標的倒數(shù)(reciprocal)。