Advertisement

about math in implementing frustum culling

Started by July 13, 2017 05:38 AM
1 comment, last by xycsoscyx 7 years, 6 months ago

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);
   }
 

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.

This topic is closed to new replies.

Advertisement