D3DXMatrixPerspectiveOffCenterLH and D3DXMatrixPerspectiveFovLH
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);
From the docs for D3DXMatrixPerspectiveLH:
From the docs for D3DXMatrixPerspectiveOffCenterLH:
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?
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:So you can see that r-l = w, t-b = h, (l+r)/(l-r) = 0, and (t+b)/(b-t) = 0.
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, 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?
Quote:Original post by akira32Don't you have a copy of the Documentation?
Hi Steve! The variables of w and h are the clipping window's size?
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.
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.
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement