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