Skip to content

Commit

Permalink
added NoDisplay view mode
Browse files Browse the repository at this point in the history
  • Loading branch information
sytelus committed Feb 17, 2018
1 parent 527916c commit e67a990
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 18 deletions.
16 changes: 10 additions & 6 deletions AirLib/include/common/AirSimSettings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,17 +303,21 @@ struct AirSimSettings {
view_mode_string = "SpringArmChase";
}

if (view_mode_string == "FlyWithMe")
initial_view_mode = 3; //ECameraDirectorMode::CAMERA_DIRECTOR_MODE_FLY_WITH_ME;
else if (view_mode_string == "Fpv")
if (view_mode_string == "Fpv")
initial_view_mode = 1; // ECameraDirectorMode::CAMERA_DIRECTOR_MODE_FPV;
else if (view_mode_string == "Manual")
initial_view_mode = 4; // ECameraDirectorMode::CAMERA_DIRECTOR_MODE_MANUAL;
else if (view_mode_string == "GroundObserver")
initial_view_mode = 2; // ECameraDirectorMode::CAMERA_DIRECTOR_MODE_GROUND_OBSERVER;
else if (view_mode_string == "FlyWithMe")
initial_view_mode = 3; //ECameraDirectorMode::CAMERA_DIRECTOR_MODE_FLY_WITH_ME;
else if (view_mode_string == "Manual")
initial_view_mode = 4; // ECameraDirectorMode::CAMERA_DIRECTOR_MODE_MANUAL;
else if (view_mode_string == "SpringArmChase")
initial_view_mode = 5; // ECameraDirectorMode::CAMERA_DIRECTOR_MODE_SPRINGARM_CHASE;
else
else if (view_mode_string == "Backup")
initial_view_mode = 6; // ECameraDirectorMode::CAMREA_DIRECTOR_MODE_BACKUP;
else if (view_mode_string == "None")
initial_view_mode = 7; // ECameraDirectorMode::CAMREA_DIRECTOR_MODE_NODISPLAY;
else
warning_messages.push_back("ViewMode setting is not recognized: " + view_mode_string);
}

Expand Down
37 changes: 27 additions & 10 deletions Unreal/Plugins/AirSim/Source/CameraDirector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@ void ACameraDirector::Tick(float DeltaTime)
manual_pose_controller_->updateActorPose(DeltaTime);
}
else if (mode_ == ECameraDirectorMode::CAMERA_DIRECTOR_MODE_SPRINGARM_CHASE) {
//do nothing
//do nothing, spring arm is pulling the camera with it
}
else {
else if (mode_ == ECameraDirectorMode::CAMREA_DIRECTOR_MODE_NODISPLAY) {
//do nothing, we have camera turned off
}
else { //make camera move in desired way
UAirBlueprintLib::FollowActor(external_camera_, follow_actor_, initial_ground_obs_offset_, ext_obs_fixed_z_);
}
}
Expand Down Expand Up @@ -88,8 +91,10 @@ void ACameraDirector::setCameras(APIPCamera* external_camera, VehiclePawnWrapper
case ECameraDirectorMode::CAMERA_DIRECTOR_MODE_GROUND_OBSERVER: inputEventGroundView(); break;
case ECameraDirectorMode::CAMERA_DIRECTOR_MODE_MANUAL: inputEventManualView(); break;
case ECameraDirectorMode::CAMERA_DIRECTOR_MODE_SPRINGARM_CHASE: inputEventSpringArmChaseView(); break;
case ECameraDirectorMode::CAMREA_DIRECTOR_MODE_BACKUP: inputEventBackupView(); break;
case ECameraDirectorMode::CAMREA_DIRECTOR_MODE_NODISPLAY: inputEventNoDisplayView(); break;
default:
throw std::out_of_range("Unknown view mode specified in CameraDirector::initializeForBeginPlay");
throw std::out_of_range("Unsupported view mode specified in CameraDirector::initializeForBeginPlay");
}

setupCameraFromSettings();
Expand Down Expand Up @@ -142,12 +147,15 @@ void ACameraDirector::setMode(ECameraDirectorMode mode)

mode_ = mode;

//if new mode is manual mode then add key bindings
if (mode_ == ECameraDirectorMode::CAMERA_DIRECTOR_MODE_MANUAL)
manual_pose_controller_->enableBindings(true);
//else remove any existing key bindings for manual mode
else if (external_camera_ != nullptr && manual_pose_controller_->getActor() == external_camera_)
manual_pose_controller_->enableBindings(false);
//else someone else is bound to manual pose controller, leave it alone

//if we switched to spring arm mode then attach to spring arm (detachment was done earlier in method)
if (mode_ == ECameraDirectorMode::CAMERA_DIRECTOR_MODE_SPRINGARM_CHASE)
attachSpringArm(true);
}
Expand All @@ -158,10 +166,11 @@ void ACameraDirector::setupInputBindings()

