ECS/Project/Project/Systems/CameraSystem/CameraSystem.cpp
//	Set the Active Camera to be the Previous Camera.
Set the Active Camera to be the Previous Camera.
Set the Active Camera to be the Previous Camera .
void CameraSystem::setPreviousCamera()
{
	std::shared_ptr<EntityManager> entityManager = getEntityManager();
	std::shared_ptr<std::vector<long int>> entities = entityManager->getEntitiesWithComponentOfType(ComponentType::CAMERA_COMPONENT);
	if (activeCameraEntity == -1 && entities != NULL)
	{
		std::shared_ptr<CameraComponent> cameraComponent = std::dynamic_pointer_cast<CameraComponent>(entityManager->getComponentOfEntity((*entities)[entities->size() - 1], ComponentType::CAMERA_COMPONENT, ModuleType::CAMERA_SYSTEM));
		cameraComponent->setActive();
		activeCameraEntity = (*entities)[entities->size() - 1];
	}
	else
	{
		if (entities != NULL)
		{
			int entityLocation = -1;
			for (int i = 0; i < entities->size(); i++)
			{
				if (activeCameraEntity == (*entities)[i])
				{
					entityLocation = i;
					break;
				}
			}
			if (entityLocation == -1)
			{
				std::shared_ptr<CameraComponent> cameraComponent = std::dynamic_pointer_cast<CameraComponent>(entityManager->getComponentOfEntity((*entities)[0], ComponentType::CAMERA_COMPONENT, ModuleType::CAMERA_SYSTEM));
				cameraComponent->setActive();
				activeCameraEntity = (*entities)[entities->size() - 1];
			}
			else
			{
				std::shared_ptr<CameraComponent> activeCameraComponent = std::dynamic_pointer_cast<CameraComponent>(entityManager->getComponentOfEntity((*entities)[entityLocation], ComponentType::CAMERA_COMPONENT, ModuleType::CAMERA_SYSTEM));
				Set it to be Inactive.
				activeCameraComponent->setInactive();
				if (entityLocation == 0)
				{
					activeCameraEntity = -1;
				}
				else
				{
					entityLocation = entityLocation - 1;
					Get the Next Active Camera Component.
					std::shared_ptr<CameraComponent> nextActiveCameraComponent = std::dynamic_pointer_cast<CameraComponent>(entityManager->getComponentOfEntity((*entities)[entityLocation], ComponentType::CAMERA_COMPONENT, ModuleType::CAMERA_SYSTEM));
					activeCameraEntity = (*entities)[entityLocation];
					Set it to be the Active Camera Component.
					nextActiveCameraComponent->setActive();
				}
			}
		}
		else
		{
			activeCameraEntity = -1;
		}
	}
}
void CameraSystem :: setPreviousCamera ( ) { std :: shared_ptr < EntityManager > entityManager = getEntityManager ( ) ; std :: shared_ptr < std :: vector < long int > > entities = entityManager -> getEntitiesWithComponentOfType ( ComponentType :: CAMERA_COMPONENT ) ; if ( activeCameraEntity == -1 && entities != NULL ) { std :: shared_ptr < CameraComponent > cameraComponent = std :: dynamic_pointer_cast < CameraComponent > ( entityManager -> getComponentOfEntity ( ( * entities ) [ entities -> size ( ) - 1 ] , ComponentType :: CAMERA_COMPONENT , ModuleType :: CAMERA_SYSTEM ) ) ; cameraComponent -> setActive ( ) ; activeCameraEntity = ( * entities ) [ entities -> size ( ) - 1 ] ; } else { if ( entities != NULL ) { int entityLocation = -1 ; for ( int i = 0 ; i < entities -> size ( ) ; i ++ ) { if ( activeCameraEntity == ( * entities ) [ i ] ) { entityLocation = i ; break ; } } if ( entityLocation == -1 ) { std :: shared_ptr < CameraComponent > cameraComponent = std :: dynamic_pointer_cast < CameraComponent > ( entityManager -> getComponentOfEntity ( ( * entities ) [ 0 ] , ComponentType :: CAMERA_COMPONENT , ModuleType :: CAMERA_SYSTEM ) ) ; cameraComponent -> setActive ( ) ; activeCameraEntity = ( * entities ) [ entities -> size ( ) - 1 ] ; } else { std :: shared_ptr < CameraComponent > activeCameraComponent = std :: dynamic_pointer_cast < CameraComponent > ( entityManager -> getComponentOfEntity ( ( * entities ) [ entityLocation ] , ComponentType :: CAMERA_COMPONENT , ModuleType :: CAMERA_SYSTEM ) ) ; activeCameraComponent -> setInactive ( ) ; if ( entityLocation == 0 ) { activeCameraEntity = -1 ; } else { entityLocation = entityLocation - 1 ; std :: shared_ptr < CameraComponent > nextActiveCameraComponent = std :: dynamic_pointer_cast < CameraComponent > ( entityManager -> getComponentOfEntity ( ( * entities ) [ entityLocation ] , ComponentType :: CAMERA_COMPONENT , ModuleType :: CAMERA_SYSTEM ) ) ; activeCameraEntity = ( * entities ) [ entityLocation ] ; nextActiveCameraComponent -> setActive ( ) ; } } } else { activeCameraEntity = -1 ; } } }
Set the Active Camera to be the Previous Camera.
Set the Active Camera to be the Previous Camera .
//	Get the EntityManager. //	Get the entities with a Transform Component. //	Check if there is no Active Camera. //	Get the Camera Component. //	Set this to be the Active Camera Component. //	Set the Active Camera Entity. //	Find the Entity Location. //	Iterate over the entites. //	 //	Get the Camera Component. //	Set this to be the Active Camera Component. //	Set the Active Camera Entity. //	Get the Camera Component. //	Set it to be Inactive. //	 //	Get the Next Active Camera Component. //	Set it to be the Active Camera Component.