青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

天行健 君子當(dāng)自強(qiáng)而不息

頂點(diǎn)坐標(biāo)變換(5)

投影變換

將攝影空間中的三維物體投影到二維膠片上,也就是Direct3D中的屏幕,這種三維到二維的變換過程就是投影變換,即從取景空間到攝影空間的變換。設(shè)三維物體在觀察空間中的坐標(biāo)為Pview,投影矩陣為Mproj,則頂點(diǎn)在投影空間中的坐標(biāo)為:

Pproj = Pview * Mproj

下面分別介紹兩種基本的投影變換:正交投影和透視投影,以及它們?cè)贒irect3D中的實(shí)現(xiàn)。

 

1、正交投影

正交投影中,投影向量和觀察平面垂直,物體坐標(biāo)沿觀察坐標(biāo)系的z軸平行投影到觀察平面上,觀察點(diǎn)和觀察平面間的距離不會(huì)影響物體的投影大小。

工程設(shè)計(jì)中的頂視圖、前視圖和側(cè)視圖就是典型的正交投影。與世界變換、取景變換類似,只需先生成一個(gè)投影矩陣mat_proj,然后調(diào)用下面的代碼就可以設(shè)置投影矩陣:

g_device->SetTransform(D3DTS_PROJECTION, &mat_proj);

下面來(lái)看看正交投影矩陣的生成。對(duì)于正交投影來(lái)說(shuō),它的取景范圍是一個(gè)長(zhǎng)方體,只有在這個(gè)長(zhǎng)方體中的景物才會(huì)被繪制出來(lái)。

Direct3D擴(kuò)展實(shí)用庫(kù)提供了函數(shù)D3DXMatrixOrthoLH(),用于創(chuàng)建一個(gè)正交投影矩陣,函數(shù)D3DXMatrixOrthoLH()的聲明如下:

Builds a left-handed orthographic projection matrix.

D3DXMATRIX * D3DXMatrixOrthoLH(
D3DXMATRIX * pOut,
FLOAT w,
FLOAT h,
FLOAT zn,
FLOAT zf
);

Parameters

pOut
[in, out] Pointer to the resulting D3DXMATRIX.
w
[in] Width of the view volume.
h
[in] Height of the view volume.
zn
[in] Minimum z-value of the view volume which is referred to as z-near.
zf
[in] Maximum z-value of the view volume which is referred to as z-far.

Return Values

Pointer to the resulting D3DXMATRIX.

Remarks

All the parameters of the D3DXMatrixOrthoLH function are distances in camera space. The parameters describe the dimensions of the view volume.

The return value for this function is the same value returned in the pOut parameter. In this way, the D3DXMatrixOrthoLH function can be used as a parameter for another function.

This function uses the following formula to compute the returned matrix.

2/w  0    0           0
0 2/h 0 0
0 0 1/(zf-zn) 0
0 0 -zn/(zf-zn) 1
 

2、透視投影

透視投影實(shí)現(xiàn)的是一個(gè)縮放、透視的投影。透視投影的特點(diǎn)是,距離攝像機(jī)越遠(yuǎn)的物體在投影平面上的成像越小,透視投影的取景范圍是一個(gè)截頭體(四棱臺(tái))。這個(gè)截頭體稱為取景截頭體(viewing frustum),攝像機(jī)位于四棱錐的頂點(diǎn)。這個(gè)四棱錐被截頭體的遠(yuǎn)平面和近平面分割,遠(yuǎn)近裁剪面中間的部分就是取景截頭體,只有這個(gè)空間里的對(duì)象才是可見的。

透視投影矩陣的作用就是將取景截頭體內(nèi)的景物投影到攝像機(jī)的二維膠片上,可以利用Direct3D功能擴(kuò)展庫(kù)提供的D3DXMatrixPerspectiveFovLH(),構(gòu)建一個(gè)透視投影矩陣:

Builds a left-handed perspective projection matrix based on a field of view.

D3DXMATRIX * D3DXMatrixPerspectiveFovLH(
D3DXMATRIX * pOut,
FLOAT fovy,
FLOAT Aspect,
FLOAT zn,
FLOAT zf
);

Parameters

