1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | // Sets default values ARevolveCameraContorller::ARevolveCameraContorller() { // Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it. PrimaryActorTick.bCanEverTick = true; RootComp = CreateDefaultSubobject<USceneComponent>(TEXT("Root")); RootComp->ComponentTags.Add("RollingBall"); RootComponent = RootComp; RevolveCam = CreateDefaultSubobject<UCameraComponent>(TEXT("Revolve Cam")); RevolveCam->SetRelativeLocation(FVector(0.0f, 0.0f, 150.0f)); RevolveCam->SetRelativeRotation(FRotator(-10.0f, 180.0f, 0.0f).Quaternion()); RevolveCam->AttachTo(RootComponent); RevolveRadious = 300.0f; CurrentRevolveAngle = 0.0f; RevolveAngleSpeed = 30.0f; } // Called when the game starts or when spawned void ARevolveCameraContorller::BeginPlay() { Super::BeginPlay(); } // Called every frame void ARevolveCameraContorller::Tick( float DeltaTime ) { Super::Tick( DeltaTime ); CurrentRevolveAngle += (RevolveAngleSpeed * DeltaTime); if (CurrentRevolveAngle > 360.0f) { CurrentRevolveAngle = 0.0f; } FVector newPosition = GetNewPosition(CurrentRevolveAngle, RevolveRadious); if (Cameratarget != nullptr) { FVector targetPos = Cameratarget->GetTransform().GetLocation(); targetPos.Z = 0.0f; newPosition = targetPos + newPosition; } RootComponent->SetWorldLocation(newPosition); RevolveCam->SetRelativeRotation(FRotator(-10.0f, 180.0f + CurrentRevolveAngle, 0.0f).Quaternion()); } FVector ARevolveCameraContorller::GetNewPosition(const float angle, const float radious) { FVector Pos = FVector::ZeroVector; float CurrentAngle = 0.0f; if (angle < 180.0f) { CurrentAngle = angle; } else if (angle < 360.0f) { CurrentAngle = 360.0f - angle; } float acos = (90.0f - CurrentAngle) / 90.0f; Pos.X = acos; float x2 = acos * acos; if (angle < 180.0f) { Pos.Y = FMath::Sqrt(1 - x2); } else if (angle < 360.0f) { Pos.Y = - FMath::Sqrt(1 - x2); } //FString str = FString::Printf(TEXT("Angle : %.1f / acos : %.1f / PosX : %.1f / PosY : %.1f "), angle, acos , Pos.X, Pos.Y); // //GEngine->AddOnScreenDebugMessage(-1, 0.2f, FColor::Green, str); return Pos * radious; } | cs |
*** aCos의 값은 0 <= angle <= π ( -1 <= value <= -1) 이다.
'Unreal Engine4 or 5 > 코드' 카테고리의 다른 글
언리얼 C++ 튜토리얼 003.CountDown Timer (0) | 2016.04.25 |
---|---|
UE4 C++ 비주얼 스튜디오 에서 BreakPoint 사용하는법 (0) | 2016.04.25 |
UE4 블루 프린트 함수 _Implementation (0) | 2016.04.21 |
UE4 Actor의 이동 (0) | 2016.04.21 |
UE4 lerp를 이용한 자연스러운 회전과 angle 구하기 (0) | 2016.04.20 |