Sources/CryGame C++/Solution1/CryGame/XPlayerCamera.cpp
//////////////////////////////////////////////////////////////////////////
// Updates the camera associated with the player

Updates the camera associated with the player
Updates the camera associated with the player
void CPlayer::UpdateCamera()
{	
	IEntityCamera *camera = m_pEntity->GetCamera();
	if (!camera)
		return;
	FUNCTION_PROFILER( GetISystem(),PROFILE_GAME );
	if (!IsMyPlayer() && !m_pGame->IsMultiplayer()) 
	{		
		camera->SetPos(m_pEntity->GetPos());
		return;
	}
	float frameTime = m_pGame->GetSystem()->GetITimer()->GetFrameTime();
	IPhysicalEntity *physEnt = m_pEntity->GetPhysics();
	if (physEnt)
	{
		pe_status_living status;
		if (physEnt->GetStatus(&status))
		{
			status.camOffset += vectorf(m_walkParams.shakeLOffset);
			camera->SetCamOffset(status.camOffset);
		}
	}
	{
		m_ValidPos = m_pEntity->GetPos();
		m_ValidPos.z += .2f;
		m_ValidAngle = m_pEntity->GetAngles();
		if (m_bFirstPerson && m_pVehicle)
		{
			UpdateBoatCamera();
		} 
		else  
		if (!m_bFirstPerson)
		{
			Vec3d pos,angles;
			pos = m_pEntity->GetPos();
			angles = m_pEntity->GetAngles();
			if (m_pVehicle && m_pVehicle->GetEntity() )	
			{
				IPhysicalEntity *physEntCar = m_pVehicle->GetEntity()->GetPhysics();
				float	camRange = m_pGame->cl_ThirdPersonRange->GetFVal();
				if(m_pVehicle->GetType() == VHT_BOAT || m_pVehicle->GetType() == VHT_PARAGLIDER )
					camRange = m_pVehicle->m_BoatParams.m_fCameraDist;
				float	camDist = m_pGame->cl_ThirdPersonOffs->GetFVal();
				float	camAVert = m_pGame->cl_ThirdPersonOffsAngVert->GetFVal();
				float	camAHor = m_pGame->cl_ThirdPersonOffsAngHor->GetFVal();
				Vec3 offset(0.0f,camDist, 0.0f);
				Matrix33 targetMt;
				targetMt.SetIdentity();
				targetMt.SetRotationXYZ((m_pVehicle->GetEntity()->GetAngles()+Vec3(camAVert,0.0f,camAHor))*gf_DEGTORAD); 
				targetMt.Transpose();
				Matrix33 offsetMt;
				offsetMt.SetIdentity();
				offset = offset*(targetMt);
				offset += m_pVehicle->GetEntity()->GetPos();
				float	waterLevel = m_pGame->GetSystem()->GetI3DEngine()->GetWaterLevel(&offset);
				float	terrainLevel = m_pGame->GetSystem()->GetI3DEngine()->GetTerrainZ((int)offset.x, (int)offset.y);
				camera->SetThirdPersonMode(offset,
						angles,CAMERA_3DPERSON1,frameTime,camRange,!m_bFirstPerson,physEnt, 
						physEntCar,
						m_pGame->GetSystem()->GetI3DEngine());
			}
			else
				camera->SetThirdPersonMode(pos,angles,CAMERA_3DPERSON1,frameTime,m_pGame->cl_ThirdPersonRange->GetFVal(),!m_bFirstPerson,physEnt );
			ICryCharInstance *pChar = m_pEntity->GetCharInterface()->GetCharacter(0);
			if (m_pGame->cl_ViewFace->GetFVal()>0.0f)
			{
				camera->SetPos( m_pEntity->GetPos()+Vec3d(0,m_pGame->cl_ViewFace->GetFVal(),1.7f));
				camera->SetAngles( Vec3d(0, 0, 0) );
				TRACE("%5.5f", m_pEntity->GetPos().z);
				if (pChar)
					pChar->SetAnimationSpeed(0.00001f);
			}
			else
			{
				if (pChar)
					pChar->SetAnimationSpeed(1.0f);
			}
		}
		else
		{
			if( m_CameraMode == PCM_CASUAL)
			{
				UpdateCameraTransition( m_vEyePos );
				camera->SetPos(m_vCurCamposVhcl);
				camera->SetAngles(m_vCurAngleVhcl);
			}
			else
			{
				camera->SetPos(m_vEyePos);
				camera->SetAngles(m_vEyeAngles);
			}
		}
	}
	if (camera)
		camera->Update();
}
void CPlayer :: UpdateCamera ( ) { IEntityCamera * camera = m_pEntity -> GetCamera ( ) ; if ( ! camera ) return ; FUNCTION_PROFILER ( GetISystem ( ) , PROFILE_GAME ) ; if ( ! IsMyPlayer ( ) && ! m_pGame -> IsMultiplayer ( ) ) { camera -> SetPos ( m_pEntity -> GetPos ( ) ) ; return ; } float frameTime = m_pGame -> GetSystem ( ) -> GetITimer ( ) -> GetFrameTime ( ) ; IPhysicalEntity * physEnt = m_pEntity -> GetPhysics ( ) ; if ( physEnt ) { pe_status_living status ; if ( physEnt -> GetStatus ( & status ) ) { status . camOffset += vectorf ( m_walkParams . shakeLOffset ) ; camera -> SetCamOffset ( status . camOffset ) ; } } { m_ValidPos = m_pEntity -> GetPos ( ) ; m_ValidPos . z += .2f ; m_ValidAngle = m_pEntity -> GetAngles ( ) ; if ( m_bFirstPerson && m_pVehicle ) { UpdateBoatCamera ( ) ; } else if ( ! m_bFirstPerson ) { Vec3d pos , angles ; pos = m_pEntity -> GetPos ( ) ; angles = m_pEntity -> GetAngles ( ) ; if ( m_pVehicle && m_pVehicle -> GetEntity ( ) ) { IPhysicalEntity * physEntCar = m_pVehicle -> GetEntity ( ) -> GetPhysics ( ) ; float camRange = m_pGame -> cl_ThirdPersonRange -> GetFVal ( ) ; if ( m_pVehicle -> GetType ( ) == VHT_BOAT || m_pVehicle -> GetType ( ) == VHT_PARAGLIDER ) camRange = m_pVehicle -> m_BoatParams . m_fCameraDist ; float camDist = m_pGame -> cl_ThirdPersonOffs -> GetFVal ( ) ; float camAVert = m_pGame -> cl_ThirdPersonOffsAngVert -> GetFVal ( ) ; float camAHor = m_pGame -> cl_ThirdPersonOffsAngHor -> GetFVal ( ) ; Vec3 offset ( 0.0f , camDist , 0.0f ) ; Matrix33 targetMt ; targetMt . SetIdentity ( ) ; targetMt . SetRotationXYZ ( ( m_pVehicle -> GetEntity ( ) -> GetAngles ( ) + Vec3 ( camAVert , 0.0f , camAHor ) ) * gf_DEGTORAD ) ; targetMt . Transpose ( ) ; Matrix33 offsetMt ; offsetMt . SetIdentity ( ) ; offset = offset * ( targetMt ) ; offset += m_pVehicle -> GetEntity ( ) -> GetPos ( ) ; float waterLevel = m_pGame -> GetSystem ( ) -> GetI3DEngine ( ) -> GetWaterLevel ( & offset ) ; float terrainLevel = m_pGame -> GetSystem ( ) -> GetI3DEngine ( ) -> GetTerrainZ ( ( int ) offset . x , ( int ) offset . y ) ; camera -> SetThirdPersonMode ( offset , angles , CAMERA_3DPERSON1 , frameTime , camRange , ! m_bFirstPerson , physEnt , physEntCar , m_pGame -> GetSystem ( ) -> GetI3DEngine ( ) ) ; } else camera -> SetThirdPersonMode ( pos , angles , CAMERA_3DPERSON1 , frameTime , m_pGame -> cl_ThirdPersonRange -> GetFVal ( ) , ! m_bFirstPerson , physEnt ) ; ICryCharInstance * pChar = m_pEntity -> GetCharInterface ( ) -> GetCharacter ( 0 ) ; if ( m_pGame -> cl_ViewFace -> GetFVal ( ) > 0.0f ) { camera -> SetPos ( m_pEntity -> GetPos ( ) + Vec3d ( 0 , m_pGame -> cl_ViewFace -> GetFVal ( ) , 1.7f ) ) ; camera -> SetAngles ( Vec3d ( 0 , 0 , 0 ) ) ; TRACE ( " " , m_pEntity -> GetPos ( ) . z ) ; if ( pChar ) pChar -> SetAnimationSpeed ( 0.00001f ) ; } else { if ( pChar ) pChar -> SetAnimationSpeed ( 1.0f ) ; } } else { if ( m_CameraMode == PCM_CASUAL ) { UpdateCameraTransition ( m_vEyePos ) ; camera -> SetPos ( m_vCurCamposVhcl ) ; camera -> SetAngles ( m_vCurAngleVhcl ) ; } else { camera -> SetPos ( m_vEyePos ) ; camera -> SetAngles ( m_vEyeAngles ) ; } } } if ( camera ) camera -> Update ( ) ; }
Updates the camera associated with the player
Updates the camera associated with the player
//get view physics status 
 //Vec3d(0, 0, status.eye_height));
 //	if (IsAlive())
 // in vehicle camera
 //third person camera
 //<<FIXME>> if something with the third person camera doesn't work, talk to Petar
 // in vehicle - third person - skip vehicle physiscs when trace camera
 //				float	waterLevel = m_pGame->GetSystem()->GetI3DEngine()->GetWaterLevel(m_pEntity);
 //RAGLIDER IsBoat())
 //					camRange = m_pGame->cl_ThirdPersonRangeBoat->GetFVal();
 //						NULL,
 //camera->GetCamOffset());
 // first person
