Improve Collision Tester

Properly filter trace and objects type
This commit is contained in:
Arnaud Jamin
2025-03-23 01:12:53 -04:00
parent 67b2676c15
commit bebc05d4fa
17 changed files with 563 additions and 419 deletions
+9 -1
View File
@@ -89,4 +89,12 @@ bool FCogHelper::ComputeBoundingBoxScreenPosition(const APlayerController* Playe
Max.Y = FMath::Min(DisplaySize.y * 2, Max.Y); Max.Y = FMath::Min(DisplaySize.y * 2, Max.Y);
return true; return true;
} }
//--------------------------------------------------------------------------------------------------------------------------
bool FCogHelper::IsTraceChannelHidden(const UCollisionProfile& InCollisionProfile, const ECollisionChannel InCollisionChannel)
{
return false;
}
+61 -32
View File
@@ -823,36 +823,32 @@ bool FCogWidgets::MultiChoiceButtonsFloat(TArray<float>& InValues, float& InValu
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
bool FCogWidgets::ComboCollisionChannel(const char* Label, ECollisionChannel& Channel) bool FCogWidgets::ComboTraceChannel(const char* Label, ECollisionChannel& Channel)
{ {
FColor ChannelColors[ECC_MAX]; FColor ChannelColors[ECC_MAX];
FCogDebug::GetDebugChannelColors(ChannelColors); FCogDebug::GetDebugChannelColors(ChannelColors);
FName SelectedChannelName;
const UCollisionProfile* CollisionProfile = UCollisionProfile::Get(); const UCollisionProfile* CollisionProfile = UCollisionProfile::Get();
if (CollisionProfile != nullptr) if (CollisionProfile == nullptr)
{ { return false; }
SelectedChannelName = CollisionProfile->ReturnChannelNameFromContainerIndex(Channel);
}
const FName SelectedChannelName = CollisionProfile->ReturnChannelNameFromContainerIndex(Channel);
bool Result = false; bool Result = false;
if (ImGui::BeginCombo(Label, TCHAR_TO_ANSI(*SelectedChannelName.ToString()), ImGuiComboFlags_HeightLarge)) if (ImGui::BeginCombo(Label, TCHAR_TO_ANSI(*SelectedChannelName.ToString()), ImGuiComboFlags_HeightLarge))
{ {
for (int32 ChannelIndex = 0; ChannelIndex < static_cast<int32>(ECC_OverlapAll_Deprecated); ++ChannelIndex) for (int32 ChannelIndex = 0; ChannelIndex < static_cast<int32>(ECC_OverlapAll_Deprecated); ++ChannelIndex)
{ {
FColor Color = ChannelColors[ChannelIndex]; if (CollisionProfile->ConvertToTraceType(static_cast<ECollisionChannel>(ChannelIndex)) == TraceTypeQuery_MAX)
if (Color == FColor::Transparent) { continue; }
{
continue;
}
ImGui::PushID(ChannelIndex); ImGui::PushID(ChannelIndex);
const FName ChannelName = CollisionProfile->ReturnChannelNameFromContainerIndex(ChannelIndex); FColor Color = ChannelColors[ChannelIndex];
FCogImguiHelper::ColorEdit4("Color", Color, ImGuiColorEditFlags_NoPicker | ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel); FCogImguiHelper::ColorEdit4("Color", Color, ImGuiColorEditFlags_NoPicker | ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel);
ImGui::SameLine(); ImGui::SameLine();
const FName ChannelName = CollisionProfile->ReturnChannelNameFromContainerIndex(ChannelIndex);
if (ChannelName.IsValid()) if (ChannelName.IsValid())
{ {
if (ImGui::Selectable(TCHAR_TO_ANSI(*ChannelName.ToString()))) if (ImGui::Selectable(TCHAR_TO_ANSI(*ChannelName.ToString())))
@@ -871,26 +867,26 @@ bool FCogWidgets::ComboCollisionChannel(const char* Label, ECollisionChannel& Ch
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
bool FCogWidgets::CollisionProfileChannel(const UCollisionProfile& CollisionProfile, const int32 ChannelIndex, FColor& ChannelColor, int32& Channels) bool FCogWidgets::CollisionProfileChannel(const UCollisionProfile& InCollisionProfile, const int32 InChannelIndex, FColor& InChannelColor, int32& InChannels)
{ {
bool Result = false; bool Result = false;
FCogImguiHelper::ColorEdit4("Color", ChannelColor, ImGuiColorEditFlags_NoPicker | ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel); FCogImguiHelper::ColorEdit4("Color", InChannelColor, ImGuiColorEditFlags_NoPicker | ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel);
ImGui::SameLine(); ImGui::SameLine();
bool IsCollisionActive = (Channels & ECC_TO_BITFIELD(ChannelIndex)) > 0; bool IsCollisionActive = (InChannels & ECC_TO_BITFIELD(InChannelIndex)) > 0;
const FName ChannelName = CollisionProfile.ReturnChannelNameFromContainerIndex(ChannelIndex); const FName ChannelName = InCollisionProfile.ReturnChannelNameFromContainerIndex(InChannelIndex);
if (ImGui::Checkbox(TCHAR_TO_ANSI(*ChannelName.ToString()), &IsCollisionActive)) if (ImGui::Checkbox(TCHAR_TO_ANSI(*ChannelName.ToString()), &IsCollisionActive))
{ {
Result = true; Result = true;
if (IsCollisionActive) if (IsCollisionActive)
{ {
Channels |= ECC_TO_BITFIELD(ChannelIndex); InChannels |= ECC_TO_BITFIELD(InChannelIndex);
} }
else else
{ {
Channels &= ~ECC_TO_BITFIELD(ChannelIndex); InChannels &= ~ECC_TO_BITFIELD(InChannelIndex);
} }
} }
@@ -898,14 +894,23 @@ bool FCogWidgets::CollisionProfileChannel(const UCollisionProfile& CollisionProf
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
bool FCogWidgets::CollisionProfileChannels(int32& Channels) bool FCogWidgets::CollisionProfileChannels(int32& OutChannels)
{
bool Result = false;
ImGui::SeparatorText("Trace Type");
Result |= CollisionTraceChannels(OutChannels);
ImGui::SeparatorText("Object Type");
Result |= CollisionObjectTypeChannels(OutChannels);
return Result;
}
//--------------------------------------------------------------------------------------------------------------------------
bool FCogWidgets::CollisionTraceChannels(int32& OutChannels)
{ {
const UCollisionProfile* CollisionProfile = UCollisionProfile::Get(); const UCollisionProfile* CollisionProfile = UCollisionProfile::Get();
if (CollisionProfile == nullptr) if (CollisionProfile == nullptr)
{ { return false; }
return false;
}
FColor ChannelColors[ECC_MAX]; FColor ChannelColors[ECC_MAX];
FCogDebug::GetDebugChannelColors(ChannelColors); FCogDebug::GetDebugChannelColors(ChannelColors);
@@ -913,14 +918,38 @@ bool FCogWidgets::CollisionProfileChannels(int32& Channels)
for (int32 ChannelIndex = 0; ChannelIndex < static_cast<int32>(ECC_OverlapAll_Deprecated); ++ChannelIndex) for (int32 ChannelIndex = 0; ChannelIndex < static_cast<int32>(ECC_OverlapAll_Deprecated); ++ChannelIndex)
{ {
FColor Color = ChannelColors[ChannelIndex]; if (CollisionProfile->ConvertToTraceType(static_cast<ECollisionChannel>(ChannelIndex)) == TraceTypeQuery_MAX)
if (Color == FColor::Transparent) { continue; }
{
continue;
}
ImGui::PushID(ChannelIndex); ImGui::PushID(ChannelIndex);
Result |= CollisionProfileChannel(*CollisionProfile, ChannelIndex, Color, Channels); FColor Color = ChannelColors[ChannelIndex];
Result |= CollisionProfileChannel(*CollisionProfile, ChannelIndex, Color, OutChannels);
ImGui::PopID();
}
return Result;
}
//--------------------------------------------------------------------------------------------------------------------------
bool FCogWidgets::CollisionObjectTypeChannels(int32& OutChannels)
{
const UCollisionProfile* CollisionProfile = UCollisionProfile::Get();
if (CollisionProfile == nullptr)
{ return false; }
FColor ChannelColors[ECC_MAX];
FCogDebug::GetDebugChannelColors(ChannelColors);
bool Result = false;
for (int32 ChannelIndex = 0; ChannelIndex < static_cast<int32>(ECC_OverlapAll_Deprecated); ++ChannelIndex)
{
if (CollisionProfile->ConvertToObjectType(static_cast<ECollisionChannel>(ChannelIndex)) == TraceTypeQuery_MAX)
{ continue; }
ImGui::PushID(ChannelIndex);
FColor Color = ChannelColors[ChannelIndex];
Result |= CollisionProfileChannel(*CollisionProfile, ChannelIndex, Color, OutChannels);
ImGui::PopID(); ImGui::PopID();
} }
@@ -4,6 +4,7 @@
#include "CoreMinimal.h" #include "CoreMinimal.h"
#include "Templates/SubclassOf.h" #include "Templates/SubclassOf.h"
class UCollisionProfile;
class COG_API FCogHelper class COG_API FCogHelper
{ {
@@ -22,6 +23,8 @@ public:
template<typename TCLass, typename TMember> template<typename TCLass, typename TMember>
static FProperty* FindProperty(TCLass* Instance, TMember TCLass::*PointerToMember); static FProperty* FindProperty(TCLass* Instance, TMember TCLass::*PointerToMember);
static bool IsTraceChannelHidden(const UCollisionProfile& InCollisionProfile, ECollisionChannel InCollisionChannel);
}; };
//---------------------------------------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------------------------------------
+8 -4
View File
@@ -56,7 +56,7 @@ public:
static bool MultiChoiceButtonsInt(TArray<int32>& Values, int32& Value, const ImVec2& Size = ImVec2(0, 0), bool InInline = true); static bool MultiChoiceButtonsInt(TArray<int32>& Values, int32& Value, const ImVec2& Size = ImVec2(0, 0), bool InInline = true);
static bool MultiChoiceButtonsFloat(TArray<float>& InValues, float& InValue, const ImVec2& InSize = ImVec2(0, 0), bool InInline = true, float InTolerance = UE_SMALL_NUMBER); static bool MultiChoiceButtonsFloat(TArray<float>& InValues, float& InValue, const ImVec2& InSize = ImVec2(0, 0), bool InInline = true, float InTolerance = UE_SMALL_NUMBER);
static void SliderWithReset(const char* Name, float* Value, float Min, float Max, const float& ResetValue, const char* Format); static void SliderWithReset(const char* Name, float* Value, float Min, float Max, const float& ResetValue, const char* Format);
static void HelpMarker(const char* Text); static void HelpMarker(const char* Text);
@@ -114,11 +114,15 @@ public:
static bool DeleteArrayItemButton(); static bool DeleteArrayItemButton();
static bool ComboCollisionChannel(const char* Label, ECollisionChannel& Channel); static bool ComboTraceChannel(const char* Label, ECollisionChannel& Channel);
static bool CollisionProfileChannel(const UCollisionProfile& CollisionProfile, int32 ChannelIndex, FColor& ChannelColor, int32& Channels); static bool CollisionProfileChannels(int32& OutChannels);
static bool CollisionProfileChannels(int32& Channels); static bool CollisionTraceChannels(int32& OutChannels);
static bool CollisionObjectTypeChannels(int32& OutChannels);
static bool CollisionProfileChannel(const UCollisionProfile& InCollisionProfile, int32 InChannelIndex, FColor& InChannelColor, int32& InChannels);
static bool MenuActorsCombo(const char* StrID, AActor*& NewSelection, const UWorld& World, const TSubclassOf<AActor>& ActorClass, const FCogWindowActorContextMenuFunction& ContextMenuFunction = nullptr); static bool MenuActorsCombo(const char* StrID, AActor*& NewSelection, const UWorld& World, const TSubclassOf<AActor>& ActorClass, const FCogWindowActorContextMenuFunction& ContextMenuFunction = nullptr);
@@ -291,12 +291,6 @@ void FCogDebug::GetDebugChannelColors(FColor ChannelColors[ECC_MAX])
ChannelColors[ECC_PhysicsBody] = Settings.ChannelColorPhysicsBody; ChannelColors[ECC_PhysicsBody] = Settings.ChannelColorPhysicsBody;
ChannelColors[ECC_Vehicle] = Settings.ChannelColorVehicle; ChannelColors[ECC_Vehicle] = Settings.ChannelColorVehicle;
ChannelColors[ECC_Destructible] = Settings.ChannelColorDestructible; ChannelColors[ECC_Destructible] = Settings.ChannelColorDestructible;
ChannelColors[ECC_EngineTraceChannel1] = Settings.ChannelColorEngineTraceChannel1;
ChannelColors[ECC_EngineTraceChannel2] = Settings.ChannelColorEngineTraceChannel2;
ChannelColors[ECC_EngineTraceChannel3] = Settings.ChannelColorEngineTraceChannel3;
ChannelColors[ECC_EngineTraceChannel4] = Settings.ChannelColorEngineTraceChannel4;
ChannelColors[ECC_EngineTraceChannel5] = Settings.ChannelColorEngineTraceChannel5;
ChannelColors[ECC_EngineTraceChannel6] = Settings.ChannelColorEngineTraceChannel6;
ChannelColors[ECC_GameTraceChannel1] = Settings.ChannelColorGameTraceChannel1; ChannelColors[ECC_GameTraceChannel1] = Settings.ChannelColorGameTraceChannel1;
ChannelColors[ECC_GameTraceChannel2] = Settings.ChannelColorGameTraceChannel2; ChannelColors[ECC_GameTraceChannel2] = Settings.ChannelColorGameTraceChannel2;
ChannelColors[ECC_GameTraceChannel3] = Settings.ChannelColorGameTraceChannel3; ChannelColors[ECC_GameTraceChannel3] = Settings.ChannelColorGameTraceChannel3;
@@ -702,7 +702,7 @@ void FCogDebugDraw::Sweep(const FLogCategoryBase& LogCategory, const UObject* Wo
} }
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
void FCogDebugDraw::Overlap(const FLogCategoryBase& LogCategory, const UObject* WorldContextObject, const FCollisionShape& Shape, const FVector& Location, const FQuat& Rotation, TArray<FOverlapResult>& OverlapResults, const FCogDebugDrawOverlapParams& Settings) void FCogDebugDraw::Overlap(const FLogCategoryBase& LogCategory, const UObject* WorldContextObject, const FCollisionShape& Shape, const FVector& Location, const FQuat& Rotation, const bool HasHits, TArray<FOverlapResult>& OverlapResults, const FCogDebugDrawOverlapParams& Settings)
{ {
if (FCogDebugLog::IsLogCategoryActive(LogCategory) == false) if (FCogDebugLog::IsLogCategoryActive(LogCategory) == false)
{ return; } { return; }
@@ -711,7 +711,7 @@ void FCogDebugDraw::Overlap(const FLogCategoryBase& LogCategory, const UObject*
if (World == nullptr) if (World == nullptr)
{ return; } { return; }
FCogDebugDrawHelper::DrawOverlap(World, Shape, Location, Rotation, OverlapResults, Settings); FCogDebugDrawHelper::DrawOverlap(World, Shape, Location, Rotation, HasHits, OverlapResults, Settings);
const FColor Color = OverlapResults.Num() > 0 const FColor Color = OverlapResults.Num() > 0
? Settings.HitColor ? Settings.HitColor
@@ -459,11 +459,12 @@ void FCogDebugDrawHelper::DrawOverlap(
const FCollisionShape& Shape, const FCollisionShape& Shape,
const FVector& Location, const FVector& Location,
const FQuat& Rotation, const FQuat& Rotation,
TArray<FOverlapResult>& OverlapResults, const bool HasHits,
const TArray<FOverlapResult>& OverlapResults,
const FCogDebugDrawOverlapParams& Settings const FCogDebugDrawOverlapParams& Settings
) )
{ {
const FColor Color = OverlapResults.Num() > 0 ? Settings.HitColor : Settings.NoHitColor; const FColor Color = HasHits ? Settings.HitColor : Settings.NoHitColor;
DrawShape(World, Shape, Location, Rotation, FVector::OneVector, Color, Settings.Persistent, Settings.LifeTime, Settings.DepthPriority, Settings.Thickness); DrawShape(World, Shape, Location, Rotation, FVector::OneVector, Color, Settings.Persistent, Settings.LifeTime, Settings.DepthPriority, Settings.Thickness);
if (Settings.DrawHitPrimitives) if (Settings.DrawHitPrimitives)
@@ -3,12 +3,12 @@
#include "CogDebug.h" #include "CogDebug.h"
#include "CogDebugDrawHelper.h" #include "CogDebugDrawHelper.h"
#include "CogImguiHelper.h" #include "CogImguiHelper.h"
#include "DrawDebugHelpers.h"
#include "imgui.h"
#include "Components/PrimitiveComponent.h" #include "Components/PrimitiveComponent.h"
#include "Components/SceneComponent.h" #include "Components/SceneComponent.h"
#include "DrawDebugHelpers.h"
#include "Engine/World.h" #include "Engine/World.h"
#include "GameFramework/PlayerController.h" #include "GameFramework/PlayerController.h"
#include "imgui.h"
#include "Kismet/GameplayStatics.h" #include "Kismet/GameplayStatics.h"
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
@@ -78,7 +78,7 @@ float ScreenDistanceToArc(const APlayerController& InPlayerController, const FVe
FVector P0 = Center + Radius * (AxisZ * FMath::Sin(CurrentAngle) + AxisY * FMath::Cos(CurrentAngle)); FVector P0 = Center + Radius * (AxisZ * FMath::Sin(CurrentAngle) + AxisY * FMath::Cos(CurrentAngle));
FVector2D ScreenP0; FVector2D ScreenP0;
UGameplayStatics::ProjectWorldToScreen(&InPlayerController, P0, ScreenP0); UGameplayStatics::ProjectWorldToScreen(&InPlayerController, P0, ScreenP0);
float MinDistanceSqr = FLT_MAX; float MinDistanceSqr = FLT_MAX;
@@ -163,14 +163,14 @@ void DrawGizmoText(const ImVec2& Position, ImU32 Color, const char* Text)
bool RenderComponent(const char* Label, double* Value, double Reset) bool RenderComponent(const char* Label, double* Value, double Reset)
{ {
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::PushItemWidth(-1); ImGui::PushItemWidth(-1);
bool Result = FCogImguiHelper::DragDouble(Label, Value, 0.1f, 0.0f, 0.0f, "%.1f"); bool Result = FCogImguiHelper::DragDouble(Label, Value, 0.1f, 0.0f, 0.0f, "%.1f");
if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) if (ImGui::IsItemClicked(ImGuiMouseButton_Right))
{ {
*Value = Reset; *Value = Reset;
Result = true; Result = true;
} }
ImGui::PopItemWidth(); ImGui::PopItemWidth();
return Result; return Result;
} }
@@ -240,7 +240,7 @@ bool FCogDebug_Gizmo::Draw(const char* Id, const APlayerController& InPlayerCont
const float GizmoScale = Settings.GizmoScale * ScaleToKeepGizmoScreenSizeConstant; const float GizmoScale = Settings.GizmoScale * ScaleToKeepGizmoScreenSizeConstant;
const FQuat RotX = Settings.GizmoUseLocalSpace ? InOutTransform.GetRotation() : FQuat(FVector(0.0f, 0.0f, 1.0f), 0.0f); const FQuat RotX = Settings.GizmoUseLocalSpace ? InOutTransform.GetRotation() : FQuat(FVector(0.0f, 0.0f, 1.0f), 0.0f);
const FQuat RotY = RotX * FQuat(FVector(0.0f, 0.0f,-1.0f), UE_HALF_PI); const FQuat RotY = RotX * FQuat(FVector(0.0f, 0.0f, -1.0f), UE_HALF_PI);
const FQuat RotZ = RotX * FQuat(FVector(0.0f, 1.0f, 0.0f), UE_HALF_PI); const FQuat RotZ = RotX * FQuat(FVector(0.0f, 1.0f, 0.0f), UE_HALF_PI);
const FVector UnitAxisX = Settings.GizmoUseLocalSpace ? RotX.GetAxisX() : FVector::XAxisVector; const FVector UnitAxisX = Settings.GizmoUseLocalSpace ? RotX.GetAxisX() : FVector::XAxisVector;
@@ -255,9 +255,9 @@ bool FCogDebug_Gizmo::Draw(const char* Id, const APlayerController& InPlayerCont
const ImVec2 ImMousePos = ImGui::GetMousePos() - Viewport->Pos; const ImVec2 ImMousePos = ImGui::GetMousePos() - Viewport->Pos;
const FVector2D MousePos = FCogImguiHelper::ToFVector2D(ImMousePos); const FVector2D MousePos = FCogImguiHelper::ToFVector2D(ImMousePos);
const FColor GizmoAxisColorsZLow[] = { Settings.GizmoAxisColorsZLowX, Settings.GizmoAxisColorsZLowY, Settings.GizmoAxisColorsZLowZ, Settings.GizmoAxisColorsZLowW }; const FColor GizmoAxisColorsZLow[] = {Settings.GizmoAxisColorsZLowX, Settings.GizmoAxisColorsZLowY, Settings.GizmoAxisColorsZLowZ, Settings.GizmoAxisColorsZLowW};
const FColor GizmoAxisColorsZHigh[] = { Settings.GizmoAxisColorsZHighX, Settings.GizmoAxisColorsZHighY, Settings.GizmoAxisColorsZHighZ, Settings.GizmoAxisColorsZHighW }; const FColor GizmoAxisColorsZHigh[] = {Settings.GizmoAxisColorsZHighX, Settings.GizmoAxisColorsZHighY, Settings.GizmoAxisColorsZHighZ, Settings.GizmoAxisColorsZHighW};
const FColor GizmoAxisColorsSelection[] = { Settings.GizmoAxisColorsSelectionX, Settings.GizmoAxisColorsSelectionY, Settings.GizmoAxisColorsSelectionZ, Settings.GizmoAxisColorsSelectionW }; const FColor GizmoAxisColorsSelection[] = {Settings.GizmoAxisColorsSelectionX, Settings.GizmoAxisColorsSelectionY, Settings.GizmoAxisColorsSelectionZ, Settings.GizmoAxisColorsSelectionW};
FCogDebug_GizmoElement GizmoElements[static_cast<uint8>(ECogDebug_GizmoElementType::MAX)]; FCogDebug_GizmoElement GizmoElements[static_cast<uint8>(ECogDebug_GizmoElementType::MAX)];
for (FCogDebug_GizmoElement& GizmoElement : GizmoElements) for (FCogDebug_GizmoElement& GizmoElement : GizmoElements)
@@ -267,35 +267,35 @@ bool FCogDebug_Gizmo::Draw(const char* Id, const APlayerController& InPlayerCont
if (EnumHasAnyFlags(Flags, ECogDebug_GizmoFlags::NoTranslationAxis) == false) if (EnumHasAnyFlags(Flags, ECogDebug_GizmoFlags::NoTranslationAxis) == false)
{ {
GizmoElements[static_cast<uint8>(ECogDebug_GizmoElementType::MoveX)] = { ECogDebug_GizmoType::MoveAxis, ECogDebug_GizmoAxis::X, FVector::XAxisVector, UnitAxisX, RotX, GizmoCenter + UnitAxisX * Settings.GizmoTranslationAxisLength * GizmoScale }; GizmoElements[static_cast<uint8>(ECogDebug_GizmoElementType::MoveX)] = {ECogDebug_GizmoType::MoveAxis, ECogDebug_GizmoAxis::X, FVector::XAxisVector, UnitAxisX, RotX, GizmoCenter + UnitAxisX * Settings.GizmoTranslationAxisLength * GizmoScale};
GizmoElements[static_cast<uint8>(ECogDebug_GizmoElementType::MoveY)] = { ECogDebug_GizmoType::MoveAxis, ECogDebug_GizmoAxis::Y, FVector::YAxisVector, UnitAxisY, RotY, GizmoCenter + UnitAxisY * Settings.GizmoTranslationAxisLength * GizmoScale }; GizmoElements[static_cast<uint8>(ECogDebug_GizmoElementType::MoveY)] = {ECogDebug_GizmoType::MoveAxis, ECogDebug_GizmoAxis::Y, FVector::YAxisVector, UnitAxisY, RotY, GizmoCenter + UnitAxisY * Settings.GizmoTranslationAxisLength * GizmoScale};
GizmoElements[static_cast<uint8>(ECogDebug_GizmoElementType::MoveZ)] = { ECogDebug_GizmoType::MoveAxis, ECogDebug_GizmoAxis::Z, FVector::ZAxisVector, UnitAxisZ, RotZ, GizmoCenter + UnitAxisZ * Settings.GizmoTranslationAxisLength * GizmoScale }; GizmoElements[static_cast<uint8>(ECogDebug_GizmoElementType::MoveZ)] = {ECogDebug_GizmoType::MoveAxis, ECogDebug_GizmoAxis::Z, FVector::ZAxisVector, UnitAxisZ, RotZ, GizmoCenter + UnitAxisZ * Settings.GizmoTranslationAxisLength * GizmoScale};
} }
if (EnumHasAnyFlags(Flags, ECogDebug_GizmoFlags::NoTranslationPlane) == false) if (EnumHasAnyFlags(Flags, ECogDebug_GizmoFlags::NoTranslationPlane) == false)
{ {
GizmoElements[static_cast<uint8>(ECogDebug_GizmoElementType::MoveXY)] = { ECogDebug_GizmoType::MovePlane, ECogDebug_GizmoAxis::Z, FVector::ZAxisVector, UnitAxisZ, RotZ, GizmoCenter + ((UnitAxisX + UnitAxisY) * Settings.GizmoTranslationPlaneOffset * GizmoScale) }; GizmoElements[static_cast<uint8>(ECogDebug_GizmoElementType::MoveXY)] = {ECogDebug_GizmoType::MovePlane, ECogDebug_GizmoAxis::Z, FVector::ZAxisVector, UnitAxisZ, RotZ, GizmoCenter + ((UnitAxisX + UnitAxisY) * Settings.GizmoTranslationPlaneOffset * GizmoScale)};
GizmoElements[static_cast<uint8>(ECogDebug_GizmoElementType::MoveXZ)] = { ECogDebug_GizmoType::MovePlane, ECogDebug_GizmoAxis::Y, FVector::YAxisVector, UnitAxisY, RotY, GizmoCenter + ((UnitAxisX + UnitAxisZ) * Settings.GizmoTranslationPlaneOffset * GizmoScale) }; GizmoElements[static_cast<uint8>(ECogDebug_GizmoElementType::MoveXZ)] = {ECogDebug_GizmoType::MovePlane, ECogDebug_GizmoAxis::Y, FVector::YAxisVector, UnitAxisY, RotY, GizmoCenter + ((UnitAxisX + UnitAxisZ) * Settings.GizmoTranslationPlaneOffset * GizmoScale)};
GizmoElements[static_cast<uint8>(ECogDebug_GizmoElementType::MoveYZ)] = { ECogDebug_GizmoType::MovePlane, ECogDebug_GizmoAxis::X, FVector::XAxisVector, UnitAxisX, RotX, GizmoCenter + ((UnitAxisY + UnitAxisZ) * Settings.GizmoTranslationPlaneOffset * GizmoScale) }; GizmoElements[static_cast<uint8>(ECogDebug_GizmoElementType::MoveYZ)] = {ECogDebug_GizmoType::MovePlane, ECogDebug_GizmoAxis::X, FVector::XAxisVector, UnitAxisX, RotX, GizmoCenter + ((UnitAxisY + UnitAxisZ) * Settings.GizmoTranslationPlaneOffset * GizmoScale)};
} }
if (EnumHasAnyFlags(Flags, ECogDebug_GizmoFlags::NoRotation) == false) if (EnumHasAnyFlags(Flags, ECogDebug_GizmoFlags::NoRotation) == false)
{ {
GizmoElements[static_cast<uint8>(ECogDebug_GizmoElementType::RotateX)] = { ECogDebug_GizmoType::Rotate, ECogDebug_GizmoAxis::X, FVector::XAxisVector, UnitAxisX, RotX, FVector::ZeroVector }; GizmoElements[static_cast<uint8>(ECogDebug_GizmoElementType::RotateX)] = {ECogDebug_GizmoType::Rotate, ECogDebug_GizmoAxis::X, FVector::XAxisVector, UnitAxisX, RotX, FVector::ZeroVector};
GizmoElements[static_cast<uint8>(ECogDebug_GizmoElementType::RotateY)] = { ECogDebug_GizmoType::Rotate, ECogDebug_GizmoAxis::Y, FVector::YAxisVector, UnitAxisY, RotY, FVector::ZeroVector }; GizmoElements[static_cast<uint8>(ECogDebug_GizmoElementType::RotateY)] = {ECogDebug_GizmoType::Rotate, ECogDebug_GizmoAxis::Y, FVector::YAxisVector, UnitAxisY, RotY, FVector::ZeroVector};
GizmoElements[static_cast<uint8>(ECogDebug_GizmoElementType::RotateZ)] = { ECogDebug_GizmoType::Rotate, ECogDebug_GizmoAxis::Z, FVector::ZAxisVector, UnitAxisZ, RotZ, FVector::ZeroVector }; GizmoElements[static_cast<uint8>(ECogDebug_GizmoElementType::RotateZ)] = {ECogDebug_GizmoType::Rotate, ECogDebug_GizmoAxis::Z, FVector::ZAxisVector, UnitAxisZ, RotZ, FVector::ZeroVector};
} }
if (EnumHasAnyFlags(Flags, ECogDebug_GizmoFlags::NoScaleUniform) == false) if (EnumHasAnyFlags(Flags, ECogDebug_GizmoFlags::NoScaleUniform) == false)
{ {
GizmoElements[static_cast<uint8>(ECogDebug_GizmoElementType::ScaleXYZ)] = { ECogDebug_GizmoType::ScaleUniform, ECogDebug_GizmoAxis::MAX, FVector::OneVector, FVector::OneVector, RotX, GizmoCenter }; GizmoElements[static_cast<uint8>(ECogDebug_GizmoElementType::ScaleXYZ)] = {ECogDebug_GizmoType::ScaleUniform, ECogDebug_GizmoAxis::MAX, FVector::OneVector, FVector::OneVector, RotX, GizmoCenter};
} }
if (EnumHasAnyFlags(Flags, ECogDebug_GizmoFlags::NoScaleAxis) == false) if (EnumHasAnyFlags(Flags, ECogDebug_GizmoFlags::NoScaleAxis) == false)
{ {
GizmoElements[static_cast<uint8>(ECogDebug_GizmoElementType::ScaleX)] = { ECogDebug_GizmoType::ScaleAxis, ECogDebug_GizmoAxis::X, FVector::XAxisVector, UnitAxisX, RotX, GizmoCenter + UnitAxisX * Settings.GizmoScaleBoxOffset * GizmoScale }; GizmoElements[static_cast<uint8>(ECogDebug_GizmoElementType::ScaleX)] = {ECogDebug_GizmoType::ScaleAxis, ECogDebug_GizmoAxis::X, FVector::XAxisVector, UnitAxisX, RotX, GizmoCenter + UnitAxisX * Settings.GizmoScaleBoxOffset * GizmoScale};
GizmoElements[static_cast<uint8>(ECogDebug_GizmoElementType::ScaleY)] = { ECogDebug_GizmoType::ScaleAxis, ECogDebug_GizmoAxis::Y, FVector::YAxisVector, UnitAxisY, RotY, GizmoCenter + UnitAxisY * Settings.GizmoScaleBoxOffset * GizmoScale }; GizmoElements[static_cast<uint8>(ECogDebug_GizmoElementType::ScaleY)] = {ECogDebug_GizmoType::ScaleAxis, ECogDebug_GizmoAxis::Y, FVector::YAxisVector, UnitAxisY, RotY, GizmoCenter + UnitAxisY * Settings.GizmoScaleBoxOffset * GizmoScale};
GizmoElements[static_cast<uint8>(ECogDebug_GizmoElementType::ScaleZ)] = { ECogDebug_GizmoType::ScaleAxis, ECogDebug_GizmoAxis::Z, FVector::ZAxisVector, UnitAxisZ, RotZ, GizmoCenter + UnitAxisZ * Settings.GizmoScaleBoxOffset * GizmoScale }; GizmoElements[static_cast<uint8>(ECogDebug_GizmoElementType::ScaleZ)] = {ECogDebug_GizmoType::ScaleAxis, ECogDebug_GizmoAxis::Z, FVector::ZAxisVector, UnitAxisZ, RotZ, GizmoCenter + UnitAxisZ * Settings.GizmoScaleBoxOffset * GizmoScale};
} }
ECogDebug_GizmoElementType HoveredElementType = ECogDebug_GizmoElementType::MAX; ECogDebug_GizmoElementType HoveredElementType = ECogDebug_GizmoElementType::MAX;
@@ -340,7 +340,7 @@ bool FCogDebug_Gizmo::Draw(const char* Id, const APlayerController& InPlayerCont
break; break;
} }
default:; default: ;
} }
if (DistanceToMouse < Settings.GizmoCursorSelectionThreshold && DistanceToMouse < MinDistanceToMouse) if (DistanceToMouse < Settings.GizmoCursorSelectionThreshold && DistanceToMouse < MinDistanceToMouse)
@@ -394,7 +394,7 @@ bool FCogDebug_Gizmo::Draw(const char* Id, const APlayerController& InPlayerCont
break; break;
} }
default: default:
break; break;
} }
} }
@@ -409,7 +409,7 @@ bool FCogDebug_Gizmo::Draw(const char* Id, const APlayerController& InPlayerCont
const FRotationTranslationMatrix Matrix(FRotator(90.0f, 0, 0), GroundHit.ImpactPoint); const FRotationTranslationMatrix Matrix(FRotator(90.0f, 0, 0), GroundHit.ImpactPoint);
FCogDebugDrawHelper::DrawArc(World, Matrix, Settings.GizmoGroundRaycastCircleRadius, Settings.GizmoGroundRaycastCircleRadius, 0.0f, 360.0f, 24, Settings.GizmoGroundRaycastCircleColor, false, 0.0f, Settings.GizmoZLow, ThicknessZLow); FCogDebugDrawHelper::DrawArc(World, Matrix, Settings.GizmoGroundRaycastCircleRadius, Settings.GizmoGroundRaycastCircleRadius, 0.0f, 360.0f, 24, Settings.GizmoGroundRaycastCircleColor, false, 0.0f, Settings.GizmoZLow, ThicknessZLow);
} }
DrawDebugLine(World, GizmoCenter, Bottom, Settings.GizmoGroundRaycastColor, false, 0.0f, Settings.GizmoZLow, ThicknessZLow); DrawDebugLine(World, GizmoCenter, Bottom, Settings.GizmoGroundRaycastColor, false, 0.0f, Settings.GizmoZLow, ThicknessZLow);
} }
if (ImGui::IsMouseReleased(ImGuiMouseButton_Left)) if (ImGui::IsMouseReleased(ImGuiMouseButton_Left))
@@ -418,7 +418,7 @@ bool FCogDebug_Gizmo::Draw(const char* Id, const APlayerController& InPlayerCont
} }
else if (DraggedElementType != ECogDebug_GizmoElementType::MAX) else if (DraggedElementType != ECogDebug_GizmoElementType::MAX)
{ {
if (ImGui::IsMouseClicked(ImGuiMouseButton_Right)) if (ImGui::IsMouseClicked(ImGuiMouseButton_Right))
{ {
InOutTransform = InitialTransform; InOutTransform = InitialTransform;
DraggedElementType = ECogDebug_GizmoElementType::MAX; DraggedElementType = ECogDebug_GizmoElementType::MAX;
@@ -429,7 +429,7 @@ bool FCogDebug_Gizmo::Draw(const char* Id, const APlayerController& InPlayerCont
switch (DraggedElement.Type) switch (DraggedElement.Type)
{ {
case ECogDebug_GizmoType::MoveAxis: case ECogDebug_GizmoType::MoveAxis:
{ {
const FVector CursorOnLine = GetMouseCursorOnLine(InPlayerController, InitialTransform.GetTranslation(), DraggedElement.Direction, MousePos - CursorOffset); const FVector CursorOnLine = GetMouseCursorOnLine(InPlayerController, InitialTransform.GetTranslation(), DraggedElement.Direction, MousePos - CursorOffset);
const float Delta = FVector::DotProduct(DraggedElement.Direction, CursorOnLine - InitialTransform.GetTranslation()); const float Delta = FVector::DotProduct(DraggedElement.Direction, CursorOnLine - InitialTransform.GetTranslation());
@@ -472,8 +472,8 @@ bool FCogDebug_Gizmo::Draw(const char* Id, const APlayerController& InPlayerCont
DrawGizmoText(FCogImguiHelper::ToImVec2(Center2D), FCogImguiHelper::ToImU32(Settings.GizmoTextColor), StringCast<ANSICHAR>(*Text).Get()); DrawGizmoText(FCogImguiHelper::ToImVec2(Center2D), FCogImguiHelper::ToImU32(Settings.GizmoTextColor), StringCast<ANSICHAR>(*Text).Get());
//DrawDebugPoint(World, InitialTransform.GetTranslation(), 5.0f, FColor::White); //DrawDebugPoint(World, InitialTransform.GetTranslation(), 5.0f, FColor::White);
//DrawDebugLine(World, InitialTransform.GetTranslation(), InitialTransform.GetTranslation() + WorldDeltaU, FColor::White); //DrawDebugLine(World, InitialTransform.GetTranslation(), InitialTransform.GetTranslation() + WorldDeltaU, FColor::White);
//DrawDebugLine(World, InitialTransform.GetTranslation() + WorldDeltaU, InitialTransform.GetTranslation() + WorldDeltaU + WorldDeltaV, FColor::White); //DrawDebugLine(World, InitialTransform.GetTranslation() + WorldDeltaU, InitialTransform.GetTranslation() + WorldDeltaU + WorldDeltaV, FColor::White);
break; break;
} }
@@ -485,7 +485,7 @@ bool FCogDebug_Gizmo::Draw(const char* Id, const APlayerController& InPlayerCont
const float NormalizedAngle = FRotator::NormalizeAxis(DragAmount * Settings.GizmoRotationSpeed); const float NormalizedAngle = FRotator::NormalizeAxis(DragAmount * Settings.GizmoRotationSpeed);
const float SnappedAngle = FMath::GridSnap(NormalizedAngle, Settings.GizmoRotationSnapEnable ? Settings.GizmoRotationSnapValue : 0.0f); const float SnappedAngle = FMath::GridSnap(NormalizedAngle, Settings.GizmoRotationSnapEnable ? Settings.GizmoRotationSnapValue : 0.0f);
const FQuat RotDelta(-DraggedElement.Axis, FMath::DegreesToRadians(SnappedAngle)); const FQuat RotDelta(-DraggedElement.Axis, FMath::DegreesToRadians(SnappedAngle));
const FQuat NewRot = (Settings.GizmoUseLocalSpace) ? InitialTransform.GetRotation() * RotDelta : RotDelta * InitialTransform.GetRotation(); const FQuat NewRot = (Settings.GizmoUseLocalSpace) ? InitialTransform.GetRotation() * RotDelta : RotDelta * InitialTransform.GetRotation();
InOutTransform.SetRotation(NewRot); InOutTransform.SetRotation(NewRot);
Result = true; Result = true;
@@ -526,84 +526,136 @@ bool FCogDebug_Gizmo::Draw(const char* Id, const APlayerController& InPlayerCont
break; break;
} }
default: default:
break; break;
} }
} }
} }
else if (HoveredElementType != ECogDebug_GizmoElementType::MAX) else if (HoveredElementType != ECogDebug_GizmoElementType::MAX)
{ {
if (ImGui::IsMouseClicked(ImGuiMouseButton_Left)) if (ImGui::IsMouseClicked(ImGuiMouseButton_Left))
{ {
DraggedElementType = HoveredElementType; DraggedElementType = HoveredElementType;
CursorOffset = MousePos - Center2D; CursorOffset = MousePos - Center2D;
InitialTransform = InOutTransform; InitialTransform = InOutTransform;
} }
//else if (ImGui::IsMouseClicked(ImGuiMouseButton_Right)) else if (ImGui::IsMouseClicked(ImGuiMouseButton_Right))
//{ {
// ImGui::OpenPopup(Id); if (Settings.GizmoSupportContextMenu)
//} {
ImGui::OpenPopup(Id);
}
}
} }
//if (ImGui::BeginPopup(Id)) if (Settings.GizmoSupportContextMenu)
//{ {
// FVector Translation = InOutTransform.GetTranslation(); if (ImGui::BeginPopup(Id))
// FRotator Rotation = InOutTransform.GetRotation().Rotator(); {
// FVector Scale = InOutTransform.GetScale3D(); FVector Translation = InOutTransform.GetTranslation();
FRotator Rotation = InOutTransform.GetRotation().Rotator();
FVector Scale = InOutTransform.GetScale3D();
// ImGui::Checkbox("Local Space", &Settings.GizmoUseLocalSpace); ImGui::Checkbox("Local Space", &Settings.GizmoUseLocalSpace);
// ImGui::Separator(); ImGui::Separator();
// ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2(1.0f, 1.0f)); ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2(1.0f, 1.0f));
// if (ImGui::BeginTable("Pools", 6, ImGuiTableFlags_SizingFixedFit)) if (ImGui::BeginTable("Pools", 6, ImGuiTableFlags_SizingFixedFit))
// { {
// ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthFixed, ImGui::GetFontSize() * 5); ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthFixed, ImGui::GetFontSize() * 5);
// ImGui::TableSetupColumn("X", ImGuiTableColumnFlags_WidthFixed, ImGui::GetFontSize() * 4); ImGui::TableSetupColumn("X", ImGuiTableColumnFlags_WidthFixed, ImGui::GetFontSize() * 4);
// ImGui::TableSetupColumn("Y", ImGuiTableColumnFlags_WidthFixed, ImGui::GetFontSize() * 4); ImGui::TableSetupColumn("Y", ImGuiTableColumnFlags_WidthFixed, ImGui::GetFontSize() * 4);
// ImGui::TableSetupColumn("Z", ImGuiTableColumnFlags_WidthFixed, ImGui::GetFontSize() * 4); ImGui::TableSetupColumn("Z", ImGuiTableColumnFlags_WidthFixed, ImGui::GetFontSize() * 4);
// ImGui::TableSetupColumn("SnapEnable", ImGuiTableColumnFlags_WidthFixed, ImGui::GetFontSize() * 4); ImGui::TableSetupColumn("SnapEnable", ImGuiTableColumnFlags_WidthFixed, ImGui::GetFontSize() * 4);
// ImGui::TableSetupColumn("Snap", ImGuiTableColumnFlags_WidthFixed, ImGui::GetFontSize() * 3); ImGui::TableSetupColumn("Snap", ImGuiTableColumnFlags_WidthFixed, ImGui::GetFontSize() * 3);
// ImGui::PushID("Location"); ImGui::PushID("Location");
// ImGui::TableNextRow(); ImGui::TableNextRow();
// ImGui::TableNextColumn(); ImGui::TableNextColumn();
// ImGui::Text("Location"); ImGui::Text("Location");
// if (RenderComponent("##X", &Translation.X, 0.0)) { InOutTransform.SetTranslation(Translation); }
// if (RenderComponent("##Y", &Translation.Y, 0.0)) { InOutTransform.SetTranslation(Translation); } bool Translate = false;
// if (RenderComponent("##Z", &Translation.Z, 0.0)) { InOutTransform.SetTranslation(Translation); } Translate |= RenderComponent("##X", &Translation.X, 0.0);
// RenderSnap(&Settings.GizmoTranslationSnapEnable, &Settings.GizmoTranslationSnapValue); Translate |= RenderComponent("##Y", &Translation.Y, 0.0);
// ImGui::PopID(); Translate |= RenderComponent("##Z", &Translation.Z, 0.0);
if (Translate)
{
if (Settings.GizmoTranslationSnapEnable)
{
Translation.X = FMath::GridSnap(Translation.X, Settings.GizmoTranslationSnapValue);
Translation.Y = FMath::GridSnap(Translation.Y, Settings.GizmoTranslationSnapValue);
Translation.Z = FMath::GridSnap(Translation.Z, Settings.GizmoTranslationSnapValue);
}
InOutTransform.SetTranslation(Translation);
Result = true;
}
RenderSnap(&Settings.GizmoTranslationSnapEnable, &Settings.GizmoTranslationSnapValue);
ImGui::PopID();
// ImGui::PushID("Rotation"); ImGui::PushID("Rotation");
// ImGui::TableNextRow(); ImGui::TableNextRow();
// ImGui::TableNextColumn(); ImGui::TableNextColumn();
// ImGui::Text("Rotation"); ImGui::Text("Rotation");
// if (RenderComponent("##X", &Rotation.Yaw, 0.0)) { InOutTransform.SetRotation(Rotation.Quaternion()); }
// if (RenderComponent("##Y", &Rotation.Pitch, 0.0)) { InOutTransform.SetRotation(Rotation.Quaternion()); }
// if (RenderComponent("##Z", &Rotation.Roll, 0.0)) { InOutTransform.SetRotation(Rotation.Quaternion()); }
// RenderSnap(&Settings.GizmoRotationSnapEnable, &Settings.GizmoRotationSnapValue);
// ImGui::PopID();
// ImGui::PushID("Scale"); bool Rotate = false;
// ImGui::TableNextRow(); Rotate |= RenderComponent("##X", &Rotation.Yaw, 0.0);
// ImGui::TableNextColumn(); Rotate |= RenderComponent("##Y", &Rotation.Pitch, 0.0);
// ImGui::Text("Scale"); Rotate |= RenderComponent("##Z", &Rotation.Roll, 0.0);
// if (RenderComponent("##X", &Scale.X, 0.0)) { InOutTransform.SetScale3D(Scale); }
// if (RenderComponent("##Y", &Scale.Y, 0.0)) { InOutTransform.SetScale3D(Scale); }
// if (RenderComponent("##Z", &Scale.Z, 0.0)) { InOutTransform.SetScale3D(Scale); }
// RenderSnap(&Settings.GizmoScaleSnapEnable, &Settings.GizmoScaleSnapValue);
// ImGui::PopID();
// ImGui::EndTable(); if (Rotate)
// } {
if (Settings.GizmoRotationSnapEnable)
{
Rotation.Yaw = FMath::GridSnap(Rotation.Yaw, Settings.GizmoRotationSnapValue);
Rotation.Pitch = FMath::GridSnap(Rotation.Pitch, Settings.GizmoRotationSnapValue);
Rotation.Roll = FMath::GridSnap(Rotation.Roll, Settings.GizmoRotationSnapValue);
}
InOutTransform.SetRotation(Rotation.Quaternion());
Result = true;
}
RenderSnap(&Settings.GizmoRotationSnapEnable, &Settings.GizmoRotationSnapValue);
ImGui::PopID();
// ImGui::PopStyleVar(); ImGui::PushID("Scale");
ImGui::TableNextRow();
ImGui::TableNextColumn();
ImGui::Text("Scale");
// ImGui::EndPopup(); bool Rescale = false;
//} Rescale |= RenderComponent("##X", &Scale.X, 1.0);
Rescale |= RenderComponent("##Y", &Scale.Y, 1.0);
Rescale |= RenderComponent("##Z", &Scale.Z, 1.0);
if (Rescale)
{
if (Settings.GizmoScaleSnapEnable)
{
Scale.X = FMath::GridSnap(Scale.X, Settings.GizmoScaleSnapValue);
Scale.Y = FMath::GridSnap(Scale.Y, Settings.GizmoScaleSnapValue);
Scale.Z = FMath::GridSnap(Scale.Z, Settings.GizmoScaleSnapValue);
}
InOutTransform.SetScale3D(Scale);
Result = true;
}
RenderSnap(&Settings.GizmoScaleSnapEnable, &Settings.GizmoScaleSnapValue);
ImGui::PopID();
ImGui::EndTable();
}
ImGui::PopStyleVar();
ImGui::EndPopup();
}
}
return Result; return Result;
} }
@@ -59,7 +59,7 @@ struct COGDEBUG_API FCogDebugDraw
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 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 Overlap(const FLogCategoryBase& LogCategory, const UObject* WorldContextObject, const FCollisionShape& Shape, const FVector& Location, const FQuat& Rotation, const bool HasHits, TArray<FOverlapResult>& OverlapResults, const FCogDebugDrawOverlapParams& Settings);
static void ReplicateShape(const UObject* WorldContextObject, const FCogDebugShape& Shape); static void ReplicateShape(const UObject* WorldContextObject, const FCogDebugShape& Shape);
@@ -64,7 +64,7 @@ public:
static void DrawPrimitiveComponent(const UPrimitiveComponent& PrimitiveComponent, const int32 BodyIndex, const FColor& Color, const bool Persistent, const float LifeTime, const uint8 DepthPriority, const float Thickness, const bool DrawName = true, const bool DrawNameShadow = true, const float DrawNameSize = 1.0f); static void DrawPrimitiveComponent(const UPrimitiveComponent& PrimitiveComponent, const int32 BodyIndex, const FColor& Color, const bool Persistent, const float LifeTime, const uint8 DepthPriority, const float Thickness, const bool DrawName = true, const bool DrawNameShadow = true, const float DrawNameSize = 1.0f);
static void DrawOverlap(const UWorld* World, const FCollisionShape& Shape, const FVector& Location, const FQuat& Rotation, TArray<FOverlapResult>& OverlapResults, const FCogDebugDrawOverlapParams& Settings); static void DrawOverlap(const UWorld* World, const FCollisionShape& Shape, const FVector& Location, const FQuat& Rotation, const bool HasHits, const TArray<FOverlapResult>& OverlapResults, const FCogDebugDrawOverlapParams& Settings);
static void DrawHitResult(const UWorld* World, const FHitResult& HitResult, const FCogDebugDrawLineTraceParams& Settings); static void DrawHitResult(const UWorld* World, const FHitResult& HitResult, const FCogDebugDrawLineTraceParams& Settings);
@@ -86,6 +86,9 @@ struct FCogDebugSettings
UPROPERTY(Config) UPROPERTY(Config)
float GizmoScale = 1.0f; float GizmoScale = 1.0f;
UPROPERTY(Config)
bool GizmoSupportContextMenu = true;
UPROPERTY(Config) UPROPERTY(Config)
bool GizmoUseLocalSpace = false; bool GizmoUseLocalSpace = false;
@@ -276,76 +279,58 @@ struct FCogDebugSettings
FColor ChannelColorDestructible = FColor(255, 255, 0, 0); FColor ChannelColorDestructible = FColor(255, 255, 0, 0);
UPROPERTY(Config) UPROPERTY(Config)
FColor ChannelColorEngineTraceChannel1 = FColor(0, 0, 0, 0); FColor ChannelColorGameTraceChannel1 = FColor(255, 255, 255, 5);
UPROPERTY(Config) UPROPERTY(Config)
FColor ChannelColorEngineTraceChannel2 = FColor(0, 0, 0, 0); FColor ChannelColorGameTraceChannel2 = FColor(255, 255, 255, 5);
UPROPERTY(Config) UPROPERTY(Config)
FColor ChannelColorEngineTraceChannel3 = FColor(0, 0, 0, 0); FColor ChannelColorGameTraceChannel3 = FColor(255, 255, 255, 5);
UPROPERTY(Config) UPROPERTY(Config)
FColor ChannelColorEngineTraceChannel4 = FColor(0, 0, 0, 0); FColor ChannelColorGameTraceChannel4 = FColor(255, 255, 255, 5);
UPROPERTY(Config) UPROPERTY(Config)
FColor ChannelColorEngineTraceChannel5 = FColor(0, 0, 0, 0); FColor ChannelColorGameTraceChannel5 = FColor(255, 255, 255, 5);
UPROPERTY(Config) UPROPERTY(Config)
FColor ChannelColorEngineTraceChannel6 = FColor(0, 0, 0, 0); FColor ChannelColorGameTraceChannel6 = FColor(255, 255, 255, 5);
UPROPERTY(Config) UPROPERTY(Config)
FColor ChannelColorGameTraceChannel1 = FColor(255, 105, 0, 5); FColor ChannelColorGameTraceChannel7 = FColor(255, 255, 255, 5);
UPROPERTY(Config) UPROPERTY(Config)
FColor ChannelColorGameTraceChannel2 = FColor(255, 30, 0, 5); FColor ChannelColorGameTraceChannel8 = FColor(255, 255, 255, 5);
UPROPERTY(Config) UPROPERTY(Config)
FColor ChannelColorGameTraceChannel3 = FColor(0, 0, 0, 0); FColor ChannelColorGameTraceChannel9 = FColor(255, 255, 255, 5);
UPROPERTY(Config) UPROPERTY(Config)
FColor ChannelColorGameTraceChannel4 = FColor(0, 0, 0, 0); FColor ChannelColorGameTraceChannel10 = FColor(255, 255, 255, 5);
UPROPERTY(Config) UPROPERTY(Config)
FColor ChannelColorGameTraceChannel5 = FColor(0, 0, 0, 0); FColor ChannelColorGameTraceChannel11 = FColor(255, 255, 255, 5);
UPROPERTY(Config) UPROPERTY(Config)
FColor ChannelColorGameTraceChannel6 = FColor(0, 0, 0, 0); FColor ChannelColorGameTraceChannel12 = FColor(255, 255, 255, 5);
UPROPERTY(Config) UPROPERTY(Config)
FColor ChannelColorGameTraceChannel7 = FColor(0, 0, 0, 0); FColor ChannelColorGameTraceChannel13 = FColor(255, 255, 255, 5);
UPROPERTY(Config) UPROPERTY(Config)
FColor ChannelColorGameTraceChannel8 = FColor(0, 0, 0, 0); FColor ChannelColorGameTraceChannel14 = FColor(255, 255, 255, 5);
UPROPERTY(Config) UPROPERTY(Config)
FColor ChannelColorGameTraceChannel9 = FColor(0, 0, 0, 0); FColor ChannelColorGameTraceChannel15 = FColor(255, 255, 255, 5);
UPROPERTY(Config) UPROPERTY(Config)
FColor ChannelColorGameTraceChannel10 = FColor(0, 0, 0, 0); FColor ChannelColorGameTraceChannel16 = FColor(255, 255, 255, 5);
UPROPERTY(Config) UPROPERTY(Config)
FColor ChannelColorGameTraceChannel11 = FColor(0, 0, 0, 0); FColor ChannelColorGameTraceChannel17 = FColor(255, 255, 255, 5);
UPROPERTY(Config) UPROPERTY(Config)
FColor ChannelColorGameTraceChannel12 = FColor(0, 0, 0, 0); FColor ChannelColorGameTraceChannel18 = FColor(255, 255, 255, 5);
UPROPERTY(Config)
FColor ChannelColorGameTraceChannel13 = FColor(0, 0, 0, 0);
UPROPERTY(Config)
FColor ChannelColorGameTraceChannel14 = FColor(0, 0, 0, 0);
UPROPERTY(Config)
FColor ChannelColorGameTraceChannel15 = FColor(0, 0, 0, 0);
UPROPERTY(Config)
FColor ChannelColorGameTraceChannel16 = FColor(0, 0, 0, 0);
UPROPERTY(Config)
FColor ChannelColorGameTraceChannel17 = FColor(0, 0, 0, 0);
UPROPERTY(Config)
FColor ChannelColorGameTraceChannel18 = FColor(0, 0, 0, 0);
UPROPERTY(Config) UPROPERTY(Config)
TArray<FString> SecondaryBoneWildcards = { TArray<FString> SecondaryBoneWildcards = {
@@ -14,10 +14,10 @@ ACogEngineCollisionTester::ACogEngineCollisionTester(const FObjectInitializer& O
PrimaryActorTick.bCanEverTick = true; PrimaryActorTick.bCanEverTick = true;
PrimaryActorTick.bStartWithTickEnabled = true; PrimaryActorTick.bStartWithTickEnabled = true;
StartComponent = CreateDefaultSubobject<USceneComponent>(TEXT("Start")); StartComponent = CreateDefaultSubobject<USceneComponent>(TEXT("Start"));
RootComponent = StartComponent; RootComponent = StartComponent;
EndComponent = CreateDefaultSubobject<USceneComponent>(TEXT("End")); EndComponent = CreateDefaultSubobject<USceneComponent>(TEXT("End"));
EndComponent->SetupAttachment(RootComponent); EndComponent->SetupAttachment(RootComponent);
EndComponent->SetRelativeLocation(FVector(1000, 0, 0)); EndComponent->SetRelativeLocation(FVector(1000, 0, 0));
} }
@@ -29,7 +29,7 @@ bool ACogEngineCollisionTester::ShouldTickIfViewportsOnly() const
{ {
return true; return true;
} }
return false; return false;
} }
@@ -42,11 +42,13 @@ void ACogEngineCollisionTester::Tick(float DeltaSeconds)
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
void ACogEngineCollisionTester::Query() const void ACogEngineCollisionTester::Query() const
{ {
const UWorld* World = GetWorld();
FVector QueryStart = StartComponent->GetComponentLocation(); FVector QueryStart = StartComponent->GetComponentLocation();
FVector QueryEnd = EndComponent->GetComponentLocation(); FVector QueryEnd = EndComponent->GetComponentLocation();
FQuat QueryRotation = StartComponent->GetComponentQuat(); FQuat QueryRotation = StartComponent->GetComponentQuat();
bool HasHits = false; bool HasHits = false;
static const FName TraceTag(TEXT("FCogWindow_Collision")); static const FName TraceTag(TEXT("FCogWindow_Collision"));
const FCollisionQueryParams QueryParams(TraceTag, SCENE_QUERY_STAT_ONLY(CogHitDetection), TraceComplex); const FCollisionQueryParams QueryParams(TraceTag, SCENE_QUERY_STAT_ONLY(CogHitDetection), TraceComplex);
@@ -58,243 +60,284 @@ void ACogEngineCollisionTester::Query() const
{ {
switch (Shape) switch (Shape)
{ {
case ECogEngine_CollisionQueryShape::Sphere: QueryShape.SetSphere(ShapeExtent.X); break; case ECogEngine_CollisionQueryShape::Sphere: QueryShape.SetSphere(ShapeExtent.X);
case ECogEngine_CollisionQueryShape::Capsule: QueryShape.SetCapsule(ShapeExtent.X, ShapeExtent.Z); break; break;
case ECogEngine_CollisionQueryShape::Box: QueryShape.SetBox(FVector3f(ShapeExtent)); break; case ECogEngine_CollisionQueryShape::Capsule: QueryShape.SetCapsule(ShapeExtent.X, ShapeExtent.Z);
break;
case ECogEngine_CollisionQueryShape::Box: QueryShape.SetBox(FVector3f(ShapeExtent));
break;
} }
} }
switch (Type) switch (Type)
{ {
case ECogEngine_CollisionQueryType::Overlap: case ECogEngine_CollisionQueryType::Overlap:
{ {
TArray<FOverlapResult> Overlaps; TArray<FOverlapResult> Overlaps;
switch (By) switch (By)
{ {
case ECogEngine_CollisionQueryBy::Channel: case ECogEngine_CollisionQueryBy::Channel:
{ {
HasHits = GetWorld()->OverlapMultiByChannel(Overlaps, QueryStart, QueryRotation, Channel, QueryShape, QueryParams); switch (OverlapMode)
break; {
} case ECogEngine_CollisionQueryOverlapMode::AnyTest:
HasHits = World->OverlapAnyTestByChannel(QueryStart, QueryRotation, TraceChannel, QueryShape, QueryParams);
break;
case ECogEngine_CollisionQueryBy::ObjectType: case ECogEngine_CollisionQueryOverlapMode::BlockingTest:
{ HasHits = World->OverlapBlockingTestByChannel(QueryStart, QueryRotation, TraceChannel, QueryShape, QueryParams);
FCollisionObjectQueryParams QueryObjectParams; break;
QueryObjectParams.ObjectTypesToQuery = ObjectTypesToQuery;
HasHits = GetWorld()->OverlapMultiByObjectType(Overlaps, QueryStart, QueryRotation, QueryObjectParams, QueryShape, QueryParams);
break;
}
case ECogEngine_CollisionQueryBy::Profile: case ECogEngine_CollisionQueryOverlapMode::Multi:
{ HasHits = World->OverlapMultiByChannel(Overlaps, QueryStart, QueryRotation, TraceChannel, QueryShape, QueryParams);
HasHits = GetWorld()->OverlapMultiByProfile(Overlaps, QueryStart, QueryRotation, ProfileName, QueryShape, QueryParams); break;
break; }
} break;
} }
FCogDebugDrawOverlapParams DrawParams; case ECogEngine_CollisionQueryBy::ObjectType:
FCogDebug::GetDebugDrawOverlapSettings(DrawParams); {
FCogDebugDrawHelper::DrawOverlap(GetWorld(), QueryShape, QueryStart, QueryRotation, Overlaps, DrawParams); FCollisionObjectQueryParams QueryObjectParams;
break; QueryObjectParams.ObjectTypesToQuery = ObjectTypesToQuery;
}
case ECogEngine_CollisionQueryType::LineTrace: switch (OverlapMode)
{ {
TArray<FHitResult> Hits; case ECogEngine_CollisionQueryOverlapMode::AnyTest:
switch (By) HasHits = World->OverlapAnyTestByObjectType(QueryStart, QueryRotation, QueryObjectParams, QueryShape, QueryParams);
{ break;
case ECogEngine_CollisionQueryBy::Channel:
{
switch (Mode)
{
case ECogEngine_CollisionQueryMode::Single:
{
FHitResult Hit;
HasHits = GetWorld()->LineTraceSingleByChannel(Hit, QueryStart, QueryEnd, Channel, QueryParams);
if (HasHits)
{
Hits.Add(Hit);
}
break;
}
case ECogEngine_CollisionQueryMode::Multi:
{
HasHits = GetWorld()->LineTraceMultiByChannel(Hits, QueryStart, QueryEnd, Channel, QueryParams);
break;
}
case ECogEngine_CollisionQueryMode::Test:
{
HasHits = GetWorld()->LineTraceTestByChannel(QueryStart, QueryEnd, Channel, QueryParams);
break;
}
}
break; case ECogEngine_CollisionQueryOverlapMode::BlockingTest:
} break;
case ECogEngine_CollisionQueryBy::ObjectType: case ECogEngine_CollisionQueryOverlapMode::Multi:
{ HasHits = World->OverlapMultiByObjectType(Overlaps, QueryStart, QueryRotation, QueryObjectParams, QueryShape, QueryParams);
FCollisionObjectQueryParams QueryObjectParams; break;
QueryObjectParams.ObjectTypesToQuery = ObjectTypesToQuery; }
break;
}
switch (Mode) case ECogEngine_CollisionQueryBy::Profile:
{ {
case ECogEngine_CollisionQueryMode::Single: switch (OverlapMode)
{ {
FHitResult Hit; case ECogEngine_CollisionQueryOverlapMode::AnyTest:
HasHits = GetWorld()->LineTraceSingleByObjectType(Hit, QueryStart, QueryEnd, QueryObjectParams, QueryParams); HasHits = World->OverlapAnyTestByProfile(QueryStart, QueryRotation, ProfileName, QueryShape, QueryParams);
if (HasHits) break;
{
Hits.Add(Hit);
}
break;
}
case ECogEngine_CollisionQueryMode::Multi:
{
HasHits = GetWorld()->LineTraceMultiByObjectType(Hits, QueryStart, QueryEnd, QueryObjectParams, QueryParams);
break;
}
case ECogEngine_CollisionQueryMode::Test:
{
HasHits = GetWorld()->LineTraceTestByObjectType(QueryStart, QueryEnd, QueryObjectParams, QueryParams);
break;
}
}
break;
}
case ECogEngine_CollisionQueryBy::Profile: case ECogEngine_CollisionQueryOverlapMode::BlockingTest:
{ HasHits = World->OverlapBlockingTestByProfile(QueryStart, QueryRotation, ProfileName, QueryShape, QueryParams);
switch (Mode) break;
{
case ECogEngine_CollisionQueryMode::Single:
{
FHitResult Hit;
HasHits = GetWorld()->LineTraceSingleByProfile(Hit, QueryStart, QueryEnd, ProfileName, QueryParams);
if (HasHits)
{
Hits.Add(Hit);
}
break;
}
case ECogEngine_CollisionQueryMode::Multi:
{
HasHits = GetWorld()->LineTraceMultiByProfile(Hits, QueryStart, QueryEnd, ProfileName, QueryParams);
break;
}
case ECogEngine_CollisionQueryMode::Test:
{
HasHits = GetWorld()->LineTraceTestByProfile(QueryStart, QueryEnd, ProfileName, QueryParams);
break;
}
}
break;
}
}
FCogDebugDrawLineTraceParams DrawParams; case ECogEngine_CollisionQueryOverlapMode::Multi:
FCogDebug::GetDebugDrawLineTraceSettings(DrawParams); HasHits = World->OverlapMultiByProfile(Overlaps, QueryStart, QueryRotation, ProfileName, QueryShape, QueryParams);
FCogDebugDrawHelper::DrawLineTrace(GetWorld(), QueryStart, QueryEnd, HasHits, Hits, DrawParams); break;
break; }
} break;
}
}
case ECogEngine_CollisionQueryType::Sweep: FCogDebugDrawOverlapParams DrawParams;
{ FCogDebug::GetDebugDrawOverlapSettings(DrawParams);
TArray<FHitResult> Hits; FCogDebugDrawHelper::DrawOverlap(World, QueryShape, QueryStart, QueryRotation, HasHits, Overlaps, DrawParams);
switch (By) break;
{ }
case ECogEngine_CollisionQueryBy::Channel:
{
switch (Mode)
{
case ECogEngine_CollisionQueryMode::Single:
{
FHitResult Hit;
HasHits = GetWorld()->SweepSingleByChannel(Hit, QueryStart, QueryEnd, QueryRotation, Channel, QueryShape, QueryParams);
if (HasHits)
{
Hits.Add(Hit);
}
break;
}
case ECogEngine_CollisionQueryMode::Multi:
{
HasHits = GetWorld()->SweepMultiByChannel(Hits, QueryStart, QueryEnd, QueryRotation, Channel, QueryShape, QueryParams);
break;
}
case ECogEngine_CollisionQueryMode::Test:
{
HasHits = GetWorld()->SweepTestByChannel(QueryStart, QueryEnd, QueryRotation, Channel, QueryShape, QueryParams);
break;
}
}
break;
}
case ECogEngine_CollisionQueryBy::ObjectType: case ECogEngine_CollisionQueryType::LineTrace:
{ {
FCollisionObjectQueryParams QueryObjectParams; TArray<FHitResult> Hits;
QueryObjectParams.ObjectTypesToQuery = ObjectTypesToQuery; switch (By)
{
case ECogEngine_CollisionQueryBy::Channel:
{
switch (TraceMode)
{
case ECogEngine_CollisionQueryTraceMode::Single:
{
FHitResult Hit;
HasHits = World->LineTraceSingleByChannel(Hit, QueryStart, QueryEnd, TraceChannel, QueryParams);
if (HasHits)
{
Hits.Add(Hit);
}
break;
}
case ECogEngine_CollisionQueryTraceMode::Multi:
{
HasHits = World->LineTraceMultiByChannel(Hits, QueryStart, QueryEnd, TraceChannel, QueryParams);
break;
}
case ECogEngine_CollisionQueryTraceMode::Test:
{
HasHits = World->LineTraceTestByChannel(QueryStart, QueryEnd, TraceChannel, QueryParams);
break;
}
}
break;
}
switch (Mode) case ECogEngine_CollisionQueryBy::ObjectType:
{ {
case ECogEngine_CollisionQueryMode::Single: FCollisionObjectQueryParams QueryObjectParams;
{ QueryObjectParams.ObjectTypesToQuery = ObjectTypesToQuery;
FHitResult Hit;
HasHits = GetWorld()->SweepSingleByObjectType(Hit, QueryStart, QueryEnd, QueryRotation, QueryObjectParams, QueryShape, QueryParams);
if (HasHits)
{
Hits.Add(Hit);
}
break;
}
case ECogEngine_CollisionQueryMode::Multi:
{
HasHits = GetWorld()->SweepMultiByObjectType(Hits, QueryStart, QueryEnd, QueryRotation, QueryObjectParams, QueryShape, QueryParams);
break;
}
case ECogEngine_CollisionQueryMode::Test:
{
HasHits = GetWorld()->SweepTestByObjectType(QueryStart, QueryEnd, QueryRotation, QueryObjectParams, QueryShape, QueryParams);
break;
}
}
break;
}
case ECogEngine_CollisionQueryBy::Profile: switch (TraceMode)
{ {
switch (Mode) case ECogEngine_CollisionQueryTraceMode::Single:
{ {
case ECogEngine_CollisionQueryMode::Single: FHitResult Hit;
{ HasHits = World->LineTraceSingleByObjectType(Hit, QueryStart, QueryEnd, QueryObjectParams, QueryParams);
FHitResult Hit; if (HasHits)
HasHits = GetWorld()->SweepSingleByProfile(Hit, QueryStart, QueryEnd, QueryRotation, ProfileName, QueryShape, QueryParams); {
if (HasHits) Hits.Add(Hit);
{ }
Hits.Add(Hit); break;
} }
break; case ECogEngine_CollisionQueryTraceMode::Multi:
} {
case ECogEngine_CollisionQueryMode::Multi: HasHits = World->LineTraceMultiByObjectType(Hits, QueryStart, QueryEnd, QueryObjectParams, QueryParams);
{ break;
HasHits = GetWorld()->SweepMultiByProfile(Hits, QueryStart, QueryEnd, QueryRotation, ProfileName, QueryShape, QueryParams); }
break; case ECogEngine_CollisionQueryTraceMode::Test:
} {
case ECogEngine_CollisionQueryMode::Test: HasHits = World->LineTraceTestByObjectType(QueryStart, QueryEnd, QueryObjectParams, QueryParams);
{ break;
HasHits = GetWorld()->SweepTestByProfile(QueryStart, QueryEnd, QueryRotation, ProfileName, QueryShape, QueryParams); }
break; }
} break;
} }
break;
}
}
FCogDebugDrawSweepParams DrawParams; case ECogEngine_CollisionQueryBy::Profile:
FCogDebug::GetDebugDrawSweepSettings(DrawParams); {
FCogDebugDrawHelper::DrawSweep(GetWorld(), QueryShape, QueryStart, QueryEnd, QueryRotation, HasHits, Hits, DrawParams); switch (TraceMode)
break; {
} case ECogEngine_CollisionQueryTraceMode::Single:
{
FHitResult Hit;
HasHits = World->LineTraceSingleByProfile(Hit, QueryStart, QueryEnd, ProfileName, QueryParams);
if (HasHits)
{
Hits.Add(Hit);
}
break;
}
case ECogEngine_CollisionQueryTraceMode::Multi:
{
HasHits = World->LineTraceMultiByProfile(Hits, QueryStart, QueryEnd, ProfileName, QueryParams);
break;
}
case ECogEngine_CollisionQueryTraceMode::Test:
{
HasHits = World->LineTraceTestByProfile(QueryStart, QueryEnd, ProfileName, QueryParams);
break;
}
}
break;
}
}
FCogDebugDrawLineTraceParams DrawParams;
FCogDebug::GetDebugDrawLineTraceSettings(DrawParams);
FCogDebugDrawHelper::DrawLineTrace(World, QueryStart, QueryEnd, HasHits, Hits, DrawParams);
break;
}
case ECogEngine_CollisionQueryType::Sweep:
{
TArray<FHitResult> Hits;
switch (By)
{
case ECogEngine_CollisionQueryBy::Channel:
{
switch (TraceMode)
{
case ECogEngine_CollisionQueryTraceMode::Single:
{
FHitResult Hit;
HasHits = World->SweepSingleByChannel(Hit, QueryStart, QueryEnd, QueryRotation, TraceChannel, QueryShape, QueryParams);
if (HasHits)
{
Hits.Add(Hit);
}
break;
}
case ECogEngine_CollisionQueryTraceMode::Multi:
{
HasHits = World->SweepMultiByChannel(Hits, QueryStart, QueryEnd, QueryRotation, TraceChannel, QueryShape, QueryParams);
break;
}
case ECogEngine_CollisionQueryTraceMode::Test:
{
HasHits = World->SweepTestByChannel(QueryStart, QueryEnd, QueryRotation, TraceChannel, QueryShape, QueryParams);
break;
}
}
break;
}
case ECogEngine_CollisionQueryBy::ObjectType:
{
FCollisionObjectQueryParams QueryObjectParams;
QueryObjectParams.ObjectTypesToQuery = ObjectTypesToQuery;
switch (TraceMode)
{
case ECogEngine_CollisionQueryTraceMode::Single:
{
FHitResult Hit;
HasHits = World->SweepSingleByObjectType(Hit, QueryStart, QueryEnd, QueryRotation, QueryObjectParams, QueryShape, QueryParams);
if (HasHits)
{
Hits.Add(Hit);
}
break;
}
case ECogEngine_CollisionQueryTraceMode::Multi:
{
HasHits = World->SweepMultiByObjectType(Hits, QueryStart, QueryEnd, QueryRotation, QueryObjectParams, QueryShape, QueryParams);
break;
}
case ECogEngine_CollisionQueryTraceMode::Test:
{
HasHits = World->SweepTestByObjectType(QueryStart, QueryEnd, QueryRotation, QueryObjectParams, QueryShape, QueryParams);
break;
}
}
break;
}
case ECogEngine_CollisionQueryBy::Profile:
{
switch (TraceMode)
{
case ECogEngine_CollisionQueryTraceMode::Single:
{
FHitResult Hit;
HasHits = World->SweepSingleByProfile(Hit, QueryStart, QueryEnd, QueryRotation, ProfileName, QueryShape, QueryParams);
if (HasHits)
{
Hits.Add(Hit);
}
break;
}
case ECogEngine_CollisionQueryTraceMode::Multi:
{
HasHits = World->SweepMultiByProfile(Hits, QueryStart, QueryEnd, QueryRotation, ProfileName, QueryShape, QueryParams);
break;
}
case ECogEngine_CollisionQueryTraceMode::Test:
{
HasHits = World->SweepTestByProfile(QueryStart, QueryEnd, QueryRotation, ProfileName, QueryShape, QueryParams);
break;
}
}
break;
}
}
FCogDebugDrawSweepParams DrawParams;
FCogDebug::GetDebugDrawSweepSettings(DrawParams);
FCogDebugDrawHelper::DrawSweep(World, QueryShape, QueryStart, QueryEnd, QueryRotation, HasHits, Hits, DrawParams);
break;
}
} }
} }
@@ -103,14 +103,27 @@ void FCogEngineWindow_CollisionTester::RenderContent()
if (const APlayerController* LocalPlayerController = GetLocalPlayerController()) if (const APlayerController* LocalPlayerController = GetLocalPlayerController())
{ {
StartGizmo.Draw("CollisionTesterStartGizmo", *LocalPlayerController, *CollisionTester->StartComponent); StartGizmo.Draw("CollisionTesterStartGizmo", *LocalPlayerController, *CollisionTester->StartComponent);
EndGizmo.Draw("CollisionTesterEndGizmo", *LocalPlayerController, *CollisionTester->EndComponent, ECogDebug_GizmoFlags::NoRotation | ECogDebug_GizmoFlags::NoScale);
if (CollisionTester->Type != ECogEngine_CollisionQueryType::Overlap)
{
EndGizmo.Draw("CollisionTesterEndGizmo", *LocalPlayerController, *CollisionTester->EndComponent, ECogDebug_GizmoFlags::NoRotation | ECogDebug_GizmoFlags::NoScale);
}
} }
FCogWidgets::SetNextItemToShortWidth(); FCogWidgets::SetNextItemToShortWidth();
FCogWidgets::ComboboxEnum("Type", CollisionTester->Type); FCogWidgets::ComboboxEnum("Type", CollisionTester->Type);
FCogWidgets::SetNextItemToShortWidth(); if (CollisionTester->Type == ECogEngine_CollisionQueryType::Overlap)
FCogWidgets::ComboboxEnum("Mode", CollisionTester->Mode); {
FCogWidgets::SetNextItemToShortWidth();
FCogWidgets::ComboboxEnum("Mode", CollisionTester->OverlapMode);
}
else
{
FCogWidgets::SetNextItemToShortWidth();
FCogWidgets::ComboboxEnum("Mode", CollisionTester->TraceMode);
}
FCogWidgets::SetNextItemToShortWidth(); FCogWidgets::SetNextItemToShortWidth();
FCogWidgets::ComboboxEnum("By", CollisionTester->By); FCogWidgets::ComboboxEnum("By", CollisionTester->By);
@@ -121,10 +134,10 @@ void FCogEngineWindow_CollisionTester::RenderContent()
if (CollisionTester->By == ECogEngine_CollisionQueryBy::Channel) if (CollisionTester->By == ECogEngine_CollisionQueryBy::Channel)
{ {
FCogWidgets::SetNextItemToShortWidth(); FCogWidgets::SetNextItemToShortWidth();
ECollisionChannel Channel = CollisionTester->Channel.GetValue(); ECollisionChannel Channel = CollisionTester->TraceChannel.GetValue();
if (FCogWidgets::ComboCollisionChannel("Channel", Channel)) if (FCogWidgets::ComboTraceChannel("Channel", Channel))
{ {
CollisionTester->Channel = Channel; CollisionTester->TraceChannel = Channel;
} }
} }
//------------------------------------------------- //-------------------------------------------------
@@ -215,6 +228,6 @@ void FCogEngineWindow_CollisionTester::RenderContent()
else if (CollisionTester->By == ECogEngine_CollisionQueryBy::ObjectType) else if (CollisionTester->By == ECogEngine_CollisionQueryBy::ObjectType)
{ {
ImGui::Separator(); ImGui::Separator();
FCogWidgets::CollisionProfileChannels(CollisionTester->ObjectTypesToQuery); FCogWidgets::CollisionObjectTypeChannels(CollisionTester->ObjectTypesToQuery);
} }
} }
@@ -132,7 +132,7 @@ void FCogEngineWindow_CollisionViewer::RenderContent()
} }
ImGui::Separator(); ImGui::Separator();
FCogWidgets::CollisionProfileChannels(Config->ObjectTypesToQuery); FCogWidgets::CollisionObjectTypeChannels(Config->ObjectTypesToQuery);
//------------------------------------------------- //-------------------------------------------------
// Perform Query // Perform Query
@@ -41,6 +41,9 @@ void FCogEngineWindow_DebugSettings::PreSaveConfig()
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
void RenderCollisionChannelColor(const UCollisionProfile& CollisionProfile, FColor& Color, ECollisionChannel Channel, ImGuiColorEditFlags ColorEditFlags) void RenderCollisionChannelColor(const UCollisionProfile& CollisionProfile, FColor& Color, ECollisionChannel Channel, ImGuiColorEditFlags ColorEditFlags)
{ {
if (CollisionProfile.ConvertToObjectType(Channel) == TraceTypeQuery_MAX && CollisionProfile.ConvertToTraceType(Channel) == TraceTypeQuery_MAX)
{ return; }
const FString ChannelName = CollisionProfile.ReturnChannelNameFromContainerIndex(Channel).ToString(); const FString ChannelName = CollisionProfile.ReturnChannelNameFromContainerIndex(Channel).ToString();
FCogImguiHelper::ColorEdit4(StringCast<ANSICHAR>(*ChannelName).Get(), Color, ColorEditFlags); FCogImguiHelper::ColorEdit4(StringCast<ANSICHAR>(*ChannelName).Get(), Color, ColorEditFlags);
} }
@@ -169,8 +172,11 @@ void FCogEngineWindow_DebugSettings::RenderContent()
ImGui::Checkbox("Use Local Space", &Settings.GizmoUseLocalSpace); ImGui::Checkbox("Use Local Space", &Settings.GizmoUseLocalSpace);
ImGui::Checkbox("Support Context Menu", &Settings.GizmoSupportContextMenu);
ImGui::SetItemTooltip("Does right clicking on the gizmo displays a context menu ?");
FCogWidgets::SetNextItemToShortWidth(); FCogWidgets::SetNextItemToShortWidth();
ImGui::DragFloat("Gizmo Scale", &Settings.GizmoScale, 0.1f, 0.1f, 10.0f, "%.1f"); ImGui::DragFloat("Scale", &Settings.GizmoScale, 0.1f, 0.1f, 10.0f, "%.1f");
ImGui::SetItemTooltip("The scale of the gizmo."); ImGui::SetItemTooltip("The scale of the gizmo.");
FCogWidgets::SetNextItemToShortWidth(); FCogWidgets::SetNextItemToShortWidth();
@@ -249,7 +255,7 @@ void FCogEngineWindow_DebugSettings::RenderContent()
FCogWidgets::SetNextItemToShortWidth(); FCogWidgets::SetNextItemToShortWidth();
ECollisionChannel Channel = Settings.GizmoGroundRaycastChannel.GetValue(); ECollisionChannel Channel = Settings.GizmoGroundRaycastChannel.GetValue();
if (FCogWidgets::ComboCollisionChannel("Channel", Channel)) if (FCogWidgets::ComboTraceChannel("Channel", Channel))
{ {
Settings.GizmoGroundRaycastChannel = Channel; Settings.GizmoGroundRaycastChannel = Channel;
} }
@@ -292,12 +298,7 @@ void FCogEngineWindow_DebugSettings::RenderContent()
RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorPhysicsBody, ECC_PhysicsBody, ColorEditFlags); RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorPhysicsBody, ECC_PhysicsBody, ColorEditFlags);
RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorVehicle, ECC_Vehicle, ColorEditFlags); RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorVehicle, ECC_Vehicle, ColorEditFlags);
RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorDestructible, ECC_Destructible, ColorEditFlags); RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorDestructible, ECC_Destructible, ColorEditFlags);
RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorEngineTraceChannel1, ECC_EngineTraceChannel1, ColorEditFlags);
RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorEngineTraceChannel2, ECC_EngineTraceChannel2, ColorEditFlags);
RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorEngineTraceChannel3, ECC_EngineTraceChannel3, ColorEditFlags);
RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorEngineTraceChannel4, ECC_EngineTraceChannel4, ColorEditFlags);
RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorEngineTraceChannel5, ECC_EngineTraceChannel5, ColorEditFlags);
RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorEngineTraceChannel6, ECC_EngineTraceChannel6, ColorEditFlags);
RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorGameTraceChannel1, ECC_GameTraceChannel1, ColorEditFlags); RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorGameTraceChannel1, ECC_GameTraceChannel1, ColorEditFlags);
RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorGameTraceChannel2, ECC_GameTraceChannel2, ColorEditFlags); RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorGameTraceChannel2, ECC_GameTraceChannel2, ColorEditFlags);
RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorGameTraceChannel3, ECC_GameTraceChannel3, ColorEditFlags); RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorGameTraceChannel3, ECC_GameTraceChannel3, ColorEditFlags);
@@ -17,13 +17,22 @@ enum class ECogEngine_CollisionQueryType : uint8
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
UENUM() UENUM()
enum class ECogEngine_CollisionQueryMode : uint8 enum class ECogEngine_CollisionQueryTraceMode : uint8
{ {
Single, Single,
Multi, Multi,
Test, Test,
}; };
//--------------------------------------------------------------------------------------------------------------------------
UENUM()
enum class ECogEngine_CollisionQueryOverlapMode : uint8
{
AnyTest,
BlockingTest,
Multi,
};
//-------------------------------------------------------------------------------------------------------------------------- //--------------------------------------------------------------------------------------------------------------------------
UENUM() UENUM()
enum class ECogEngine_CollisionQueryBy : uint8 enum class ECogEngine_CollisionQueryBy : uint8
@@ -49,7 +58,6 @@ class COGENGINE_API ACogEngineCollisionTester : public AActor
GENERATED_BODY() GENERATED_BODY()
public: public:
ACogEngineCollisionTester(const FObjectInitializer& ObjectInitializer); ACogEngineCollisionTester(const FObjectInitializer& ObjectInitializer);
virtual void Tick(float DeltaSeconds) override; virtual void Tick(float DeltaSeconds) override;
@@ -65,7 +73,10 @@ public:
ECogEngine_CollisionQueryType Type = ECogEngine_CollisionQueryType::LineTrace; ECogEngine_CollisionQueryType Type = ECogEngine_CollisionQueryType::LineTrace;
UPROPERTY(EditAnywhere) UPROPERTY(EditAnywhere)
ECogEngine_CollisionQueryMode Mode = ECogEngine_CollisionQueryMode::Multi; ECogEngine_CollisionQueryTraceMode TraceMode = ECogEngine_CollisionQueryTraceMode::Multi;
UPROPERTY(EditAnywhere)
ECogEngine_CollisionQueryOverlapMode OverlapMode = ECogEngine_CollisionQueryOverlapMode::Multi;
UPROPERTY(EditAnywhere) UPROPERTY(EditAnywhere)
ECogEngine_CollisionQueryBy By = ECogEngine_CollisionQueryBy::Channel; ECogEngine_CollisionQueryBy By = ECogEngine_CollisionQueryBy::Channel;
@@ -80,7 +91,7 @@ public:
int32 ObjectTypesToQuery = 0; int32 ObjectTypesToQuery = 0;
UPROPERTY(EditAnywhere) UPROPERTY(EditAnywhere)
TEnumAsByte<ECollisionChannel> Channel = ECC_WorldStatic; TEnumAsByte<ECollisionChannel> TraceChannel = ECC_Visibility;
UPROPERTY() UPROPERTY()
int32 ProfileIndex = 0; int32 ProfileIndex = 0;
@@ -68,7 +68,7 @@ public:
ECogEngine_CollisionQueryType Type; ECogEngine_CollisionQueryType Type;
UPROPERTY(Config) UPROPERTY(Config)
ECogEngine_CollisionQueryMode Mode; ECogEngine_CollisionQueryTraceMode Mode;
UPROPERTY(Config) UPROPERTY(Config)
ECogEngine_CollisionQueryBy By; ECogEngine_CollisionQueryBy By;
@@ -97,7 +97,7 @@ public:
Type = ECogEngine_CollisionQueryType::LineTrace; Type = ECogEngine_CollisionQueryType::LineTrace;
By = ECogEngine_CollisionQueryBy::Channel; By = ECogEngine_CollisionQueryBy::Channel;
Mode = ECogEngine_CollisionQueryMode::Multi; Mode = ECogEngine_CollisionQueryTraceMode::Multi;
Channel = ECC_WorldStatic; Channel = ECC_WorldStatic;
TraceComplex = false; TraceComplex = false;
Shape = ECogEngine_CollisionQueryShape::Sphere; Shape = ECogEngine_CollisionQueryShape::Sphere;