Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update inputs to use the Unreal Input Mapping Project Settings. #4489

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Yet another way to use AirSim is the so-called "Computer Vision" mode. In this m

### Weather Effects

Press F10 to see various options available for weather effects. You can also control the weather using [APIs](https://microsoft.github.io/AirSim/apis#weather-apis). Press F1 to see other options available.
Press F10 to see various options available for weather effects. You can also control the weather using [APIs](https://microsoft.github.io/AirSim/apis#weather-apis). Press F9 to see other options available.

![record screenshot](docs/images/weather_menu.png)

Expand Down
43 changes: 43 additions & 0 deletions Unreal/Environments/Blocks/Config/DefaultInput.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,49 @@ bDefaultViewportMouseLock=False
DefaultViewportMouseLockMode=DoNotLock
bAlwaysShowTouchInterface=False
bShowConsoleOnFourFingerTap=True
+ActionMappings=(ActionName="inputEventToggleRecording",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=R)
+ActionMappings=(ActionName="InputEventToggleReport",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=Semicolon)
+ActionMappings=(ActionName="InputEventToggleHelp",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=F9)
+ActionMappings=(ActionName="InputEventToggleTrace",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=T)
+ActionMappings=(ActionName="InputEventToggleSubwindow0",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=One)
+ActionMappings=(ActionName="InputEventToggleSubwindow1",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=Two)
+ActionMappings=(ActionName="InputEventToggleSubwindow2",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=Three)
+ActionMappings=(ActionName="InputEventToggleAll",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=Zero)
+ActionMappings=(ActionName="inputEventFpvView",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=F)
+ActionMappings=(ActionName="inputEventFlyWithView",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=B)
+ActionMappings=(ActionName="inputEventGroundView",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=Backslash)
+ActionMappings=(ActionName="inputEventManualView",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=M)
+ActionMappings=(ActionName="inputEventSpringArmChaseView",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=Slash)
+ActionMappings=(ActionName="inputEventBackupView",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=K)
+ActionMappings=(ActionName="inputEventNoDisplayView",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=Hyphen)
+ActionMappings=(ActionName="inputEventFrontView",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=I)
+ActionMappings=(ActionName="InputEventResetVehicles",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=BackSpace)
+ActionMappings=(ActionName="inputEventToggleWeather",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=F10)
+ActionMappings=(ActionName="Handbrake",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=End)
+ActionMappings=(ActionName="Handbrake",bShift=False,bCtrl=False,bAlt=False,bCmd=False,Key=Gamepad_FaceButton_Right)
+AxisMappings=(AxisName="MoveForward",Scale=1.000000,Key=Up)
+AxisMappings=(AxisName="MoveForward",Scale=-1.000000,Key=Down)
+AxisMappings=(AxisName="MoveRight",Scale=-0.500000,Key=Left)
+AxisMappings=(AxisName="MoveForward",Scale=1.000000,Key=Gamepad_RightTriggerAxis)
+AxisMappings=(AxisName="Footbrake",Scale=1.000000,Key=SpaceBar)
+AxisMappings=(AxisName="Footbrake",Scale=1.000000,Key=Gamepad_LeftShoulder)
+AxisMappings=(AxisName="inputManualForward",Scale=1.000000,Key=Up)
+AxisMappings=(AxisName="inputManualArrowUp",Scale=1.000000,Key=PageUp)
+AxisMappings=(AxisName="inputManualUpPitch",Scale=1.000000,Key=W)
+AxisMappings=(AxisName="inputManualSpeedIncrease",Scale=1.000000,Key=LeftShift)
+AxisMappings=(AxisName="inputManualForward",Scale=-1.000000,Key=Down)
+AxisMappings=(AxisName="inputManualArrowUp",Scale=-1.000000,Key=PageDown)
+AxisMappings=(AxisName="inputManualRightYaw",Scale=-1.000000,Key=A)
+AxisMappings=(AxisName="inputManualRightRoll",Scale=-1.000000,Key=Q)
+AxisMappings=(AxisName="inputManualUpPitch",Scale=-1.000000,Key=S)
+AxisMappings=(AxisName="inputManualSpeedIncrease",Scale=-1.000000,Key=LeftControl)
+AxisMappings=(AxisName="MoveRight",Scale=0.500000,Key=Right)
+AxisMappings=(AxisName="MoveRight",Scale=1.000000,Key=Gamepad_LeftX)
+AxisMappings=(AxisName="inputManualRightYaw",Scale=1.000000,Key=D)
+AxisMappings=(AxisName="inputManualRightRoll",Scale=1.000000,Key=E)
+AxisMappings=(AxisName="inputManualArrowRight",Scale=-1.000000,Key=Left)
+AxisMappings=(AxisName="inputManualArrowRight",Scale=1.000000,Key=Right)
+AxisMappings=(AxisName="MoveForward",Scale=-1.000000,Key=Gamepad_LeftTriggerAxis)
DefaultTouchInterface=/Engine/MobileResources/HUD/DefaultVirtualJoysticks.DefaultVirtualJoysticks
ConsoleKey=None
-ConsoleKeys=Tilde
Expand Down
Binary file not shown.
Binary file modified Unreal/Plugins/AirSim/Content/HUDAssets/OptionsMenu.uasset
Binary file not shown.
Binary file modified Unreal/Plugins/AirSim/Content/Weather/UI/MenuActor.uasset
Binary file not shown.
28 changes: 28 additions & 0 deletions Unreal/Plugins/AirSim/Source/AirBlueprintLib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,29 @@ int UAirBlueprintLib::RemoveAxisBinding(const FInputAxisKeyMapping& axis, FInput
return -1;
}

int UAirBlueprintLib::RemoveAxisBinding(FInputAxisBinding* axis_binding, AActor* actorForWorldContext)
{
if (axis_binding == nullptr && actorForWorldContext == nullptr) {
return -1;
}

APlayerController* controller = actorForWorldContext->GetWorld()->GetFirstPlayerController();
//removing binding
int found_binding_index = -1, cur_binding_index = -1;
for (const auto& axisBindingArrayEntry : controller->InputComponent->AxisBindings) {
++cur_binding_index;
if (axisBindingArrayEntry.AxisName == axis_binding->AxisName) {
found_binding_index = cur_binding_index;
break;
}
}
if (found_binding_index >= 0) {
controller->InputComponent->AxisBindings.RemoveAt(found_binding_index);
}

return found_binding_index;
}

float UAirBlueprintLib::GetDisplayGamma()
{
return GEngine->DisplayGamma;
Expand All @@ -722,6 +745,11 @@ void UAirBlueprintLib::EnableInput(AActor* actor)
actor->EnableInput(actor->GetWorld()->GetFirstPlayerController());
}

void UAirBlueprintLib::DisableInput(AActor* actor)
{
actor->DisableInput(actor->GetWorld()->GetFirstPlayerController());
}

UObject* UAirBlueprintLib::LoadObject(const std::string& name)
{
FString str(name.c_str());
Expand Down
20 changes: 20 additions & 0 deletions Unreal/Plugins/AirSim/Source/AirBlueprintLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,15 @@ class UAirBlueprintLib : public UBlueprintFunctionLibrary
return controller->InputComponent->BindAction(action_name, on_press_or_release ? IE_Pressed : IE_Released, actor, func);
}

// BindAction helper function to allow utilization of Unreal's Input mapping from Project Settings.
template <class UserClass>
static FInputActionBinding& BindAction(const FName action_name, AActor* actorForWorldContext, UserClass* obj,
typename FInputActionHandlerSignature::TUObjectMethodDelegate<UserClass>::FMethodPtr func, bool on_press_or_release = false)
{
APlayerController* controller = actorForWorldContext->GetWorld()->GetFirstPlayerController();
return controller->InputComponent->BindAction(action_name, on_press_or_release ? IE_Pressed : IE_Released, obj, func);
}

template <class UserClass>
static FInputAxisBinding& BindAxisToKey(const FName axis_name, const FKey in_key, AActor* actor, UserClass* obj,
typename FInputAxisHandlerSignature::TUObjectMethodDelegate<UserClass>::FMethodPtr func)
Expand All @@ -158,9 +167,20 @@ class UAirBlueprintLib : public UBlueprintFunctionLibrary
return controller->InputComponent->BindAxis(axis.AxisName, obj, func);
}

// BindAxis helper function to allow utilization of Unreal's Input mapping from Project Settings.
template <class UserClass>
static FInputAxisBinding& BindAxis(const FName axis_name, AActor* actorForWorldContext, UserClass* obj,
typename FInputAxisHandlerSignature::TUObjectMethodDelegate<UserClass>::FMethodPtr func)
{
APlayerController* controller = actorForWorldContext->GetWorld()->GetFirstPlayerController();
return controller->InputComponent->BindAxis(axis_name, obj, func);
}

static int RemoveAxisBinding(const FInputAxisKeyMapping& axis, FInputAxisBinding* axis_binding, AActor* actor);
static int RemoveAxisBinding(FInputAxisBinding* axis_binding, AActor* actorForWorldContext);

static void EnableInput(AActor* actor);
static void DisableInput(AActor* actor);

static void RunCommandOnGameThread(TFunction<void()> InFunction, bool wait = false, const TStatId InStatId = TStatId());

Expand Down
18 changes: 9 additions & 9 deletions Unreal/Plugins/AirSim/Source/CameraDirector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,14 @@ void ACameraDirector::setupInputBindings()
{
UAirBlueprintLib::EnableInput(this);

UAirBlueprintLib::BindActionToKey("inputEventFpvView", EKeys::F, this, &ACameraDirector::inputEventFpvView);
UAirBlueprintLib::BindActionToKey("inputEventFlyWithView", EKeys::B, this, &ACameraDirector::inputEventFlyWithView);
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("inputEventNoDisplayView", EKeys::Hyphen, this, &ACameraDirector::inputEventNoDisplayView);
UAirBlueprintLib::BindActionToKey("inputEventFrontView", EKeys::I, this, &ACameraDirector::inputEventFrontView);
UAirBlueprintLib::BindAction("inputEventFpvView", this, this, &ACameraDirector::inputEventFpvView);
UAirBlueprintLib::BindAction("inputEventFlyWithView", this, this, &ACameraDirector::inputEventFlyWithView);
UAirBlueprintLib::BindAction("inputEventGroundView", this, this, &ACameraDirector::inputEventGroundView);
UAirBlueprintLib::BindAction("inputEventManualView", this, this, &ACameraDirector::inputEventManualView);
UAirBlueprintLib::BindAction("inputEventSpringArmChaseView", this, this, &ACameraDirector::inputEventSpringArmChaseView);
UAirBlueprintLib::BindAction("inputEventBackupView", this, this, &ACameraDirector::inputEventBackupView);
UAirBlueprintLib::BindAction("inputEventNoDisplayView", this, this, &ACameraDirector::inputEventNoDisplayView);
UAirBlueprintLib::BindAction("inputEventFrontView", this, this, &ACameraDirector::inputEventFrontView);
}

void ACameraDirector::EndPlay(const EEndPlayReason::Type EndPlayReason)
Expand Down Expand Up @@ -292,7 +292,7 @@ void ACameraDirector::inputEventFrontView()
disableCameras(true, true, true, false);
}
else
UAirBlueprintLib::LogMessageString("Camera is not available: ", "backup_camera", LogDebugLevel::Failure);
UAirBlueprintLib::LogMessageString("Camera is not available: ", "front_camera", LogDebugLevel::Failure);

