Jump to content
  • Advertisement
Sign in to follow this  
amadeus12

about math in implementing frustum culling

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

this code is from introduction to DX11 by Frank D Luna.
I kind of understand the theory of this.
first get frustum coordinates in view space.
get model's world matrix and view matrix.
get inverse matrix to find out frustum's coordinates in model's local.

my question is, why do I only need X component of scale matrix?
what if the object got stretched by z,y axis?
 


    for(UINT i = 0; i < mInstancedData.size(); ++i)
          {
             XMMATRIX W = XMLoadFloat4x4(&mInstancedData.World);
             XMMATRIX invWorld = XMMatrixInverse(&XMMatrixDeterminant(W), W);
         // View space to the object's local space.
         XMMATRIX toLocal = XMMatrixMultiply(invView, invWorld);
      
         // Decompose the matrix into its individual parts.
         XMVECTOR scale;
         XMVECTOR rotQuat;
         XMVECTOR translation;
         XMMatrixDecompose(&scale, &rotQuat, &translation, toLocal);

         // Transform the camera frustum from view space to the object's local space.
         XNA::Frustum localspaceFrustum;
         //TransformFrustum(&localspaceFrustum, &mCamFrustum, XMVectorGetX(scale), rotQuat, translation);
         XNA::TransformFrustum(&localspaceFrustum, &mCamFrustum, XMVectorGetX(scale), rotQuat, translation);
         
         // Perform the box/frustum intersection test in local space.
         if(XNA::IntersectAxisAlignedBoxFrustum(&mSkullBox, &localspaceFrustum) != 0)
         {
            // Write the instance data to dynamic VB of the visible objects.
            dataView[mVisibleObjectCount++] = mInstancedData;
         }
      }

      md3dImmediateContext->Unmap(mInstancedBuffer, 0);
   }
 

Share this post


Link to post
Share on other sites
Advertisement

It looks like TransformFrustum only takes a single value as a scale, so even though the matrix supports full XYZ 3d scaling, this just breaks it down to 1D scaling, so the X scale is used for all XYZ values.

Oddly, if you look inside the TransformFrustum call, it actually creates a full XYZ 3D vector from the single scale value, then uses that with its internal transformations.  It seems like the function should just take a XYZ scale to begin with, instead of converting from/to.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!