[UE] C++에서 SpringArm과 Camera 구현하기

2023. 12. 22. 12:37·Unreal 공부/Unreal Engine 4 C++ The Ultimate Shooter

우선 헤더에 전방 선언을통해 포인터 변수를 생성해주고 ,Getter 함수를 UE INLINE 매크로로 선언해준다.

※ 전방 선언이란?
include를 하면 코드의 양이 증가하는데, 헤더에서 변수 선언시 구현 부분(멤버 함수 및 변수)이 필요 없는 경우에는 [class USpringArmComponent] 처럼 사용하여 구현부의 링킹을 미룬다. 주로 CPP파일에서 구현 부분을 사용하기 때문에 헤더의 크기를 줄이는 기법이다. (하나의 헤더를 여러 cpp이 include할 때 필요한 구현 부분만 cpp가 include 할 수 있어 코드의 양을 줄여준다.)
// ShooterCharacter.h
class UCameraComponent;
class USpringArmComponent;

...

public:
	FORCEINLINE USpringArmComponent *GetCameraBoom() const { return CameraBoom; };

	FORCEINLINE UCameraComponent *GetFollowCamera() const { return FollowCamera; };

private:
	// CameraBoom은 카메라를 캐릭터 뒷쪽에 위치시킵니다.
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
	USpringArmComponent *CameraBoom;

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Camera, meta = (AllowPrivateAccess = "true"))
	UCameraComponent *FollowCamera;

 

 

CPP 파일에서 필요한 부분을 include하고,  생성자에서 CameraBoom과 FollowCamera의 생성과 설정을 한다.

// ShooterCharacter.cpp
AShooterCharacter::AShooterCharacter()
{
	// Set this character to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

	// Create a CameraBoom (pulls in towards the character if there is a collision)
	CameraBoom = CreateDefaultSubobject<USpringArmComponent>(TEXT("CameraBoom"));
	CameraBoom->SetupAttachment(RootComponent);
	CameraBoom->TargetArmLength = 300.f;		// The camera follows at this distance behinde the character
	CameraBoom->bUsePawnControlRotation = true; // Rotate the arm based on the controller

	// Create a follow camera
	FollowCamera = CreateDefaultSubobject<UCameraComponent>(TEXT("FollowCamera"));
	FollowCamera->SetupAttachment(CameraBoom, USpringArmComponent::SocketName); // Attach camera to end of CameraBoom [const FName USpringArmComponent::SocketName(TEXT("SpringEndpoint"));]
	FollowCamera->bUsePawnControlRotation = false;								// Camera does not rotate relative to arm
}
  • CreateDefaultSubobject : 컴포넌트 또는 서브오브젝트를 생성하는 기능으로, 자식 클래스를 생성하고 부모 클래스를 반환할 수 있게 합니다.
  • SetupAttachment : 컴포넌트가 등록될 때 붙여질 원하는 부착 부모(Attach Parent)와 소켓 이름(SocketName)을 초기화합니다.
  • USpringArmComponent::SocketName : SpringArm의 종단점의 소켓 FName 변수
    • FName USpringArmComponent::SocketName(TEXT("SpringEndpoint"))
  • TargetArmLength : USpringArmComopnent가 가지는 SpringArm의 길이 변수
  • bUsePawnControlRotation : 컴포넌트가 폰(게임 내 캐릭터나 오브젝트)의 시야 또는 조종 회전을 따를지 여부를 결정합니다. 활성화되면 컴포넌트는 폰의 회전을 따라갑니다.

 

컴파일 후 구현된 BP_ShooterCharacter

'Unreal 공부 > Unreal Engine 4 C++ The Ultimate Shooter' 카테고리의 다른 글

Animation - 5  (1) 2023.12.31
Animation - 4  (1) 2023.12.31
Animation - 3  (1) 2023.12.30
Animation - 2  (1) 2023.12.28
Animation  (0) 2023.12.27
'Unreal 공부/Unreal Engine 4 C++ The Ultimate Shooter' 카테고리의 다른 글
  • Animation - 4
  • Animation - 3
  • Animation - 2
  • Animation
메카인
메카인
  • 메카인
    메카인의 지식창고
    메카인
  • 전체
    오늘
    어제
    • 분류 전체보기
      • 코딩 공부
        • TIL(Today I Learn)
        • TIL
        • 백준(C++)
        • Python
        • 알고리즘
        • 프로젝트 회고
      • C++
        • C++
        • C++ STL
        • C,C++ mCoding yotube
      • 게임개발
        • 언데드서바이벌_골드메탈_클론코딩
        • 3D_골드메탈_클론코딩
        • 유니티_문제해결
        • 게임 수학
      • Unreal 공부
        • UE5 GameDev
        • Unreal Engine 4 C++ The Ult..
      • 교재 문제 풀이
        • 운영체제
      • 정보처리기사
        • 정처기 요약
        • 정처기 오답노트
      • 학교수업
        • 데이터베이스
        • 프로그래밍 언어론
        • 리눅스 시스템
        • 네트워크
      • 일상
        • 주식
        • 독서
        • 일기
      • (비공개 전용)
        • memory
        • Build
        • OOP
        • Smart Pointer
        • lamda
        • 게임 수학
        • 모던 C++
        • 모던 C++ STL
        • 모던 C++ Concurrency, Paralle..
        • 책
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
    • 글쓰기
    • 블로그 관리
  • 링크

  • 공지사항

    • 공지사항 - 인생과 블로그의 목표
  • 인기 글

  • 태그

    ~
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
메카인
[UE] C++에서 SpringArm과 Camera 구현하기
상단으로

티스토리툴바