//---------------------------------------------------------------------------- void PartitionMesh::ClassifyVertices ( const std::vector<APoint>& clipVertices, const HPlane& plane) { const int numVertices = (int)clipVertices.size(); for (int i = 0; i < numVertices; ++i) { mSignedDistances[i] = plane.DistanceTo(clipVertices[i]); } }
//---------------------------------------------------------------------------- int Bound::WhichSide (const HPlane& plane) const { float signedDistance = plane.DistanceTo(mCenter); if (signedDistance <= -mRadius) { return -1; } if (signedDistance >= mRadius) { return +1; } return 0; }
//---------------------------------------------------------------------------- int Culler::WhichSide (const HPlane& plane) const { // The plane is N*(X-C) = 0 where the * indicates dot product. The signed // distance from the camera location E to the plane is N*(E-C). float NdEmC = plane.DistanceTo(mCamera->GetPosition()); AVector normal = plane.GetNormal(); float NdD = normal.Dot(mCamera->GetDVector()); float NdU = normal.Dot(mCamera->GetUVector()); float NdR = normal.Dot(mCamera->GetRVector()); float FdN = mFrustum[Camera::VF_DMAX]/mFrustum[Camera::VF_DMIN]; int positive = 0, negative = 0; float sgnDist; // Check near-plane vertices. float PDMin = mFrustum[Camera::VF_DMIN]*NdD; float NUMin = mFrustum[Camera::VF_UMIN]*NdU; float NUMax = mFrustum[Camera::VF_UMAX]*NdU; float NRMin = mFrustum[Camera::VF_RMIN]*NdR; float NRMax = mFrustum[Camera::VF_RMAX]*NdR; // V = E + dmin*D + umin*U + rmin*R // N*(V-C) = N*(E-C) + dmin*(N*D) + umin*(N*U) + rmin*(N*R) sgnDist = NdEmC + PDMin + NUMin + NRMin; if (sgnDist > 0.0f) { positive++; } else if (sgnDist < 0.0f) { negative++; } // V = E + dmin*D + umin*U + rmax*R // N*(V-C) = N*(E-C) + dmin*(N*D) + umin*(N*U) + rmax*(N*R) sgnDist = NdEmC + PDMin + NUMin + NRMax; if (sgnDist > 0.0f) { positive++; } else if (sgnDist < 0.0f) { negative++; } // V = E + dmin*D + umax*U + rmin*R // N*(V-C) = N*(E-C) + dmin*(N*D) + umax*(N*U) + rmin*(N*R) sgnDist = NdEmC + PDMin + NUMax + NRMin; if (sgnDist > 0.0f) { positive++; } else if (sgnDist < 0.0f) { negative++; } // V = E + dmin*D + umax*U + rmax*R // N*(V-C) = N*(E-C) + dmin*(N*D) + umax*(N*U) + rmax*(N*R) sgnDist = NdEmC + PDMin + NUMax + NRMax; if (sgnDist > 0.0f) { positive++; } else if (sgnDist < 0.0f) { negative++; } // check far-plane vertices (s = dmax/dmin) float PDMax = mFrustum[Camera::VF_DMAX]*NdD; float FUMin = FdN*NUMin; float FUMax = FdN*NUMax; float FRMin = FdN*NRMin; float FRMax = FdN*NRMax; // V = E + dmax*D + umin*U + rmin*R // N*(V-C) = N*(E-C) + dmax*(N*D) + s*umin*(N*U) + s*rmin*(N*R) sgnDist = NdEmC + PDMax + FUMin + FRMin; if (sgnDist > 0.0f) { positive++; } else if (sgnDist < 0.0f) { negative++; } // V = E + dmax*D + umin*U + rmax*R // N*(V-C) = N*(E-C) + dmax*(N*D) + s*umin*(N*U) + s*rmax*(N*R) sgnDist = NdEmC + PDMax + FUMin + FRMax; if (sgnDist > 0.0f) { positive++; } else if (sgnDist < 0.0f) { negative++; } // V = E + dmax*D + umax*U + rmin*R // N*(V-C) = N*(E-C) + dmax*(N*D) + s*umax*(N*U) + s*rmin*(N*R) sgnDist = NdEmC + PDMax + FUMax + FRMin; if (sgnDist > 0.0f) { positive++; } else if (sgnDist < 0.0f) { negative++; } // V = E + dmax*D + umax*U + rmax*R // N*(V-C) = N*(E-C) + dmax*(N*D) + s*umax*(N*U) + s*rmax*(N*R) sgnDist = NdEmC + PDMax + FUMax + FRMax; if (sgnDist > 0.0f) { positive++; } else if (sgnDist < 0.0f) { negative++; } if (positive > 0) { if (negative > 0) { // Frustum straddles the plane. return 0; } // Frustum is fully on the positive side. return +1; } // Frustum is fully on the negative side. return -1; }