Can someone doing frustum culling in Direct3D 8/9 please give a little code?
Hey there. I''ve been trying to get this working for a while. I posted on this subject once, but I didn''t get the correct response. A few people responded, and they offered some help, but it wasn''t what I needed. Anyhow, I am trying to do frustum culling in Direct3D 8.
I do not perform any transformations on my world matrix (D3DTS_WORLD). I am transforming the view matrix, using the eye, look-at, and up vectors. I do not know how to correctly extract the six planes for the view frustum. Well, I know how to SETUP the planes, but I do not know which matrices to multiply before I do the extraction.
Would it be:
World · View
View · Projection
or
World · View · Projection
Any answers or a code for setting up a frustum would be greatly appreciated.
Thanks everyone.
http://www.flipcode.com/articles/article_frustumculling.shtml should answer any most questions. If there is something specific not answered in there (or either of it''s associated linked articles), then ask away... I''m sure someone will be able to help when we know exactly where your trouble lies.
Here's what i do
just look at the cull example in the sdk
[edited by - kapru on March 22, 2004 10:44:27 PM]
D3DXMATRIX matView; D3DXMatrixLookAtLH( &matView, &Camera.from,&Camera.to,&Camera.up); d3ddevice->SetTransform( D3DTS_VIEW, &matView ); D3DXMATRIX matProj; D3DXMatrixPerspectiveFovLH(&matProj, 1.0f, 1.0f, 0.01f, 1000.0f); d3ddevice->SetTransform(D3DTS_PROJECTION, &matProj); //calculate the vectors and planes for the frustrim D3DXMATRIX mat; D3DXMatrixMultiply( &mat, &matView, &matProj ); D3DXMatrixInverse( &mat, NULL, &mat ); vecFrustum[0] = D3DXVECTOR3(-1.0f, -1.0f, 0.0f); // xyz vecFrustum[1] = D3DXVECTOR3( 1.0f, -1.0f, 0.0f); // Xyz vecFrustum[2] = D3DXVECTOR3(-1.0f, 1.0f, 0.0f); // xYz vecFrustum[3] = D3DXVECTOR3( 1.0f, 1.0f, 0.0f); // XYz vecFrustum[4] = D3DXVECTOR3(-1.0f, -1.0f, 1.0f); // xyZ vecFrustum[5] = D3DXVECTOR3( 1.0f, -1.0f, 1.0f); // XyZ vecFrustum[6] = D3DXVECTOR3(-1.0f, 1.0f, 1.0f); // xYZ vecFrustum[7] = D3DXVECTOR3( 1.0f, 1.0f, 1.0f); // XYZ for( INT i = 0; i < 8; i++ ) { D3DXVec3TransformCoord( &vecFrustum[i], &vecFrustum[i], &mat ); } D3DXPlaneFromPoints( &planeFrustum[0], &vecFrustum[0], &vecFrustum[1], &vecFrustum[2] ); // Near D3DXPlaneFromPoints( &planeFrustum[1], &vecFrustum[6], &vecFrustum[7], &vecFrustum[5] ); // Far D3DXPlaneFromPoints( &planeFrustum[2], &vecFrustum[2], &vecFrustum[6], &vecFrustum[4] ); // Left D3DXPlaneFromPoints( &planeFrustum[3], &vecFrustum[7], &vecFrustum[3], &vecFrustum[5] ); // Right D3DXPlaneFromPoints( &planeFrustum[4], &vecFrustum[2], &vecFrustum[3], &vecFrustum[6] ); // Top D3DXPlaneFromPoints( &planeFrustum[5], &vecFrustum[1], &vecFrustum[0], &vecFrustum[4] ); // Bottom //transform the frustum plane into world space for(i=0;i<6;i++) { D3DXPlaneTransform(&WorldplaneFrustum[i],&planeFrustum[i],&mat); }
just look at the cull example in the sdk
[edited by - kapru on March 22, 2004 10:44:27 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement