此代碼來自Frank D Luna向DX11的介紹。 我有點理解這個理論。 首先在視圖空間中獲得平截頭體座標。獲取模型的世界矩陣和視圖矩陣。獲取逆矩陣來找出模型局部的平截頭體座標。關於實施錐體剔除
我的問題是,爲什麼我只需要X分量矩陣? 如果物體被Y,Z軸拉伸會怎樣?
for(UINT i = 0; i < mInstancedData.size(); ++i)
{
XMMATRIX W = XMLoadFloat4x4(&mInstancedData[i].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[i];
}
}
md3dImmediateContext->Unmap(mInstancedBuffer, 0);
}
3年前我在大學裏學過這本書,從我的計算機圖形學課程開始,我的導師告訴我們,你只需要X位置,因爲它隱含地假定對象的比例是(1,1,1)以便保持正確的網格比例,顯然這並不總是成立,我建議不要完全忽略其他飛機。 – Alex