notifyViewModeChanged();
}
Expand Down
121 changes: 20 additions & 101 deletions Unreal/Plugins/AirSim/Source/ManualPoseController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,7 @@ void UManualPoseController::initializeForPlay()
actor_ = nullptr;
clearBindings();

left_mapping_ = FInputAxisKeyMapping("inputManualArrowLeft", EKeys::Left);
right_mapping_ = FInputAxisKeyMapping("inputManualArrowRight", EKeys::Right);
forward_mapping_ = FInputAxisKeyMapping("inputManualForward", EKeys::Up);
backward_mapping_ = FInputAxisKeyMapping("inputManualBackward", EKeys::Down);
up_mapping_ = FInputAxisKeyMapping("inputManualArrowUp", EKeys::PageUp);
down_mapping_ = FInputAxisKeyMapping("inputManualArrowDown", EKeys::PageDown);
left_yaw_mapping_ = FInputAxisKeyMapping("inputManualLeftYaw", EKeys::A);
right_yaw_mapping_ = FInputAxisKeyMapping("inputManualRightYaw", EKeys::D);
left_roll_mapping_ = FInputAxisKeyMapping("inputManualLefRoll", EKeys::Q);
right_roll_mapping_ = FInputAxisKeyMapping("inputManualRightRoll", EKeys::E);
up_pitch_mapping_ = FInputAxisKeyMapping("inputManualUpPitch", EKeys::W);
down_pitch_mapping_ = FInputAxisKeyMapping("inputManualDownPitch", EKeys::S);
inc_speed_mapping_ = FInputAxisKeyMapping("inputManualSpeedIncrease", EKeys::LeftShift);
dec_speed_mapping_ = FInputAxisKeyMapping("inputManualSpeedDecrease", EKeys::LeftControl);
input_positive_ = inpute_negative_ = last_velocity_ = FVector::ZeroVector;
input_ = last_velocity_ = FVector::ZeroVector;
}

