오늘은 게임 플레이내에서 구나 선, 점을 통해 매쉬가 없이도 화면에 나타날 수 있게 해보자
1. 디버그 구 그리기
일단 블루프린트상에서는 Draw Debug Sphere을 추가하여 만들 수 있다.
이렇게하면 0,0,0에 구가 나오게 된다.
이제 액터위치에서 구가 보이도록 만들어주자
이제 이걸 C++로 구현해보자
구현하려면 일단 DrawDebugHelpers 헤더파일을 추가해줘야한다.
DrawDebugSphere 함수를 통해 그려주면 되는데 이 함수의 매개변수에는 UWorld와 FVector가 들어가는데 이때
GetWorld GetActorLocation을 통해 값을 전달해주면 된다.
UWorld* World = GetWorld();
if (World)
{
FVector Location = GetActorLocation();
DrawDebugSphere(World, Location, 25.f, 24, FColor::Red, false, 30.f);
}
이것을 매크로 함수를 통해 구현해보자
#define THIRTY 30
#define DRAW_SPHERE(Location) if (GetWorld()) DrawDebugSphere(GetWorld(),Location,25.f,12,FColor::Red,true);
FVector Location = GetActorLocation();
DRAW_SPHERE(Location);
이 매크로 함수는 Slash.h에 넣어서 모든 클래스에서 사용가능하도록 만들어주자
Slash.h
// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
#define DRAW_SPHERE(Location) if (GetWorld()) DrawDebugSphere(GetWorld(),Location,25.f,12,FColor::Red,true);
#include "Slash\Slash.h"
동일하게 동작하는 것을 볼 수 있다.
2. 디버그 선 그리기
블루 프린트에서는 Draw Debug Line을 사용하여 선을 그릴 수 있다.
이제 이것을 코드로 구현해보자
C++에서는 DrawDebugLine으로 선을 그릴 수 있다.
if (World)
{
FVector Forward = GetActorForwardVector();
DrawDebugLine(World, Location, Location + Forward * 100.f, FColor::Red, true, -1.f, 0, 1.f);
}
이제 이것을 매크로로 만들어 간결하게 쓸 수 있도록 만들어 보자
#define DRAW_LINE(StartLocation,EndLocation) if(GetWorld()) DrawDebugLine(World, StartLocation,EndLocation, FColor::Red, true, -1.f, 0, 1.f);
DRAW_LINE(Location, Location+Forward * 100.f);
3.디버그 점 그리기
블루 프린트에서는 Draw Debug Point를 통해 그릴 수 있다.
★디버그 포인트는 크기가 어느곳에서 보던 일정하다 하지만 구나 선은 멀어질수록 작아진다
이제 이것을 코드로 구현해보자
코드에서는 DrawDebugPoint함수를 사용한다.
if (World)
{
DrawDebugPoint(World, Location + Forward * 100.f, 15, FColor::Red, true);
}
이제 편하게 사용할 수 있도록 매크로 함수로 만들어주자
#define DRAW_POINT(Location) if(GetWorld()) DrawDebugPoint(World, Location, 15.f, FColor::Red, true);
DRAW_POINT(Location + Forward * 100.f);
추가적으로 점과 선을 한번에 그려주는 즉 벡터를 그려주는 매크로 함수를 만들어보자 벡터는 이전에 만들었던 라인과 점을 그리는 것을 통합하여 만들어주자
#define DRAW_VECTOR(StartLocation,EndLocation) if (GetWorld()) \
{ \
DrawDebugLine(World, StartLocation, EndLocation, FColor::Red, true, -1.f, 0, 1.f); \
DrawDebugPoint(World, EndLocation, 15.f, FColor::Red, true); \
}
/*DRAW_LINE(Location, Location + Forward * 100.f);
DRAW_POINT(Location + Forward * 100.f);*/
DRAW_VECTOR(Location, Location + Forward * 100.f);
이제 매크로 함수를 모아둔 헤더파일을 하나 만들어주자
Source/Slash/
경로에 넣어주자
DebugMacros.h
#pragma once
#include "DrawDebugHelpers.h"
#define DRAW_SPHERE(Location) if (GetWorld()) DrawDebugSphere(GetWorld(),Location,25.f,12,FColor::Red,true);
#define DRAW_LINE(StartLocation,EndLocation) if(GetWorld()) DrawDebugLine(World, StartLocation,EndLocation, FColor::Red, true, -1.f, 0, 1.f);
#define DRAW_POINT(Location) if(GetWorld()) DrawDebugPoint(World, Location, 15.f, FColor::Red, true);
#define DRAW_VECTOR(StartLocation,EndLocation) if (GetWorld()) \
{ \
DrawDebugLine(World, StartLocation, EndLocation, FColor::Red, true, -1.f, 0, 1.f); \
DrawDebugPoint(World, EndLocation, 15.f, FColor::Red, true); \
}
'게임공부 > Unreal Engine' 카테고리의 다른 글
[Unreal Engine][C++]5.Pawn 클래스 (0) | 2024.07.15 |
---|---|
[Unreal Engine][C++]4. 캐릭터 움직이기 (1) | 2024.07.11 |
[Unreal Engine][C++]2. C++살펴보기 (0) | 2024.07.09 |
[Unreal Engine][C++]1.시작 (0) | 2024.07.08 |
[Unreal Engine][C++]0.오픈월드 (0) | 2024.07.04 |