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

天行健 君子當自強而不息

頂點坐標變換(5)

投影變換

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

Pproj = Pview * Mproj

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

 

1、正交投影

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

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

g_device->SetTransform(D3DTS_PROJECTION, &mat_proj);

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

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

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

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

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

透視投影矩陣的作用是將一個取景截頭體轉換成一個立方體。因為截頭體的近端比遠端小,所以靠近攝像機的對象將被放大,而對象距離攝像機越遠,其成像越小,這就是場景的透視原理。透視變換把一個取景截頭體轉換成一個新的坐標空間,注意,該截頭體變成了一個立方體,同時,原點從場景的右上角移動到了立方體的中心。在透視變換中,x軸和z軸方向的極限都是-1和1,z軸方向對于前平面的極限是0,對后平面的極限是1。

另外,D3DX還提供了下列函數供程序員創建透視投影變換矩陣:

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友好投影矩陣

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

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

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


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


只有注冊用戶登錄后才能發表評論。
網站導航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


公告

導航

統計

常用鏈接

隨筆分類(178)

3D游戲編程相關鏈接

搜索

最新評論

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <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>
            一区精品久久| 日韩天堂在线视频| 久久亚洲精品一区二区| 欧美中文字幕在线播放| 一色屋精品亚洲香蕉网站| 久久五月婷婷丁香社区| 裸体一区二区| 一本色道久久综合一区 | 狠狠色噜噜狠狠狠狠色吗综合| 欧美与黑人午夜性猛交久久久| 新67194成人永久网站| 国产亚洲综合在线| 亚洲电影天堂av| 欧美日韩亚洲成人| 亚洲综合欧美| 久久深夜福利免费观看| 在线视频欧美日韩| 亚洲摸下面视频| 亚洲国产成人在线| 亚洲视频自拍偷拍| 在线看无码的免费网站| 99国产精品久久久久久久| 国产伦精品一区二区三区在线观看| 久久天天躁夜夜躁狠狠躁2022| 美女主播精品视频一二三四| 亚洲欧美日韩精品在线| 久久久噜噜噜久久| 亚洲欧美国产毛片在线| 久久综合色影院| 午夜精品视频在线| 欧美黑人在线观看| 久久先锋资源| 国产精品高清一区二区三区| 欧美成人在线影院| 国产精品你懂的| 亚洲国产综合在线| 在线观看国产一区二区| 亚洲视频欧美在线| 日韩视频免费观看高清在线视频| 性欧美1819性猛交| 亚洲综合首页| 欧美日韩国产首页| 欧美成人一品| 狠狠色综合色区| 亚洲欧美日本国产有色| 在线综合亚洲| 欧美精品国产一区| 欧美国产日韩一二三区| 很黄很黄激情成人| 亚洲专区在线| 亚洲欧美综合另类中字| 欧美日韩国产小视频| 欧美高清视频一二三区| 极品日韩av| 久久精品视频在线免费观看| 久久国产精彩视频| 国产日韩精品在线观看| 亚洲欧美国产另类| 欧美在线免费观看亚洲| 国产精品网站视频| 亚洲一区二区三区四区五区午夜 | 亚洲精品一区二区三区婷婷月| 久久国产精品久久久久久| 久久成人羞羞网站| 国产一区二区三区日韩欧美| 亚洲欧美卡通另类91av| 久久av资源网| 国内精品久久久久影院 日本资源| 午夜日韩激情| 久久久国产精品亚洲一区 | 国产精品国产三级国产专播品爱网 | 国产日韩欧美在线观看| 一区二区三区欧美日韩| 亚洲综合成人婷婷小说| 欧美丝袜一区二区三区| 亚洲视频免费观看| 午夜国产精品影院在线观看| 国产精品午夜电影| 欧美在线视频免费观看| 久热精品视频在线| 免费一级欧美片在线观看| 亚洲第一中文字幕在线观看| 美女999久久久精品视频| 亚洲高清一区二区三区| 午夜亚洲影视| 国产亚洲欧美一级| 巨乳诱惑日韩免费av| 亚洲激情网站免费观看| 亚洲视频一区在线| 国产日韩av高清| 久久日韩粉嫩一区二区三区| 亚洲黄色成人久久久| 午夜国产精品影院在线观看| 韩国女主播一区| 欧美伦理在线观看| 欧美一区二区免费| 亚洲电影观看| 久久国产66| 日韩亚洲欧美成人一区| 国产欧美日韩精品a在线观看| 久久久久久久久久久一区| 亚洲日本成人女熟在线观看| 久久成人人人人精品欧| 亚洲免费观看| 国产亚洲综合性久久久影院| 欧美精品一线| 久久精品在这里| 中文亚洲欧美| 亚洲国产精品视频| 久久精品免费观看| 亚洲亚洲精品三区日韩精品在线视频| 国产日韩专区在线| 欧美视频免费在线| 久热精品视频在线观看一区| 一区二区国产日产| 亚洲第一在线综合网站| 久久国产日韩| 亚洲综合丁香| 亚洲伦理网站| 亚洲东热激情| 国内精品99| 国产日产亚洲精品| 欧美性大战久久久久久久蜜臀| 麻豆国产va免费精品高清在线| 午夜精品福利电影| 一区二区日韩伦理片| 亚洲日本免费电影| 亚洲第一网站免费视频| 美国十次成人| 久久久另类综合| 欧美一区二区在线免费观看| 亚洲视频欧美在线| 99这里有精品| 日韩视频免费观看高清在线视频 | 日韩亚洲欧美精品| 在线视频国内自拍亚洲视频| 国产日韩欧美视频| 国产私拍一区| 国产亚洲视频在线观看| 国产午夜精品一区二区三区欧美 | 影音先锋一区| 黄色成人在线网站| 激情成人亚洲| 在线电影一区| 亚洲国产日韩一级| 亚洲国产精品久久久久婷婷老年| 国产综合色精品一区二区三区| 国产精品影片在线观看| 国产精品亚洲网站| 国产日韩欧美在线视频观看| 国产午夜亚洲精品不卡| 国产自产2019最新不卡| 国产亚洲精品成人av久久ww| 国产一区二区三区在线观看视频 | 日韩亚洲不卡在线| 一片黄亚洲嫩模| 亚洲一区在线直播| 午夜一区二区三区不卡视频| 午夜精品区一区二区三| 久久精品人人做人人爽| 久久免费观看视频| 美日韩在线观看| 欧美日韩精品欧美日韩精品 | 欧美国产日本韩| 欧美日韩一区二区高清| 国产欧美日韩激情| 亚洲第一免费播放区| 亚洲美女啪啪| 香蕉久久a毛片| 男女精品网站| 在线视频亚洲欧美| 久久久久国产精品一区| 欧美激情日韩| 国产欧美日韩亚州综合| 亚洲电影第1页| 亚洲一区二区成人| 久久综合亚洲社区| 91久久在线观看| 香蕉成人久久| 欧美精品福利在线| 狠狠色综合一区二区| 一区电影在线观看| 久久免费国产精品1| 亚洲毛片在线看| 久久久亚洲精品一区二区三区 | 久久国产精品久久w女人spa| 美女精品在线| 国产午夜精品全部视频播放| 99精品视频一区| 另类尿喷潮videofree| 亚洲精品一区二区三区婷婷月| 亚洲天堂第二页| 欧美高清在线一区二区| 国产网站欧美日韩免费精品在线观看 | 夜夜嗨av一区二区三区免费区| 亚洲免费在线观看| 欧美韩国日本综合| 在线播放中文一区| 久久成人精品电影| 一本色道久久综合亚洲精品小说|