(五)Slate编辑器之射线

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ywjun0919/article/details/86693816

https://api.unrealengine.com/CHN/Engine/Physics/Tracing/index.html

这里使用 World->LineTraceSingleByChannel

void FProEditorModule::DrawPoint(FVector point)
{
	UWorld* world = GetWorld();
	FVector start = point + FVector(0, 0, 1000);
	FVector end = start + FVector(0, 0, -2000);
	DrawDebugLine(world, start, end, FColor(255, 0, 0), true, 1000000, 0, 12.333);
	FVector forward = FVector(0, 0, 1);
	FHitResult OutHit;
	FCollisionQueryParams TraceParams;
	TraceParams.bTraceComplex = true;
	if (world->LineTraceSingleByChannel(OutHit, start, end, ECC_WorldStatic, TraceParams))
	{
		DrawCircle(world, OutHit.ImpactPoint+ FVector(0, 0, 100), FVector(1, 0, 0), FVector(0, 1, 0), FColor::Blue, 50, 20, true, 10000);
	}
}
UWorld * FProEditorModule::GetWorld()
{
	UWorld* world = NULL;
	for (auto& viewPort : GEditor->LevelViewportClients)
	{
		world = viewPort->GetWorld();
		if (NULL != world)
		{
			break;
		}
	}
	return world;
}

其中 划线部分使用 #include "DrawDebugHelpers.h"

DrawDebugHelpers中有很多绘制的方法,这里只贴一部分

效果图:

最后需要注意的是:使用 FlushPersistentDebugLines(GetWorld());去除Level中的绘制

猜你喜欢

转载自blog.csdn.net/ywjun0919/article/details/86693816