bool Frustum::CheckRectangle(FLOAT xCenter, FLOAT yCenter, FLOAT zCenter, FLOAT xSize, FLOAT ySize, FLOAT zSize) { // Check if any of the 6 planes of the rectangle are inside the view frustum. for (INT i = 0; i < 6; i++) { if (XMPlaneDotCoord(XMLoadFloat4(&m_planes[i]), XMLoadFloat4(&XMFLOAT4((xCenter - xSize), (yCenter - ySize), (zCenter - zSize), 1.0f))).vector4_f32[0] >= 0.0f) { continue; } if (XMPlaneDotCoord(XMLoadFloat4(&m_planes[i]), XMLoadFloat4(&XMFLOAT4((xCenter + xSize), (yCenter - ySize), (zCenter - zSize), 1.0f))).vector4_f32[0] >= 0.0f) { continue; } if (XMPlaneDotCoord(XMLoadFloat4(&m_planes[i]), XMLoadFloat4(&XMFLOAT4((xCenter - xSize), (yCenter + ySize), (zCenter - zSize), 1.0f))).vector4_f32[0] >= 0.0f) { continue; } if (XMPlaneDotCoord(XMLoadFloat4(&m_planes[i]), XMLoadFloat4(&XMFLOAT4((xCenter - xSize), (yCenter - ySize), (zCenter + zSize), 1.0f))).vector4_f32[0] >= 0.0f) { continue; } if (XMPlaneDotCoord(XMLoadFloat4(&m_planes[i]), XMLoadFloat4(&XMFLOAT4((xCenter + xSize), (yCenter + ySize), (zCenter - zSize), 1.0f))).vector4_f32[0] >= 0.0f) { continue; } if (XMPlaneDotCoord(XMLoadFloat4(&m_planes[i]), XMLoadFloat4(&XMFLOAT4((xCenter + xSize), (yCenter - ySize), (zCenter + zSize), 1.0f))).vector4_f32[0] >= 0.0f) { continue; } if (XMPlaneDotCoord(XMLoadFloat4(&m_planes[i]), XMLoadFloat4(&XMFLOAT4((xCenter - xSize), (yCenter + ySize), (zCenter + zSize), 1.0f))).vector4_f32[0] >= 0.0f) { continue; } if (XMPlaneDotCoord(XMLoadFloat4(&m_planes[i]), XMLoadFloat4(&XMFLOAT4((xCenter + xSize), (yCenter + ySize), (zCenter + zSize), 1.0f))).vector4_f32[0] >= 0.0f) { continue; } return false; } return true; }
bool Frustum::CheckCube(FLOAT xCenter, FLOAT yCenter, FLOAT zCenter, FLOAT radius) { // Check if any one point of the cube is in the view frustum. for (INT i = 0; i < 6; i++) { if (XMPlaneDotCoord(XMLoadFloat4(&m_planes[i]), XMLoadFloat4(&XMFLOAT4((xCenter - radius), (yCenter - radius), (zCenter - radius), 1.0f))).vector4_f32[0] >= 0.0f) { continue; } if (XMPlaneDotCoord(XMLoadFloat4(&m_planes[i]), XMLoadFloat4(&XMFLOAT4((xCenter + radius), (yCenter - radius), (zCenter - radius), 1.0f))).vector4_f32[0] >= 0.0f) { continue; } if (XMPlaneDotCoord(XMLoadFloat4(&m_planes[i]), XMLoadFloat4(&XMFLOAT4((xCenter - radius), (yCenter + radius), (zCenter - radius), 1.0f))).vector4_f32[0] >= 0.0f) { continue; } if (XMPlaneDotCoord(XMLoadFloat4(&m_planes[i]), XMLoadFloat4(&XMFLOAT4((xCenter + radius), (yCenter + radius), (zCenter - radius), 1.0f))).vector4_f32[0] >= 0.0f) { continue; } if (XMPlaneDotCoord(XMLoadFloat4(&m_planes[i]), XMLoadFloat4(&XMFLOAT4((xCenter - radius), (yCenter - radius), (zCenter + radius), 1.0f))).vector4_f32[0] >= 0.0f) { continue; } if (XMPlaneDotCoord(XMLoadFloat4(&m_planes[i]), XMLoadFloat4(&XMFLOAT4((xCenter + radius), (yCenter - radius), (zCenter + radius), 1.0f))).vector4_f32[0] >= 0.0f) { continue; } if (XMPlaneDotCoord(XMLoadFloat4(&m_planes[i]), XMLoadFloat4(&XMFLOAT4((xCenter - radius), (yCenter + radius), (zCenter + radius), 1.0f))).vector4_f32[0] >= 0.0f) { continue; } if (XMPlaneDotCoord(XMLoadFloat4(&m_planes[i]), XMLoadFloat4(&XMFLOAT4((xCenter + radius), (yCenter + radius), (zCenter + radius), 1.0f))).vector4_f32[0] >= 0.0f) { continue; } return false; } return true; }
bool Frustum::CheckSphere(FLOAT xCenter, FLOAT yCenter, FLOAT zCenter, FLOAT radius) { // Check if the radius of the sphere is inside the view frustum. for (INT i = 0; i < 6; i++) { if (XMPlaneDotCoord(XMLoadFloat4(&m_planes[i]), XMLoadFloat4(&XMFLOAT4(xCenter, yCenter, zCenter, 1.0f))).vector4_f32[0] < -radius) { return false; } } return true; }
bool FrustumClass::CheckPoint(float x, float y, float z) { for (int i = 0; i < 6; i++) { XMVECTOR vector = XMPlaneDotCoord(XMLoadFloat4(&m_planes[i]), XMLoadFloat4(&XMFLOAT4(x, y, z, 1.0f))); if (vector.m128_f32[0] < 0.0f) { return false; } } return true; }
bool Frustum::CheckPoint(const XMFLOAT3& point) { XMVECTOR p = XMLoadFloat3(&point); for(short i=0; i<6; i++) { if(XMVectorGetX( XMPlaneDotCoord(XMLoadFloat4(&m_planesNorm[i]), p) ) < 0.0f) { return false; } } return true; }
bool FrustumClass::CheckRectangle(float xCenter, float yCenter, float zCenter, float xSize, float ySize, float zSize) { for (int i = 0; i < 6; i++) { if (XMPlaneDotCoord(XMLoadFloat4(&m_planes[i]), XMLoadFloat4(&XMFLOAT4((xCenter - xSize), (yCenter - ySize), (zCenter - zSize), 1.0f))).m128_f32[0] >= 0.0f) { continue; } if (XMPlaneDotCoord(XMLoadFloat4(&m_planes[i]), XMLoadFloat4(&XMFLOAT4((xCenter + xSize), (yCenter - ySize), (zCenter - zSize), 1.0f))).m128_f32[0] >= 0.0f) { continue; } if (XMPlaneDotCoord(XMLoadFloat4(&m_planes[i]), XMLoadFloat4(&XMFLOAT4((xCenter - xSize), (yCenter + ySize), (zCenter - zSize), 1.0f))).m128_f32[0] >= 0.0f) { continue; } if (XMPlaneDotCoord(XMLoadFloat4(&m_planes[i]), XMLoadFloat4(&XMFLOAT4((xCenter - xSize), (yCenter - ySize), (zCenter + zSize), 1.0f))).m128_f32[0] >= 0.0f) { continue; } if (XMPlaneDotCoord(XMLoadFloat4(&m_planes[i]), XMLoadFloat4(&XMFLOAT4((xCenter + xSize), (yCenter + ySize), (zCenter - zSize), 1.0f))).m128_f32[0] >= 0.0f) { continue; } if (XMPlaneDotCoord(XMLoadFloat4(&m_planes[i]), XMLoadFloat4(&XMFLOAT4((xCenter + xSize), (yCenter - ySize), (zCenter + zSize), 1.0f))).m128_f32[0] >= 0.0f) { continue; } if (XMPlaneDotCoord(XMLoadFloat4(&m_planes[i]), XMLoadFloat4(&XMFLOAT4((xCenter - xSize), (yCenter + ySize), (zCenter + zSize), 1.0f))).m128_f32[0] >= 0.0f) { continue; } if (XMPlaneDotCoord(XMLoadFloat4(&m_planes[i]), XMLoadFloat4(&XMFLOAT4((xCenter + xSize), (yCenter + ySize), (zCenter + zSize), 1.0f))).m128_f32[0] >= 0.0f) { continue; } return false; } return true; }
bool Frustum::CheckSphere(const XMFLOAT3& center, float radius) { int i; XMVECTOR c = XMLoadFloat3(¢er); for(i=0; i<6; i++) { if(XMVectorGetX( XMPlaneDotCoord(XMLoadFloat4(&m_planesNorm[i]), c) ) < -radius) { return false; } } return true; }
bool bounding_sphere::intersects(const frustum & frustum) const { auto & planes = frustum.get_planes(); for (const plane & plane : planes) { const point & dot = XMPlaneDotCoord(plane, origin); if (dot[axis::x] <= -get_radius()) return false; } return true; }
bool Frustum::CheckPoint(FLOAT x, FLOAT y, FLOAT z) { // Check if the point is inside all six planes of the view frustum. for (INT i = 0; i < 6; i++) { XMVECTOR vector = XMPlaneDotCoord(XMLoadFloat4(&m_planes[i]), XMLoadFloat4(&XMFLOAT4(x, y, z, 1.0f))); if (vector.vector4_f32[0] < 0.0f) { return false; } } return true; }
bool Frustum::CheckSphere(float xCenter, float yCenter, float zCenter, float radius) { int i; XMFLOAT4 res; // Check if the radius of the sphere is inside the view frustum. for (i = 0; i < 6; i++) { XMStoreFloat4(&res, XMPlaneDotCoord(m_planes[i], XMVectorSet(xCenter, yCenter, zCenter, 1))); if (res.w < -radius) { return false; } } return true; }
//--------------------------------------------------------------------- Frustum::LocateSide Frustum::testContainState(FXMVECTOR plane, const Util::AABBPtr & aabb) { Util::real dist = XMVectorGetX(XMPlaneDotCoord(plane, aabb->getCenterPoint())); XMVECTOR halfSize = aabb->getHalfSize(); Util::real maxAbsDist = abs(XMVectorGetX(plane) * XMVectorGetX(halfSize)) + abs(XMVectorGetY(plane) * XMVectorGetY(halfSize)) + abs(XMVectorGetZ(plane) * XMVectorGetZ(halfSize)); if (dist < -maxAbsDist) return LS_NEGATIVE; if (dist > + maxAbsDist) return LS_POSITIVE; return LS_INTERSECT; }
// Tests a frustum for intersection with a sphere uint32 TestFrustumSphere(const Frustum& frustum, const BSphere& sphere, bool ignoreNearZ) { XMVECTOR sphereCenter = XMLoadFloat3(&sphere.Center); uint32 result = 1; uint32 numPlanes = ignoreNearZ ? 5 : 6; for (uint32 i = 0; i < numPlanes; i++) { float distance = XMVectorGetX(XMPlaneDotCoord(frustum.Planes[i], sphereCenter)); if (distance < -sphere.Radius) return 0; else if (distance < sphere.Radius) result = 1; } return result; }
bool Frustum::CheckPoint(float x, float y, float z) { int i; // Check if the point is inside all six planes of the view frustum. for (i = 0; i<6; i++) { XMFLOAT4 res; XMStoreFloat4(&res, XMPlaneDotCoord(m_planes[i], XMVectorSet(x, y, z, 1))); if (res.w < 0.0f) { return false; } } return true; }
int Frustum::CheckBox(XMFLOAT3 corners[8]){ int iTotalIn = 0; for(int p = 0; p < 6; ++p) { int iInCount = 8; int iPtIn = 1; for(int i = 0; i < 8; ++i) { if(XMVectorGetX( XMPlaneDotCoord(XMLoadFloat4(&m_planesNorm[p]), XMLoadFloat3(&corners[i])) ) < 0.0f) { iPtIn=0; --iInCount; } } if(iInCount == 0) return(false); iTotalIn += iPtIn; } if(iTotalIn == 6) return(BOX_FRUSTUM_INSIDE); return(BOX_FRUSTUM_INTERSECTS); }
bool Frustum::IntersectBB(XMVECTOR* boundingBox) { XMVECTOR* p1; XMVECTOR* p2; bool pointInside = false; int insideAll = 0; for (int i = 0; i < 8; i++) { //Loop through all the corner points for bounding box for (int j = 0; j < 6; j++) { //Check if any point is inside all frustum planes if (XMVectorGetX(XMPlaneDotCoord(this->planes[i], boundingBox[j])) + XMVectorGetW(this->planes[i]) >= 0.0f) { insideAll++; } /*if (XMVectorGetX(XMVector3Dot(this->planes[i], boundingBox[j])) + XMVectorGetW(this->planes[i]) >= 0.0f) { insideAll++; }*/ } if (insideAll == 6) { //If any point is inside frustum -> return intersection return true; } insideAll = 0; } return false; }
bool Frustum::CheckCube(float xCenter, float yCenter, float zCenter, float radius) { int i; // Check if any one point of the cube is in the view frustum. for (i = 0; i<6; i++) { XMFLOAT4 res; XMStoreFloat4(&res, XMPlaneDotCoord(m_planes[i], XMVectorSet((xCenter - radius), (yCenter - radius), (zCenter - radius), 1))); if (res.w >= 0.0f) { continue; } XMStoreFloat4(&res, XMPlaneDotCoord(m_planes[i], XMVectorSet((xCenter + radius), (yCenter - radius), (zCenter - radius), 1))); if (res.w >= 0.0f) { continue; } XMStoreFloat4(&res, XMPlaneDotCoord(m_planes[i], XMVectorSet((xCenter - radius), (yCenter + radius), (zCenter - radius), 1))); if (res.w >= 0.0f) { continue; } XMStoreFloat4(&res, XMPlaneDotCoord(m_planes[i], XMVectorSet((xCenter + radius), (yCenter + radius), (zCenter - radius), 1))); if (res.w >= 0.0f) { continue; } XMStoreFloat4(&res, XMPlaneDotCoord(m_planes[i], XMVectorSet((xCenter - radius), (yCenter - radius), (zCenter + radius), 1))); if (res.w >= 0.0f) { continue; } XMStoreFloat4(&res, XMPlaneDotCoord(m_planes[i], XMVectorSet((xCenter + radius), (yCenter - radius), (zCenter + radius), 1))); if (res.w >= 0.0f) { continue; } XMStoreFloat4(&res, XMPlaneDotCoord(m_planes[i], XMVectorSet((xCenter - radius), (yCenter + radius), (zCenter + radius), 1))); if (res.w >= 0.0f) { continue; } XMStoreFloat4(&res, XMPlaneDotCoord(m_planes[i], XMVectorSet((xCenter + radius), (yCenter + radius), (zCenter + radius), 1))); if (res.w >= 0.0f) { continue; } return false; } return true; }
float Plane::distance(const Vector3& v) const { return XMVectorGetX(XMPlaneDotCoord(*this, v)); }