• UE4中提供了很多预定义的调试绘制函数,在做调试的时候还是比较方便的。可以在场景里绘制点、线、圆、球、箭头、椎体、胶囊、甚至样条线、字符串、网格等等,基本上该有的都有了。比较赞的是,你能控制线条的厚度,调试的时候就比较直观了。
    要使用这些函数,只需要包含DrawDebugHelpers.h 头文件即可。下面介绍几个主要的绘制函数:

1.绘制点

view source print ?

1.
       ENGINE_API voidDrawDebugPoint(constUWorld* InWorld, FVector const& Position, floatSize, FColor const& PointColor, bool bPersistentLines = false, floatLifeTime=-1.f, uint8 DepthPriority = 0);
  • 可选参数里面,我们可以控制点的尺寸、颜色、持续时间等。bPersistentLines表示,当前绘制的整个对象,是不是持久对象,设为true,它会一直显示当前World,直到你调用下面这个方法,释放它:

view source print ?

1. voidFlushPersistentDebugLines(constUWorld* InWorld);

  • 其他的绘制函数,此参数意义都是一样的。

2.绘制线

view source print ?

1.
       ENGINE_API voidDrawDebugLine(constUWorld* InWorld, FVector const& LineStart, FVector const& LineEnd, FColor const& Color, bool bPersistentLines = false, floatLifeTime=-1.f, uint8 DepthPriority = 0, floatThickness = 0.f);
  • 注意Thickness这个参数,它控制线条的厚度。

3.绘制箭头

view source print ?

1.
       ENGINE_API voidDrawDebugDirectionalArrow(constUWorld* InWorld, FVector const& LineStart, FVector const& LineEnd, floatArrowSize, FColor const& Color, bool bPersistentLines = false, floatLifeTime=-1.f, uint8 DepthPriority = 0);
  • 这个函数绘制一个有向箭头,和绘制线差不多,ArrowSize是箭头的尺寸。

4.绘制Box

view source print ?

1.
       ENGINE_API voidDrawDebugBox(constUWorld* InWorld, FVector const& Center, FVector const& Extent, FColor const& Color, bool bPersistentLines = false, floatLifeTime=-1.f, uint8 DepthPriority = 0);
2.
       /** Draw a debug box with rotation */
3.
       ENGINE_API voidDrawDebugBox(constUWorld* InWorld, FVector const& Center, FVector const& Box, constFQuat & Rotation, FColor const& Color, bool bPersistentLines = false, floatLifeTime=-1.f, uint8 DepthPriority = 0);
  • 第一个根据Box的尺寸绘制,第二个额外的可以按照一定的旋转绘制。

5.绘制球体

view source print ?

1.
       ENGINE_API voidDrawDebugSphere(constUWorld* InWorld, FVector const& Center, floatRadius, int32 Segments, FColor const& Color, bool bPersistentLines = false, floatLifeTime=-1.f, uint8 DepthPriority = 0);
  • Segments控制球体的分段,越大越精细。

6.其他

  • 还有很多不太常用的,可以绘制2D圆、圆柱、椎体、平截头体、胶囊等。这里只列出来,具体见DrawDebugHelpers.h

view source print ?

01.
       ENGINE_API voidDrawDebugCoordinateSystem(constUWorld* InWorld, FVector const& AxisLoc, FRotator const& AxisRot, floatScale, bool bPersistentLines = false, floatLifeTime=-1.f, uint8 DepthPriority = 0);
02.
       /** Draw Debug Circle */
03.
       ENGINE_API voidDrawDebugCircle(constUWorld* InWorld, constFMatrix& TransformMatrix, floatRadius, int32 Segments, constFColor& Color, bool bPersistentLines = false, floatLifeTime=-1.f, uint8 DepthPriority = 0);
04.
       /** Draw Debug 2D donut */
05.
       ENGINE_API voidDrawDebug2DDonut(constUWorld* InWorld, constFMatrix& TransformMatrix, floatInnerRadius, floatOuterRadius, int32 Segments, constFColor& Color, bool bPersistentLines = false, floatLifeTime=-1.f, uint8 DepthPriority = 0);
06.
       /** Draw a debug sphere */
07.
       ENGINE_API voidDrawDebugSphere(constUWorld* InWorld, FVector const& Center, floatRadius, int32 Segments, FColor const& Color, bool bPersistentLines = false, floatLifeTime=-1.f, uint8 DepthPriority = 0);
08.
       /** Draw a debug cylinder */
