D3DXMatrixPerspectiveOffCenterLH and D3DXMatrixPerspectiveFovLH

Started by
5 comments, last by akira32 16 years, 3 months ago
How to calculate the parameters of D3DXMatrixPerspectiveOffCenterLH and let its Projection Matrix is the same as D3DXMatrixPerspectiveFovLH(&mProj, 0.5f, 1.0f, NEARPLANE, FARPLANE); D3DXVECTOR3 m_LightPos=D3DXVECTOR3(-5.0f, 5.0f, -2.0f); D3DXMATRIX mView, mProj; D3DXVECTOR3 vLookatPt = D3DXVECTOR3(0.0f, 0.0f, 0.0f); D3DXVECTOR3 vUpVec = D3DXVECTOR3(0.0f, 1.0f, 0.0f); D3DXMatrixLookAtLH(&mView, &m_LightPos, &vLookatPt, &vUpVec); D3DXMatrixPerspectiveFovLH(&mProj, 0.5f, 1.0f, NEARPLANE, FARPLANE); //D3DXMatrixPerspectiveOffCenterLH(&mProj,0, 1, -1, 0, 1, 100);
akira32 編程之家 Yahoohttp://tw.myblog.yahoo.com/akira32-akira32
Advertisement
From the docs for D3DXMatrixPerspectiveLH:
Quote:
This function uses the following formula to compute the returned matrix.
2*zn/w  0       0              00       2*zn/h  0              00       0       zf/(zf-zn)     10       0       zn*zf/(zn-zf)  0


From the docs for D3DXMatrixPerspectiveOffCenterLH:
Quote:
This function uses the following formula to compute the returned matrix.
2*zn/(r-l)   0            0              00            2*zn/(t-b)   0              0(l+r)/(l-r)  (t+b)/(b-t)  zf/(zf-zn)     10            0            zn*zf/(zn-zf)  0
So you can see that r-l = w, t-b = h, (l+r)/(l-r) = 0, and (t+b)/(b-t) = 0.

So, the equivalent matrix would be where l = -w/2, r = w/2, t = h/2, b = -h/2.

However, the functions do semi-different things, why does it matter what you need to know what the equivalent parameters are?
Thank you,Steve! I am implementing the Adpative Shadow Maps for my research.
akira32 編程之家 Yahoohttp://tw.myblog.yahoo.com/akira32-akira32
Hi Steve! The variables of w and h are the clipping window's size?
akira32 編程之家 Yahoohttp://tw.myblog.yahoo.com/akira32-akira32
Quote:Original post by akira32
Hi Steve! The variables of w and h are the clipping window's size?
Don't you have a copy of the Documentation?
Oh! Steve, sorry! I got it.
I means the relation of D3DXMatrixPerspectiveFovLH and D3DXMatrixPerspectiveOffCenterLH.(not D3DXMatrixPerspectiveLH)
I want to calculate the parameters(l,r,b,t) of D3DXMatrixPerspectiveOffCenterLH and let its projection matrix is equivalent to the projection matrix of D3DXMatrixPerspectiveFovLH.
akira32 編程之家 Yahoohttp://tw.myblog.yahoo.com/akira32-akira32
Quote:
D3DXMatrixPerspectiveFovLH
xScale     0          0               00        yScale       0               00          0       zf/(zf-zn)         10          0       -zn*zf/(zf-zn)     0where:yScale = cot(fovY/2)xScale = yScale / aspect ratio


Quote:
D3DXMatrixPerspectiveOffCenterLH
2*zn/(r-l)   0            0              00            2*zn/(t-b)   0              0(l+r)/(l-r)  (t+b)/(b-t)  zf/(zf-zn)     10            0            zn*zf/(zn-zf)  0


xScale=2*zn/(r-l)
ysclae=2*zn/(t-b)
l+r=0
t+b=0

So, the equivalent matrix would be where
r=zn/xScale
l=-zn/xScale
t=zn/yScale
b=-zn/yScale

Thank you, Steve! You give me a lot of help and idea.
akira32 編程之家 Yahoohttp://tw.myblog.yahoo.com/akira32-akira32

This topic is closed to new replies.

Advertisement