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