void UManualPoseController::clearBindings()
Expand Down Expand Up @@ -80,61 +66,25 @@ void UManualPoseController::resetDelta()

void UManualPoseController::removeInputBindings()
{
if (left_binding_)
UAirBlueprintLib::RemoveAxisBinding(left_mapping_, left_binding_, actor_);
if (right_binding_)
UAirBlueprintLib::RemoveAxisBinding(right_mapping_, right_binding_, actor_);
if (forward_binding_)
UAirBlueprintLib::RemoveAxisBinding(forward_mapping_, forward_binding_, actor_);
if (backward_binding_)
UAirBlueprintLib::RemoveAxisBinding(backward_mapping_, backward_binding_, actor_);
if (up_binding_)
UAirBlueprintLib::RemoveAxisBinding(up_mapping_, up_binding_, actor_);
if (down_binding_)
UAirBlueprintLib::RemoveAxisBinding(down_mapping_, down_binding_, actor_);
if (left_yaw_binding_)
UAirBlueprintLib::RemoveAxisBinding(left_yaw_mapping_, left_yaw_binding_, actor_);
if (right_yaw_binding_)
UAirBlueprintLib::RemoveAxisBinding(right_yaw_mapping_, right_yaw_binding_, actor_);
if (left_roll_binding_)
UAirBlueprintLib::RemoveAxisBinding(left_roll_mapping_, left_roll_binding_, actor_);
if (right_roll_binding_)
UAirBlueprintLib::RemoveAxisBinding(right_roll_mapping_, right_roll_binding_, actor_);
if (up_pitch_binding_)
UAirBlueprintLib::RemoveAxisBinding(up_pitch_mapping_, up_pitch_binding_, actor_);
if (down_pitch_binding_)
UAirBlueprintLib::RemoveAxisBinding(down_pitch_mapping_, down_pitch_binding_, actor_);
if (inc_speed_binding_)
UAirBlueprintLib::RemoveAxisBinding(inc_speed_mapping_, inc_speed_binding_, actor_);
if (dec_speed_binding_)
UAirBlueprintLib::RemoveAxisBinding(dec_speed_mapping_, dec_speed_binding_, actor_);

clearBindings();
UAirBlueprintLib::DisableInput(actor_);
}

