Add game modes, states and controller
This commit is contained in:
parent
135c02c59b
commit
24a7d23c96
|
@ -0,0 +1,15 @@
|
|||
// CARLA, Copyright (C) 2017 Computer Vision Center (CVC)
|
||||
|
||||
#include "Carla.h"
|
||||
#include "CarlaGameMode.h"
|
||||
|
||||
#include "CarlaGameState.h"
|
||||
#include "CarlaPlayerState.h"
|
||||
#include "CarlaServerController.h"
|
||||
|
||||
ACarlaGameMode::ACarlaGameMode()
|
||||
{
|
||||
PlayerControllerClass = ACarlaServerController::StaticClass();
|
||||
GameStateClass = ACarlaGameState::StaticClass();
|
||||
PlayerStateClass = ACarlaPlayerState::StaticClass();
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
// CARLA, Copyright (C) 2017 Computer Vision Center (CVC)
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "GameFramework/GameModeBase.h"
|
||||
#include "CarlaGameMode.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class CARLA_API ACarlaGameMode : public AGameModeBase
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
ACarlaGameMode();
|
||||
};
|
|
@ -0,0 +1,8 @@
|
|||
// CARLA, Copyright (C) 2017 Computer Vision Center (CVC)
|
||||
|
||||
#include "Carla.h"
|
||||
#include "CarlaGameState.h"
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
// CARLA, Copyright (C) 2017 Computer Vision Center (CVC)
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "GameFramework/GameStateBase.h"
|
||||
#include "CarlaGameState.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class CARLA_API ACarlaGameState : public AGameStateBase
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
|
@ -0,0 +1,8 @@
|
|||
// CARLA, Copyright (C) 2017 Computer Vision Center (CVC)
|
||||
|
||||
#include "Carla.h"
|
||||
#include "CarlaPlayerState.h"
|
||||
|
||||
|
||||
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
// CARLA, Copyright (C) 2017 Computer Vision Center (CVC)
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "GameFramework/PlayerState.h"
|
||||
#include "CarlaPlayerState.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class CARLA_API ACarlaPlayerState : public APlayerState
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
|
||||
|
||||
|
||||
};
|
|
@ -0,0 +1,81 @@
|
|||
// CARLA, Copyright (C) 2017 Computer Vision Center (CVC)
|
||||
|
||||
#include "Carla.h"
|
||||
#include "CarlaServerController.h"
|
||||
|
||||
#include "Camera/CameraComponent.h"
|
||||
#include "GameFramework/Pawn.h"
|
||||
#include "GameFramework/SpringArmComponent.h"
|
||||
// #include "CarlaPlayerCameraManager.h"
|
||||
|
||||
ACarlaServerController::ACarlaServerController()
|
||||
{
|
||||
// PlayerCameraManagerClass = ACarlaPlayerCameraManager::StaticClass();
|
||||
bAutoManageActiveCameraTarget = false;
|
||||
|
||||
// Create the spring arm component
|
||||
SpringArm = CreateDefaultSubobject<USpringArmComponent>(TEXT("SpringArm0"));
|
||||
SpringArm->TargetOffset = FVector(0.f, 0.f, 200.f);
|
||||
SpringArm->SetRelativeRotation(FRotator(-15.f, 0.f, 0.f));
|
||||
SpringArm->SetupAttachment(RootComponent);
|
||||
SpringArm->TargetArmLength = 600.0f;
|
||||
SpringArm->bEnableCameraRotationLag = true;
|
||||
SpringArm->CameraRotationLagSpeed = 7.f;
|
||||
SpringArm->bInheritPitch = false;
|
||||
SpringArm->bInheritRoll = false;
|
||||
|
||||
// Do not collide, may clip into level.
|
||||
SpringArm->bDoCollisionTest = false;
|
||||
|
||||
// Create the camera component
|
||||
PlayerCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("Camera0"));
|
||||
PlayerCamera->SetupAttachment(SpringArm, USpringArmComponent::SocketName);
|
||||
PlayerCamera->bUsePawnControlRotation = false;
|
||||
PlayerCamera->FieldOfView = 90.f;
|
||||
}
|
||||
|
||||
ACarlaServerController::~ACarlaServerController() {}
|
||||
|
||||
void ACarlaServerController::SetupInputComponent()
|
||||
{
|
||||
Super::SetupInputComponent();
|
||||
check(InputComponent);
|
||||
InputComponent->BindAxis("CameraZoom", this, &ACarlaServerController::ChangeCameraZoom);
|
||||
InputComponent->BindAxis("CameraUp", this, &ACarlaServerController::ChangeCameraUp);
|
||||
InputComponent->BindAxis("CameraRight", this, &ACarlaServerController::ChangeCameraRight);
|
||||
InputComponent->BindAction("RestartLevel", IE_Pressed, this, &ACarlaServerController::RestartLevel);
|
||||
}
|
||||
|
||||
void ACarlaServerController::Possess(APawn *aPawn)
|
||||
{
|
||||
Super::Possess(aPawn);
|
||||
if (aPawn != nullptr) {
|
||||
SpringArm->AttachToComponent(
|
||||
aPawn->GetRootComponent(),
|
||||
FAttachmentTransformRules::KeepRelativeTransform);
|
||||
}
|
||||
}
|
||||
|
||||
void ACarlaServerController::CalcCamera(float DeltaTime, FMinimalViewInfo& OutResult)
|
||||
{
|
||||
PlayerCamera->GetCameraView(DeltaTime, OutResult);
|
||||
}
|
||||
|
||||
void ACarlaServerController::ChangeCameraZoom(float Value)
|
||||
{
|
||||
SpringArm->TargetArmLength = FMath::Clamp(SpringArm->TargetArmLength + Value, 200.0f, 1e4f);
|
||||
}
|
||||
|
||||
void ACarlaServerController::ChangeCameraUp(float Value)
|
||||
{
|
||||
auto rotation = SpringArm->GetRelativeTransform().Rotator();
|
||||
rotation.Pitch = FMath::Clamp(rotation.Pitch - Value, -80.0f, 0.0f);
|
||||
SpringArm->SetRelativeRotation(rotation);
|
||||
}
|
||||
|
||||
void ACarlaServerController::ChangeCameraRight(float Value)
|
||||
{
|
||||
auto rotation = SpringArm->GetRelativeTransform().Rotator();
|
||||
rotation.Yaw -= Value;
|
||||
SpringArm->SetRelativeRotation(rotation);
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
// CARLA, Copyright (C) 2017 Computer Vision Center (CVC)
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "GameFramework/PlayerController.h"
|
||||
#include "CarlaServerController.generated.h"
|
||||
|
||||
class USpringArmComponent;
|
||||
class UCameraComponent;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class CARLA_API ACarlaServerController : public APlayerController
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
ACarlaServerController();
|
||||
|
||||
~ACarlaServerController();
|
||||
|
||||
virtual void SetupInputComponent() override;
|
||||
|
||||
virtual void Possess(APawn *aPawn) override;
|
||||
|
||||
// virtual void UnPossess() override;
|
||||
|
||||
virtual void CalcCamera(float DeltaTime, FMinimalViewInfo& OutResult) override;
|
||||
|
||||
private:
|
||||
|
||||
void ChangeCameraZoom(float Value);
|
||||
|
||||
void ChangeCameraUp(float Value);
|
||||
|
||||
void ChangeCameraRight(float Value);
|
||||
|
||||
UPROPERTY()
|
||||
USpringArmComponent *SpringArm;
|
||||
|
||||
UPROPERTY()
|
||||
UCameraComponent *PlayerCamera;
|
||||
};
|
Loading…
Reference in New Issue