Sources/CryGame C++/Solution1/CryGame/XArea.cpp
//////////////////////////////////////////////////////////////////////
// check if the point is within the area
// first BBox check, then count number of intersections for horizontal ray from point and area segments
// if the number is odd - the point is inside

check if the point is within the area
first BBox check, then count number of intersections for horizontal ray from point and area segments
if the number is odd - the point is inside
check if the point is within the area first BBox check then count number of intersections for horizontal ray from point and area segments if the number is odd - the point is inside
bool	CXArea::IsPointWithin(const Vec3d& point3d) const
{
	if( m_AreaType == ATP_SPHERE )
	{
		Vec3d	sPnt = point3d - m_Center;
		if( GetLengthSquared(sPnt) < m_Radius2 )
			return true;
		return false;
	}
	if( m_AreaType == ATP_BOX )
	{
		Vec3d p3d=m_InvMatrix.TransformPointOLD(point3d);
		if (	(p3d.x<m_Min.x) ||
					(p3d.y<m_Min.y) ||
					(p3d.z<m_Min.z) ||
					(p3d.x>m_Max.x) ||
					(p3d.y>m_Max.y) ||
					(p3d.z>m_Max.z))
						return false;
		return true;
	}
	if( m_AreaType == ATP_SHAPE )
	{
		if( m_VSize>0.0f )
			if( point3d.z<m_VOrigin || point3d.z>m_VOrigin + m_VSize )
				return false;
		a2DPoint	*point = (CXArea::a2DPoint*)(&point3d);
		if( m_BBox.PointOutBBox2D( *point ) )
			return false;
		int	cntr=0;	
		for(unsigned int sIdx=0; sIdx<m_vpSegments.size(); sIdx++)
		{
			if(m_vpSegments[sIdx]->isHorizontal)
				continue;
			if(!m_vpSegments[sIdx]->bbox.PointOutBBox2DVertical( *point ))
				if( m_vpSegments[sIdx]->IntersectsXPosVertical( *point ) )
					cntr++;
			else
				if(!m_vpSegments[sIdx]->bbox.PointOutBBox2DVertical( *point ))
					if( m_vpSegments[sIdx]->IntersectsXPos( *point ) )
						cntr++;
		}
		return (cntr & 0x1);
	}
	assert(0); 
	return false; 
}
bool CXArea :: IsPointWithin ( const Vec3d & point3d ) const { if ( m_AreaType == ATP_SPHERE ) { Vec3d sPnt = point3d - m_Center ; if ( GetLengthSquared ( sPnt ) < m_Radius2 ) return true ; return false ; } if ( m_AreaType == ATP_BOX ) { Vec3d p3d = m_InvMatrix . TransformPointOLD ( point3d ) ; if ( ( p3d . x < m_Min . x ) || ( p3d . y < m_Min . y ) || ( p3d . z < m_Min . z ) || ( p3d . x > m_Max . x ) || ( p3d . y > m_Max . y ) || ( p3d . z > m_Max . z ) ) return false ; return true ; } if ( m_AreaType == ATP_SHAPE ) { if ( m_VSize > 0.0f ) if ( point3d . z < m_VOrigin || point3d . z > m_VOrigin + m_VSize ) return false ; a2DPoint * point = ( CXArea :: a2DPoint * ) ( & point3d ) ; if ( m_BBox . PointOutBBox2D ( * point ) ) return false ; int cntr = 0 ; for ( unsigned int sIdx = 0 ; sIdx < m_vpSegments . size ( ) ; sIdx ++ ) { if ( m_vpSegments [ sIdx ] -> isHorizontal ) continue ; if ( ! m_vpSegments [ sIdx ] -> bbox . PointOutBBox2DVertical ( * point ) ) if ( m_vpSegments [ sIdx ] -> IntersectsXPosVertical ( * point ) ) cntr ++ ; else if ( ! m_vpSegments [ sIdx ] -> bbox . PointOutBBox2DVertical ( * point ) ) if ( m_vpSegments [ sIdx ] -> IntersectsXPos ( * point ) ) cntr ++ ; } return ( cntr & 0x1 ) ; } assert ( 0 ) ; return false ; }
check if the point is within the area
first BBox check, then count number of intersections for horizontal ray from point and area segments
if the number is odd - the point is inside
check if the point is within the area first BBox check then count number of intersections for horizontal ray from point and area segments if the number is odd - the point is inside
// to keep the compiler happy and give more robustness to the code with the assert...
 // can never reach this part
 // default behavior
