Skip to content

Commit

Permalink
microsoft#1051 Add generic settings to change speed units and scale f…
Browse files Browse the repository at this point in the history
…actor

Allows the user to specify any units they want and then convert the speed as appropriate.  Defaults to m/s with a scale factor of 1.
  • Loading branch information
NextSim committed Jun 22, 2018
1 parent 5636fba commit f61e68d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
6 changes: 4 additions & 2 deletions AirLib/include/common/AirSimSettings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,8 @@ struct AirSimSettings {
std::map<std::string, PawnPath> pawn_paths; //path for pawn blueprint
std::map<std::string, std::unique_ptr<VehicleSetting>> vehicles;
CameraSetting camera_defaults;
bool speed_in_mph = false;
float speed_unit_factor = 1.0f;
std::string speed_unit_label = "m\\s";

public: //methods
static AirSimSettings& singleton()
Expand Down Expand Up @@ -940,7 +941,8 @@ struct AirSimSettings {
is_record_ui_visible = settings_json.getBool("RecordUIVisible", true);
engine_sound = settings_json.getBool("EngineSound", false);
enable_rpc = settings_json.getBool("EnableRpc", enable_rpc);
speed_in_mph = settings_json.getBool("SpeedInMph", false);
speed_unit_factor = settings_json.getFloat("SpeedUnitFactor", 1.0f);
speed_unit_label = settings_json.getString("SpeedUnitLabel", "m\\s");
log_messages_visible = settings_json.getBool("LogMessagesVisible", true);

{ //load origin geopoint
Expand Down
14 changes: 5 additions & 9 deletions Unreal/Plugins/AirSim/Source/Vehicles/Car/CarPawn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,19 +270,15 @@ void ACarPawn::BeginPlay()

void ACarPawn::updateHUDStrings()
{

float speed_unit_factor = AirSimSettings::singleton().speed_unit_factor;
FText speed_unit_label = FText::FromString(FString(AirSimSettings::singleton().speed_unit_label.c_str()));
float vel = FMath::Abs(GetVehicleMovement()->GetForwardSpeed() / 100); //cm/s -> m/s
float vel_rounded = FMath::FloorToInt(vel * 10) / 10.0f;
float vel_rounded = FMath::FloorToInt(vel * 10 * speed_unit_factor) / 10.0f;
int32 Gear = GetVehicleMovement()->GetCurrentGear();
bool speed_in_mph = AirSimSettings::singleton().speed_in_mph;
FText speed_units = FText::FromString("m/s");

if (speed_in_mph == true){
vel_rounded = FMath::FloorToInt(vel_rounded * 2.23694f);
speed_units = FText::FromString("mph");
}

// Using FText because this is display text that should be localizable
last_speed_ = FText::Format(LOCTEXT("SpeedFormat", "{0} {1}"), FText::AsNumber(vel_rounded), speed_units);
last_speed_ = FText::Format(LOCTEXT("SpeedFormat", "{0} {1}"), FText::AsNumber(vel_rounded), speed_unit_label);

if (GetVehicleMovement()->GetCurrentGear() < 0)
{
Expand Down

0 comments on commit f61e68d

Please # to comment.