Sources/CryGame C++/Solution1/CryGame/XVehicleProxyHeli.cpp
//////////////////////////////////////////////////////////////////////
//	desiredAltitude - alr above terrain
//	absMinAlt - never go below

alr above terrain
absMinAlt - never go below
alr above terrain absMinAlt - never go below
float CXVehicleProxy::UpdateAltitude( const Vec3d& moveDir, float desiredAltitude, float absMinAlt, 
																		 bool useObjects )
{
	Vec3d curPos = m_pEntity->GetPos();
	float	allowedObjectDist = 7.0f;
	float	objectsDist=-1000, fwdObjectDist=-1000;
	float	minPossibleAlt=0;	
	Vec3d	fwdPos = m_pEntity->GetPos() + moveDir*5.0f;
	float	terrainAltitude = -1000;
	if(useObjects)		
	{
		terrainAltitude = HelyGetTerrainElevation( curPos, fwdPos, 15 );
		objectsDist = GetObjectsBelowHeight( curPos, allowedObjectDist, .6f );
		fwdObjectDist = GetObjectsBelowHeight( fwdPos, allowedObjectDist, .6f );
		if(objectsDist < fwdObjectDist)
			objectsDist = (objectsDist + fwdObjectDist)*.5f;
	}
	else				
	{
		terrainAltitude = HelyGetTerrainElevation( curPos, curPos, 1 );
	}
	float	waterAltitude = m_pGame->GetSystem()->GetI3DEngine()->GetWaterLevel(m_pEntity);
	if( terrainAltitude < waterAltitude )
		terrainAltitude = waterAltitude;
	if(terrainAltitude<objectsDist)
		minPossibleAlt = objectsDist;
	else
		minPossibleAlt = terrainAltitude;
	desiredAltitude = desiredAltitude + terrainAltitude;
	if( desiredAltitude<objectsDist+6.1f )
		desiredAltitude = objectsDist+6.1f;
	if( desiredAltitude<absMinAlt )
		desiredAltitude = absMinAlt;
	float	deltaAltitude = desiredAltitude - curPos.z;
	float	scale = 1.0f;
	if( deltaAltitude > 1.0f )
		scale = 1.0f;
	else if( deltaAltitude > 0.0f )
		scale *= scale;
	if(deltaAltitude>-15 && deltaAltitude<0)
		scale = (1.0f+deltaAltitude/15.0f);
	if(deltaAltitude>7.0f)		
		deltaAltitude = 7.0f;
	else if(deltaAltitude<-7.0f)
		deltaAltitude = -7.0f;
	if( (curPos.z - 5) < minPossibleAlt) 
	{
		if(m_Movement.z < 0 ) 
			m_Movement.z *= .5f;	
		scale = 1.0f;
		float	upInput = -((curPos.z - 5) - minPossibleAlt);	
		if( upInput<10 )
			deltaAltitude = 17 + 5.0f*upInput/10.0f;
		else
			deltaAltitude = 17 + upInput*5.0f;
		if(deltaAltitude>30)
			deltaAltitude = 30;
	}
	return 	deltaAltitude*scale;
}
float CXVehicleProxy :: UpdateAltitude ( const Vec3d & moveDir , float desiredAltitude , float absMinAlt , bool useObjects ) { Vec3d curPos = m_pEntity -> GetPos ( ) ; float allowedObjectDist = 7.0f ; float objectsDist = -1000 , fwdObjectDist = -1000 ; float minPossibleAlt = 0 ; Vec3d fwdPos = m_pEntity -> GetPos ( ) + moveDir * 5.0f ; float terrainAltitude = -1000 ; if ( useObjects ) { terrainAltitude = HelyGetTerrainElevation ( curPos , fwdPos , 15 ) ; objectsDist = GetObjectsBelowHeight ( curPos , allowedObjectDist , .6f ) ; fwdObjectDist = GetObjectsBelowHeight ( fwdPos , allowedObjectDist , .6f ) ; if ( objectsDist < fwdObjectDist ) objectsDist = ( objectsDist + fwdObjectDist ) * .5f ; } else { terrainAltitude = HelyGetTerrainElevation ( curPos , curPos , 1 ) ; } float waterAltitude = m_pGame -> GetSystem ( ) -> GetI3DEngine ( ) -> GetWaterLevel ( m_pEntity ) ; if ( terrainAltitude < waterAltitude ) terrainAltitude = waterAltitude ; if ( terrainAltitude < objectsDist ) minPossibleAlt = objectsDist ; else minPossibleAlt = terrainAltitude ; desiredAltitude = desiredAltitude + terrainAltitude ; if ( desiredAltitude < objectsDist + 6.1f ) desiredAltitude = objectsDist + 6.1f ; if ( desiredAltitude < absMinAlt ) desiredAltitude = absMinAlt ; float deltaAltitude = desiredAltitude - curPos . z ; float scale = 1.0f ; if ( deltaAltitude > 1.0f ) scale = 1.0f ; else if ( deltaAltitude > 0.0f ) scale *= scale ; if ( deltaAltitude > -15 && deltaAltitude < 0 ) scale = ( 1.0f + deltaAltitude / 15.0f ) ; if ( deltaAltitude > 7.0f ) deltaAltitude = 7.0f ; else if ( deltaAltitude < -7.0f ) deltaAltitude = -7.0f ; if ( ( curPos . z - 5 ) < minPossibleAlt ) { if ( m_Movement . z < 0 ) m_Movement . z *= .5f ; scale = 1.0f ; float upInput = - ( ( curPos . z - 5 ) - minPossibleAlt ) ; if ( upInput < 10 ) deltaAltitude = 17 + 5.0f * upInput / 10.0f ; else deltaAltitude = 17 + upInput * 5.0f ; if ( deltaAltitude > 30 ) deltaAltitude = 30 ; } return deltaAltitude * scale ; }
desiredAltitude - alr above terrain
absMinAlt - never go below
desiredAltitude - alr above terrain absMinAlt - never go below
// never go below this
 // get terrain/ objects below in box
 // get only terrain below in small box
 // don't go too close to objects below
 // don't go lower desired absolute flight altitude
 //float	deltaAltitude = desiredAltitude - (curPos.z - terrainAltitude);
 // if moving down - make it smooth
 // cup the force 
 // if in ground or objects - froce go up
 // if moving down
 // slow it
 // deeper in something - more up force