pOut
[in, out] Pointer to the D3DXMATRIX structure that is the result of the operation.
fovy
[in] Field of view in the y direction, in radians.
Aspect
[in] Aspect ratio, defined as view space width divided by height.
zn
[in] Z-value of the near view-plane.
zf
[in] Z-value of the far view-plane.

Return Values

Pointer to a D3DXMATRIX structure that is a left-handed perspective projection matrix.

Remarks

The return value for this function is the same value returned in the pOut parameter. In this way, the D3DXMatrixPerspectiveFovLH function can be used as a parameter for another function.

This function computes the returned matrix as shown:

xScale     0          0               0
0 yScale 0 0
0 0 zf/(zf-zn) 1
0 0 -zn*zf/(zf-zn) 0
where:
yScale = cot(fovY/2)

xScale = yScale / aspect ratio

透視投影矩陣的作用是將一個(gè)取景截頭體轉(zhuǎn)換成一個(gè)立方體。因?yàn)榻仡^體的近端比遠(yuǎn)端小,所以靠近攝像機(jī)的對(duì)象將被放大,而對(duì)象距離攝像機(jī)越遠(yuǎn),其成像越小,這就是場(chǎng)景的透視原理。透視變換把一個(gè)取景截頭體轉(zhuǎn)換成一個(gè)新的坐標(biāo)空間,注意,該截頭體變成了一個(gè)立方體,同時(shí),原點(diǎn)從場(chǎng)景的右上角移動(dòng)到了立方體的中心。在透視變換中,x軸和z軸方向的極限都是-1和1,z軸方向?qū)τ谇捌矫娴臉O限是0,對(duì)后平面的極限是1。

另外,D3DX還提供了下列函數(shù)供程序員創(chuàng)建透視投影變換矩陣:

D3DXMatrixPerspectiveLH

Builds a left-handed perspective projection matrix

D3DXMATRIX * D3DXMatrixPerspectiveLH(
D3DXMATRIX * pOut,
FLOAT w,
FLOAT h,
FLOAT zn,
FLOAT zf
);

Parameters

pOut
[in, out] Pointer to the D3DXMATRIX structure that is the result of the operation.
w
[in] Width of the view volume at the near view-plane.
h
[in] Height of the view volume at the near view-plane.
zn
[in] Z-value of the near view-plane.
zf
[in] Z-value of the far view-plane.

Return Values

Pointer to a D3DXMATRIX structure that is a left-handed perspective projection matrix.

Remarks

All the parameters of the D3DXMatrixPerspectiveLH function are distances in camera space. The parameters describe the dimensions of the view volume.

The return value for this function is the same value returned in the pOut parameter. In this way, the D3DXMatrixPerspectiveLH function can be used as a parameter for another function.

This function uses the following formula to compute the returned matrix.

2*zn/w  0       0              0
0 2*zn/h 0 0
0 0 zf/(zf-zn) 1
0 0 zn*zf/(zn-zf) 0
 

D3DXMatrixPerspectiveRH

Builds a right-handed perspective projection matrix.

D3DXMATRIX * D3DXMatrixPerspectiveRH(
D3DXMATRIX * pOut,
FLOAT w,
FLOAT h,
FLOAT zn,
FLOAT zf
);

Parameters

pOut
[in, out] Pointer to the D3DXMATRIX structure that is the result of the operation.
w
[in] Width of the view volume at the near view-plane.
h
[in] Height of the view volume at the near view-plane.
zn
[in] Z-value of the near view-plane.
zf
[in] Z-value of the far view-plane.

Return Values

Pointer to a D3DXMATRIX structure that is a right-handed perspective projection matrix.

Remarks

All the parameters of the D3DXMatrixPerspectiveRH function are distances in camera space. The parameters describe the dimensions of the view volume.

The return value for this function is the same value returned in the pOut parameter. In this way, the D3DXMatrixPerspectiveRH function can be used as a parameter for another function.

This function uses the following formula to compute the returned matrix.

2*zn/w  0       0              0
0 2*zn/h 0 0
0 0 zf/(zn-zf) -1
0 0 zn*zf/(zn-zf) 0

 

D3DXMatrixPerspectiveFovRH

Builds a right-handed perspective projection matrix based on a field of view.

D3DXMATRIX * D3DXMatrixPerspectiveFovRH(
D3DXMATRIX * pOut,
FLOAT fovy,
FLOAT Aspect,
FLOAT zn,
FLOAT zf
);

Parameters

pOut
[in, out] Pointer to the D3DXMATRIX structure that is the result of the operation.
fovy
[in] Field of view in the y direction, in radians.
Aspect
[in] Aspect ratio, defined as view space width divided by height.
zn
[in] Z-value of the near view-plane.
zf
[in] Z-value of the far view-plane.

Return Values

Pointer to a D3DXMATRIX structure that is a right-handed perspective projection matrix.

Remarks

The return value for this function is the same value returned in the pOut parameter. In this way, the D3DXMatrixPerspectiveFovRH function can be used as a parameter for another function.

This function computes the returned matrix as shown.

xScale     0          0              0
0 yScale 0 0
0 0 zf/(zn-zf) -1
0 0 zn*zf/(zn-zf) 0
where:
yScale = cot(fovY/2)

xScale = yScale / aspect ratio

 

D3DXMatrixPerspectiveOffCenterLH

Builds a customized, left-handed perspective projection matrix.

D3DXMATRIX * D3DXMatrixPerspectiveOffCenterLH(
D3DXMATRIX * pOut,
FLOAT l,
FLOAT r,
FLOAT b,
FLOAT t,
FLOAT zn,
FLOAT zf
);

Parameters

pOut
[in, out] Pointer to the D3DXMATRIX structure that is the result of the operation.
l
[in] Minimum x-value of the view volume.
r
[in] Maximum x-value of the view volume.
b
[in] Minimum y-value of the view volume.
t
[in] Maximum y-value of the view volume.
zn
[in] Minimum z-value of the view volume.
zf
[in] Maximum z-value of the view volume.

Return Values

Pointer to a D3DXMATRIX structure that is a customized, left-handed perspective projection matrix.

Remarks

All the parameters of the D3DXMatrixPerspectiveOffCenterLH function are distances in camera space. The parameters describe the dimensions of the view volume.

The return value for this function is the same value returned in the pOut parameter. In this way, the D3DXMatrixPerspectiveOffCenterLH function can be used as a parameter for another function.

This function uses the following formula to compute the returned matrix.

2*zn/(r-l)   0            0              0
0 2*zn/(t-b) 0 0
(l+r)/(l-r) (t+b)/(b-t) zf/(zf-zn) 1
0 0 zn*zf/(zn-zf) 0

D3DXMatrixPerspectiveOffCenterRH

Builds a customized, right-handed perspective projection matrix.

D3DXMATRIX * D3DXMatrixPerspectiveOffCenterRH(
D3DXMATRIX * pOut,
FLOAT l,
FLOAT r,
FLOAT b,
FLOAT t,
FLOAT zn,
FLOAT zf
);

Parameters

pOut
[in, out] Pointer to the D3DXMATRIX structure that is the result of the operation.
l
[in] Minimum x-value of the view volume.
r
[in] Maximum x-value of the view volume.
b
[in] Minimum y-value of the view volume.
t
[in] Maximum y-value of the view volume.
zn
[in] Minimum z-value of the view volume.
zf
[in] Maximum z-value of the view volume.

Return Values

Pointer to a D3DXMATRIX structure that is a customized, right-handed perspective projection matrix.

Remarks

All the parameters of the D3DXMatrixPerspectiveOffCenterRH function are distances in camera space. The parameters describe the dimensions of the view volume.

The return value for this function is the same value returned in the pOut parameter. In this way, the D3DXMatrixPerspectiveOffCenterRH function can be used as a parameter for another function.

This function uses the following formula to compute the returned matrix.

2*zn/(r-l)   0            0                0
0 2*zn/(t-b) 0 0
(l+r)/(r-l) (t+b)/(t-b) zf/(zn-zf) -1
0 0 zn*zf/(zn-zf) 0

3、w友好投影矩陣

