mirror of
https://github.com/Ed94/Cog.git
synced 2026-06-13 00:01:37 -07:00
Add collision debug draw functions
This commit is contained in:
@@ -638,6 +638,90 @@ void FCogDebugDraw::Skeleton(const FLogCategoryBase& LogCategory, const USkeleta
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void FCogDebugDraw::LineTrace(const FLogCategoryBase& LogCategory, const UObject* WorldContextObject, const FVector& Start, const FVector& End, const bool HasHits, TArray<FHitResult>& HitResults, const FCogDebugDrawLineTraceParams& Settings)
|
||||
{
|
||||
if (FCogDebugLog::IsLogCategoryActive(LogCategory) == false)
|
||||
{ return; }
|
||||
|
||||
const UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::LogAndReturnNull);
|
||||
if (World == nullptr)
|
||||
{ return; }
|
||||
|
||||
Settings.Persistent = FCogDebug::GetDebugPersistent(Settings.Persistent);
|
||||
FCogDebugDrawHelper::DrawLineTrace(World, Start, End, HasHits, HitResults, Settings);
|
||||
|
||||
ReplicateShape(WorldContextObject,
|
||||
FCogDebugShape::MakeArrow(Start,
|
||||
End,
|
||||
FCogDebug::Settings.ArrowSize,
|
||||
HasHits
|
||||
? Settings.HitColor
|
||||
: Settings.NoHitColor,
|
||||
FCogDebug::Settings.Thickness,
|
||||
Settings.Persistent,
|
||||
Settings.DepthPriority));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void FCogDebugDraw::Sweep(const FLogCategoryBase& LogCategory, const UObject* WorldContextObject, const FCollisionShape& Shape, const FVector& Start, const FVector& End, const FQuat& Rotation, const bool HasHits, TArray<FHitResult>& HitResults, const FCogDebugDrawSweepParams& Settings)
|
||||
{
|
||||
if (FCogDebugLog::IsLogCategoryActive(LogCategory) == false)
|
||||
{ return; }
|
||||
|
||||
const UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::LogAndReturnNull);
|
||||
if (World == nullptr)
|
||||
{ return; }
|
||||
|
||||
FCogDebugDrawHelper::DrawSweep(World, Shape, Start, End, Rotation, HasHits, HitResults, Settings);
|
||||
|
||||
const FColor Color = HasHits
|
||||
? Settings.HitColor
|
||||
: Settings.NoHitColor;
|
||||
ReplicateShape(WorldContextObject,
|
||||
FCogDebugShape::MakeCollisionShape(Shape,
|
||||
Start,
|
||||
Rotation,
|
||||
Shape.GetExtent(),
|
||||
Color,
|
||||
FCogDebug::Settings.Thickness,
|
||||
Settings.Persistent,
|
||||
Settings.DepthPriority));
|
||||
ReplicateShape(WorldContextObject,
|
||||
FCogDebugShape::MakeArrow(Start,
|
||||
End,
|
||||
FCogDebug::Settings.ArrowSize,
|
||||
Color,
|
||||
FCogDebug::Settings.Thickness,
|
||||
Settings.Persistent,
|
||||
Settings.DepthPriority));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void FCogDebugDraw::Overlap(const FLogCategoryBase& LogCategory, const UObject* WorldContextObject, const FCollisionShape& Shape, const FVector& Location, const FQuat& Rotation, TArray<FOverlapResult>& OverlapResults, const FCogDebugDrawOverlapParams& Settings)
|
||||
{
|
||||
if (FCogDebugLog::IsLogCategoryActive(LogCategory) == false)
|
||||
{ return; }
|
||||
|
||||
const UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::LogAndReturnNull);
|
||||
if (World == nullptr)
|
||||
{ return; }
|
||||
|
||||
FCogDebugDrawHelper::DrawOverlap(World, Shape, Location, Rotation, OverlapResults, Settings);
|
||||
|
||||
const FColor Color = OverlapResults.Num() > 0
|
||||
? Settings.HitColor
|
||||
: Settings.NoHitColor;
|
||||
ReplicateShape(WorldContextObject,
|
||||
FCogDebugShape::MakeCollisionShape(Shape,
|
||||
Location,
|
||||
Rotation,
|
||||
Shape.GetExtent(),
|
||||
Color,
|
||||
FCogDebug::Settings.Thickness,
|
||||
Settings.Persistent,
|
||||
Settings.DepthPriority));
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void FCogDebugDraw::ReplicateShape(const UObject* WorldContextObject, const FCogDebugShape& Shape)
|
||||
|
||||
@@ -596,6 +596,22 @@ FCogDebugShape FCogDebugShape::MakePolygon(const TArray<FVector>& Verts, const F
|
||||
return NewElement;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
FCogDebugShape FCogDebugShape::MakeCollisionShape(const FCollisionShape& Shape, const FVector& Location, const FQuat& Rotation, const FVector& Extent, const FColor& Color, const float Thickness, const bool bPersistent, const uint8 DepthPriority)
|
||||
{
|
||||
switch (Shape.ShapeType)
|
||||
{
|
||||
case ECollisionShape::Box:
|
||||
return MakeBox(Location, Rotation.Rotator(), Extent, Color, Thickness, bPersistent, DepthPriority);
|
||||
case ECollisionShape::Capsule:
|
||||
return MakeCapsule(Location, Rotation, Extent.X, Extent.Z, Color, Thickness, bPersistent, DepthPriority);
|
||||
|
||||
default:
|
||||
case ECollisionShape::Sphere:
|
||||
return MakeCapsule(Location, Rotation, Extent.X, 0.0f, Color, Thickness, bPersistent, DepthPriority);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
void FCogDebugShape::DrawPolygon(const UWorld* World) const
|
||||
{
|
||||
|
||||
@@ -5,6 +5,9 @@
|
||||
|
||||
class USkeletalMeshComponent;
|
||||
struct FCogDebugShape;
|
||||
struct FCollisionShape;
|
||||
struct FHitResult;
|
||||
struct FOverlapResult;
|
||||
|
||||
#if ENABLE_COG
|
||||
|
||||
@@ -52,6 +55,12 @@ struct COGDEBUG_API FCogDebugDraw
|
||||
|
||||
static void Skeleton(const FLogCategoryBase& LogCategory, const USkeletalMeshComponent* Skeleton, const FColor& Color, bool DrawSecondaryBones = false, const uint8 DepthPriority = 1);
|
||||
|
||||
static void LineTrace(const FLogCategoryBase& LogCategory, const UObject* WorldContextObject, const FVector& Start, const FVector& End, const bool HasHits, TArray<FHitResult>& HitResults, const FCogDebugDrawLineTraceParams& Settings);
|
||||
|
||||
static void Sweep(const FLogCategoryBase& LogCategory, const UObject* WorldContextObject, const FCollisionShape& Shape, const FVector& Start, const FVector& End, const FQuat& Rotation, const bool HasHits, TArray<FHitResult>& HitResults, const FCogDebugDrawSweepParams& Settings);
|
||||
|
||||
static void Overlap(const FLogCategoryBase& LogCategory, const UObject* WorldContextObject, const FCollisionShape& Shape, const FVector& Location, const FQuat& Rotation, TArray<FOverlapResult>& OverlapResults, const FCogDebugDrawOverlapParams& Settings);
|
||||
|
||||
static void ReplicateShape(const UObject* WorldContextObject, const FCogDebugShape& Shape);
|
||||
};
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ struct FCogDebugDrawOverlapParams
|
||||
bool DrawHitPrimitiveActorsName = false;
|
||||
bool HitPrimitiveActorsNameShadow = true;
|
||||
float HitPrimitiveActorsNameSize = 1.0f;
|
||||
bool Persistent = false;
|
||||
mutable bool Persistent = false;
|
||||
float LifeTime = 0.0f;
|
||||
uint8 DepthPriority = 0;
|
||||
float Thickness = 0.0f;
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
DECLARE_LOG_CATEGORY_EXTERN(LogCogServerVLOG, Verbose, All);
|
||||
|
||||
struct FCollisionShape;
|
||||
|
||||
enum class ECogDebugShape : uint8
|
||||
{
|
||||
Invalid,
|
||||
@@ -59,6 +61,7 @@ struct COGDEBUG_API FCogDebugShape
|
||||
static FCogDebugShape MakeCapsule(const FVector& Center, const FQuat& Rotation, const float Radius, const float HalfHeight, const FColor& Color, const float Thickness, const bool bPersistent, const uint8 DepthPriority);
|
||||
static FCogDebugShape MakeFlatCapsule(const FVector2D& Start, const FVector2D& End, const float Radius, const float Z, const FColor& Color, const float Thickness, const bool bPersistent, const uint8 DepthPriority);
|
||||
static FCogDebugShape MakePolygon(const TArray<FVector>& Verts, const FColor& Color, const bool bPersistent, const uint8 DepthPriority);
|
||||
static FCogDebugShape MakeCollisionShape(const FCollisionShape& Shape, const FVector& Location, const FQuat& Rotation, const FVector& Extent, const FColor& Color, const float Thickness, const bool bPersistent, const uint8 DepthPriority);
|
||||
|
||||
void DrawPoint(const UWorld* World) const;
|
||||
void DrawSegment(const UWorld* World) const;
|
||||
|
||||
@@ -139,6 +139,16 @@ void FCogWindow::SetSelection(AActor* NewSelection)
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
void FCogWindow::SetIsVisible(const bool Value)
|
||||
{
|
||||
if (bIsVisible == Value)
|
||||
{ return; }
|
||||
|
||||
bIsVisible = Value;
|
||||
OnWindowVisibilityChanged(Value);
|
||||
}
|
||||
|
||||
APawn* FCogWindow::GetLocalPlayerPawn() const
|
||||
{
|
||||
const APlayerController* LocalPlayerController = GetLocalPlayerController();
|
||||
|
||||
@@ -59,7 +59,7 @@ public:
|
||||
|
||||
bool GetIsVisible() const { return bIsVisible; }
|
||||
|
||||
void SetIsVisible(bool Value) { bIsVisible = Value; }
|
||||
void SetIsVisible(bool Value);
|
||||
|
||||
bool HasWidget() const { return bHasWidget; }
|
||||
|
||||
@@ -103,6 +103,8 @@ protected:
|
||||
|
||||
virtual bool CheckEditorVisibility();
|
||||
|
||||
virtual void OnWindowVisibilityChanged(bool NewVisibility) { }
|
||||
|
||||
virtual void OnSelectionChanged(AActor* OldSelection, AActor* NewSelection) {}
|
||||
|
||||
APawn* GetLocalPlayerPawn() const;
|
||||
|
||||
Reference in New Issue
Block a user