Sign in to follow this  

camera frustum disoriented

This topic is 3293 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

I have a calculated frustum points. Set the world transformation with the camera's inverse view matrix and this is the result: On the left, the camera is looking straight at the building. Apparently when i switch view and look at the rendered camera frustum, its disoriented and its position is off(right image). Not sure where I went wrong.

Share this post


Link to post
Share on other sites
I think there is some error perhaps happened:

1. Camera's position is looks bad(From your image^^).
D3DXMATRIX mtxViewStraightInverse;
D3DXMatrixInverse(&mtxViewStraightInverse, NULL, &mtxViewStraight);
D3DXVECTOR3 camPostion = D3DXVECTOR3(mtxViewStraightInverse._41, mtxViewStraightInverse._42, mtxViewStraightInverse._43);

2. The projection matrix is not match.

3. If the frustum is calculated with the viewport paramater, but the viewport is not match.

Share this post


Link to post
Share on other sites
Hi Armterla

Thanks for trying to help.

But I think the camera's position should be fine, as well as the projection and view matrix.

I use the code from DXUT - FirstPersonCamera.

Also the frustum points are calculated using the view and projection matrix.

Thanks.

Share this post


Link to post
Share on other sites
Hi Guys

Thanks for trying to help. This code is from the PSSM tutorial, which in turn is converted from the frustum culling OpenGL tutorial:

http://www.lighthouse3d.com/opengl/viewfrustum/


D3DXVECTOR3 vZ = m_vLookAt - m_vEye;
D3DXVec3Normalize( &vZ, &vZ );

D3DXVECTOR3 vX;
D3DXVec3Cross( &vX, GetWorldUp(), &vZ );
D3DXVec3Normalize( &vX, &vX );

D3DXVECTOR3 vY;
D3DXVec3Cross( &vY, &vZ, &vX );

float fNearPlaneHeight = tanf(m_fFOV * 0.5f) * m_fNearPlane;
float fNearPlaneWidth = fNearPlaneHeight * m_fAspect;

float fFarPlaneHeight = tanf(m_fFOV * 0.5f) * m_fFarPlane;
float fFarPlaneWidth = fFarPlaneHeight * m_fAspect;

D3DXVECTOR3 vNearPlaneCenter = m_vEye + vZ * m_fNearPlane;
D3DXVECTOR3 vFarPlaneCenter = m_vEye + vZ * m_fFarPlane;

// Near
mFrustumPoints[0]=D3DXVECTOR3(vNearPlaneCenter - vX*fNearPlaneWidth - vY*fNearPlaneHeight); // LR
mFrustumPoints[1]=D3DXVECTOR3(vNearPlaneCenter - vX*fNearPlaneWidth + vY*fNearPlaneHeight); // UR
mFrustumPoints[2]=D3DXVECTOR3(vNearPlaneCenter + vX*fNearPlaneWidth + vY*fNearPlaneHeight); // UL
mFrustumPoints[3]=D3DXVECTOR3(vNearPlaneCenter + vX*fNearPlaneWidth - vY*fNearPlaneHeight); // LL

// Far
mFrustumPoints[4]=D3DXVECTOR3(vFarPlaneCenter - vX*fFarPlaneWidth - vY*fFarPlaneHeight); // LR
mFrustumPoints[5]=D3DXVECTOR3(vFarPlaneCenter - vX*fFarPlaneWidth + vY*fFarPlaneHeight); // UR
mFrustumPoints[6]=D3DXVECTOR3(vFarPlaneCenter + vX*fFarPlaneWidth + vY*fFarPlaneHeight); // UL
mFrustumPoints[7]=D3DXVECTOR3(vFarPlaneCenter + vX*fFarPlaneWidth - vY*fFarPlaneHeight); // LL



I think I may just need to rotate the frustum but I want to understand if there anything that went wrong.

Thanks!

Share this post


Link to post
Share on other sites
Probably the easiest way to do it is to calculate the frustum coordinate in view-space every time your projection parameters change, and then transform them by the camera's world matrix every time its position or orientation changes. Like this:


void OnProjectionChanged()
{
float fNearPlaneHeight = tanf(m_fFOV * 0.5f) * m_fNearPlane;
float fNearPlaneWidth = fNearPlaneHeight * m_fAspect;

float fFarPlaneHeight = tanf(m_fFOV * 0.5f) * m_fFarPlane;
float fFarPlaneWidth = fFarPlaneHeight * m_fAspect;

D3DXVECTOR3 vNearPlaneCenter = D3DXVECTOR3(0, 0, fNearPlane);
D3DXVECTOR3 vFarPlaneCenter = D3DXVECTOR3(0, 0, fFarPlane);

// Near
mFrustumPointsVS[0]=D3DXVECTOR3(vNearPlaneCenter - fNearPlaneWidth - fNearPlaneHeight); // LR
mFrustumPointsVS[1]=D3DXVECTOR3(vNearPlaneCenter - fNearPlaneWidth + fNearPlaneHeight); // UR
mFrustumPointsVS[2]=D3DXVECTOR3(vNearPlaneCenter + vfNearPlaneWidth + fNearPlaneHeight); // UL
mFrustumPointsVS[3]=D3DXVECTOR3(vNearPlaneCenter + fNearPlaneWidth - fNearPlaneHeight); // LL

// Far
mFrustumPointsVS[4]=D3DXVECTOR3(vFarPlaneCenter - fFarPlaneWidth - fFarPlaneHeight); // LR
mFrustumPointsVS[5]=D3DXVECTOR3(vFarPlaneCenter - fFarPlaneWidth + fFarPlaneHeight); // UR
mFrustumPointsVS[6]=D3DXVECTOR3(vFarPlaneCenter + fFarPlaneWidth + fFarPlaneHeight); // UL
mFrustumPointsVS[7]=D3DXVECTOR3(vFarPlaneCenter + fFarPlaneWidth - fFarPlaneHeight); // LL
}

void OnCameraMoveOrRotate()
{
// Camera's world matrix is inverse of the view matrix
D3DXMATRIXA16 cameraWorldMatrix;
D3DXMatrixInverse(&cameraWorldMatrix, NULL, &mViewMatrix);

// Transform frustum coordinates to world space
D3DXVec3TransformCoordArray(mFrustumPointsWS, sizeof(D3DXVECTOR3), mFrustumPointsVS, sizeof(D3DXVECTOR3), &cameraWorldMatrix, 8);
}

Share this post


Link to post
Share on other sites
Quote:
Original post by mickeyren
The calculated frustum points are already in word space, so I shouldn't be doing any transformation at all and just set the world transformation to identity.


Right, but it looked like you weren't properly accounting for rotation in your code (which is why I suggested an alternative).

Share this post


Link to post
Share on other sites

This topic is 3293 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