經(jīng)過頂點(diǎn)坐標(biāo)變換后,每個(gè)頂點(diǎn)坐標(biāo)將具有4個(gè)元素(x, y, z, w)。Direct3D使用這個(gè)w坐標(biāo)在深度緩沖區(qū)和霧化效果中執(zhí)行一些深度相關(guān)的運(yùn)算。為了能夠使用這個(gè)w坐標(biāo)進(jìn)行深度相關(guān)運(yùn)算,要求投影矩陣必須是w友好投影矩陣(w-friendly projection matrix,也稱作兼容矩陣),即投影矩陣第三行第四列的元素必須是1,以使w坐標(biāo)與世界空間中頂點(diǎn)的z坐標(biāo)相當(dāng)。如果投影變換矩陣第三行第四列的元素不是1,必須將所有的矩陣元素除以投影矩陣第三行第四列元素的值,將投影矩陣變換為w友好投影矩陣。如果沒有提供一個(gè)w友好投影矩陣,基于深度的霧化效果和深度緩沖就不能正確實(shí)現(xiàn)。

下面給出的就是從一個(gè)非w友好投影矩陣到w友好投影矩陣的轉(zhuǎn)換。

Direct3D在進(jìn)行以w為基礎(chǔ)的深度計(jì)算中,需要使用w友好投影矩陣,因此即使應(yīng)用程序不需要進(jìn)行頂點(diǎn)坐標(biāo)變換,也需要設(shè)置一個(gè)w友好投影矩陣。通過實(shí)用庫(kù)函數(shù)D3DXMatrixPerspectiveFovLH()得到的投影矩陣通常都是w友好投影矩陣,所以通常不需要關(guān)心這個(gè)問題。


posted on 2008-05-02 13:02 lovedday 閱讀(2733) 評(píng)論(0)  編輯 收藏 引用


只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


公告

導(dǎo)航

統(tǒng)計(jì)

常用鏈接

隨筆分類(178)

3D游戲編程相關(guān)鏈接

搜索

