void FreeMovementController::Update(float frameTime)
{
	auto& input = Input::GetInstance();

	UpdateLookAround(frameTime);

	auto deltaX = GetInputX();
	auto deltaZ = GetInputZ();
	float deltaY = 0.0f;

	if (input.IsKeyDown('X'))
	{
		deltaY -= 1.0f;
	}

	if (input.IsKeyDown(VK_SPACE))
	{
		deltaY += 1.0f;
	}

	if (deltaX == 0.0f && deltaZ == 0.0f && deltaY == 0.0f)
	{
		return;
	}

	auto length = sqrt(deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ);
	auto multiplier = 5.0f * frameTime / length;

	auto cameraPosition = m_Camera.GetPosition();
	auto& cameraRotation = m_Camera.GetRotation();

	deltaX *= multiplier;
	deltaY *= multiplier;
	deltaZ *= multiplier;
	
	cameraPosition.x += deltaX * cos(cameraRotation.y);
	cameraPosition.z -= deltaX * sin(cameraRotation.y);
	
	cameraPosition.y += deltaY;

	cameraPosition.x += deltaZ * cos(cameraRotation.x) * sin(cameraRotation.y);
	cameraPosition.y -= deltaZ * sin(cameraRotation.x);
	cameraPosition.z += deltaZ * cos(cameraRotation.x) * cos(cameraRotation.y);
	
	UpdateSoundListener(frameTime, m_LastPosition);
	m_LastPosition = m_Camera.GetPosition();
	m_Camera.SetPosition(cameraPosition);
}
Exemplo n.º 2
0
//------------------------------------------------------------------------
void CPlayerStateSwim::OnExit( CPlayer& player )
{
	player.m_playerStateSwim_WaterTestProxy.OnExitWater(player);
	player.m_actorPhysics.groundNormal = Vec3(0,0,1);
	
	if (player.IsClient())
	{
		player.GetPlayerCamera()->SetCameraMode( eCameraMode_Default, "Leaving swim state" );

		//Unselect underwater weapon here
		player.SendMusicLogicEvent(eMUSICLOGICEVENT_PLAYER_SWIM_LEAVE);
		if (!player.IsCinematicFlagActive(SPlayerStats::eCinematicFlag_HolsterWeapon))
		{
			player.HolsterItem(false);
		}

		if (gEnv->bMultiplayer)	// any left hand holding in SP?
		{
			player.HideLeftHandObject(false);
		}

		player.PlaySound(CPlayer::ESound_Underwater, false);

		UpdateSoundListener(player);

		StopEnduranceSound( player.GetEntityId() );
	}

	IPhysicalEntity* pPhysEnt = player.GetEntity()->GetPhysics();
	if (pPhysEnt != NULL)
	{
		CPlayerStateUtil::PhySetNoFly( player, m_gravity );
	}

	// Record 'Swim' telemetry stats.

	CStatsRecordingMgr::TryTrackEvent(&player, eGSE_Swim, false);
}