09.
       ENGINE_API voidDrawDebugCylinder(constUWorld* InWorld, FVector const& Start, FVector const& End, floatRadius, int32 Segments, FColor const& Color, bool bPersistentLines = false, floatLifeTime=-1.f, uint8 DepthPriority = 0);
10.
       ENGINE_API voidDrawDebugCone(constUWorld* InWorld, FVector const& Origin, FVector const& Direction, floatLength, floatAngleWidth, floatAngleHeight, int32 NumSides, FColor const& Color, bool bPersistentLines=false, floatLifeTime=-1.f, uint8 DepthPriority = 0);
11.
       /** Used by gameplay when defining a cone by a vertical and horizontal dot products. */
12.
       ENGINE_API voidDrawDebugAltCone(constUWorld* InWorld, FVector const& Origin, FRotator const& Rotation, floatLength, floatAngleWidth, floatAngleHeight, FColor const& DrawColor, bool bPersistentLines=false, floatLifeTime=-1.f, uint8 DepthPriority=0);
13.
       ENGINE_API voidDrawDebugString(constUWorld* InWorld, FVector const& TextLocation, constFString& Text, classAActor* TestBaseActor = NULL, FColor const& TextColor = FColor::White, floatDuration = -1.000000);
14.
       ENGINE_API voidDrawDebugFrustum(constUWorld* InWorld, constFMatrix& FrustumToWorld, FColor const& Color, bool bPersistentLines = false, floatLifeTime=-1.f, uint8 DepthPriority = 0);
15.
       /** Draw a capsule using the LineBatcher */
16.
       ENGINE_API voidDrawDebugCapsule(constUWorld* InWorld, FVector const& Center, floatHalfHeight, floatRadius, constFQuat & Rotation, FColor const& Color, bool bPersistentLines=false, floatLifeTime=-1.f, uint8 DepthPriority = 0);
17.
       /** Draw a debug camera shape.  FOV is full angle in degrees. */
18.
       ENGINE_API voidDrawDebugCamera(constUWorld* InWorld, FVector const& Location, FRotator const& Rotation, floatFOVDeg, floatScale=1.f, FColor const& Color=FColor::White, bool bPersistentLines=false, floatLifeTime=-1.f, uint8 DepthPriority = 0);
19.
       ENGINE_API voidFlushDebugStrings(constUWorld* InWorld);
20.
        
21.
       ENGINE_API voidDrawDebugSolidBox(constUWorld* InWorld, FVector const& Center, FVector const& Box, FColor const& Color, bool bPersistent=false, floatLifeTime=-1.f, uint8 DepthPriority = 0);
22.
       ENGINE_API voidDrawDebugSolidBox(constUWorld* InWorld, FVector const& Center, FVector const& Extent, FQuat const& Rotation, FColor const& Color, bool bPersistent=false, floatLifeTime=-1.f, uint8 DepthPriority = 0);
23.
       ENGINE_API voidDrawDebugMesh(constUWorld* InWorld, TArray<FVector> const& Verts, TArray<int32> const& Indices, FColor const& Color, bool bPersistent=false, floatLifeTime=-1.f, uint8 DepthPriority = 0);
24.
       ENGINE_API voidDrawDebugSolidPlane(constUWorld* InWorld, FPlane const& P, FVector const& Loc, floatSize, FColor const& Color, bool bPersistent=false, floatLifeTime=-1, uint8 DepthPriority = 0);
25.
        
26.
       /* Draws a 2D Histogram of size 'DrawSize' based FDebugFloatHistory struct, using DrawTransform for the position in the world. */
27.
       ENGINE_API voidDrawDebugFloatHistory(UWorld const& WorldRef, FDebugFloatHistory const& FloatHistory, FTransform const& DrawTransform, FVector2D const& DrawSize, FColor const& DrawColor, bool const& bPersistent = false, floatconst& LifeTime = -1.f, uint8 const& DepthPriority = 0);
28.
        
29.
       /* Draws a 2D Histogram of size 'DrawSize' based FDebugFloatHistory struct, using DrawLocation for the location in the world, rotation will face camera of first player. */
30.
       ENGINE_API voidDrawDebugFloatHistory(UWorld const& WorldRef, FDebugFloatHistory const& FloatHistory, FVector const& DrawLocation, FVector2D const& DrawSize, FColor const& DrawColor, bool const& bPersistent = false, floatconst& LifeTime = -1.f, uint8 const& DepthPriority = 0);


阿里云国内75折 回扣 微信号:monov8
阿里云国际,腾讯云国际,低至75折。AWS 93折 免费开户实名账号 代冲值 优惠多多 微信号:monov8 飞机:@monov6
标签: c++