最新評(píng)論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            欧美一区二区三区四区高清| 欧美wwwwww| 小嫩嫩精品导航| 亚洲国产另类精品专区| av成人免费在线| 一区二区在线不卡| 国产精品日韩在线播放| 欧美性淫爽ww久久久久无| 午夜国产不卡在线观看视频| 日韩午夜在线播放| 美女主播精品视频一二三四| 亚洲欧美中文日韩在线| 亚洲欧美日韩专区| 亚洲欧美视频| 久久精品论坛| 欧美成人免费播放| 亚洲国产成人在线播放| 久久亚洲视频| 久久久久久久欧美精品| 亚洲黄色成人网| 亚洲乱亚洲高清| 久久成人羞羞网站| 欧美一区二区三区电影在线观看| 久久xxxx精品视频| 日韩视频在线免费| 性高湖久久久久久久久| 蜜臀99久久精品久久久久久软件| 国产精品久久二区二区| 激情欧美一区| 久久香蕉国产线看观看av| 一本久道久久综合婷婷鲸鱼| 一区免费视频| 国产有码在线一区二区视频| 亚洲美女黄网| 欧美成人一区二区三区在线观看| 亚洲欧洲一区| 欧美在线3区| 国产精品福利在线观看网址| 国产精品第一页第二页第三页| 国产麻豆精品theporn| 亚洲国产精选| 久久婷婷国产综合精品青草| 亚洲视频精品在线| 久久天天躁狠狠躁夜夜av| 国产麻豆日韩欧美久久| 亚洲欧洲在线播放| 久久gogo国模裸体人体| 一区二区三区不卡视频在线观看 | 亚洲人成网站色ww在线| 一二美女精品欧洲| 久久精品九九| 最新69国产成人精品视频免费| 亚洲一区二区在线播放| 亚洲精品乱码久久久久久久久 | 午夜伦理片一区| 亚洲一区二区三区四区中文| 亚洲免费一区二区| 麻豆freexxxx性91精品| 欧美国产综合视频| 亚洲精品裸体| 国产一区自拍视频| 亚洲国产一区二区三区a毛片| 亚洲日韩欧美一区二区在线| 午夜欧美不卡精品aaaaa| 欧美激情中文字幕一区二区| 欧美激情视频一区二区三区在线播放| 亚洲电影第1页| 亚洲综合第一页| 久久日韩精品| 国产精品成人v| 最新日韩在线| 久久精品欧美日韩精品| 亚洲高清在线视频| 欧美中文字幕在线| 国产农村妇女毛片精品久久麻豆 | 狠狠色狠狠色综合| 亚洲一区图片| 一区二区免费在线观看| 欧美激情综合色| 99精品久久| 亚洲国产成人精品久久| 久久国产一区| 国语对白精品一区二区| 亚欧成人精品| 一区二区三区回区在观看免费视频| 欧美高清视频一区| 精品成人国产| 麻豆成人小视频| 久久精品国产在热久久| 国产毛片精品视频| 久久亚洲综合色| 久久久久国产精品厨房| 激情欧美一区二区| 亚洲成色777777在线观看影院| 久久精品成人一区二区三区| 国语自产精品视频在线看抢先版结局 | 亚洲第一精品福利| 欧美视频在线一区| 久久视频精品在线| 在线观看国产精品网站| 久久久久网址| 欧美视频你懂的| 欧美专区福利在线| 久久精品噜噜噜成人av农村| 99视频超级精品| 午夜欧美大片免费观看| 亚洲激情视频在线播放| 亚洲电影在线免费观看| 国产嫩草影院久久久久 | 牛牛国产精品| aa级大片欧美三级| 久久精品夜色噜噜亚洲a∨| 91久久中文| 亚洲午夜在线观看| 一区在线视频观看| 亚洲视频日本| 亚洲久久成人| 欧美黄色免费网站| 欧美护士18xxxxhd| 国产一区自拍视频| 欧美一区二区三区喷汁尤物| 国产一区日韩欧美| 亚洲一区激情| 亚洲愉拍自拍另类高清精品| 免费欧美电影| 欧美激情一区二区三区全黄| 最新国产拍偷乱拍精品| 久久爱www.| 久久九九精品| 国产亚洲人成网站在线观看| 亚洲欧美三级伦理| 久久久九九九九| 国产欧美亚洲视频| 午夜久久黄色| 亚洲电影欧美电影有声小说| 韩日在线一区| 欧美国产精品中文字幕| 亚洲欧洲一区二区三区在线观看| 亚洲国产日本| 欧美日韩三区| 午夜精品久久| 欧美高清在线播放| 99ri日韩精品视频| 欧美日韩三级在线| 亚洲一区二区成人在线观看| 久久免费黄色| 免费欧美电影| 日韩视频一区二区三区在线播放| 亚洲综合导航| 欧美国产欧美亚洲国产日韩mv天天看完整| 在线观看亚洲视频啊啊啊啊| 鲁大师成人一区二区三区 | 一本久久a久久免费精品不卡| 亚洲在线观看免费视频| 国产一区二区三区高清在线观看| 美女国产精品| 一卡二卡3卡四卡高清精品视频| 久久er99精品| 一区二区三区欧美日韩| 国产日本精品| 欧美精品一区二区三区很污很色的| 亚洲视频免费观看| 亚洲欧美日韩第一区| 国内综合精品午夜久久资源| 欧美国产日韩在线| 久久女同精品一区二区| 在线视频日本亚洲性| 最新日韩精品| 久久尤物电影视频在线观看| 亚洲精品日韩一| 亚洲国产精品一区| 国产日韩精品在线播放| 国产精品视频免费观看| 欧美日韩国产精品一卡| 久久午夜精品一区二区| 久久精品久久综合| 一本色道婷婷久久欧美| 一区二区三区 在线观看视| 欧美激情一区二区三区在线视频观看 | 国产一区二区三区四区| 欧美高清视频一区| 久久激情视频| 亚洲香蕉网站| 亚洲永久免费| 午夜精品影院在线观看| 小处雏高清一区二区三区| 免费在线观看日韩欧美| 欧美揉bbbbb揉bbbbb| 久久亚洲精品网站| 老司机午夜精品| 欧美成年人在线观看| 欧美电影在线观看完整版| 欧美激情久久久久| 欧美婷婷六月丁香综合色| 国产精品乱码一区二三区小蝌蚪| 国产日韩欧美二区| 国产精品老女人精品视频| 国产日韩在线一区| 99re亚洲国产精品| 午夜在线a亚洲v天堂网2018|