# 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.

## 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 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 on other sites

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.

1. 1
2. 2
Rutin
19
3. 3
khawk
18
4. 4
5. 5
A4L
11

• 9
• 12
• 16
• 26
• 10
• ### Forum Statistics

• Total Topics
633769
• Total Posts
3013755
×