UE4绘制线和平面,在平面内随机取点

1.绘制线

UWorld* World = GetWorld();
if (World)
{
   
    FlushPersistentDebugLines(World);

    for (int i = 0; i < PointLocationArr.Num() - 1; ++i)
    {
   
        //画线
        DrawDebugLine(
        World,
        PointLocationArr[i],
        PointLocationArr[i + 1],
        FColor::Yellow,
        true,
        0.0f,
        SDPG_MAX,
        0.0f
        );
    }
}

2.绘制平面(代码是逆时针画)

得先在Actor里创建一个Component

	//Procedural Mesh Component
	UPROPERTY(VisibleAnywhere)
		UProceduralMeshComponent* ProceduralMeshComponent;

.h

/**
* Triangulate a polygon as projected to the XY plane, using ear clipping.  Orientation of triangles will match orientation of input curve
* Adapted from TriangulateSimplePolygon in GeometryProcessing's PolygonTriangulation.cpp, to avoid using any types/functions in GeometryProcessing
*
* @return bool indicating orientation of output triangles
*/
bool TriangulateSimpleXYPlanarPolygon(const TArray<FVector>& VertexPositions, TArray<FIntVector>& OutTriangles);

.cpp

bool FSplineMakerEdMode::TriangulateSimpleXYPlanarPolygon(const TArray<FVector>& VertexPositions, TArray<FIntVector>& OutTriangles)
{
   
// helper functions for analyzing XY-projected triangles
struct Local
{
   
// returns 2*signed_area of the triangle formed by pts A, B, C
static inline float XYArea2(const FVector& A, const FVector& B, const FVector& C)
{
   
return (A.X * B.Y - A.Y * B.X) + (B.X * C.Y - B.Y * C.X) + (C.X * A.Y - C.Y * A.X);
}
static inline bool XYIsTriangleFlipped(float OrientationSign, const FVector& A, const FVector& B, const FVector& C)
{
   
float XYSignedDoubleArea = XYArea2(A, B, C);
return XYSignedDoubleArea * OrientationSign < 0;
}
static inline bool XYIsInsideTriangle(const FVector& A, const FV
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值