From e67a990798e3bf96fb503403c620083ec0a4dda0 Mon Sep 17 00:00:00 2001 From: Shital Shah Date: Sat, 17 Feb 2018 01:49:17 -0800 Subject: [PATCH] added NoDisplay view mode --- AirLib/include/common/AirSimSettings.hpp | 16 +++++--- .../Plugins/AirSim/Source/CameraDirector.cpp | 37 ++++++++++++++----- Unreal/Plugins/AirSim/Source/CameraDirector.h | 6 ++- Unreal/Plugins/AirSim/Source/PIPCamera.cpp | 3 ++ 4 files changed, 44 insertions(+), 18 deletions(-) diff --git a/AirLib/include/common/AirSimSettings.hpp b/AirLib/include/common/AirSimSettings.hpp index 19def177cd..ba933c73c9 100644 --- a/AirLib/include/common/AirSimSettings.hpp +++ b/AirLib/include/common/AirSimSettings.hpp @@ -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); } diff --git a/Unreal/Plugins/AirSim/Source/CameraDirector.cpp b/Unreal/Plugins/AirSim/Source/CameraDirector.cpp index 17af5e89ab..34d755c819 100644 --- a/Unreal/Plugins/AirSim/Source/CameraDirector.cpp +++ b/Unreal/Plugins/AirSim/Source/CameraDirector.cpp @@ -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_); } } @@ -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(); @@ -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); } @@ -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); } @@ -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; } @@ -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); @@ -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(); } diff --git a/Unreal/Plugins/AirSim/Source/CameraDirector.h b/Unreal/Plugins/AirSim/Source/CameraDirector.h index 1031ba3c58..a2c4cfa2d8 100644 --- a/Unreal/Plugins/AirSim/Source/CameraDirector.h +++ b/Unreal/Plugins/AirSim/Source/CameraDirector.h @@ -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() @@ -38,6 +39,7 @@ class AIRSIM_API ACameraDirector : public AActor void inputEventFlyWithView(); void inputEventSpringArmChaseView(); void inputEventBackupView(); + void inputEventNoDisplayView(); public: ACameraDirector(); @@ -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(); diff --git a/Unreal/Plugins/AirSim/Source/PIPCamera.cpp b/Unreal/Plugins/AirSim/Source/PIPCamera.cpp index db21e37f52..7f0273523e 100644 --- a/Unreal/Plugins/AirSim/Source/PIPCamera.cpp +++ b/Unreal/Plugins/AirSim/Source/PIPCamera.cpp @@ -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); }