diff --git a/Unreal/Plugins/AirSim/Source/CameraDirector.cpp b/Unreal/Plugins/AirSim/Source/CameraDirector.cpp index d092208da5..5b10af0758 100644 --- a/Unreal/Plugins/AirSim/Source/CameraDirector.cpp +++ b/Unreal/Plugins/AirSim/Source/CameraDirector.cpp @@ -28,7 +28,7 @@ void ACameraDirector::Tick(float DeltaTime) Super::Tick(DeltaTime); if (mode_ == ECameraDirectorMode::CAMERA_DIRECTOR_MODE_MANUAL) { - manual_pose_controller_->updateActorPose(); + manual_pose_controller_->updateActorPose(DeltaTime); } else if (mode_ == ECameraDirectorMode::CAMERA_DIRECTOR_MODE_SPRINGARM_CHASE) { //do nothing diff --git a/Unreal/Plugins/AirSim/Source/ManualPoseController.cpp b/Unreal/Plugins/AirSim/Source/ManualPoseController.cpp index c6887e9484..9671c60f4e 100644 --- a/Unreal/Plugins/AirSim/Source/ManualPoseController.cpp +++ b/Unreal/Plugins/AirSim/Source/ManualPoseController.cpp @@ -41,9 +41,11 @@ AActor* UManualPoseController::getActor() const return actor_; } -void UManualPoseController::updateActorPose() +void UManualPoseController::updateActorPose(float delta_sec) { if (actor_ != nullptr) { + updateDeltaPosition(delta_sec); + FVector location = actor_->GetActorLocation(); FRotator rotation = actor_->GetActorRotation(); actor_->SetActorLocationAndRotation(location + delta_position_, rotation + delta_rotation_); @@ -65,7 +67,7 @@ void UManualPoseController::getActorDeltaPose(FVector& delta_position, FRotator& void UManualPoseController::resetDelta() { - delta_position_ = FVector::ZeroVector; + delta_position_ = input_positive_ = inpute_negative_ = last_velocity_ = FVector::ZeroVector; delta_rotation_ = FRotator::ZeroRotator; } @@ -107,36 +109,40 @@ void UManualPoseController::enableBindings(bool enable) right_yaw_binding_->bConsumeInput = down_pitch_binding_->bConsumeInput = enable; } -void UManualPoseController::inputManualLeft(float val) +void UManualPoseController::updateDeltaPosition(float delta_sec) { - if (!FMath::IsNearlyEqual(val, 0.f)) { - delta_position_ += actor_->GetActorRotation().RotateVector(FVector(0,-val*10,0)); + FVector input = input_positive_ - inpute_negative_; + if (!FMath::IsNearlyZero(input.SizeSquared())) { + last_velocity_ += input * (acceleration_ * delta_sec); + delta_position_ += actor_->GetActorRotation().RotateVector(last_velocity_ * delta_sec); + } else { + delta_position_ = last_velocity_ = FVector::ZeroVector; } } + +void UManualPoseController::inputManualLeft(float val) +{ + inpute_negative_.Y = val; +} void UManualPoseController::inputManualRight(float val) { - if (!FMath::IsNearlyEqual(val, 0.f)) - delta_position_ += actor_->GetActorRotation().RotateVector(FVector(0, val * 10, 0)); + input_positive_.Y = val; } void UManualPoseController::inputManualForward(float val) { - if (!FMath::IsNearlyEqual(val, 0.f)) - delta_position_ += actor_->GetActorRotation().RotateVector(FVector(val * 10, 0, 0)); + input_positive_.X = val; } void UManualPoseController::inputManualBackward(float val) { - if (!FMath::IsNearlyEqual(val, 0.f)) - delta_position_ += actor_->GetActorRotation().RotateVector(FVector(-val * 10, 0, 0)); + inpute_negative_.X = val; } void UManualPoseController::inputManualMoveUp(float val) { - if (!FMath::IsNearlyEqual(val, 0.f)) - delta_position_ += actor_->GetActorRotation().RotateVector(FVector(0, 0, val * 10)); + input_positive_.Z = val; } void UManualPoseController::inputManualDown(float val) { - if (!FMath::IsNearlyEqual(val, 0.f)) - delta_position_ += actor_->GetActorRotation().RotateVector(FVector(0, 0, -val * 10)); + inpute_negative_.Z = val; } void UManualPoseController::inputManualLeftYaw(float val) { diff --git a/Unreal/Plugins/AirSim/Source/ManualPoseController.h b/Unreal/Plugins/AirSim/Source/ManualPoseController.h index 1619b9ebcb..19ff9d15d4 100644 --- a/Unreal/Plugins/AirSim/Source/ManualPoseController.h +++ b/Unreal/Plugins/AirSim/Source/ManualPoseController.h @@ -12,7 +12,7 @@ class AIRSIM_API UManualPoseController : public UObject { void initializeForPlay(); void setActor(AActor* actor, bool enable_binding = true); AActor* getActor() const; - void updateActorPose(); + void updateActorPose(float delta_sec); void restoreLastActor(); void enableBindings(bool enable); void getActorDeltaPose(FVector& delta_position, FRotator& delta_rotation, bool reset_delta); @@ -32,6 +32,8 @@ class AIRSIM_API UManualPoseController : public UObject { void setupInputBindings(); void removeInputBindings(); void resetDelta(); + void updateDeltaPosition(float delta_sec); + private: FInputAxisBinding *left_binding_, *right_binding_, *up_binding_, *down_binding_; @@ -47,4 +49,8 @@ class AIRSIM_API UManualPoseController : public UObject { FRotator delta_rotation_; AActor *actor_, *last_actor_; + + float acceleration_ = 10; + FVector input_positive_, inpute_negative_; + FVector last_velocity_; }; \ No newline at end of file