Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
sytelus committed Nov 22, 2017
1 parent a62163c commit 400b024
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Unreal/Plugins/AirSim/Source/CameraDirector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 21 additions & 15 deletions Unreal/Plugins/AirSim/Source/ManualPoseController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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_);
Expand All @@ -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;
}

Expand Down Expand Up @@ -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)
{
Expand Down
8 changes: 7 additions & 1 deletion Unreal/Plugins/AirSim/Source/ManualPoseController.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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_;
Expand All @@ -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_;
};

0 comments on commit 400b024

Please sign in to comment.