Sign in to follow this  

D3DXMatrixPerspectiveOffCenterLH and D3DXMatrixPerspectiveFovLH

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
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              0
0 2*zn/h 0 0
0 0 zf/(zf-zn) 1
0 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              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
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:

D3DXMatrixPerspectiveFovLH

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


Quote:

D3DXMatrixPerspectiveOffCenterLH

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


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.

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this