Sources/CryGame C++/Solution1/CryGame/XArea.cpp
//////////////////////////////////////////////////////////////////////
//calculate distance to area. player is inside of the area 

calculate distance to area. player is inside of the area
calculate distance to area . player is inside of the area
float	CXArea::CalculateFade( const Vec3d& pos3D )
{
	a2DPoint pos = CXArea::a2DPoint(pos3D);
	float fadeCoeff;
	switch(m_AreaType)
	{
	case	 ATP_SHAPE:
					fadeCoeff = CalcDistToPoint( pos );		
					break;
	case	 ATP_SPHERE:
		{
					if (m_Proximity<=0.0f)
					{
						fadeCoeff=1.0f;
						break;
					}
					Vec3d Delta=pos3D-m_Center;
					fadeCoeff=(m_Radius-Delta.Length())/m_Proximity;
					if (fadeCoeff>1.0f)
						fadeCoeff=1.0f;
					break;
		}
	case	 ATP_BOX:
		{
					if (m_Proximity<=0.0f)
					{
						fadeCoeff=1.0f;
						break;
					}
					Vec3d p3D=m_InvMatrix.TransformPointOLD(pos3D);
					Vec3d MinDelta=p3D-m_Min;
					Vec3d MaxDelta=m_Max-p3D;
					Vec3d EdgeDist=(m_Max-m_Min)/2.0f;
					if ((!EdgeDist.x) ||
							(!EdgeDist.y) ||
							(!EdgeDist.z))
					{
						fadeCoeff=1.0f;
						break;
					}
					float fFadeScale=m_Proximity/100.0f;
					EdgeDist*=fFadeScale;
					float fMinFade=MinDelta.x/EdgeDist.x;					
					for (int k=0;k<3;k++)
					{
						float fFade1=MinDelta[k]/EdgeDist[k];
						float fFade2=MaxDelta[k]/EdgeDist[k];
						fMinFade=min(fMinFade,min(fFade1,fFade2));
					} 
					fadeCoeff=fMinFade;
					if (fadeCoeff>1.0f)
						fadeCoeff=1.0f;
					break;
		}
	}
	return fadeCoeff;
}
float CXArea :: CalculateFade ( const Vec3d & pos3D ) { a2DPoint pos = CXArea :: a2DPoint ( pos3D ) ; float fadeCoeff ; switch ( m_AreaType ) { case ATP_SHAPE : fadeCoeff = CalcDistToPoint ( pos ) ; break ; case ATP_SPHERE : { if ( m_Proximity <= 0.0f ) { fadeCoeff = 1.0f ; break ; } Vec3d Delta = pos3D - m_Center ; fadeCoeff = ( m_Radius - Delta . Length ( ) ) / m_Proximity ; if ( fadeCoeff > 1.0f ) fadeCoeff = 1.0f ; break ; } case ATP_BOX : { if ( m_Proximity <= 0.0f ) { fadeCoeff = 1.0f ; break ; } Vec3d p3D = m_InvMatrix . TransformPointOLD ( pos3D ) ; Vec3d MinDelta = p3D - m_Min ; Vec3d MaxDelta = m_Max - p3D ; Vec3d EdgeDist = ( m_Max - m_Min ) / 2.0f ; if ( ( ! EdgeDist . x ) || ( ! EdgeDist . y ) || ( ! EdgeDist . z ) ) { fadeCoeff = 1.0f ; break ; } float fFadeScale = m_Proximity / 100.0f ; EdgeDist *= fFadeScale ; float fMinFade = MinDelta . x / EdgeDist . x ; for ( int k = 0 ; k < 3 ; k ++ ) { float fFade1 = MinDelta [ k ] / EdgeDist [ k ] ; float fFade2 = MaxDelta [ k ] / EdgeDist [ k ] ; fMinFade = min ( fMinFade , min ( fFade1 , fFade2 ) ) ; } fadeCoeff = fMinFade ; if ( fadeCoeff > 1.0f ) fadeCoeff = 1.0f ; break ; } } return fadeCoeff ; }
calculate distance to area.
calculate distance to area .
//float fFade=MinDelta.x/EdgeDist.x;
 //k
