錐台関連のコードを実装していますが、表示されているオブジェクトが多い場合でも、カリングテストでは何も返されません。私の数学的サポートライブラリは平面サポートなどを提供していないため、このコードの多くはゼロから作成されており、利用可能なテストはほとんどありません。障害点について何か提案があれば、アドバイスしてください。幸い、それほど多くはないので、Little'Wall'o'コードは次のようになります。
class Plane {
public:
Plane() {
r0 = Math::Vector(0,0,0);
normal = Math::Vector(0,1,0);
}
Plane(Math::Vector p1, Math::Vector p2, Math::Vector p3) {
r0 = p1;
normal = Math::Cross(p2 - p1, p3 - p1);
}
Math::Vector r0;
Math::Vector normal;
};
class Frustum {
public:
Frustum(
const std::array<Math::Vector, 8>& points
)
{
planes[0] = Plane(points[0], points[1], points[2]);
planes[1] = Plane(points[4], points[5], points[6]);
planes[2] = Plane(points[0], points[1], points[4]);
planes[3] = Plane(points[2], points[3], points[6]);
planes[4] = Plane(points[0], points[2], points[4]);
planes[5] = Plane(points[1], points[3], points[5]);
}
Plane planes[6];
};
// http://www.cescg.org/CESCG-2002/DSykoraJJelinek/index.html
bool Intersects(Math::AABB lhs, const Frustum& rhs) const {
for(int i = 0; i < 6; i++) {
Math::Vector pvertex = lhs.TopRightFurthest;
Math::Vector nvertex = lhs.BottomLeftClosest;
if (rhs.planes[i].normal.x <= -0.0f) {
std::swap(pvertex.x, nvertex.x);
}
if (rhs.planes[i].normal.y <= -0.0f) {
std::swap(pvertex.y, nvertex.y);
}
if (rhs.planes[i].normal.z <= -0.0f) {
std::swap(pvertex.z, nvertex.z);
}
if (Math::Dot(nvertex - rhs.planes[i].r0, rhs.planes[i].normal) > 0.0f) {
return false;
}
}
return true;
}
また、左手座標系を使用しているため、外積の結果を反転したことにも注意してください(Cross関数内)。
編集:正確に述べたように、私は頂点インデックスを見逃しました。これらは、各ビットが1つの軸のコーナーを示すようにインデックスが付けられます。つまり、0は右、上、後ろの順になります。
また、質問の質が一般的に低いことをお詫びしますが、他に何を追加すればよいかわかりません。コンパイラの警告やエラーはなく、デバッガで読み取る可能性のあるものを理解するのに十分な理解がありません。これは通常のフィールドの範囲外です。そして、コードはとの比較的明白な実装でコンパイルされVector
ますAABB
。