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

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

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

投影變換

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

Pproj = Pview * Mproj

下面分別介紹兩種基本的投影變換:正交投影和透視投影,以及它們在Direct3D中的實現(xiàn)。

 

1、正交投影

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

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

g_device->SetTransform(D3DTS_PROJECTION, &mat_proj);

下面來看看正交投影矩陣的生成。對于正交投影來說,它的取景范圍是一個長方體,只有在這個長方體中的景物才會被繪制出來。

Direct3D擴展實用庫提供了函數(shù)D3DXMatrixOrthoLH(),用于創(chuàng)建一個正交投影矩陣,函數(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、透視投影

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

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

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

透視投影矩陣的作用是將一個取景截頭體轉(zhuǎn)換成一個立方體。因為截頭體的近端比遠(yuǎn)端小,所以靠近攝像機的對象將被放大,而對象距離攝像機越遠(yuǎn),其成像越小,這就是場景的透視原理。透視變換把一個取景截頭體轉(zhuǎn)換成一個新的坐標(biāo)空間,注意,該截頭體變成了一個立方體,同時,原點從場景的右上角移動到了立方體的中心。在透視變換中,x軸和z軸方向的極限都是-1和1,z軸方向?qū)τ谇捌矫娴臉O限是0,對后平面的極限是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)過頂點坐標(biāo)變換后,每個頂點坐標(biāo)將具有4個元素(x, y, z, w)。Direct3D使用這個w坐標(biāo)在深度緩沖區(qū)和霧化效果中執(zhí)行一些深度相關(guān)的運算。為了能夠使用這個w坐標(biāo)進(jìn)行深度相關(guān)運算,要求投影矩陣必須是w友好投影矩陣(w-friendly projection matrix,也稱作兼容矩陣),即投影矩陣第三行第四列的元素必須是1,以使w坐標(biāo)與世界空間中頂點的z坐標(biāo)相當(dāng)。如果投影變換矩陣第三行第四列的元素不是1,必須將所有的矩陣元素除以投影矩陣第三行第四列元素的值,將投影矩陣變換為w友好投影矩陣。如果沒有提供一個w友好投影矩陣,基于深度的霧化效果和深度緩沖就不能正確實現(xiàn)。

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

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


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


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


公告

導(dǎo)航

統(tǒng)計

常用鏈接

隨筆分類(178)

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

搜索

