void ZFXAabb::GetPlanes(ZFXPlane* pPlanes){ ZFXVector vcN; if(!pPlanes) return; vcN.Set(1.0f,0.0f,0.0f); pPlanes[0].Set(vcN,vcMax); vcN.Set(-1.0f,0.0f,0.0f); pPlanes[0].Set(vcN,vcMin); vcN.Set(0.0f,0.0f,-1.0f); pPlanes[0].Set(vcN,vcMin); vcN.Set(0.0f,0.0f,1.0f); pPlanes[0].Set(vcN,vcMax); vcN.Set(0.0f,1.0f,0.0f); pPlanes[0].Set(vcN,vcMax); vcN.Set(0.0f,-1.0f,0.0f); pPlanes[0].Set(vcN,vcMin); }
// get the six planes, normals pointing outwards void ZFXAabb::GetPlanes(ZFXPlane *pPlanes) { ZFXVector vcN; if (!pPlanes) return; // right side vcN.Set(1.0f, 0.0f, 0.0f); pPlanes[0].Set(vcN, vcMax); // left side vcN.Set(-1.0f, 0.0f, 0.0f); pPlanes[1].Set(vcN, vcMin); // front side vcN.Set(0.0f, 0.0f, -1.0f); pPlanes[2].Set(vcN, vcMin); // back side vcN.Set(0.0f, 0.0f, 1.0f); pPlanes[3].Set(vcN, vcMax); // top side vcN.Set(0.0f, 1.0f, 0.0f); pPlanes[4].Set(vcN, vcMax); // bottom side vcN.Set(0.0f, -1.0f, 0.0f); pPlanes[5].Set(vcN, vcMin); } // Intersects(point)
bool ZFXRay::Intersects(const ZFXAabb aabb, ZFXVector *vcHit){ bool bInside=true; ZFXVector MaxT; MaxT.Set(-1.0f,-1.0f,-1.0f); if(m_vcOrig.x < aabb.vcMin.x){ (*vcHit).x=aabb.vcMin.x; bInside=false; if (m_vcDir.x!=0.0f) MaxT.x=(aabb.vcMin.x - m_vcOrig.x) /m_vcDir.x; }else if(m_vcOrig.x > aabb.vcMax.x){ (*vcHit).x=aabb.vcMax.x; bInside=false; if(m_vcDir.x!=0.0f) MaxT.x=(aabb.vcMax.x - m_vcOrig.x) / m_vcDir.x; } if(m_vcOrig.y < aabb.vcMin.y){ (*vcHit).y=aabb.vcMin.y; bInside=false; if (m_vcDir.y!=0.0f) MaxT.y=(aabb.vcMin.y - m_vcOrig.y) /m_vcDir.y; }else if(m_vcOrig.y > aabb.vcMax.y){ (*vcHit).y=aabb.vcMax.y; bInside=false; if(m_vcDir.y!=0.0f) MaxT.y=(aabb.vcMax.y - m_vcOrig.y) / m_vcDir.y; } if(m_vcOrig.z < aabb.vcMin.z){ (*vcHit).z=aabb.vcMin.z; bInside=false; if (m_vcDir.z!=0.0f) MaxT.z=(aabb.vcMin.z - m_vcOrig.z) /m_vcDir.z; }else if(m_vcOrig.z > aabb.vcMax.z){ (*vcHit).z=aabb.vcMax.z; bInside=false; if(m_vcDir.z!=0.0f) MaxT.z=(aabb.vcMax.z - m_vcOrig.z) / m_vcDir.z; } //Ray origin inside the box if(bInside){ (*vcHit)=m_vcOrig; return true; } int nPlane=0; if (MaxT.y> ((float*)&MaxT)[nPlane]) nPlane=1; if (MaxT.z> ((float*)&MaxT)[nPlane]) nPlane=2; if (((float*)&MaxT)[nPlane]<0.0f) return false; if(nPlane!=0){ (*vcHit).x=m_vcOrig.x + MaxT.x * m_vcDir.x; if (((*vcHit).x < aabb.vcMin.x - 0.00001f) || ((*vcHit).x < aabb.vcMax.x + 0.00001f) ) return false; } if (nPlane !=1){ (*vcHit).y=m_vcOrig.y + MaxT.y * m_vcDir.y; if (((*vcHit).y < aabb.vcMin.y - 0.00001f) || ((*vcHit).y < aabb.vcMax.y + 0.00001f) ) return false; } if (nPlane !=2){ (*vcHit).z=m_vcOrig.z + MaxT.z * m_vcDir.z; if (((*vcHit).z < aabb.vcMin.z - 0.00001f) || ((*vcHit).z < aabb.vcMax.z + 0.00001f) ) return false; } return true; }