void UManualPoseController::setupInputBindings()
{
UAirBlueprintLib::EnableInput(actor_);

left_binding_ = &UAirBlueprintLib::BindAxisToKey(left_mapping_, actor_, this, &UManualPoseController::inputManualLeft);
right_binding_ = &UAirBlueprintLib::BindAxisToKey(right_mapping_, actor_, this, &UManualPoseController::inputManualRight);
forward_binding_ = &UAirBlueprintLib::BindAxisToKey(forward_mapping_, actor_, this, &UManualPoseController::inputManualForward);
backward_binding_ = &UAirBlueprintLib::BindAxisToKey(backward_mapping_, actor_, this, &UManualPoseController::inputManualBackward);
up_binding_ = &UAirBlueprintLib::BindAxisToKey(up_mapping_, actor_, this, &UManualPoseController::inputManualMoveUp);
down_binding_ = &UAirBlueprintLib::BindAxisToKey(down_mapping_, actor_, this, &UManualPoseController::inputManualDown);
left_yaw_binding_ = &UAirBlueprintLib::BindAxisToKey(left_yaw_mapping_, actor_, this, &UManualPoseController::inputManualLeftYaw);
right_yaw_binding_ = &UAirBlueprintLib::BindAxisToKey(right_yaw_mapping_, actor_, this, &UManualPoseController::inputManualRightYaw);
left_roll_binding_ = &UAirBlueprintLib::BindAxisToKey(left_roll_mapping_, actor_, this, &UManualPoseController::inputManualLeftRoll);
right_roll_binding_ = &UAirBlueprintLib::BindAxisToKey(right_roll_mapping_, actor_, this, &UManualPoseController::inputManualRightRoll);
up_pitch_binding_ = &UAirBlueprintLib::BindAxisToKey(up_pitch_mapping_, actor_, this, &UManualPoseController::inputManualUpPitch);
down_pitch_binding_ = &UAirBlueprintLib::BindAxisToKey(down_pitch_mapping_, actor_, this, &UManualPoseController::inputManualDownPitch);
inc_speed_binding_ = &UAirBlueprintLib::BindAxisToKey(inc_speed_mapping_, actor_, this, &UManualPoseController::inputManualSpeedIncrease);
dec_speed_binding_ = &UAirBlueprintLib::BindAxisToKey(dec_speed_mapping_, actor_, this, &UManualPoseController::inputManualSpeedDecrease);
UAirBlueprintLib::BindAxis("inputManualArrowRight", getActor(), this, &UManualPoseController::inputManualMoveRight);
UAirBlueprintLib::BindAxis("inputManualForward", getActor(), this, &UManualPoseController::inputManualMoveForward);
UAirBlueprintLib::BindAxis("inputManualArrowUp", getActor(), this, &UManualPoseController::inputManualMoveUp);
UAirBlueprintLib::BindAxis("inputManualRightYaw", getActor(), this, &UManualPoseController::inputManualYaw);
UAirBlueprintLib::BindAxis("inputManualRightRoll", getActor(), this, &UManualPoseController::inputManualRoll);
UAirBlueprintLib::BindAxis("inputManualUpPitch", getActor(), this, &UManualPoseController::inputManualPitch);
UAirBlueprintLib::BindAxis("inputManualSpeedIncrease", getActor(), this, &UManualPoseController::inputManualSpeedChange);
}