UAirBlueprintLib::BindActionToKey("inputEventFpvView", EKeys::F, this, &ACameraDirector::inputEventFpvView);
UAirBlueprintLib::BindActionToKey("inputEventFlyWithView", EKeys::B, this, &ACameraDirector::inputEventFlyWithView);
UAirBlueprintLib::BindActionToKey("inputEventBackupView", EKeys::K, this, &ACameraDirector::inputEventBackupView);
UAirBlueprintLib::BindActionToKey("inputEventGroundView", EKeys::Backslash, this, &ACameraDirector::inputEventGroundView);
UAirBlueprintLib::BindActionToKey("inputEventManualView", EKeys::M, this, &ACameraDirector::inputEventManualView);
UAirBlueprintLib::BindActionToKey("inputEventSpringArmChaseView", EKeys::Slash, this, &ACameraDirector::inputEventSpringArmChaseView);
UAirBlueprintLib::BindActionToKey("inputEventBackupView", EKeys::K, this, &ACameraDirector::inputEventBackupView);
UAirBlueprintLib::BindActionToKey("inputEventNoDispalyView", EKeys::Hyphen, this, &ACameraDirector::inputEventNoDisplayView);
}


Expand All @@ -179,14 +188,14 @@ void ACameraDirector::inputEventSpringArmChaseView()
{
setMode(ECameraDirectorMode::CAMERA_DIRECTOR_MODE_SPRINGARM_CHASE);
external_camera_->showToScreen();
disableNonExternalCameras();
disableCameras(true, true, false);
}

void ACameraDirector::inputEventGroundView()
{
setMode(ECameraDirectorMode::CAMERA_DIRECTOR_MODE_GROUND_OBSERVER);
external_camera_->showToScreen();
disableNonExternalCameras();
disableCameras(true, true, false);
ext_obs_fixed_z_ = true;
}

Expand Down Expand Up @@ -217,6 +226,12 @@ void ACameraDirector::inputEventManualView()
setMode(ECameraDirectorMode::CAMERA_DIRECTOR_MODE_MANUAL);
}

void ACameraDirector::inputEventNoDisplayView()
{
setMode(ECameraDirectorMode::CAMREA_DIRECTOR_MODE_NODISPLAY);
disableCameras(true, true, true);
}

void ACameraDirector::inputEventBackupView()
{
setMode(ECameraDirectorMode::CAMREA_DIRECTOR_MODE_BACKUP);
Expand All @@ -235,16 +250,18 @@ void ACameraDirector::inputEventFlyWithView()
if (follow_actor_)
external_camera_->SetActorLocationAndRotation(
follow_actor_->GetActorLocation() + initial_ground_obs_offset_, camera_start_rotation_);
disableNonExternalCameras();
disableCameras(true, true, false);
ext_obs_fixed_z_ = false;
}

void ACameraDirector::disableNonExternalCameras()
void ACameraDirector::disableCameras(bool fpv, bool backup, bool external)
{
if (fpv_camera_)
if (fpv && fpv_camera_)
fpv_camera_->disableMain();
if (backup_camera_)
if (backup && backup_camera_)
backup_camera_->disableMain();
if (external && external_camera_)
external_camera_->disableMain();
}


6 changes: 4 additions & 2 deletions Unreal/Plugins/AirSim/Source/CameraDirector.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ enum class ECameraDirectorMode : uint8
CAMERA_DIRECTOR_MODE_FLY_WITH_ME = 3 UMETA(DisplayName = "FlyWithMe"),
CAMERA_DIRECTOR_MODE_MANUAL = 4 UMETA(DisplayName = "Manual"),
CAMERA_DIRECTOR_MODE_SPRINGARM_CHASE = 5 UMETA(DisplayName = "SpringArmChase"),
CAMREA_DIRECTOR_MODE_BACKUP = 6 UMETA(DisplayName = "Backup")
CAMREA_DIRECTOR_MODE_BACKUP = 6 UMETA(DisplayName = "Backup"),
CAMREA_DIRECTOR_MODE_NODISPLAY = 7 UMETA(DisplayName = "No Display")
};

UCLASS()
Expand All @@ -38,6 +39,7 @@ class AIRSIM_API ACameraDirector : public AActor
void inputEventFlyWithView();
void inputEventSpringArmChaseView();
void inputEventBackupView();
void inputEventNoDisplayView();

public:
ACameraDirector();
Expand Down Expand Up @@ -68,7 +70,7 @@ class AIRSIM_API ACameraDirector : public AActor
private:
void setupInputBindings();
void attachSpringArm(bool attach);
void disableNonExternalCameras();
void disableCameras(bool fpv, bool backup, bool external);
void setupCameraFromSettings();


Expand Down
3 changes: 3 additions & 0 deletions Unreal/Plugins/AirSim/Source/PIPCamera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@ void APIPCamera::disableMain()
{
camera_->Deactivate();
camera_->SetVisibility(false);
APlayerController* controller = this->GetWorld()->GetFirstPlayerController();
if (controller && controller->GetViewTarget() == this)
controller->SetViewTarget(nullptr);
}


Expand Down

0 comments on commit e67a990

Please sign in to comment.