회전 상태 저장

고스트 프리뷰 회전을 위해 GridBuildComponent에 회전 상태를 저장했다.

FIntPoint BaseBuildingSize = FIntPoint(1, 1);
FIntPoint CurrentBuildingSize = FIntPoint(1, 1);

int32 CurrentRotationStep = 0;

BaseBuildingSize : 데이터 테이블에서 가져온 원본 건물 크기 / 회전해도 변하지 않는 기준값

CurrentBuildingSize : 현재 회전 상태가 반영된 실제 점유 크기 / 90도 또는 270도 회전 시 X/Y가 바뀜

예를 들어 원래 건물 크기가 2x1이라면 다음과 같이 처리된다.

0도 → CurrentBuildingSize = (2, 1)
90도 → CurrentBuildingSize = (1, 2)
180도 → CurrentBuildingSize = (2, 1)
270도 → CurrentBuildingSize = (1, 2)

이렇게 해야 고스트 프리뷰의 외형만 회전하는 것이 아니라, 실제 그리드 점유 영역도 올바르게 계산된다.


회전 구현

회전은 CurrentRotationStep 값을 0~3 사이에서 순환시키는 방식으로 처리했다.

const int32 Step = Direction > 0 ? 1 : -1;

CurrentRotationStep = (CurrentRotationStep + Step + 4) % 4;

CurrentBuildingSize = GetRotatedBuildingSize();

회전값 계산

FRotator(0.0f, CurrentRotationStep * 90.0f, 0.0f);

즉, CurrentRotationStep이 1이면 90도, 2이면 180도, 3이면 270도가 된다.


회전된 그리드 크기 계산

비정사각형 건물은 90도 회전하면 점유 크기의 X/Y가 바뀌어야 한다.

if (CurrentRotationStep % 2 == 0)
{
    return BaseBuildingSize;
}

return FIntPoint(BaseBuildingSize.Y, BaseBuildingSize.X);

0도와 180도에서는 원래 크기를 그대로 사용하고 90도와 270도에서는 X/Y를 교환한다.


마우스 휠 입력 처리

const float AxisValue = Value.Get<float>();
const int32 Direction = AxisValue > 0.0f ? -1 : 1;

GridBuildComponent->RotatePlacementPreview(Direction);

Mouse Wheel Up → -1
Mouse Wheel Down → +1

따라서 휠을 올리면 왼쪽으로, 휠을 내리면 오른쪽으로 회전하게 처리했다.


정리

건물 설치 중 고스트 프리뷰를 마우스 휠로 90도씩 회전시킬 수 있는 기능을 추가하였다.

1. 회전 단계 저장
2. 고스트 프리뷰 회전 적용
3. 회전 상태에 따른 그리드 점유 크기 갱신
4. 실제 설치 건물 Spawn 회전 적용
5. 건설 모드 종료 시 회전 상태 초기화