D3DXMatrixPerspectiveOffCenterLH and D3DXMatrixPerspectiveFovLH

This topic is 3987 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

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);

Share on other sites
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?

Share on other sites
Thank you,Steve! I am implementing the Adpative Shadow Maps for my research.

Share on other sites
Hi Steve! The variables of w and h are the clipping window's size?

Share on other sites
Quote:
 Original post by akira32Hi Steve! The variables of w and h are the clipping window's size?
Don't you have a copy of the Documentation?

Share on other sites
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.

Share on other sites
Quote:
 D3DXMatrixPerspectiveFovLHxScale 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:
 D3DXMatrixPerspectiveOffCenterLH2*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.

1. 1
2. 2
3. 3
Rutin
23
4. 4
5. 5
khawk
14

• 9
• 11
• 11
• 23
• 12
• Forum Statistics

• Total Topics
633653
• Total Posts
3013166
×