UE4 c++一些调试用的绘制函数

[复制链接]
查看3595 | 回复1 | 2017-6-29 14:35:48 | 显示全部楼层 |阅读模式
Unreal engine 4 C++ 一些调试用的绘制函数
UE4中提供了很多预定义的调试绘制函数,在做调试的时候还是比较方便的。可以在场景里绘制点、线、圆、球、箭头、椎体、胶囊、甚至样条线、字符串、网格等等,基本上该有的都有了。比较赞的是,你能控制线条的厚度,调试的时候就比较直观了。
要使用这些函数,只需要包含DrawDebugHelpers.h 头文件即可。下面介绍几个主要的绘制函数:
1.绘制点ENGINE_API void DrawDebugPoint(const UWorld* InWorld, FVector const& Position, float Size, FColor const& PointColor, bool bPersistentLines = false, float LifeTime=-1.f, uint8 DepthPriority = 0);  
可选参数里面,我们可以控制点的尺寸、颜色、持续时间等。bPersistentLines表示,当前绘制的整个对象,是不是持久对象,设为true,它会一直显示当前World,直到你调用下面这个方法,释放它:
void FlushPersistentDebugLines(const UWorld* InWorld);  
其他的绘制函数,此参数意义都是一样的。
2.绘制线
ENGINE_API void DrawDebugLine(const UWorld* InWorld, FVector const& LineStart, FVector const& LineEnd, FColor const& Color, bool bPersistentLines = false, float LifeTime=-1.f, uint8 DepthPriority = 0, float Thickness = 0.f);  
注意Thickness这个参数,它控制线条的厚度。
3.绘制箭头ENGINE_API void DrawDebugDirectionalArrow(const UWorld* InWorld, FVector const& LineStart, FVector const& LineEnd, float ArrowSize, FColor const& Color, bool bPersistentLines = false, float LifeTime=-1.f, uint8 DepthPriority = 0);  
这个函数绘制一个有向箭头,和绘制线差不多,ArrowSize是箭头的尺寸。
4.绘制Box、ENGINE_API void DrawDebugBox(const UWorld* InWorld, FVector const& Center, FVector const& Extent, FColor const& Color, bool bPersistentLines = false, float LifeTime=-1.f, uint8 DepthPriority = 0);
/** Draw a debug box with rotation */  
ENGINE_API void DrawDebugBox(const UWorld* InWorld, FVector const& Center, FVector const& Box, const FQuat & Rotation, FColor const& Color, bool bPersistentLines = false, float LifeTime=-1.f, uint8 DepthPriority = 0);  
第一个根据Box的尺寸绘制,第二个额外的可以按照一定的旋转绘制。
5.绘制球体ENGINE_API void DrawDebugSphere(const UWorld* InWorld, FVector const& Center, float Radius, int32 Segments, FColor const& Color, bool bPersistentLines = false, float LifeTime=-1.f, uint8 DepthPriority = 0);  
Segments控制球体的分段,越大越精细。
6.其他
还有很多不太常用的,可以绘制2D圆、圆柱、椎体、平截头体、胶囊等。这里只列出来,具体见DrawDebugHelpers.h


论坛帖子长度有限,发一个word附件把!

UE4 c 一些调试用的绘制函数.rar

14.78 KB, 下载次数: 10

售价: 2 枚能量币  [记录]

caishengxi | 2017-7-14 16:03:42 | 显示全部楼层
有用的东西
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

4

主题

126

回帖

3922

积分

初始化成员

积分
3922