最新評論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            亚洲国产成人高清精品| 宅男精品视频| 久久综合久久综合久久| 欧美一区二区三区视频在线 | 狂野欧美激情性xxxx欧美| 欧美亚洲专区| 亚洲大胆在线| 日韩午夜电影| 国产美女一区二区| 鲁鲁狠狠狠7777一区二区| 蜜臀99久久精品久久久久久软件| 亚洲精品视频免费在线观看| 99综合视频| 国产欧美va欧美va香蕉在| 免费成人黄色片| 欧美区亚洲区| 久久精品卡一| 欧美精品在线免费播放| 亚洲欧美精品一区| 久久女同精品一区二区| 亚洲一二区在线| 久久久久久久久久久久久久一区| 亚洲人成网站777色婷婷| 一本色道久久加勒比精品| 99www免费人成精品| 国产啪精品视频| 亚洲国产欧美一区| 国产精品福利网| 免费日韩成人| 国产女精品视频网站免费| 欧美成人国产va精品日本一级| 欧美涩涩视频| 欧美黑人在线播放| 国产麻豆91精品| 亚洲欧洲一区二区在线观看| 国产日本欧美一区二区三区| 亚洲区在线播放| 黑人巨大精品欧美一区二区| 欧美一区二区免费| 欧美va亚洲va日韩∨a综合色| 欧美一区二区三区另类| 欧美激情视频在线免费观看 欧美视频免费一| 亚洲欧美国产高清| 欧美成黄导航| 欧美v国产在线一区二区三区| 国产精品入口66mio| 最新精品在线| 怡红院精品视频| 先锋影音国产精品| 午夜视频在线观看一区二区三区| 欧美电影免费网站| 嫩草影视亚洲| 激情久久综艺| 亚洲精品在线观看视频| 亚洲国产电影| 久久视频这里只有精品| 久久久久综合网| 国产亚洲成av人片在线观看桃| 9色精品在线| 亚洲午夜免费视频| 欧美美女日韩| 亚洲美女在线看| 一区二区三区国产| 欧美日韩一区二区三区四区在线观看| 欧美激情日韩| 日韩网站免费观看| 欧美精品久久一区二区| 亚洲娇小video精品| 亚洲人成在线观看| 欧美大片免费观看| 亚洲精品免费网站| 99视频精品全国免费| 欧美日韩国产bt| 99精品国产在热久久婷婷| 亚洲一区二区三区国产| 欧美四级剧情无删版影片| 99国产精品99久久久久久粉嫩| 亚洲视频图片小说| 国产精品一二三| 久久精品国产99| 欧美第十八页| 一区二区三区四区蜜桃| 国产精品久久久久免费a∨| 亚洲一区免费视频| 久久久久国产精品一区三寸| 尤物yw午夜国产精品视频明星| 蜜桃久久av| 99精品久久久| 久久美女性网| 亚洲福利视频一区| 欧美日韩亚洲一区二区三区在线| 亚洲视频 欧洲视频| 久久久蜜桃精品| 亚洲蜜桃精久久久久久久| 国产精品v亚洲精品v日韩精品| 午夜精品久久久久影视| 免费人成网站在线观看欧美高清| 亚洲美女在线看| 国产欧美精品日韩精品| 欧美 日韩 国产精品免费观看| 亚洲美女性视频| 久久久水蜜桃av免费网站| 亚洲精品美女91| 国产精品一区久久久久| 巨胸喷奶水www久久久免费动漫| 亚洲美女诱惑| 久久综合一区二区三区| 亚洲一级二级在线| 在线欧美日韩| 国产精品女主播一区二区三区| 久久天天躁狠狠躁夜夜爽蜜月 | 亚洲视频一二三| 国内揄拍国内精品久久| 欧美日韩国产123| 久久精品最新地址| 亚洲一区二区三区影院| 亚洲高清视频在线观看| 久久99在线观看| 亚洲午夜在线观看| 亚洲黄一区二区三区| 国产欧美一区二区精品性| 欧美日韩黄色一区二区| 巨乳诱惑日韩免费av| 欧美一区二视频在线免费观看| 99精品久久久| 亚洲精品乱码久久久久久久久| 美女尤物久久精品| 久久久www成人免费精品| 亚洲综合色激情五月| 日韩亚洲欧美综合| 亚洲经典视频在线观看| 今天的高清视频免费播放成人 | 国产视频一区免费看| 欧美私人网站| 欧美久久视频| 欧美激情视频在线免费观看 欧美视频免费一| 亚洲欧美国产一区二区三区| 一区二区三区偷拍| 亚洲欧洲一二三| 亚洲国产婷婷| 亚洲国产裸拍裸体视频在线观看乱了中文 | 欧美日韩国产精品一卡| 欧美高清视频在线| 老鸭窝亚洲一区二区三区| 久久久国产精彩视频美女艺术照福利 | 亚洲少妇自拍| 亚洲尤物在线视频观看| 亚洲自拍电影| 午夜伦理片一区| 欧美专区在线播放| 久久久久久久精| 另类亚洲自拍| 亚洲国产精品久久精品怡红院| 欧美激情区在线播放| 亚洲黄色在线| 99精品国产在热久久| 亚洲无线视频| 欧美中文字幕不卡| 久久午夜视频| 欧美精品综合| 国产精品久久久久久久久果冻传媒 | 欧美手机在线视频| 国产美女精品| 影音先锋欧美精品| 亚洲日韩中文字幕在线播放| 99精品99| 午夜精品久久久99热福利| 久久成人资源| 免费短视频成人日韩| 亚洲精品国产无天堂网2021| 一本久久精品一区二区| 午夜精品免费| 欧美成人中文| 国产精品乱码妇女bbbb| 极品尤物久久久av免费看| 日韩写真视频在线观看| 欧美亚洲免费在线| 欧美激情91| 亚洲欧美一区二区三区极速播放| 久久精品国产999大香线蕉| 欧美电影在线| 国产亚洲a∨片在线观看| 亚洲久色影视| 久久精品日韩一区二区三区| 亚洲国产另类久久精品| 午夜亚洲福利| 欧美精品一区二| 极品av少妇一区二区| 亚洲图片欧洲图片av| 六月婷婷久久| 亚洲一区二区三区乱码aⅴ蜜桃女 亚洲一区二区三区乱码aⅴ | 亚洲三级影院| 久久婷婷丁香| 一区二区久久久久| 欧美 日韩 国产 一区| 国产日韩欧美91| 亚洲综合99| 亚洲精品四区| 久久综合久久综合这里只有精品| 国产精品国产三级国产aⅴ浪潮|