void UManualPoseController::updateDeltaPosition(float dt)
{
FVector input = input_positive_ - inpute_negative_;
FVector input = input_;
if (!FMath::IsNearlyZero(input.SizeSquared())) {
if (FMath::IsNearlyZero(acceleration_))
last_velocity_ = input * speed_scaler_;
Expand All @@ -147,71 +97,40 @@ void UManualPoseController::updateDeltaPosition(float dt)
}
}

void UManualPoseController::inputManualSpeedIncrease(float val)
void UManualPoseController::inputManualSpeedChange(float val)
{
if (!FMath::IsNearlyEqual(val, 0.f))
speed_scaler_ += val * 20;
}
void UManualPoseController::inputManualSpeedDecrease(float val)
{
if (!FMath::IsNearlyEqual(val, 0.f))
speed_scaler_ -= val * 20;

if (speed_scaler_ <= 0.0)
speed_scaler_ = 20.0;
}

void UManualPoseController::inputManualLeft(float val)
void UManualPoseController::inputManualMoveRight(float val)
{
inpute_negative_.Y = val;
input_.Y = val;
}
void UManualPoseController::inputManualRight(float val)
void UManualPoseController::inputManualMoveForward(float val)
{
input_positive_.Y = val;
}
void UManualPoseController::inputManualForward(float val)
{
input_positive_.X = val;
}
void UManualPoseController::inputManualBackward(float val)
{
inpute_negative_.X = val;
input_.X = val;
}
void UManualPoseController::inputManualMoveUp(float val)
{
input_positive_.Z = val;
}
void UManualPoseController::inputManualDown(float val)
{
inpute_negative_.Z = val;
input_.Z = val;
}
void UManualPoseController::inputManualLeftYaw(float val)
{
if (!FMath::IsNearlyEqual(val, 0.f))
delta_rotation_.Add(0, -val, 0);
}
void UManualPoseController::inputManualRightYaw(float val)

void UManualPoseController::inputManualYaw(float val)
{
if (!FMath::IsNearlyEqual(val, 0.f))
delta_rotation_.Add(0, val, 0);
}
void UManualPoseController::inputManualLeftRoll(float val)
{
if (!FMath::IsNearlyEqual(val, 0.f))
delta_rotation_.Add(0, 0, -val);
}
void UManualPoseController::inputManualRightRoll(float val)
void UManualPoseController::inputManualRoll(float val)
{
if (!FMath::IsNearlyEqual(val, 0.f))
delta_rotation_.Add(0, 0, val);
}
void UManualPoseController::inputManualUpPitch(float val)
void UManualPoseController::inputManualPitch(float val)
{
if (!FMath::IsNearlyEqual(val, 0.f))
delta_rotation_.Add(val, 0, 0);
}
void UManualPoseController::inputManualDownPitch(float val)
{
if (!FMath::IsNearlyEqual(val, 0.f))
delta_rotation_.Add(-val, 0, 0);
}
Loading