From 751761d176ee22ef4065c2cbce4a600fc4da3630 Mon Sep 17 00:00:00 2001 From: Arnaud Jamin Date: Sun, 17 Dec 2023 16:40:59 -0500 Subject: [PATCH 1/8] Adding collision tester --- Content/Core/Debug/DA_Debug_Engine.uasset | Bin 4664 -> 4664 bytes .../CogDebug/Private/CogDebugDrawHelper.cpp | 55 + .../CogDebug/Public/CogDebugDrawHelper.h | 4 + .../CogEngineWindow_CollisionTester.cpp | 955 ++++++++++++++++++ ...pp => CogEngineWindow_CollisionViewer.cpp} | 14 +- .../Public/CogEngineWindow_CollisionTester.h | 297 ++++++ ...ns.h => CogEngineWindow_CollisionViewer.h} | 10 +- Source/CogSample/CogSampleGameState.cpp | 7 +- TODO.txt | 1 + 9 files changed, 1329 insertions(+), 14 deletions(-) create mode 100644 Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CollisionTester.cpp rename Plugins/Cog/Source/CogEngine/Private/{CogEngineWindow_Collisions.cpp => CogEngineWindow_CollisionViewer.cpp} (97%) create mode 100644 Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_CollisionTester.h rename Plugins/Cog/Source/CogEngine/Public/{CogEngineWindow_Collisions.h => CogEngineWindow_CollisionViewer.h} (84%) diff --git a/Content/Core/Debug/DA_Debug_Engine.uasset b/Content/Core/Debug/DA_Debug_Engine.uasset index 84dc0e1acd89981d077b4af3da51e49770ad5390..a6278288f4d82a8ffe9d549f7aba9b4e2cf51016 100644 GIT binary patch delta 27 jcmdm?vO{IUK7n|(1KRPCm)-mRO*J#|&X~RNT$UgJsC^79 delta 27 lcmV+$0ObF;B)BAyz7SisSHPLwg+QXURk$gQpsKOXY7xH;4cGtx diff --git a/Plugins/Cog/Source/CogDebug/Private/CogDebugDrawHelper.cpp b/Plugins/Cog/Source/CogDebug/Private/CogDebugDrawHelper.cpp index f670e81..f8c1125 100644 --- a/Plugins/Cog/Source/CogDebug/Private/CogDebugDrawHelper.cpp +++ b/Plugins/Cog/Source/CogDebug/Private/CogDebugDrawHelper.cpp @@ -449,3 +449,58 @@ void FCogDebugDrawHelper::DrawFrustum( DrawDebugLine(World, Verts[2], Verts[6], Color, bPersistentLines, LifeTime, DepthPriority, Thickness); DrawDebugLine(World, Verts[3], Verts[7], Color, bPersistentLines, LifeTime, DepthPriority, Thickness); } + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogDebugDrawHelper::DrawQuad(const UWorld* World, const FVector& Position, const FQuat& Rotation, const FVector2D& Extents, const FColor& Color, bool bPersistent, float LifeTime, uint8 DepthPriority, const float Thickness) +{ + if (GEngine->GetNetMode(World) == NM_DedicatedServer) + { + return; + } + + const FVector U = Rotation.GetAxisZ() * Extents.X; + const FVector V = Rotation.GetAxisY() * Extents.Y; + + const FVector V0 = Position + U + V; + const FVector V1 = Position + U - V; + const FVector V2 = Position - U - V; + const FVector V3 = Position - U + V; + + DrawDebugLine(World, V0, V1, Color, bPersistent, LifeTime, DepthPriority, Thickness); + DrawDebugLine(World, V1, V2, Color, bPersistent, LifeTime, DepthPriority, Thickness); + DrawDebugLine(World, V2, V3, Color, bPersistent, LifeTime, DepthPriority, Thickness); + DrawDebugLine(World, V3, V0, Color, bPersistent, LifeTime, DepthPriority, Thickness); +} + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogDebugDrawHelper::DrawSolidQuad(const UWorld* World, const FVector& Position, const FQuat& Rotation, const FVector2D& Extents, const FColor& Color, bool bPersistent, float LifeTime, uint8 DepthPriority) +{ + if (GEngine->GetNetMode(World) == NM_DedicatedServer) + { + return; + } + + const FVector U = Rotation.GetAxisZ() * Extents.X; + const FVector V = Rotation.GetAxisY() * Extents.Y; + + TArray Verts; + Verts.AddUninitialized(4); + + Verts[0] = Position + U + V; + Verts[1] = Position - U + V; + Verts[2] = Position + U - V; + Verts[3] = Position - U - V; + + TArray Indices; + Indices.AddUninitialized(6); + + Indices[0] = 0; + Indices[1] = 2; + Indices[2] = 1; + + Indices[3] = 1; + Indices[4] = 2; + Indices[5] = 3; + + DrawDebugMesh(World, Verts, Indices, Color, bPersistent, LifeTime, DepthPriority); +} \ No newline at end of file diff --git a/Plugins/Cog/Source/CogDebug/Public/CogDebugDrawHelper.h b/Plugins/Cog/Source/CogDebug/Public/CogDebugDrawHelper.h index 256cd43..5dcc8e8 100644 --- a/Plugins/Cog/Source/CogDebug/Public/CogDebugDrawHelper.h +++ b/Plugins/Cog/Source/CogDebug/Public/CogDebugDrawHelper.h @@ -40,4 +40,8 @@ public: static void DrawHitResult(const UWorld* World, const FHitResult& Hit, const int HitIndex, const EDrawDebugTrace::Type DrawType, const bool ShowHitIndex, const float HitSize, const FLinearColor HitColor, const float DrawDuration, const uint8 DepthPriority = 0); + static void DrawQuad(const UWorld* World, const FVector& Position, const FQuat& Rotation, const FVector2D& Extents, const FColor& Color, bool bPersistent = false, float LifeTime = -1, uint8 DepthPriority = 0, const float Thickness = 0.0f); + + static void DrawSolidQuad(const UWorld* World, const FVector& Position, const FQuat& Rotation, const FVector2D& Extents, const FColor& Color, bool bPersistent = false, float LifeTime = -1, uint8 DepthPriority = 0); + }; diff --git a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CollisionTester.cpp b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CollisionTester.cpp new file mode 100644 index 0000000..c3250e1 --- /dev/null +++ b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CollisionTester.cpp @@ -0,0 +1,955 @@ +#include "CogEngineWindow_CollisionTester.h" + +#include "CogDebugDrawHelper.h" +#include "CogDebugSettings.h" +#include "CogEngineDataAsset.h" +#include "CogImGuiHelper.h" +#include "CogWindowHelper.h" +#include "CogWindowWidgets.h" +#include "Components/BoxComponent.h" +#include "Components/CapsuleComponent.h" +#include "Components/PrimitiveComponent.h" +#include "Components/SceneComponent.h" +#include "Components/SphereComponent.h" +#include "imgui.h" +#include "Kismet/GameplayStatics.h" + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogEngineWindow_CollisionTester::Initialize() +{ + Super::Initialize(); + + bHasMenu = true; + + SetAsset(GetAsset()); + + Config = GetConfig(); +} + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogEngineWindow_CollisionTester::RenderHelp() +{ + ImGui::Text("This window is used to inspect collisions by performing a collision query with the selected channels. " + "The query can be configured in the options. " + "The displayed collision channels can be configured in the '%s' data asset. " + , TCHAR_TO_ANSI(*GetNameSafe(Asset.Get())) + ); +} + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogEngineWindow_CollisionTester::ResetConfig() +{ + Super::ResetConfig(); + + Config->Reset(); +} + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogEngineWindow_CollisionTester::RenderContent() +{ + Super::RenderContent(); + + //------------------------------------------------- + // Query Profile + //------------------------------------------------- + + const UCollisionProfile* CollisionProfile = UCollisionProfile::Get(); + if (CollisionProfile == nullptr) + { + return; + } + + //------------------------------------------------- + // Menu + //------------------------------------------------- + if (ImGui::BeginMenuBar()) + { + if (ImGui::BeginMenu("Options")) + { + ImGui::Checkbox("Draw Hit Locations", &Config->DrawHitLocations); + ImGui::Checkbox("Draw Hit Impact Points", &Config->DrawHitImpactPoints); + ImGui::Checkbox("Draw Hit Shapes", &Config->DrawHitShapes); + ImGui::Checkbox("Draw Hit Normal", &Config->DrawHitNormals); + ImGui::Checkbox("Draw Hit Impact Normal", &Config->DrawHitImpactNormals); + ImGui::Checkbox("Draw Hit Primitives", &Config->DrawHitPrimitives); + ImGui::Checkbox("Draw Hit Actors Names", &Config->DrawHitActorsNames); + + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::SliderFloat("Hit Point Size", &Config->HitPointSize, 0.0f, 20.0f, "%0.f"); + + ImGui::ColorEdit4("No Hit Color", (float*)&Config->NoHitColor, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); + ImGui::ColorEdit4("Hit Color", (float*)&Config->HitColor, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); + ImGui::ColorEdit4("Normal Color", (float*)&Config->NormalColor, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); + ImGui::ColorEdit4("Impact Normal Color", (float*)&Config->ImpactNormalColor, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); + + ImGui::EndMenu(); + } + + ImGui::EndMenuBar(); + } + + FCogWindowWidgets::SetNextItemToShortWidth(); + FCogWindowWidgets::ComboboxEnum("Placement", Config->Placement); + + if (Config->Placement == ECogEngine_CollisionQueryPlacement::Selection) + { + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragFloat3("Location", &Config->LocationStart.X, 1.0f, 0.0f, 0.0f, "%.1f"); + + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragFloat3("Rotation", &Config->Rotation.Pitch, 1.0f, 0.0f, 0.0f, "%.1f"); + } + else if (Config->Placement == ECogEngine_CollisionQueryPlacement::Transform) + { + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragFloat3("Start Location", &Config->LocationStart.X, 1.0f, 0.0f, 0.0f, "%.1f"); + + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragFloat3("End Location", &Config->LocationEnd.X, 1.0f, 0.0f, 0.0f, "%.1f"); + + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragFloat3("Rotation", &Config->Rotation.Pitch, 1.0f, 0.0f, 0.0f, "%.1f"); + } + + if (Config->Type == ECogEngine_CollisionQueryType::LineTrace || Config->Type == ECogEngine_CollisionQueryType::Sweep) + { + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::SliderFloat("Distance", &Config->QueryLength, 0.0f, 20000.0f, "%0.f"); + } + + FCogWindowWidgets::SetNextItemToShortWidth(); + FCogWindowWidgets::ComboboxEnum("Type", Config->Type); + + FCogWindowWidgets::SetNextItemToShortWidth(); + FCogWindowWidgets::ComboboxEnum("By", Config->By); + + //------------------------------------------------- + // Channel + //------------------------------------------------- + if (Config->By == ECogEngine_CollisionQueryBy::Channel) + { + const FName SelectedChannelName = CollisionProfile->ReturnChannelNameFromContainerIndex(Config->Channel); + + FCogWindowWidgets::SetNextItemToShortWidth(); + if (ImGui::BeginCombo("Channel", TCHAR_TO_ANSI(*SelectedChannelName.ToString()), ImGuiComboFlags_HeightLarge)) + { + for (int32 ChannelIndex = 0; ChannelIndex < (int32)ECC_MAX; ++ChannelIndex) + { + const FChannel& Channel = Channels[ChannelIndex]; + if (Channel.IsValid == false) + { + continue; + } + + ImGui::PushID(ChannelIndex); + + const FName ChannelName = CollisionProfile->ReturnChannelNameFromContainerIndex(ChannelIndex); + + if (ImGui::Selectable(TCHAR_TO_ANSI(*ChannelName.ToString()))) + { + Config->Channel = ChannelIndex; + } + + ImGui::PopID(); + } + ImGui::EndCombo(); + } + } + //------------------------------------------------- + // Profile + //------------------------------------------------- + else if (Config->By == ECogEngine_CollisionQueryBy::Profile) + { + const FCollisionResponseTemplate* SelectedProfile = CollisionProfile->GetProfileByIndex(Config->ProfileIndex); + FName SelectedProfileName = SelectedProfile != nullptr ? SelectedProfile->Name : FName("Custom"); + + FCogWindowWidgets::SetNextItemToShortWidth(); + if (ImGui::BeginCombo("Profile", TCHAR_TO_ANSI(*SelectedProfileName.ToString()), ImGuiComboFlags_HeightLargest)) + { + for (int i = 0; i < CollisionProfile->GetNumOfProfiles(); ++i) + { + const FCollisionResponseTemplate* Profile = CollisionProfile->GetProfileByIndex(i); + if (ImGui::Selectable(TCHAR_TO_ANSI(*Profile->Name.ToString()), false)) + { + Config->ProfileIndex = i; + Config->ObjectTypesToQuery = 0; + SelectedProfile = CollisionProfile->GetProfileByIndex(Config->ProfileIndex); + + if (Profile->CollisionEnabled != ECollisionEnabled::NoCollision) + { + for (int j = 0; j < ECC_MAX; ++j) + { + ECollisionResponse Response = Profile->ResponseToChannels.GetResponse((ECollisionChannel)j); + if (Response != ECR_Ignore) + { + Config->ObjectTypesToQuery |= ECC_TO_BITFIELD(j); + } + } + } + } + } + ImGui::EndCombo(); + } + ImGui::Separator(); + + //------------------------------------------------- + // Query Filtering + //------------------------------------------------- + for (int ChannelIndex = 0; ChannelIndex < (int32)ECC_MAX; ++ChannelIndex) + { + const FChannel& Channel = Channels[ChannelIndex]; + if (Channel.IsValid == false) + { + continue; + } + + ImGui::PushID(ChannelIndex); + + ImColor Color = FCogImguiHelper::ToImColor(Channel.Color); + ImGui::ColorEdit4("Color", (float*)&Color.Value, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel); + ImGui::SameLine(); + + bool IsCollisionActive = (Config->ObjectTypesToQuery & ECC_TO_BITFIELD(ChannelIndex)) > 0; + const FName ChannelName = CollisionProfile->ReturnChannelNameFromContainerIndex(ChannelIndex); + if (ImGui::Checkbox(TCHAR_TO_ANSI(*ChannelName.ToString()), &IsCollisionActive)) + { + if (IsCollisionActive) + { + Config->ObjectTypesToQuery |= ECC_TO_BITFIELD(ChannelIndex); + Config->ProfileIndex = INDEX_NONE; + } + else + { + Config->ObjectTypesToQuery &= ~ECC_TO_BITFIELD(ChannelIndex); + Config->ProfileIndex = INDEX_NONE; + } + } + + ImGui::PopID(); + } + } + + //------------------------------------------------- + // Shape + //------------------------------------------------- + if (Config->Type != ECogEngine_CollisionQueryType::LineTrace) + { + FCogWindowWidgets::SetNextItemToShortWidth(); + FCogWindowWidgets::ComboboxEnum("Shape", Config->Shape); + + switch (Config->Shape) + { + case ECogEngine_CollisionQueryShape::Sphere: + { + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragFloat("Sphere Radius", &Config->SphereRadius, 0.1f, 0, 100.0f, "%.1f"); + break; + } + + case ECogEngine_CollisionQueryShape::Box: + { + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragFloat3("Box Extent", &Config->BoxExtent.X, 0.1f, 0, 100.0f, "%.1f"); + break; + } + + case ECogEngine_CollisionQueryShape::Capsule: + { + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragFloat("Capsule Radius", &Config->CapsuleRadius, 0.1f, 0, 100.0f, "%.1f"); + + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragFloat("Capsule Half Height", &Config->CapsuleHalfHeight, 0.1f, 0, 100.0f, "%.1f"); + break; + } + } + + } + + ImGui::Checkbox("Multi", &Config->MultiHits); + ImGui::Checkbox("Complex", &Config->TraceComplex); + + Query(); +} + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogEngineWindow_CollisionTester::Query() +{ + AlreadyDrawnActors.Empty(); + AlreadyDrawnComponents.Empty(); + + const APlayerController* PlayerController = GetLocalPlayerController(); + if (PlayerController == nullptr) + { + return; + } + + FVector QueryStart = FVector::ZeroVector; + FVector QueryEnd = FVector::ZeroVector; + FQuat QueryRotation = FQuat::Identity; + TArray Hits; + TArray Overlaps; + bool HasHits = false; + + switch (Config->Placement) + { + case ECogEngine_CollisionQueryPlacement::Selection: + { + if (const AActor* Selection = GetSelection()) + { + QueryStart = Selection->GetActorLocation() + FVector(Config->LocationStart); + QueryRotation = Selection->GetActorQuat() * FQuat(FRotator(Config->Rotation)); + QueryEnd = QueryStart + Selection->GetActorQuat().GetForwardVector() * Config->QueryLength; + } + + break; + } + + case ECogEngine_CollisionQueryPlacement::View: + { + FRotator Rotation; + PlayerController->GetPlayerViewPoint(QueryStart, Rotation); + QueryRotation = FQuat(Rotation); + QueryEnd = QueryStart + QueryRotation.GetForwardVector() * Config->QueryLength; + break; + } + + case ECogEngine_CollisionQueryPlacement::Cursor: + { + FVector Direction; + const ImGuiViewport* Viewport = ImGui::GetMainViewport(); + const ImVec2 ViewportPos = Viewport != nullptr ? Viewport->Pos : ImVec2(0, 0); + UGameplayStatics::DeprojectScreenToWorld(PlayerController, FCogImguiHelper::ToFVector2D(ImGui::GetMousePos() - ViewportPos), QueryStart, Direction); + QueryEnd = QueryStart + Direction * Config->QueryLength; + break; + } + + case ECogEngine_CollisionQueryPlacement::Transform: + { + QueryStart = FVector(Config->LocationStart); + QueryEnd = FVector(Config->LocationEnd); + QueryRotation = FQuat(FRotator(Config->Rotation)); + break; + } + } + + static const FName TraceTag(TEXT("FCogWindow_Collision")); + FCollisionQueryParams QueryParams(TraceTag, SCENE_QUERY_STAT_ONLY(CogHitDetection), Config->TraceComplex); + + FCollisionShape QueryShape; + + const bool bIsUsingShape = Config->Type == ECogEngine_CollisionQueryType::Overlap || Config->Type == ECogEngine_CollisionQueryType::Sweep; + if (bIsUsingShape) + { + switch (Config->Shape) + { + case ECogEngine_CollisionQueryShape::Sphere: QueryShape.SetSphere(Config->SphereRadius); break; + case ECogEngine_CollisionQueryShape::Capsule: QueryShape.SetCapsule(Config->CapsuleRadius, Config->CapsuleHalfHeight); break; + case ECogEngine_CollisionQueryShape::Box: QueryShape.SetBox(Config->BoxExtent); break; + } + } + + switch (Config->Type) + { + case ECogEngine_CollisionQueryType::Overlap: + { + switch (Config->By) + { + case ECogEngine_CollisionQueryBy::Channel: + { + HasHits = GetWorld()->OverlapMultiByChannel(Overlaps, QueryStart, QueryRotation, (ECollisionChannel)Config->Channel, QueryShape, QueryParams); + break; + } + + case ECogEngine_CollisionQueryBy::ObjectType: + { + FCollisionObjectQueryParams QueryObjectParams; + QueryObjectParams.ObjectTypesToQuery = Config->ObjectTypesToQuery; + HasHits = GetWorld()->OverlapMultiByObjectType(Overlaps, QueryStart, QueryRotation, QueryObjectParams, QueryShape, QueryParams); + break; + } + + case ECogEngine_CollisionQueryBy::Profile: + { + HasHits = GetWorld()->OverlapMultiByProfile(Overlaps, QueryStart, QueryRotation, Config->Profile, QueryShape, QueryParams); + break; + } + } + + break; + } + + case ECogEngine_CollisionQueryType::LineTrace: + { + switch (Config->By) + { + case ECogEngine_CollisionQueryBy::Channel: + { + if (Config->MultiHits) + { + HasHits = GetWorld()->LineTraceMultiByChannel(Hits, QueryStart, QueryEnd, (ECollisionChannel)Config->Channel, QueryParams); + } + else + { + FHitResult Hit; + HasHits = GetWorld()->LineTraceSingleByChannel(Hit, QueryStart, QueryEnd, (ECollisionChannel)Config->Channel, QueryParams); + if (HasHits) + { + Hits.Add(Hit); + } + } + break; + } + + case ECogEngine_CollisionQueryBy::ObjectType: + { + FCollisionObjectQueryParams QueryObjectParams; + QueryObjectParams.ObjectTypesToQuery = Config->ObjectTypesToQuery; + + if (Config->MultiHits) + { + HasHits = GetWorld()->LineTraceMultiByObjectType(Hits, QueryStart, QueryEnd, QueryObjectParams, QueryParams); + } + else + { + FHitResult Hit; + HasHits = GetWorld()->LineTraceSingleByObjectType(Hit, QueryStart, QueryEnd, QueryObjectParams, QueryParams); + if (HasHits) + { + Hits.Add(Hit); + } + } + break; + } + + case ECogEngine_CollisionQueryBy::Profile: + { + if (Config->MultiHits) + { + GetWorld()->LineTraceMultiByProfile(Hits, QueryStart, QueryEnd, Config->Profile, QueryParams); + } + else + { + FHitResult Hit; + HasHits = GetWorld()->LineTraceSingleByProfile(Hit, QueryStart, QueryEnd, Config->Profile, QueryParams); + if (HasHits) + { + Hits.Add(Hit); + } + } + break; + } + } + break; + } + + case ECogEngine_CollisionQueryType::Sweep: + { + switch (Config->By) + { + case ECogEngine_CollisionQueryBy::Channel: + { + if (Config->MultiHits) + { + HasHits = GetWorld()->SweepMultiByChannel(Hits, QueryStart, QueryEnd, QueryRotation, (ECollisionChannel)Config->Channel, QueryShape, QueryParams); + } + else + { + FHitResult Hit; + HasHits = GetWorld()->SweepSingleByChannel(Hit, QueryStart, QueryEnd, QueryRotation, (ECollisionChannel)Config->Channel, QueryShape, QueryParams); + if (HasHits) + { + Hits.Add(Hit); + } + } + break; + } + + case ECogEngine_CollisionQueryBy::ObjectType: + { + if (Config->MultiHits) + { + FCollisionObjectQueryParams QueryObjectParams; + QueryObjectParams.ObjectTypesToQuery = Config->ObjectTypesToQuery; + HasHits = GetWorld()->SweepMultiByObjectType(Hits, QueryStart, QueryEnd, QueryRotation, QueryObjectParams, QueryShape, QueryParams); + } + else + { + FCollisionObjectQueryParams QueryObjectParams; + QueryObjectParams.ObjectTypesToQuery = Config->ObjectTypesToQuery; + + FHitResult Hit; + HasHits = GetWorld()->SweepSingleByObjectType(Hit, QueryStart, QueryEnd, QueryRotation, QueryObjectParams, QueryShape, QueryParams); + if (HasHits) + { + Hits.Add(Hit); + } + } + break; + } + + case ECogEngine_CollisionQueryBy::Profile: + { + if (Config->MultiHits) + { + HasHits = GetWorld()->SweepMultiByProfile(Hits, QueryStart, QueryEnd, QueryRotation, Config->Profile, QueryShape, QueryParams); + } + else + { + FHitResult Hit; + HasHits = GetWorld()->SweepSingleByProfile(Hit, QueryStart, QueryEnd, QueryRotation, Config->Profile, QueryShape, QueryParams); + if (HasHits) + { + Hits.Add(Hit); + } + } + break; + } + } + break; + } + } + + const FColor Color = HasHits ? FLinearColor(Config->HitColor).ToFColor(true) : FLinearColor(Config->NoHitColor).ToFColor(true); + + const bool bUseTrace = Config->Type == ECogEngine_CollisionQueryType::LineTrace || Config->Type == ECogEngine_CollisionQueryType::Sweep; + if (bUseTrace) + { + DrawDebugDirectionalArrow( + GetWorld(), + QueryStart, + QueryEnd, + FCogDebugSettings::ArrowSize, + Color, + false, + 0.0f, + FCogDebugSettings::GetDebugDepthPriority(0), + FCogDebugSettings::GetDebugThickness(0.0f)); + } + + if (bIsUsingShape) + { + DrawShape(QueryShape, QueryStart, QueryRotation, FVector::OneVector, Color, false); + } + + for (const FOverlapResult& Overlap : Overlaps) + { + if (Config->DrawHitPrimitives) + { + DrawPrimitive(Overlap.GetComponent()); + } + } + + for (const FHitResult& Hit : Hits) + { + if (Config->DrawHitLocations) + { + DrawDebugPoint( + GetWorld(), + Hit.Location, + Config->HitPointSize, + Color, + false, + 0.0f, + FCogDebugSettings::GetDebugDepthPriority(0)); + } + + if (Config->DrawHitImpactPoints) + { + DrawDebugPoint( + GetWorld(), + Hit.ImpactPoint, + Config->HitPointSize, + Color, + false, + 0.0f, + FCogDebugSettings::GetDebugDepthPriority(0)); + } + + if (bIsUsingShape && Config->DrawHitShapes) + { + DrawShape(QueryShape, Hit.Location, QueryRotation, FVector::OneVector, Color, false); + } + + if (Config->DrawHitNormals) + { + DrawDebugDirectionalArrow( + GetWorld(), + Hit.Location, + Hit.Location + Hit.Normal * 20.0f, + FCogDebugSettings::ArrowSize, + FLinearColor(Config->NormalColor).ToFColor(true), + false, + 0.0f, + FCogDebugSettings::GetDebugDepthPriority(0), + FCogDebugSettings::GetDebugThickness(0.0f)); + } + + if (Config->DrawHitImpactNormals) + { + DrawDebugDirectionalArrow( + GetWorld(), + Hit.ImpactPoint, + Hit.ImpactPoint + Hit.ImpactNormal * 20.0f, + FCogDebugSettings::ArrowSize, + FLinearColor(Config->ImpactNormalColor).ToFColor(true), + false, + 0.0f, + FCogDebugSettings::GetDebugDepthPriority(0), + FCogDebugSettings::GetDebugThickness(0.0f)); + } + + if (Config->DrawHitPrimitives) + { + DrawPrimitive(Hit.GetComponent()); + } + } + + FTransform Transform1(QueryRotation, QueryStart, FVector::OneVector); + DrawTransformGizmos(GetWorld(), Transform1); + FTransform Transform2(QueryRotation, QueryEnd, FVector::OneVector); + DrawTransformGizmos(GetWorld(), Transform2); +} + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogEngineWindow_CollisionTester::DrawPrimitive(const UPrimitiveComponent* PrimitiveComponent) +{ + //------------------------------------------------------- + // Don't draw same primitives multiple times (for bones) + //------------------------------------------------------- + if (AlreadyDrawnComponents.Contains(PrimitiveComponent)) + { + return; + } + + AlreadyDrawnComponents.Add(PrimitiveComponent); + + ECollisionChannel CollisionObjectType = PrimitiveComponent->GetCollisionObjectType(); + FColor Color = Channels[CollisionObjectType].Color; + + //------------------------------------------------------- + // Draw Name + //------------------------------------------------------- + if (Config->DrawHitActorsNames) + { + const AActor* Actor = PrimitiveComponent->GetOwner(); + if (Actor != nullptr) + { + if (AlreadyDrawnActors.Contains(Actor) == false) + { + FColor TextColor = Color.WithAlpha(255); + DrawDebugString(GetWorld(), Actor->GetActorLocation(), GetNameSafe(Actor->GetClass()), nullptr, FColor::White, 0.0f, FCogDebugSettings::TextShadow, FCogDebugSettings::TextSize); + AlreadyDrawnActors.Add(Actor); + } + } + } + + const FVector Location = PrimitiveComponent->GetComponentLocation(); + const FQuat Rotation = PrimitiveComponent->GetComponentQuat(); + const FVector Scale = PrimitiveComponent->GetComponentScale(); + const FCollisionShape Shape = PrimitiveComponent->GetCollisionShape(); + DrawShape(Shape, Location, Rotation, Scale, Color, true); +} + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogEngineWindow_CollisionTester::DrawShape(const FCollisionShape& Shape, const FVector& Location, const FQuat& Rotation, const FVector& Scale, const FColor& Color, bool DrawSolid) const +{ + switch (Shape.ShapeType) + { + case ECollisionShape::Box: + { + //-------------------------------------------------- + // see UBoxComponent::GetScaledBoxExtent() + //-------------------------------------------------- + const FVector HalfExtent(Shape.Box.HalfExtentX * Scale.X, Shape.Box.HalfExtentY * Scale.Y, Shape.Box.HalfExtentZ * Scale.Z); + + if (DrawSolid) + { + DrawDebugSolidBox( + GetWorld(), + Location, + HalfExtent, + Rotation, + Color, + false, + 0.0f, + FCogDebugSettings::GetDebugDepthPriority(0)); + } + + DrawDebugBox( + GetWorld(), + Location, + HalfExtent, + Rotation, + Color, + false, + 0.0f, + FCogDebugSettings::GetDebugDepthPriority(0), + FCogDebugSettings::GetDebugThickness(0.0f)); + + break; + } + + case ECollisionShape::Sphere: + { + //-------------------------------------------------- + // see UCapsuleComponent::GetScaledCapsuleRadius() + //-------------------------------------------------- + const float RadiusScale = FMath::Min(Scale.X, FMath::Min(Scale.Y, Scale.Z)); + const float Radius = Shape.Sphere.Radius * RadiusScale; + + FCogDebugDrawHelper::DrawSphere( + GetWorld(), + Location, + Radius, + FCogDebugSettings::GetCircleSegments(), + Color, + false, + 0.0f, + FCogDebugSettings::GetDebugDepthPriority(0), + FCogDebugSettings::GetDebugThickness(0.0f)); + break; + } + + case ECollisionShape::Capsule: + { + //-------------------------------------------------- + // see UCapsuleComponent::GetScaledCapsuleRadius() + //-------------------------------------------------- + const float Radius = Shape.Capsule.Radius * FMath::Min(Scale.X, Scale.Y); + const float HalfHeight = Shape.Capsule.HalfHeight * UE_REAL_TO_FLOAT(Scale.Z); + + DrawDebugCapsule( + GetWorld(), + Location, + HalfHeight, + Radius, + Rotation, + Color, + false, + 0.0f, + FCogDebugSettings::GetDebugDepthPriority(0), + FCogDebugSettings::GetDebugThickness(0.0f)); + break; + } + } +} + + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogEngineWindow_CollisionTester::SetAsset(const UCogEngineDataAsset* Value) +{ + Asset = Value; + + if (Asset == nullptr) + { + return; + } + + for (FChannel& Channel : Channels) + { + Channel.IsValid = false; + } + + for (const FCogCollisionChannel& AssetChannel : Asset->Channels) + { + FChannel& Channel = Channels[(uint8)AssetChannel.Channel]; + Channel.IsValid = true; + Channel.Color = AssetChannel.Color.ToFColor(true); + } +} + +//-------------------------------------------------------------------------------------------------------------------------- +static void FindSegmentPointDistance(const FVector2D& Segment1, const FVector2D& Segment2, const FVector2D& Point, FVector2D& Projection, float& Time, float& Distance) +{ + const float DistSquared = FVector2D::DistSquared(Segment1, Segment2); + if (FMath::IsNearlyZero(DistSquared)) + { + Time = 0.0f; + Projection = Segment1; + Distance = FVector2D::Distance(Point, Segment1); + } + else + { + Time = FMath::Max(0.0f, FMath::Min(1.0f, FVector2D::DotProduct(Point - Segment1, Segment2 - Segment1) / DistSquared)); + Projection = Segment1 + Time * (Segment2 - Segment1); + Distance = FVector2D::Distance(Point, Projection); + } +} + +//-------------------------------------------------------------------------------------------------------------------------- +static float FindSegmentPointDistance2(const FVector2D& Segment1, const FVector2D& Segment2, const FVector2D& Point) +{ + FVector2D Projection; + float Time, Distance; + FindSegmentPointDistance(Segment1, Segment2, Point, Projection, Time, Distance); + return Distance; +} + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogEngineWindow_CollisionTester::DrawTransformGizmos(const UWorld* InWorld, FTransform& InTransform) +{ + APlayerController* PlayerController = GetLocalPlayerController(); + if (PlayerController == nullptr) + { + return; + } + + const ImGuiViewport* Viewport = ImGui::GetMainViewport(); + if (Viewport == nullptr) + { + return; + } + + const uint8 ZLow = 0; + const uint8 ZHigh = 100; + const float ThicknessZLow = 1.0f; + const float ThicknessZHigh = 0.0f; + const float AxisLength = 50.0f; + const float PlaneOffset = 25.0f; + const FVector2D PlaneExtent(10.0f, 10.0f); + const FVector BoxExtent(2.0f, 2.0f, 2.0f); + const float MaxMouseDistance = 5.0f; + const float RotationRadius = 15.0f; + const int32 RotationSegments = 32; + + const FColor AxisColorsZHigh [] = { FColor(255, 50, 50, 255), FColor(50, 255, 50, 255), FColor(50, 50, 255, 255), FColor(255, 255, 255, 255) }; + const FColor AxisColorsZLow [] = { FColor(128, 0, 0, 255), FColor(0, 128, 0, 255), FColor(0, 0, 128, 255), FColor(128, 128, 128, 255) }; + + const FColor SelectionColor = FColor(255, 255, 0, 255); + + const FVector Center = InTransform.GetTranslation(); + const FQuat RotX = InTransform.GetRotation(); + 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 FVector UnitAxisX = RotX.GetAxisX(); + const FVector UnitAxisY = RotX.GetAxisY(); + const FVector UnitAxisZ = RotX.GetAxisZ(); + + const FVector AxisX = Center + UnitAxisX * AxisLength; + const FVector AxisY = Center + UnitAxisY * AxisLength; + const FVector AxisZ = Center + UnitAxisZ * AxisLength; + + const FVector PlaneXY = Center + ((UnitAxisX + UnitAxisY) * PlaneOffset); + const FVector PlaneXZ = Center + ((UnitAxisX + UnitAxisZ) * PlaneOffset); + const FVector PlaneYZ = Center + ((UnitAxisY + UnitAxisZ) * PlaneOffset); + + const ImVec2 ImMousePos = ImGui::GetMousePos() - Viewport->Pos; + const FVector2D MousePos = FCogImguiHelper::ToFVector2D(ImMousePos); + + FVector2D ScreenGizmoCenter; + if (UGameplayStatics::ProjectWorldToScreen(PlayerController, Center, ScreenGizmoCenter) == false) + { + return; + } + + FCogEngine_GizmoElement GizmoElements[ECogEngine_GizmoElementType::MAX]; + + GizmoElements[(int32)ECogEngine_GizmoElementType::MoveX] = FCogEngine_GizmoElement { ECogEngine_GizmoType::MoveAxis, ECogEngine_GizmoAxis::X, FQuat::Identity, AxisX }; + GizmoElements[(int32)ECogEngine_GizmoElementType::MoveY] = FCogEngine_GizmoElement { ECogEngine_GizmoType::MoveAxis, ECogEngine_GizmoAxis::Y, FQuat::Identity, AxisY }; + GizmoElements[(int32)ECogEngine_GizmoElementType::MoveZ] = FCogEngine_GizmoElement { ECogEngine_GizmoType::MoveAxis, ECogEngine_GizmoAxis::Z, FQuat::Identity, AxisZ }; + GizmoElements[(int32)ECogEngine_GizmoElementType::MoveXY] = FCogEngine_GizmoElement { ECogEngine_GizmoType::MovePlane, ECogEngine_GizmoAxis::Z, RotZ, PlaneXY }; + GizmoElements[(int32)ECogEngine_GizmoElementType::MoveXZ] = FCogEngine_GizmoElement { ECogEngine_GizmoType::MovePlane, ECogEngine_GizmoAxis::Y, RotY, PlaneXZ }; + GizmoElements[(int32)ECogEngine_GizmoElementType::MoveYZ] = FCogEngine_GizmoElement { ECogEngine_GizmoType::MovePlane, ECogEngine_GizmoAxis::X, RotX, PlaneYZ }; + GizmoElements[(int32)ECogEngine_GizmoElementType::RotateX] = FCogEngine_GizmoElement { ECogEngine_GizmoType::Rotate, ECogEngine_GizmoAxis::X, RotX, AxisX }; + GizmoElements[(int32)ECogEngine_GizmoElementType::RotateY] = FCogEngine_GizmoElement { ECogEngine_GizmoType::Rotate, ECogEngine_GizmoAxis::Y, RotY, AxisY }; + GizmoElements[(int32)ECogEngine_GizmoElementType::RotateZ] = FCogEngine_GizmoElement { ECogEngine_GizmoType::Rotate, ECogEngine_GizmoAxis::Z, RotZ, AxisZ }; + GizmoElements[(int32)ECogEngine_GizmoElementType::ScaleXYZ] = FCogEngine_GizmoElement { ECogEngine_GizmoType::ScaleUniform, ECogEngine_GizmoAxis::MAX, RotX, Center }; + GizmoElements[(int32)ECogEngine_GizmoElementType::ScaleX] = FCogEngine_GizmoElement { ECogEngine_GizmoType::ScaleAxis, ECogEngine_GizmoAxis::X, RotX, AxisX }; + GizmoElements[(int32)ECogEngine_GizmoElementType::ScaleY] = FCogEngine_GizmoElement { ECogEngine_GizmoType::ScaleAxis, ECogEngine_GizmoAxis::Y, RotY, AxisY }; + GizmoElements[(int32)ECogEngine_GizmoElementType::ScaleZ] = FCogEngine_GizmoElement { ECogEngine_GizmoType::ScaleAxis, ECogEngine_GizmoAxis::Z, RotZ, AxisZ }; + + float MinDistanceToMouse = FLT_MAX; + ECogEngine_GizmoElementType ClosestGizmoElementType = ECogEngine_GizmoElementType::MAX; + for (uint8 i = (uint8)ECogEngine_GizmoElementType::MoveX; i < (uint8)ECogEngine_GizmoElementType::MAX; ++i) + { + FCogEngine_GizmoElement& Elm = GizmoElements[i]; + float DistanceToMouse = FLT_MAX; + + switch (Elm.Type) + { + case ECogEngine_GizmoType::MoveAxis: + { + FVector2D ScreenElementLocation; + UGameplayStatics::ProjectWorldToScreen(PlayerController, Elm.Location, ScreenElementLocation); + DistanceToMouse = FindSegmentPointDistance2(ScreenGizmoCenter, ScreenElementLocation, MousePos); + break; + } + + case ECogEngine_GizmoType::MovePlane: + { + //DistanceToMouse = + break; + } + } + + if (DistanceToMouse < MaxMouseDistance && DistanceToMouse < MinDistanceToMouse) + { + ClosestGizmoElementType = (ECogEngine_GizmoElementType)i; + MinDistanceToMouse = DistanceToMouse; + } + } + + for (uint8 i = (uint8)ECogEngine_GizmoElementType::MoveX; i < (uint8)ECogEngine_GizmoElementType::MAX; ++i) + { + const FCogEngine_GizmoElement& Elm = GizmoElements[i]; + const bool IsClosestToMouse = i == (uint8)ClosestGizmoElementType; + + switch (Elm.Type) + { + case ECogEngine_GizmoType::MoveAxis: + { + DrawDebugLine(InWorld, Center, Elm.Location, IsClosestToMouse ? SelectionColor : AxisColorsZLow[(uint8)Elm.Axis], false, 0.0f, ZLow, ThicknessZLow); + DrawDebugLine(InWorld, Center, Elm.Location, IsClosestToMouse ? SelectionColor : AxisColorsZHigh[(uint8)Elm.Axis], false, 0.0f, ZHigh, ThicknessZHigh); + break; + } + + case ECogEngine_GizmoType::MovePlane: + { + FCogDebugDrawHelper::DrawQuad(InWorld, Elm.Location, Elm.Rotation, PlaneExtent, IsClosestToMouse ? SelectionColor : AxisColorsZLow[(uint8)Elm.Axis], false, 0.0f, ZLow, ThicknessZLow); + FCogDebugDrawHelper::DrawQuad(InWorld, Elm.Location, Elm.Rotation, PlaneExtent, IsClosestToMouse ? SelectionColor : AxisColorsZLow[(uint8)Elm.Axis], false, 0.0f, ZHigh, ThicknessZHigh); + FCogDebugDrawHelper::DrawSolidQuad(InWorld, Elm.Location, Elm.Rotation, PlaneExtent, IsClosestToMouse ? SelectionColor : AxisColorsZHigh[(uint8)Elm.Axis], false, 0.0f, ZHigh); + break; + } + + case ECogEngine_GizmoType::Rotate: + { + //FRotationTranslationMatrix Matrix(FRotator(Elm.Rotation), Elm.Location); + //DrawDebugCircle(InWorld, Matrix, RotationRadius, RotationSegments, IsClosestToMouse ? SelectionColor : AxisColorsZLow[(uint8)Elm.Axis], false, 0.0f, ZLow, ThicknessZLow, false); + //DrawDebugCircle(InWorld, Matrix, RotationRadius, RotationSegments, IsClosestToMouse ? SelectionColor : AxisColorsZLow[(uint8)Elm.Axis], false, 0.0f, ZHigh, ThicknessZHigh, false); + break; + } + + case ECogEngine_GizmoType::ScaleUniform: + case ECogEngine_GizmoType::ScaleAxis: + { + DrawDebugBox(InWorld, Elm.Location, BoxExtent, Elm.Rotation, IsClosestToMouse ? SelectionColor : AxisColorsZLow[(uint8)Elm.Axis], false, 0.0f, ZLow, ThicknessZLow); + DrawDebugBox(InWorld, Elm.Location, BoxExtent, Elm.Rotation, IsClosestToMouse ? SelectionColor : AxisColorsZHigh[(uint8)Elm.Axis], false, 0.0f, ZHigh, ThicknessZHigh); + DrawDebugSolidBox(InWorld, Elm.Location, BoxExtent, Elm.Rotation, IsClosestToMouse ? SelectionColor : AxisColorsZLow[(uint8)Elm.Axis], false, 0.0f, ZHigh); + break; + } + } + } + + + if (ImGui::IsMouseDown(ImGuiMouseButton_Left)) + { + IsDragging = ClosestGizmoElementType != ECogEngine_GizmoElementType::MAX; + StartTransform = InTransform; + } + else if (ImGui::IsMouseReleased(ImGuiMouseButton_Left)) + { + IsDragging = false; + } + + if (IsDragging) + { + if (ImGui::IsMouseDragging(ImGuiMouseButton_Left, 4.0f)) + { + ImVec2 Delta = ImGui::GetMouseDragDelta(ImGuiMouseButton_Left); + FVector WorldOrigin, WorldDirection; + UGameplayStatics::DeprojectScreenToWorld(PlayerController, MousePos, WorldOrigin, WorldDirection); + } + } +} diff --git a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Collisions.cpp b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CollisionViewer.cpp similarity index 97% rename from Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Collisions.cpp rename to Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CollisionViewer.cpp index 822006c..08a5743 100644 --- a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Collisions.cpp +++ b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CollisionViewer.cpp @@ -1,4 +1,4 @@ -#include "CogEngineWindow_Collisions.h" +#include "CogEngineWindow_CollisionViewer.h" #include "CogDebugDrawHelper.h" #include "CogDebugSettings.h" @@ -18,7 +18,7 @@ //-------------------------------------------------------------------------------------------------------------------------- -void FCogEngineWindow_Collisions::Initialize() +void FCogEngineWindow_CollisionViewer::Initialize() { Super::Initialize(); @@ -26,11 +26,11 @@ void FCogEngineWindow_Collisions::Initialize() SetAsset(GetAsset()); - Config = GetConfig(); + Config = GetConfig(); } //-------------------------------------------------------------------------------------------------------------------------- -void FCogEngineWindow_Collisions::RenderHelp() +void FCogEngineWindow_CollisionViewer::RenderHelp() { ImGui::Text("This window is used to inspect collisions by performing a collision query with the selected channels. " "The query can be configured in the options. " @@ -40,7 +40,7 @@ void FCogEngineWindow_Collisions::RenderHelp() } //-------------------------------------------------------------------------------------------------------------------------- -void FCogEngineWindow_Collisions::ResetConfig() +void FCogEngineWindow_CollisionViewer::ResetConfig() { Super::ResetConfig(); @@ -48,7 +48,7 @@ void FCogEngineWindow_Collisions::ResetConfig() } //-------------------------------------------------------------------------------------------------------------------------- -void FCogEngineWindow_Collisions::RenderContent() +void FCogEngineWindow_CollisionViewer::RenderContent() { Super::RenderContent(); @@ -387,7 +387,7 @@ void FCogEngineWindow_Collisions::RenderContent() } //-------------------------------------------------------------------------------------------------------------------------- -void FCogEngineWindow_Collisions::SetAsset(const UCogEngineDataAsset* Value) +void FCogEngineWindow_CollisionViewer::SetAsset(const UCogEngineDataAsset* Value) { Asset = Value; diff --git a/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_CollisionTester.h b/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_CollisionTester.h new file mode 100644 index 0000000..264bc97 --- /dev/null +++ b/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_CollisionTester.h @@ -0,0 +1,297 @@ +#pragma once + +#include "CoreMinimal.h" +#include "CogWindow.h" +#include "CogWindowConfig.h" +#include "Engine/HitResult.h" +#include "CogEngineWindow_CollisionTester.generated.h" + +class UCogEngineConfig_CollisionViewer; +class UCogEngineDataAsset; +class UPrimitiveComponent; +struct FCollisionShape; + +//-------------------------------------------------------------------------------------------------------------------------- +UENUM() +enum class ECogEngine_CollisionQueryPlacement : uint8 +{ + Selection, + View, + Cursor, + Transform, +}; + +//-------------------------------------------------------------------------------------------------------------------------- +UENUM() +enum class ECogEngine_CollisionQueryType : uint8 +{ + Overlap, + LineTrace, + Sweep, +}; + +//-------------------------------------------------------------------------------------------------------------------------- +UENUM() +enum class ECogEngine_CollisionQueryCount : uint8 +{ + Single, + Multi, +}; + +//-------------------------------------------------------------------------------------------------------------------------- +UENUM() +enum class ECogEngine_CollisionQueryBy : uint8 +{ + Channel, + ObjectType, + Profile, +}; + +//-------------------------------------------------------------------------------------------------------------------------- +UENUM() +enum class ECogEngine_CollisionQueryShape : uint8 +{ + Sphere, + Box, + Capsule, +}; + +//-------------------------------------------------------------------------------------------------------------------------- +UENUM() +enum class ECogEngine_GizmoType : uint8 +{ + MoveAxis, + MovePlane, + Rotate, + ScaleAxis, + ScaleUniform, + MAX, +}; + +//-------------------------------------------------------------------------------------------------------------------------- +UENUM() +enum class ECogEngine_GizmoAxis : uint8 +{ + X, + Y, + Z, + MAX, +}; + +//-------------------------------------------------------------------------------------------------------------------------- +UENUM() +enum class ECogEngine_GizmoElementType : uint8 +{ + MoveX, + MoveY, + MoveZ, + MoveXY, + MoveXZ, + MoveYZ, + RotateX, + RotateY, + RotateZ, + ScaleXYZ, + ScaleX, + ScaleY, + ScaleZ, + MAX, +}; + +//-------------------------------------------------------------------------------------------------------------------------- +struct FCogEngine_GizmoElement +{ + ECogEngine_GizmoType Type; + ECogEngine_GizmoAxis Axis; + FQuat Rotation; + FVector Location; +}; + +//-------------------------------------------------------------------------------------------------------------------------- +class COGENGINE_API FCogEngineWindow_CollisionTester : public FCogWindow +{ + typedef FCogWindow Super; + +public: + + virtual void Initialize() override; + +protected: + + virtual void ResetConfig() override; + + virtual void RenderHelp() override; + + virtual void RenderContent() override; + + virtual void SetAsset(const UCogEngineDataAsset* Value); + + void Query(); + + void DrawPrimitive(const UPrimitiveComponent* PrimitiveComponent); + + void DrawShape(const FCollisionShape& Shape, const FVector& Location, const FQuat& Rotation, const FVector& Scale, const FColor& Color, bool DrawSolid) const; + + void DrawTransformGizmos(const UWorld* InWorld, FTransform& InTransform); + + struct FChannel + { + bool IsValid = false; + FColor Color; + }; + + FChannel Channels[ECC_MAX]; + + TObjectPtr Asset = nullptr; + + TObjectPtr Config = nullptr; + + TSet AlreadyDrawnActors; + + TSet AlreadyDrawnComponents; + + bool IsDragging = false; + + FTransform StartTransform; + +}; + +//-------------------------------------------------------------------------------------------------------------------------- +UCLASS(Config = Cog) +class UCogEngineConfig_CollisionTester : public UCogWindowConfig +{ + GENERATED_BODY() + +public: + + UPROPERTY(Config) + ECogEngine_CollisionQueryPlacement Placement; + + UPROPERTY(Config) + FVector3f LocationStart; + + UPROPERTY(Config) + FVector3f LocationEnd; + + UPROPERTY(Config) + FRotator3f Rotation; + + UPROPERTY(Config) + ECogEngine_CollisionQueryType Type; + + UPROPERTY(Config) + ECogEngine_CollisionQueryBy By; + + UPROPERTY(Config) + ECogEngine_CollisionQueryShape Shape; + + UPROPERTY(Config) + bool MultiHits; + + UPROPERTY(Config) + bool TraceComplex; + + UPROPERTY(Config) + int32 ObjectTypesToQuery; + + UPROPERTY(Config) + FName Profile; + + UPROPERTY(Config) + int32 Channel; + + UPROPERTY(Config) + int32 ProfileIndex; + + UPROPERTY(Config) + float SphereRadius; + + UPROPERTY(Config) + FVector3f BoxExtent; + + UPROPERTY(Config) + float CapsuleRadius; + + UPROPERTY(Config) + float CapsuleHalfHeight; + + UPROPERTY(Config) + int QueryTypeOld; + + UPROPERTY(Config) + float QueryLength; + + UPROPERTY(Config) + bool DrawHitLocations; + + UPROPERTY(Config) + bool DrawHitImpactPoints; + + UPROPERTY(Config) + bool DrawHitShapes; + + UPROPERTY(Config) + bool DrawHitNormals; + + UPROPERTY(Config) + bool DrawHitImpactNormals; + + UPROPERTY(Config) + bool DrawHitPrimitives; + + UPROPERTY(Config) + bool DrawHitActorsNames; + + UPROPERTY(Config) + float HitPointSize; + + UPROPERTY(Config) + FVector4f NoHitColor; + + UPROPERTY(Config) + FVector4f HitColor; + + UPROPERTY(Config) + FVector4f NormalColor; + + UPROPERTY(Config) + FVector4f ImpactNormalColor; + + UCogEngineConfig_CollisionTester() + { + Reset(); + } + + virtual void Reset() override + { + Super::Reset(); + + Placement = ECogEngine_CollisionQueryPlacement::Selection; + Type = ECogEngine_CollisionQueryType::LineTrace; + By = ECogEngine_CollisionQueryBy::Channel; + Shape = ECogEngine_CollisionQueryShape::Sphere; + MultiHits = false; + TraceComplex = false; + SphereRadius = 50.0f; + BoxExtent = FVector3f(50.0f, 50.0f, 50.0f); + CapsuleRadius = 50.0f; + CapsuleHalfHeight = 50.0f; + + ObjectTypesToQuery = 0; + ProfileIndex = 0; + QueryTypeOld = 0; + QueryLength = 5000.0f; + DrawHitLocations = true; + DrawHitImpactPoints = true; + DrawHitShapes = true; + DrawHitNormals = true; + DrawHitImpactNormals = true; + DrawHitPrimitives = true; + DrawHitActorsNames = false; + HitPointSize = 10.0f; + NoHitColor = FVector4f(1.0f, 0.0f, 0.0f, 1.0f); + HitColor = FVector4f(0.0f, 1.0f, 0.0f, 1.0f); + NormalColor = FVector4f(0.0f, 1.0f, 0.0f, 1.0f); + ImpactNormalColor = FVector4f(0.0f, 1.0f, 0.0f, 1.0f); + } +}; \ No newline at end of file diff --git a/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_Collisions.h b/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_CollisionViewer.h similarity index 84% rename from Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_Collisions.h rename to Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_CollisionViewer.h index c214631..721534e 100644 --- a/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_Collisions.h +++ b/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_CollisionViewer.h @@ -4,13 +4,13 @@ #include "CogWindow.h" #include "CogWindowConfig.h" #include "Engine/EngineTypes.h" -#include "CogEngineWindow_Collisions.generated.h" +#include "CogEngineWindow_CollisionViewer.generated.h" -class UCogEngineConfig_Collisions; +class UCogEngineConfig_CollisionViewer; class UCogEngineDataAsset; //-------------------------------------------------------------------------------------------------------------------------- -class COGENGINE_API FCogEngineWindow_Collisions : public FCogWindow +class COGENGINE_API FCogEngineWindow_CollisionViewer : public FCogWindow { typedef FCogWindow Super; @@ -38,12 +38,12 @@ protected: TObjectPtr Asset = nullptr; - TObjectPtr Config = nullptr; + TObjectPtr Config = nullptr; }; //-------------------------------------------------------------------------------------------------------------------------- UCLASS(Config = Cog) -class UCogEngineConfig_Collisions : public UCogWindowConfig +class UCogEngineConfig_CollisionViewer : public UCogWindowConfig { GENERATED_BODY() diff --git a/Source/CogSample/CogSampleGameState.cpp b/Source/CogSample/CogSampleGameState.cpp index e68584b..2b2ab61 100644 --- a/Source/CogSample/CogSampleGameState.cpp +++ b/Source/CogSample/CogSampleGameState.cpp @@ -23,7 +23,8 @@ #include "CogDebugPlot.h" #include "CogEngineDataAsset.h" #include "CogEngineModule.h" -#include "CogEngineWindow_Collisions.h" +#include "CogEngineWindow_CollisionTester.h" +#include "CogEngineWindow_CollisionViewer.h" #include "CogEngineWindow_CommandBindings.h" #include "CogEngineWindow_DebugSettings.h" #include "CogEngineWindow_ImGui.h" @@ -128,7 +129,9 @@ void ACogSampleGameState::InitializeCog() //--------------------------------------- // Engine //--------------------------------------- - CogWindowManager->AddWindow("Engine.Collision"); + CogWindowManager->AddWindow("Engine.Collision Tester"); + + CogWindowManager->AddWindow("Engine.Collision Viewer"); CogWindowManager->AddWindow("Engine.Command Bindings"); diff --git a/TODO.txt b/TODO.txt index 7eef99c..ff54ee7 100644 --- a/TODO.txt +++ b/TODO.txt @@ -32,3 +32,4 @@ - CogInput: Add help about usnig CTRL+Drag on the stick to lock them +- CogAbility: Add inputs to level up/down abilities and effects From bd29211013b37059d67c5f7086a745c1fd000237 Mon Sep 17 00:00:00 2001 From: Arnaud Jamin Date: Tue, 19 Dec 2023 01:08:26 -0500 Subject: [PATCH 2/8] CogDebug: Refactor debug settings for easier serialization CogDebug: Move DebugGizmo to CogDebug --- .../8/EO/J2O30Y8BP1IJGKNHYD8SUY.uasset | Bin 4475 -> 4475 bytes .../Source/CogDebug/Private/CogDebugDraw.cpp | 22 +- .../Source/CogDebug/Private/CogDebugGizmo.cpp | 285 ++++++++++++++++++ .../CogDebug/Private/CogDebugSettings.cpp | 91 ++---- .../Source/CogDebug/Public/CogDebugGizmo.h | 67 ++++ .../Source/CogDebug/Public/CogDebugSettings.h | 188 ++++++++++-- .../CogEngineWindow_CollisionTester.cpp | 241 ++------------- .../CogEngineWindow_CollisionViewer.cpp | 2 +- .../Private/CogEngineWindow_DebugSettings.cpp | 149 ++++++--- .../Private/CogEngineWindow_Skeleton.cpp | 6 +- .../Public/CogEngineWindow_CollisionTester.h | 75 +---- .../Public/CogEngineWindow_DebugSettings.h | 63 +--- .../CogImgui/Private/CogImguiWidget.cpp | 9 +- .../Source/CogImgui/Public/CogImguiWidget.h | 2 +- .../CogWindow/Private/CogWindowWidgets.cpp | 21 ++ .../CogWindow/Public/CogWindowWidgets.h | 6 + 16 files changed, 716 insertions(+), 511 deletions(-) create mode 100644 Plugins/Cog/Source/CogDebug/Private/CogDebugGizmo.cpp create mode 100644 Plugins/Cog/Source/CogDebug/Public/CogDebugGizmo.h diff --git a/Content/__ExternalActors__/Maps/L_Default/8/EO/J2O30Y8BP1IJGKNHYD8SUY.uasset b/Content/__ExternalActors__/Maps/L_Default/8/EO/J2O30Y8BP1IJGKNHYD8SUY.uasset index a7c2a2991aac87d04910e0178c16e7f61301bace..59b54cc3d2baefa1d91d9651d53ad6d2e88daf17 100644 GIT binary patch delta 70 zcmeyZ^jm2|Bcp)dyWF`tVa3k 0.0f && B0.Y > 0.0f && B0.Z > 0.0f; + const bool Inside1 = B1.X > 0.0f && B1.Y > 0.0f && B1.Z > 0.0f; + + const float D = (Inside0 || Inside1) ? 0.0f : FLT_MAX; + return D; +} + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogDebug_Gizmo::Draw(const APlayerController& InPlayerController, FTransform& InOutTransform) +{ + UWorld* World = InPlayerController.GetWorld(); + + const ImGuiViewport* Viewport = ImGui::GetMainViewport(); + if (Viewport == nullptr) + { + return; + } + + const FVector GizmoCenter = InOutTransform.GetTranslation(); + + FVector2D Center2D; + if (UGameplayStatics::ProjectWorldToScreen(&InPlayerController, GizmoCenter, Center2D) == false) + { + return; + } + + const FCogDebugData& Debug = FCogDebugSettings::Data; + + FVector CenterProjection, CenterDirection, AxisProjection, AxisDirection; + UGameplayStatics::DeprojectScreenToWorld(&InPlayerController, Center2D, CenterProjection, CenterDirection); + UGameplayStatics::DeprojectScreenToWorld(&InPlayerController, Center2D + FVector2d(0, 1.0f), AxisProjection, AxisDirection); + const FVector CameraLocation = InPlayerController.PlayerCameraManager->GetCameraLocation(); + const float Sc = FVector::Dist(AxisProjection, CenterProjection) * FVector::Dist(CameraLocation, GizmoCenter) / FVector::Dist(CameraLocation, CenterProjection); + const float Scale = Debug.GizmoScale * Sc; + + const FQuat RotX = InOutTransform.GetRotation(); + 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 FVector UnitAxisX = RotX.GetAxisX(); + const FVector UnitAxisY = RotX.GetAxisY(); + const FVector UnitAxisZ = RotX.GetAxisZ(); + + const FVector AxisX = GizmoCenter + UnitAxisX * Debug.GizmoAxisLength * Scale; + const FVector AxisY = GizmoCenter + UnitAxisY * Debug.GizmoAxisLength * Scale; + const FVector AxisZ = GizmoCenter + UnitAxisZ * Debug.GizmoAxisLength * Scale; + + const FVector PlaneXY = GizmoCenter + ((UnitAxisX + UnitAxisY) * Debug.GizmoPlaneOffset * Scale); + const FVector PlaneXZ = GizmoCenter + ((UnitAxisX + UnitAxisZ) * Debug.GizmoPlaneOffset * Scale); + const FVector PlaneYZ = GizmoCenter + ((UnitAxisY + UnitAxisZ) * Debug.GizmoPlaneOffset * Scale); + + const float AdjustedScaleBoxExtent = Debug.GizmoScaleBoxExtent * Scale; + const float AdjustedPlaneExtent = Debug.GizmoPlaneExtent * Scale; + const float AdjustedThicknessZLow = Debug.GizmoThicknessZLow * Scale; + const float AdjustedThicknessZHigh = Debug.GizmoThicknessZHigh * Scale; + + const ImVec2 ImMousePos = ImGui::GetMousePos() - Viewport->Pos; + const FVector2D MousePos = FCogImguiHelper::ToFVector2D(ImMousePos); + + const FColor GizmoAxisColorsZLow[] = { Debug.GizmoAxisColorsZLowX, Debug.GizmoAxisColorsZLowY, Debug.GizmoAxisColorsZLowZ, Debug.GizmoAxisColorsZLowW }; + const FColor GizmoAxisColorsZHigh[] = { Debug.GizmoAxisColorsZHighX, Debug.GizmoAxisColorsZHighY, Debug.GizmoAxisColorsZHighZ, Debug.GizmoAxisColorsZHighW }; + const FColor GizmoAxisColorsSelection[] = { Debug.GizmoAxisColorsSelectionX, Debug.GizmoAxisColorsSelectionY, Debug.GizmoAxisColorsSelectionZ, Debug.GizmoAxisColorsSelectionW }; + + FCogDebug_GizmoElement GizmoElements[ECogDebug_GizmoElementType::MAX]; + GizmoElements[(uint8)ECogDebug_GizmoElementType::MoveX] = { ECogDebug_GizmoType::MoveAxis, ECogDebug_GizmoAxis::X, FVector::XAxisVector, UnitAxisX, FQuat::Identity, AxisX }; + GizmoElements[(uint8)ECogDebug_GizmoElementType::MoveY] = { ECogDebug_GizmoType::MoveAxis, ECogDebug_GizmoAxis::Y, FVector::YAxisVector, UnitAxisY, FQuat::Identity, AxisY }; + GizmoElements[(uint8)ECogDebug_GizmoElementType::MoveZ] = { ECogDebug_GizmoType::MoveAxis, ECogDebug_GizmoAxis::Z, FVector::ZAxisVector, UnitAxisZ, FQuat::Identity, AxisZ }; + GizmoElements[(uint8)ECogDebug_GizmoElementType::MoveXY] = { ECogDebug_GizmoType::MovePlane, ECogDebug_GizmoAxis::Z, FVector::ZAxisVector, UnitAxisZ, RotZ, PlaneXY }; + GizmoElements[(uint8)ECogDebug_GizmoElementType::MoveXZ] = { ECogDebug_GizmoType::MovePlane, ECogDebug_GizmoAxis::Y, FVector::YAxisVector, UnitAxisY, RotY, PlaneXZ }; + GizmoElements[(uint8)ECogDebug_GizmoElementType::MoveYZ] = { ECogDebug_GizmoType::MovePlane, ECogDebug_GizmoAxis::X, FVector::XAxisVector, UnitAxisX, RotX, PlaneYZ }; + GizmoElements[(uint8)ECogDebug_GizmoElementType::RotateX] = { ECogDebug_GizmoType::Rotate, ECogDebug_GizmoAxis::X, FVector::XAxisVector, UnitAxisX, RotX, AxisX }; + GizmoElements[(uint8)ECogDebug_GizmoElementType::RotateY] = { ECogDebug_GizmoType::Rotate, ECogDebug_GizmoAxis::Y, FVector::YAxisVector, UnitAxisY, RotY, AxisY }; + GizmoElements[(uint8)ECogDebug_GizmoElementType::RotateZ] = { ECogDebug_GizmoType::Rotate, ECogDebug_GizmoAxis::Z, FVector::ZAxisVector, UnitAxisZ, RotZ, AxisZ }; + GizmoElements[(uint8)ECogDebug_GizmoElementType::ScaleXYZ] = { ECogDebug_GizmoType::ScaleUniform, ECogDebug_GizmoAxis::MAX, FVector::OneVector, FVector::OneVector, RotX, GizmoCenter }; + GizmoElements[(uint8)ECogDebug_GizmoElementType::ScaleX] = { ECogDebug_GizmoType::ScaleAxis, ECogDebug_GizmoAxis::X, FVector::XAxisVector, UnitAxisX, RotX, AxisX }; + GizmoElements[(uint8)ECogDebug_GizmoElementType::ScaleY] = { ECogDebug_GizmoType::ScaleAxis, ECogDebug_GizmoAxis::Y, FVector::YAxisVector, UnitAxisY, RotY, AxisY }; + GizmoElements[(uint8)ECogDebug_GizmoElementType::ScaleZ] = { ECogDebug_GizmoType::ScaleAxis, ECogDebug_GizmoAxis::Z, FVector::ZAxisVector, UnitAxisZ, RotZ, AxisZ }; + + ECogDebug_GizmoElementType HoveredElementType = ECogDebug_GizmoElementType::MAX; + if (DraggedElementType != ECogDebug_GizmoElementType::MAX) + { + HoveredElementType = DraggedElementType; + } + else + { + float MinDistanceToMouse = FLT_MAX; + for (uint8 i = (uint8)ECogDebug_GizmoElementType::MoveX; i < (uint8)ECogDebug_GizmoElementType::MAX; ++i) + { + FCogDebug_GizmoElement& Elm = GizmoElements[i]; + float DistanceToMouse = FLT_MAX; + + switch (Elm.Type) + { + case ECogDebug_GizmoType::MoveAxis: + { + FVector2D ElementLocation2D; + UGameplayStatics::ProjectWorldToScreen(&InPlayerController, Elm.Location, ElementLocation2D); + const FVector2D ClosestPoint = FMath::ClosestPointOnSegment2D(MousePos, Center2D, ElementLocation2D); + DistanceToMouse = (ClosestPoint - MousePos).Length(); + break; + } + + case ECogDebug_GizmoType::MovePlane: + { + DistanceToMouse = PointDistanceToQuad(InPlayerController, MousePos, Elm.Location, Elm.Rotation, FVector2D(AdjustedPlaneExtent, AdjustedPlaneExtent)); + break; + } + + case ECogDebug_GizmoType::ScaleUniform: + case ECogDebug_GizmoType::ScaleAxis: + { + FVector2D ElementLocation2D; + UGameplayStatics::ProjectWorldToScreen(&InPlayerController, Elm.Location, ElementLocation2D); + DistanceToMouse = FVector2D::Distance(ElementLocation2D, MousePos) - Debug.GizmoScaleBoxExtent; + break; + } + } + + if (DistanceToMouse < Debug.GizmoMouseMaxDistance && DistanceToMouse < MinDistanceToMouse) + { + HoveredElementType = (ECogDebug_GizmoElementType)i; + MinDistanceToMouse = DistanceToMouse; + } + } + } + + for (uint8 i = (uint8)ECogDebug_GizmoElementType::MoveX; i < (uint8)ECogDebug_GizmoElementType::MAX; ++i) + { + const FCogDebug_GizmoElement& Elm = GizmoElements[i]; + const bool IsClosestToMouse = i == (uint8)HoveredElementType; + const uint8 AxisIndex = (uint8)Elm.AxisType; + const FColor ZLowColor = IsClosestToMouse ? GizmoAxisColorsSelection[AxisIndex] : GizmoAxisColorsZLow[AxisIndex]; + const FColor ZHighColor = IsClosestToMouse ? GizmoAxisColorsSelection[AxisIndex] : GizmoAxisColorsZHigh[AxisIndex]; + + switch (Elm.Type) + { + case ECogDebug_GizmoType::MoveAxis: + { + DrawDebugLine(World, GizmoCenter, Elm.Location, ZLowColor, false, 0.0f, Debug.GizmoZLow, AdjustedThicknessZLow); + DrawDebugLine(World, GizmoCenter, Elm.Location, ZHighColor, false, 0.0f, Debug.GizmoZHigh, Debug.GizmoThicknessZHigh); + break; + } + + case ECogDebug_GizmoType::MovePlane: + { + FCogDebugDrawHelper::DrawQuad(World, Elm.Location, Elm.Rotation, FVector2D(AdjustedPlaneExtent, AdjustedPlaneExtent), ZLowColor, false, 0.0f, Debug.GizmoZLow, AdjustedThicknessZLow); + FCogDebugDrawHelper::DrawQuad(World, Elm.Location, Elm.Rotation, FVector2D(AdjustedPlaneExtent, AdjustedPlaneExtent), ZHighColor, false, 0.0f, Debug.GizmoZHigh, AdjustedThicknessZHigh); + FCogDebugDrawHelper::DrawSolidQuad(World, Elm.Location, Elm.Rotation, FVector2D(AdjustedPlaneExtent, AdjustedPlaneExtent), ZLowColor, false, 0.0f, Debug.GizmoZLow); + break; + } + + case ECogDebug_GizmoType::Rotate: + { + FRotationTranslationMatrix Matrix(FRotator(Elm.Rotation), Elm.Location); + DrawDebugCircle(World, Matrix, Debug.GizmoRotationRadius, Debug.GizmoRotationSegments, ZLowColor, false, 0.0f, Debug.GizmoZLow, AdjustedThicknessZLow, false); + DrawDebugCircle(World, Matrix, Debug.GizmoRotationRadius, Debug.GizmoRotationSegments, ZHighColor, false, 0.0f, Debug.GizmoZHigh, AdjustedThicknessZHigh, false); + break; + } + + case ECogDebug_GizmoType::ScaleUniform: + case ECogDebug_GizmoType::ScaleAxis: + { + DrawDebugBox(World, Elm.Location, FVector::OneVector * AdjustedScaleBoxExtent, Elm.Rotation, ZLowColor, false, 0.0f, Debug.GizmoZLow, AdjustedThicknessZLow); + DrawDebugBox(World, Elm.Location, FVector::OneVector * AdjustedScaleBoxExtent, Elm.Rotation, ZHighColor, false, 0.0f, Debug.GizmoZHigh, AdjustedThicknessZHigh); + DrawDebugSolidBox(World, Elm.Location, FVector::OneVector * AdjustedScaleBoxExtent, Elm.Rotation, ZLowColor, false, 0.0f, Debug.GizmoZLow); + break; + } + } + } + + if (ImGui::IsMouseReleased(ImGuiMouseButton_Left)) + { + DraggedElementType = ECogDebug_GizmoElementType::MAX; + } + else if (DraggedElementType != ECogDebug_GizmoElementType::MAX) + { + if (ImGui::IsMouseDragging(ImGuiMouseButton_Left, 4.0f)) + { + FVector MouseWorldOrigin, MouseWorldDirection; + UGameplayStatics::DeprojectScreenToWorld(&InPlayerController, MousePos - CursorOffset, MouseWorldOrigin, MouseWorldDirection); + + FCogDebug_GizmoElement& DraggedElement = GizmoElements[(uint8)DraggedElementType]; + + switch (DraggedElement.Type) + { + case ECogDebug_GizmoType::MoveAxis: + { + FVector Pa, Pb; + FMath::SegmentDistToSegmentSafe( + GizmoCenter - DraggedElement.Direction * 10000, + GizmoCenter + DraggedElement.Direction * 10000, + MouseWorldOrigin - MouseWorldDirection * 10000, + MouseWorldOrigin + MouseWorldDirection * 10000, + Pa, Pb); + InOutTransform.SetLocation(Pa); + break; + } + + case ECogDebug_GizmoType::MovePlane: + { + const FPlane Plane(GizmoCenter, DraggedElement.Direction); + const FVector PlaneIntersection = FMath::RayPlaneIntersection(MouseWorldOrigin, MouseWorldDirection, Plane); + InOutTransform.SetLocation(PlaneIntersection); + break; + } + + case ECogDebug_GizmoType::ScaleAxis: + { + FVector Pa, Pb; + FMath::SegmentDistToSegmentSafe( + GizmoCenter - DraggedElement.Direction * 10000, + GizmoCenter + DraggedElement.Direction * 10000, + MouseWorldOrigin - MouseWorldDirection * 10000, + MouseWorldOrigin + MouseWorldDirection * 10000, + Pa, Pb); + + const float Sign = FMath::Sign(FVector::DotProduct(DraggedElement.Direction, Pa - GizmoCenter)); + const float Delta = (Pa - GizmoCenter).Length() * Sign; + FVector NewScale = InitialScale + (DraggedElement.Axis * Delta * Debug.GizmoScaleSpeed); + NewScale.X = FMath::Max(NewScale.X, Debug.GizmoScaleMin); + NewScale.Y = FMath::Max(NewScale.Y, Debug.GizmoScaleMin); + NewScale.Z = FMath::Max(NewScale.Z, Debug.GizmoScaleMin); + InOutTransform.SetScale3D(NewScale); + break; + } + + case ECogDebug_GizmoType::ScaleUniform: + { + const FVector2D DragDelta = FCogImguiHelper::ToFVector2D(ImGui::GetMouseDragDelta(ImGuiMouseButton_Left)); + FVector NewScale = InitialScale + (DraggedElement.Axis * (DragDelta.X - DragDelta.Y) * Debug.GizmoScaleSpeed); + NewScale.X = FMath::Max(NewScale.X, Debug.GizmoScaleMin); + NewScale.Y = FMath::Max(NewScale.Y, Debug.GizmoScaleMin); + NewScale.Z = FMath::Max(NewScale.Z, Debug.GizmoScaleMin); + InOutTransform.SetScale3D(NewScale); + break; + } + + default: + break; + } + + } + } + else if (ImGui::IsMouseDown(ImGuiMouseButton_Left)) + { + DraggedElementType = HoveredElementType; + + if (HoveredElementType != ECogDebug_GizmoElementType::MAX) + { + CursorOffset = MousePos - Center2D; + InitialScale = InOutTransform.GetScale3D(); + } + } +} diff --git a/Plugins/Cog/Source/CogDebug/Private/CogDebugSettings.cpp b/Plugins/Cog/Source/CogDebug/Private/CogDebugSettings.cpp index 5099c35..8e61ae8 100644 --- a/Plugins/Cog/Source/CogDebug/Private/CogDebugSettings.cpp +++ b/Plugins/Cog/Source/CogDebug/Private/CogDebugSettings.cpp @@ -7,65 +7,12 @@ //-------------------------------------------------------------------------------------------------------------------------- TWeakObjectPtr FCogDebugSettings::Selection; -bool FCogDebugSettings::bIsFilteringBySelection = true; -bool FCogDebugSettings::Persistent = false; -bool FCogDebugSettings::TextShadow = true; -bool FCogDebugSettings::Fade2D = true; -float FCogDebugSettings::Duration = 3.0f; -int FCogDebugSettings::DepthPriority = 0; -int FCogDebugSettings::Segments = 12; -float FCogDebugSettings::Thickness = 0.0f; -float FCogDebugSettings::ServerThickness = 2.0f; -float FCogDebugSettings::ServerColorMultiplier = 0.8f; -float FCogDebugSettings::ArrowSize = 10.0f; -float FCogDebugSettings::AxesScale = 1.0f; -float FCogDebugSettings::GradientColorIntensity = 0.0f; -float FCogDebugSettings::GradientColorSpeed = 2.0f; -float FCogDebugSettings::TextSize = 1.0f; -TArray FCogDebugSettings::SecondaryBoneWildcards = -{ - "interaction", - "center_of_mass", - "ik_*", - "index_*", - "middle_*", - "pinky_*", - "ring_*", - "thumb_*", - "wrist_*", - "*_bck_*", - "*_fwd_*", - "*_in_*", - "*_out_*", - "*_pec_*", - "*_scap_*", - "*_bicep_*", - "*_tricep_*", - "*ankle*", - "*knee*", - "*corrective*", - "*twist*", - "*latissimus*", -}; +FCogDebugData FCogDebugSettings::Data = FCogDebugData(); //-------------------------------------------------------------------------------------------------------------------------- void FCogDebugSettings::Reset() { - bIsFilteringBySelection = true; - Persistent = false; - TextShadow = true; - Fade2D = true; - Duration = 3.0f; - DepthPriority = 0; - Segments = 12; - Thickness = 0.0f; - ServerThickness = 2.0f; - ServerColorMultiplier = 0.8f; - ArrowSize = 10.0f; - AxesScale = 1.0f; - GradientColorIntensity = 0.0f; - GradientColorSpeed = 2.0f; - TextSize = 1.0f; + Data = FCogDebugData(); } //-------------------------------------------------------------------------------------------------------------------------- @@ -82,7 +29,7 @@ bool FCogDebugSettings::IsDebugActiveForObject(const UObject* WorldContextObject return true; } - bool Result = IsDebugActiveForObject_Internal(WorldContextObject, Selection.Get(), bIsFilteringBySelection); + bool Result = IsDebugActiveForObject_Internal(WorldContextObject, Selection.Get(), Data.bIsFilteringBySelection); return Result; } @@ -160,13 +107,13 @@ void FCogDebugSettings::SetSelection(UWorld* World, AActor* Value) //-------------------------------------------------------------------------------------------------------------------------- bool FCogDebugSettings::GetIsFilteringBySelection() { - return bIsFilteringBySelection; + return Data.bIsFilteringBySelection; } //-------------------------------------------------------------------------------------------------------------------------- void FCogDebugSettings::SetIsFilteringBySelection(UWorld* World, bool Value) { - bIsFilteringBySelection = Value; + Data.bIsFilteringBySelection = Value; if (World != nullptr && World->GetNetMode() == NM_Client) { @@ -180,13 +127,13 @@ void FCogDebugSettings::SetIsFilteringBySelection(UWorld* World, bool Value) //-------------------------------------------------------------------------------------------------------------------------- bool FCogDebugSettings::GetDebugPersistent(bool bPersistent) { - return Persistent && bPersistent; + return Data.Persistent && bPersistent; } //-------------------------------------------------------------------------------------------------------------------------- float FCogDebugSettings::GetDebugDuration(bool bPersistent) { - return bPersistent == false ? 0.0f : Duration; + return bPersistent == false ? 0.0f : Data.Duration; } //-------------------------------------------------------------------------------------------------------------------------- @@ -194,7 +141,7 @@ float FCogDebugSettings::GetDebugTextDuration(bool bPersistent) { if (bPersistent) { - return Persistent ? 100 : Duration; + return Data.Persistent ? 100 : Data.Duration; } else { @@ -205,31 +152,31 @@ float FCogDebugSettings::GetDebugTextDuration(bool bPersistent) //-------------------------------------------------------------------------------------------------------------------------- int FCogDebugSettings::GetDebugSegments() { - return Segments; + return Data.Segments; } //-------------------------------------------------------------------------------------------------------------------------- int FCogDebugSettings::GetCircleSegments() { - return (Segments * 2) + 2; // because DrawDebugCircle does Segments = FMath::Max((Segments - 2) / 2, 4) for some reason + return (Data.Segments * 2) + 2; // because DrawDebugCircle does Segments = FMath::Max((Segments - 2) / 2, 4) for some reason } //-------------------------------------------------------------------------------------------------------------------------- float FCogDebugSettings::GetDebugThickness(float InThickness) { - return (Thickness + InThickness); + return (Data.Thickness + InThickness); } //-------------------------------------------------------------------------------------------------------------------------- float FCogDebugSettings::GetDebugServerThickness(float InThickness) { - return (ServerThickness + InThickness); + return (Data.ServerThickness + InThickness); } //-------------------------------------------------------------------------------------------------------------------------- uint8 FCogDebugSettings::GetDebugDepthPriority(float InDepthPriority) { - return (DepthPriority + InDepthPriority); + return (Data.DepthPriority + InDepthPriority); } //-------------------------------------------------------------------------------------------------------------------------- @@ -252,8 +199,8 @@ FColor FCogDebugSettings::ModulateDebugColor(const UWorld* World, const FColor& ComplementaryColor = ComplementaryColor.HSVToLinearRGB(); - const FLinearColor GradientColor = FLinearColor::LerpUsingHSV(FLinearColor(Color), ComplementaryColor, FMath::Cos(GradientColorSpeed * Time)); - const FLinearColor FBlendColor = BaseColor * (1.0f - FCogDebugSettings::GradientColorIntensity) + GradientColor * GradientColorIntensity; + const FLinearColor GradientColor = FLinearColor::LerpUsingHSV(FLinearColor(Color), ComplementaryColor, FMath::Cos(Data.GradientColorSpeed * Time)); + const FLinearColor FBlendColor = BaseColor * (1.0f - Data.GradientColorIntensity) + GradientColor * Data.GradientColorIntensity; return FBlendColor.ToFColor(true); } @@ -262,9 +209,9 @@ FColor FCogDebugSettings::ModulateDebugColor(const UWorld* World, const FColor& FColor FCogDebugSettings::ModulateServerColor(const FColor& Color) { FColor ServerColor( - Color.R * ServerColorMultiplier, - Color.G * ServerColorMultiplier, - Color.B * ServerColorMultiplier, + Color.R * Data.ServerColorMultiplier, + Color.G * Data.ServerColorMultiplier, + Color.B * Data.ServerColorMultiplier, Color.A); return ServerColor; @@ -275,7 +222,7 @@ bool FCogDebugSettings::IsSecondarySkeletonBone(FName BoneName) { FString BoneString = BoneName.ToString().ToLower(); - for (const FString& Wildcard : SecondaryBoneWildcards) + for (const FString& Wildcard : Data.SecondaryBoneWildcards) { if (BoneString.MatchesWildcard(Wildcard)) { diff --git a/Plugins/Cog/Source/CogDebug/Public/CogDebugGizmo.h b/Plugins/Cog/Source/CogDebug/Public/CogDebugGizmo.h new file mode 100644 index 0000000..a8dee69 --- /dev/null +++ b/Plugins/Cog/Source/CogDebug/Public/CogDebugGizmo.h @@ -0,0 +1,67 @@ +#pragma once + +#include "CoreMinimal.h" +#include "CogDebugGizmo.generated.h" + +//-------------------------------------------------------------------------------------------------------------------------- +UENUM() +enum class ECogDebug_GizmoType : uint8 +{ + MoveAxis, + MovePlane, + Rotate, + ScaleAxis, + ScaleUniform, + MAX, +}; + +//-------------------------------------------------------------------------------------------------------------------------- +UENUM() +enum class ECogDebug_GizmoAxis : uint8 +{ + X, + Y, + Z, + MAX, +}; + +//-------------------------------------------------------------------------------------------------------------------------- +UENUM() +enum class ECogDebug_GizmoElementType : uint8 +{ + MoveX, + MoveY, + MoveZ, + MoveXY, + MoveXZ, + MoveYZ, + RotateX, + RotateY, + RotateZ, + ScaleXYZ, + ScaleX, + ScaleY, + ScaleZ, + MAX, +}; + +//-------------------------------------------------------------------------------------------------------------------------- +struct FCogDebug_GizmoElement +{ + ECogDebug_GizmoType Type; + ECogDebug_GizmoAxis AxisType; + FVector Axis; + FVector Direction; + FQuat Rotation; + FVector Location; +}; + +//-------------------------------------------------------------------------------------------------------------------------- +struct COGDEBUG_API FCogDebug_Gizmo +{ + void Draw(const APlayerController& InPlayerController, FTransform& InOutTransform); + + ECogDebug_GizmoElementType DraggedElementType = ECogDebug_GizmoElementType::MAX; + FVector2D CursorOffset = FVector2D::ZeroVector; + FVector InitialScale = FVector::OneVector; +}; diff --git a/Plugins/Cog/Source/CogDebug/Public/CogDebugSettings.h b/Plugins/Cog/Source/CogDebug/Public/CogDebugSettings.h index 89da83c..01e0f55 100644 --- a/Plugins/Cog/Source/CogDebug/Public/CogDebugSettings.h +++ b/Plugins/Cog/Source/CogDebug/Public/CogDebugSettings.h @@ -2,11 +2,167 @@ #include "CoreMinimal.h" #include "UObject/WeakObjectPtrTemplates.h" +#include "CogDebugSettings.generated.h" class UObject; class AActor; class UWorld; +USTRUCT() +struct FCogDebugData +{ + GENERATED_BODY() + + UPROPERTY(Config) + bool bIsFilteringBySelection = true; + + UPROPERTY(Config) + bool Persistent = false; + + UPROPERTY(Config) + bool TextShadow = true; + + UPROPERTY(Config) + bool Fade2D = true; + + UPROPERTY(Config) + float Duration = 3.0f; + + UPROPERTY(Config) + int DepthPriority = 0; + + UPROPERTY(Config) + int Segments = 12; + + UPROPERTY(Config) + float Thickness = 0.0f; + + UPROPERTY(Config) + float ServerThickness = 2.0f; + + UPROPERTY(Config) + float ServerColorMultiplier = 0.8f; + + UPROPERTY(Config) + float ArrowSize = 10.0f; + + UPROPERTY(Config) + float AxesScale = 1.0f; + + UPROPERTY(Config) + float GradientColorIntensity = 0.0f; + + UPROPERTY(Config) + float GradientColorSpeed = 2.0f; + + UPROPERTY(Config) + float TextSize = 1.0f; + + UPROPERTY(Config) + float GizmoScale = 1.0f; + + UPROPERTY(Config) + float GizmoAxisLength = 50.0f; + + UPROPERTY(Config) + int GizmoZLow = 0; + + UPROPERTY(Config) + int GizmoZHigh = 100; + + UPROPERTY(Config) + float GizmoThicknessZLow = 1.0f; + + UPROPERTY(Config) + float GizmoThicknessZHigh = 0.0f; + + UPROPERTY(Config) + float GizmoMouseMaxDistance = 5.0f; + + UPROPERTY(Config) + float GizmoPlaneOffset = 25.0f; + + UPROPERTY(Config) + float GizmoPlaneExtent = 5.0f; + + UPROPERTY(Config) + float GizmoScaleBoxExtent = 2.0f; + + UPROPERTY(Config) + float GizmoScaleSpeed = 0.5f; + + UPROPERTY(Config) + float GizmoScaleMin = 0.001f; + + UPROPERTY(Config) + float GizmoRotationRadius = 15.0f; + + UPROPERTY(Config) + int GizmoRotationSegments = 32; + + UPROPERTY(Config) + FColor GizmoAxisColorsZHighX = FColor(255, 50, 50, 255); + + UPROPERTY(Config) + FColor GizmoAxisColorsZHighY = FColor(50, 255, 50, 255); + + UPROPERTY(Config) + FColor GizmoAxisColorsZHighZ = FColor(50, 50, 255, 255); + + UPROPERTY(Config) + FColor GizmoAxisColorsZHighW = FColor(255, 255, 255, 255); + + UPROPERTY(Config) + FColor GizmoAxisColorsZLowX = FColor(128, 0, 0, 255); + + UPROPERTY(Config) + FColor GizmoAxisColorsZLowY = FColor(0, 128, 0, 255); + + UPROPERTY(Config) + FColor GizmoAxisColorsZLowZ = FColor(0, 0, 128, 255); + + UPROPERTY(Config) + FColor GizmoAxisColorsZLowW = FColor(128, 128, 128, 255); + + UPROPERTY(Config) + FColor GizmoAxisColorsSelectionX = FColor(255, 255, 0, 255); + + UPROPERTY(Config) + FColor GizmoAxisColorsSelectionY = FColor(255, 255, 0, 255); + + UPROPERTY(Config) + FColor GizmoAxisColorsSelectionZ = FColor(255, 255, 0, 255); + + UPROPERTY(Config) + FColor GizmoAxisColorsSelectionW = FColor(255, 255, 0, 255); + + UPROPERTY(Config) + TArray SecondaryBoneWildcards = { + "interaction", + "center_of_mass", + "ik_*", + "index_*", + "middle_*", + "pinky_*", + "ring_*", + "thumb_*", + "wrist_*", + "*_bck_*", + "*_fwd_*", + "*_in_*", + "*_out_*", + "*_pec_*", + "*_scap_*", + "*_bicep_*", + "*_tricep_*", + "*ankle*", + "*knee*", + "*corrective*", + "*twist*", + "*latissimus*", + }; +}; + struct COGDEBUG_API FCogDebugSettings { public: @@ -48,41 +204,11 @@ public: static void Reset(); - static bool Persistent; - - static bool TextShadow; - - static bool Fade2D; - - static float Duration; - - static int DepthPriority; - - static int Segments; - - static float Thickness; - - static float ServerThickness; - - static float ServerColorMultiplier; - - static float ArrowSize; - - static float AxesScale; - - static float GradientColorIntensity; - - static float GradientColorSpeed; - - static float TextSize; - - static TArray SecondaryBoneWildcards; + static FCogDebugData Data; private: static bool IsDebugActiveForObject_Internal(const UObject* WorldContextObject, const AActor* InSelection, bool InIsFilteringBySelection); static TWeakObjectPtr Selection; - - static bool bIsFilteringBySelection; }; diff --git a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CollisionTester.cpp b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CollisionTester.cpp index c3250e1..f9ac217 100644 --- a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CollisionTester.cpp +++ b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CollisionTester.cpp @@ -4,13 +4,9 @@ #include "CogDebugSettings.h" #include "CogEngineDataAsset.h" #include "CogImGuiHelper.h" -#include "CogWindowHelper.h" #include "CogWindowWidgets.h" -#include "Components/BoxComponent.h" -#include "Components/CapsuleComponent.h" #include "Components/PrimitiveComponent.h" #include "Components/SceneComponent.h" -#include "Components/SphereComponent.h" #include "imgui.h" #include "Kismet/GameplayStatics.h" @@ -242,24 +238,24 @@ void FCogEngineWindow_CollisionTester::RenderContent() case ECogEngine_CollisionQueryShape::Sphere: { FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Sphere Radius", &Config->SphereRadius, 0.1f, 0, 100.0f, "%.1f"); + ImGui::DragFloat("Sphere Radius", &Config->ShapeExtent.X, 0.1f, 0, 100.0f, "%.1f"); break; } case ECogEngine_CollisionQueryShape::Box: { FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat3("Box Extent", &Config->BoxExtent.X, 0.1f, 0, 100.0f, "%.1f"); + ImGui::DragFloat3("Box Extent", &Config->ShapeExtent.X, 0.1f, 0, 100.0f, "%.1f"); break; } case ECogEngine_CollisionQueryShape::Capsule: { FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Capsule Radius", &Config->CapsuleRadius, 0.1f, 0, 100.0f, "%.1f"); + ImGui::DragFloat("Capsule Radius", &Config->ShapeExtent.X, 0.1f, 0, 100.0f, "%.1f"); FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Capsule Half Height", &Config->CapsuleHalfHeight, 0.1f, 0, 100.0f, "%.1f"); + ImGui::DragFloat("Capsule Half Height", &Config->ShapeExtent.Z, 0.1f, 0, 100.0f, "%.1f"); break; } } @@ -343,9 +339,9 @@ void FCogEngineWindow_CollisionTester::Query() { switch (Config->Shape) { - case ECogEngine_CollisionQueryShape::Sphere: QueryShape.SetSphere(Config->SphereRadius); break; - case ECogEngine_CollisionQueryShape::Capsule: QueryShape.SetCapsule(Config->CapsuleRadius, Config->CapsuleHalfHeight); break; - case ECogEngine_CollisionQueryShape::Box: QueryShape.SetBox(Config->BoxExtent); break; + case ECogEngine_CollisionQueryShape::Sphere: QueryShape.SetSphere(Config->ShapeExtent.X); break; + case ECogEngine_CollisionQueryShape::Capsule: QueryShape.SetCapsule(Config->ShapeExtent.X, Config->ShapeExtent.Z); break; + case ECogEngine_CollisionQueryShape::Box: QueryShape.SetBox(Config->ShapeExtent); break; } } @@ -519,7 +515,7 @@ void FCogEngineWindow_CollisionTester::Query() GetWorld(), QueryStart, QueryEnd, - FCogDebugSettings::ArrowSize, + FCogDebugSettings::Data.ArrowSize, Color, false, 0.0f, @@ -577,7 +573,7 @@ void FCogEngineWindow_CollisionTester::Query() GetWorld(), Hit.Location, Hit.Location + Hit.Normal * 20.0f, - FCogDebugSettings::ArrowSize, + FCogDebugSettings::Data.ArrowSize, FLinearColor(Config->NormalColor).ToFColor(true), false, 0.0f, @@ -591,7 +587,7 @@ void FCogEngineWindow_CollisionTester::Query() GetWorld(), Hit.ImpactPoint, Hit.ImpactPoint + Hit.ImpactNormal * 20.0f, - FCogDebugSettings::ArrowSize, + FCogDebugSettings::Data.ArrowSize, FLinearColor(Config->ImpactNormalColor).ToFColor(true), false, 0.0f, @@ -605,10 +601,20 @@ void FCogEngineWindow_CollisionTester::Query() } } - FTransform Transform1(QueryRotation, QueryStart, FVector::OneVector); - DrawTransformGizmos(GetWorld(), Transform1); - FTransform Transform2(QueryRotation, QueryEnd, FVector::OneVector); - DrawTransformGizmos(GetWorld(), Transform2); + if (const APlayerController* LocalPlayerController = GetLocalPlayerController()) + { + FVector ScaleStart(Config->ShapeExtent); + FTransform TransformStart(QueryRotation, QueryStart, ScaleStart); + GizmoStart.Draw(*LocalPlayerController, TransformStart); + Config->LocationStart = FVector3f(TransformStart.GetLocation()); + Config->ShapeExtent = FVector3f(TransformStart.GetScale3D()); + + FVector ScaleEnd(Config->ShapeExtent); + FTransform TransformEnd(QueryRotation, QueryEnd, ScaleEnd); + GizmoEnd.Draw(*LocalPlayerController, TransformEnd); + Config->LocationEnd = FVector3f(TransformEnd.GetLocation()); + Config->ShapeExtent = FVector3f(TransformEnd.GetScale3D()); + } } //-------------------------------------------------------------------------------------------------------------------------- @@ -638,7 +644,7 @@ void FCogEngineWindow_CollisionTester::DrawPrimitive(const UPrimitiveComponent* if (AlreadyDrawnActors.Contains(Actor) == false) { FColor TextColor = Color.WithAlpha(255); - DrawDebugString(GetWorld(), Actor->GetActorLocation(), GetNameSafe(Actor->GetClass()), nullptr, FColor::White, 0.0f, FCogDebugSettings::TextShadow, FCogDebugSettings::TextSize); + DrawDebugString(GetWorld(), Actor->GetActorLocation(), GetNameSafe(Actor->GetClass()), nullptr, FColor::White, 0.0f, FCogDebugSettings::Data.TextShadow, FCogDebugSettings::Data.TextSize); AlreadyDrawnActors.Add(Actor); } } @@ -693,7 +699,7 @@ void FCogEngineWindow_CollisionTester::DrawShape(const FCollisionShape& Shape, c case ECollisionShape::Sphere: { //-------------------------------------------------- - // see UCapsuleComponent::GetScaledCapsuleRadius() + // see USphereComponent::GetScaledSphereRadius() //-------------------------------------------------- const float RadiusScale = FMath::Min(Scale.X, FMath::Min(Scale.Y, Scale.Z)); const float Radius = Shape.Sphere.Radius * RadiusScale; @@ -758,198 +764,3 @@ void FCogEngineWindow_CollisionTester::SetAsset(const UCogEngineDataAsset* Value Channel.Color = AssetChannel.Color.ToFColor(true); } } - -//-------------------------------------------------------------------------------------------------------------------------- -static void FindSegmentPointDistance(const FVector2D& Segment1, const FVector2D& Segment2, const FVector2D& Point, FVector2D& Projection, float& Time, float& Distance) -{ - const float DistSquared = FVector2D::DistSquared(Segment1, Segment2); - if (FMath::IsNearlyZero(DistSquared)) - { - Time = 0.0f; - Projection = Segment1; - Distance = FVector2D::Distance(Point, Segment1); - } - else - { - Time = FMath::Max(0.0f, FMath::Min(1.0f, FVector2D::DotProduct(Point - Segment1, Segment2 - Segment1) / DistSquared)); - Projection = Segment1 + Time * (Segment2 - Segment1); - Distance = FVector2D::Distance(Point, Projection); - } -} - -//-------------------------------------------------------------------------------------------------------------------------- -static float FindSegmentPointDistance2(const FVector2D& Segment1, const FVector2D& Segment2, const FVector2D& Point) -{ - FVector2D Projection; - float Time, Distance; - FindSegmentPointDistance(Segment1, Segment2, Point, Projection, Time, Distance); - return Distance; -} - -//-------------------------------------------------------------------------------------------------------------------------- -void FCogEngineWindow_CollisionTester::DrawTransformGizmos(const UWorld* InWorld, FTransform& InTransform) -{ - APlayerController* PlayerController = GetLocalPlayerController(); - if (PlayerController == nullptr) - { - return; - } - - const ImGuiViewport* Viewport = ImGui::GetMainViewport(); - if (Viewport == nullptr) - { - return; - } - - const uint8 ZLow = 0; - const uint8 ZHigh = 100; - const float ThicknessZLow = 1.0f; - const float ThicknessZHigh = 0.0f; - const float AxisLength = 50.0f; - const float PlaneOffset = 25.0f; - const FVector2D PlaneExtent(10.0f, 10.0f); - const FVector BoxExtent(2.0f, 2.0f, 2.0f); - const float MaxMouseDistance = 5.0f; - const float RotationRadius = 15.0f; - const int32 RotationSegments = 32; - - const FColor AxisColorsZHigh [] = { FColor(255, 50, 50, 255), FColor(50, 255, 50, 255), FColor(50, 50, 255, 255), FColor(255, 255, 255, 255) }; - const FColor AxisColorsZLow [] = { FColor(128, 0, 0, 255), FColor(0, 128, 0, 255), FColor(0, 0, 128, 255), FColor(128, 128, 128, 255) }; - - const FColor SelectionColor = FColor(255, 255, 0, 255); - - const FVector Center = InTransform.GetTranslation(); - const FQuat RotX = InTransform.GetRotation(); - 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 FVector UnitAxisX = RotX.GetAxisX(); - const FVector UnitAxisY = RotX.GetAxisY(); - const FVector UnitAxisZ = RotX.GetAxisZ(); - - const FVector AxisX = Center + UnitAxisX * AxisLength; - const FVector AxisY = Center + UnitAxisY * AxisLength; - const FVector AxisZ = Center + UnitAxisZ * AxisLength; - - const FVector PlaneXY = Center + ((UnitAxisX + UnitAxisY) * PlaneOffset); - const FVector PlaneXZ = Center + ((UnitAxisX + UnitAxisZ) * PlaneOffset); - const FVector PlaneYZ = Center + ((UnitAxisY + UnitAxisZ) * PlaneOffset); - - const ImVec2 ImMousePos = ImGui::GetMousePos() - Viewport->Pos; - const FVector2D MousePos = FCogImguiHelper::ToFVector2D(ImMousePos); - - FVector2D ScreenGizmoCenter; - if (UGameplayStatics::ProjectWorldToScreen(PlayerController, Center, ScreenGizmoCenter) == false) - { - return; - } - - FCogEngine_GizmoElement GizmoElements[ECogEngine_GizmoElementType::MAX]; - - GizmoElements[(int32)ECogEngine_GizmoElementType::MoveX] = FCogEngine_GizmoElement { ECogEngine_GizmoType::MoveAxis, ECogEngine_GizmoAxis::X, FQuat::Identity, AxisX }; - GizmoElements[(int32)ECogEngine_GizmoElementType::MoveY] = FCogEngine_GizmoElement { ECogEngine_GizmoType::MoveAxis, ECogEngine_GizmoAxis::Y, FQuat::Identity, AxisY }; - GizmoElements[(int32)ECogEngine_GizmoElementType::MoveZ] = FCogEngine_GizmoElement { ECogEngine_GizmoType::MoveAxis, ECogEngine_GizmoAxis::Z, FQuat::Identity, AxisZ }; - GizmoElements[(int32)ECogEngine_GizmoElementType::MoveXY] = FCogEngine_GizmoElement { ECogEngine_GizmoType::MovePlane, ECogEngine_GizmoAxis::Z, RotZ, PlaneXY }; - GizmoElements[(int32)ECogEngine_GizmoElementType::MoveXZ] = FCogEngine_GizmoElement { ECogEngine_GizmoType::MovePlane, ECogEngine_GizmoAxis::Y, RotY, PlaneXZ }; - GizmoElements[(int32)ECogEngine_GizmoElementType::MoveYZ] = FCogEngine_GizmoElement { ECogEngine_GizmoType::MovePlane, ECogEngine_GizmoAxis::X, RotX, PlaneYZ }; - GizmoElements[(int32)ECogEngine_GizmoElementType::RotateX] = FCogEngine_GizmoElement { ECogEngine_GizmoType::Rotate, ECogEngine_GizmoAxis::X, RotX, AxisX }; - GizmoElements[(int32)ECogEngine_GizmoElementType::RotateY] = FCogEngine_GizmoElement { ECogEngine_GizmoType::Rotate, ECogEngine_GizmoAxis::Y, RotY, AxisY }; - GizmoElements[(int32)ECogEngine_GizmoElementType::RotateZ] = FCogEngine_GizmoElement { ECogEngine_GizmoType::Rotate, ECogEngine_GizmoAxis::Z, RotZ, AxisZ }; - GizmoElements[(int32)ECogEngine_GizmoElementType::ScaleXYZ] = FCogEngine_GizmoElement { ECogEngine_GizmoType::ScaleUniform, ECogEngine_GizmoAxis::MAX, RotX, Center }; - GizmoElements[(int32)ECogEngine_GizmoElementType::ScaleX] = FCogEngine_GizmoElement { ECogEngine_GizmoType::ScaleAxis, ECogEngine_GizmoAxis::X, RotX, AxisX }; - GizmoElements[(int32)ECogEngine_GizmoElementType::ScaleY] = FCogEngine_GizmoElement { ECogEngine_GizmoType::ScaleAxis, ECogEngine_GizmoAxis::Y, RotY, AxisY }; - GizmoElements[(int32)ECogEngine_GizmoElementType::ScaleZ] = FCogEngine_GizmoElement { ECogEngine_GizmoType::ScaleAxis, ECogEngine_GizmoAxis::Z, RotZ, AxisZ }; - - float MinDistanceToMouse = FLT_MAX; - ECogEngine_GizmoElementType ClosestGizmoElementType = ECogEngine_GizmoElementType::MAX; - for (uint8 i = (uint8)ECogEngine_GizmoElementType::MoveX; i < (uint8)ECogEngine_GizmoElementType::MAX; ++i) - { - FCogEngine_GizmoElement& Elm = GizmoElements[i]; - float DistanceToMouse = FLT_MAX; - - switch (Elm.Type) - { - case ECogEngine_GizmoType::MoveAxis: - { - FVector2D ScreenElementLocation; - UGameplayStatics::ProjectWorldToScreen(PlayerController, Elm.Location, ScreenElementLocation); - DistanceToMouse = FindSegmentPointDistance2(ScreenGizmoCenter, ScreenElementLocation, MousePos); - break; - } - - case ECogEngine_GizmoType::MovePlane: - { - //DistanceToMouse = - break; - } - } - - if (DistanceToMouse < MaxMouseDistance && DistanceToMouse < MinDistanceToMouse) - { - ClosestGizmoElementType = (ECogEngine_GizmoElementType)i; - MinDistanceToMouse = DistanceToMouse; - } - } - - for (uint8 i = (uint8)ECogEngine_GizmoElementType::MoveX; i < (uint8)ECogEngine_GizmoElementType::MAX; ++i) - { - const FCogEngine_GizmoElement& Elm = GizmoElements[i]; - const bool IsClosestToMouse = i == (uint8)ClosestGizmoElementType; - - switch (Elm.Type) - { - case ECogEngine_GizmoType::MoveAxis: - { - DrawDebugLine(InWorld, Center, Elm.Location, IsClosestToMouse ? SelectionColor : AxisColorsZLow[(uint8)Elm.Axis], false, 0.0f, ZLow, ThicknessZLow); - DrawDebugLine(InWorld, Center, Elm.Location, IsClosestToMouse ? SelectionColor : AxisColorsZHigh[(uint8)Elm.Axis], false, 0.0f, ZHigh, ThicknessZHigh); - break; - } - - case ECogEngine_GizmoType::MovePlane: - { - FCogDebugDrawHelper::DrawQuad(InWorld, Elm.Location, Elm.Rotation, PlaneExtent, IsClosestToMouse ? SelectionColor : AxisColorsZLow[(uint8)Elm.Axis], false, 0.0f, ZLow, ThicknessZLow); - FCogDebugDrawHelper::DrawQuad(InWorld, Elm.Location, Elm.Rotation, PlaneExtent, IsClosestToMouse ? SelectionColor : AxisColorsZLow[(uint8)Elm.Axis], false, 0.0f, ZHigh, ThicknessZHigh); - FCogDebugDrawHelper::DrawSolidQuad(InWorld, Elm.Location, Elm.Rotation, PlaneExtent, IsClosestToMouse ? SelectionColor : AxisColorsZHigh[(uint8)Elm.Axis], false, 0.0f, ZHigh); - break; - } - - case ECogEngine_GizmoType::Rotate: - { - //FRotationTranslationMatrix Matrix(FRotator(Elm.Rotation), Elm.Location); - //DrawDebugCircle(InWorld, Matrix, RotationRadius, RotationSegments, IsClosestToMouse ? SelectionColor : AxisColorsZLow[(uint8)Elm.Axis], false, 0.0f, ZLow, ThicknessZLow, false); - //DrawDebugCircle(InWorld, Matrix, RotationRadius, RotationSegments, IsClosestToMouse ? SelectionColor : AxisColorsZLow[(uint8)Elm.Axis], false, 0.0f, ZHigh, ThicknessZHigh, false); - break; - } - - case ECogEngine_GizmoType::ScaleUniform: - case ECogEngine_GizmoType::ScaleAxis: - { - DrawDebugBox(InWorld, Elm.Location, BoxExtent, Elm.Rotation, IsClosestToMouse ? SelectionColor : AxisColorsZLow[(uint8)Elm.Axis], false, 0.0f, ZLow, ThicknessZLow); - DrawDebugBox(InWorld, Elm.Location, BoxExtent, Elm.Rotation, IsClosestToMouse ? SelectionColor : AxisColorsZHigh[(uint8)Elm.Axis], false, 0.0f, ZHigh, ThicknessZHigh); - DrawDebugSolidBox(InWorld, Elm.Location, BoxExtent, Elm.Rotation, IsClosestToMouse ? SelectionColor : AxisColorsZLow[(uint8)Elm.Axis], false, 0.0f, ZHigh); - break; - } - } - } - - - if (ImGui::IsMouseDown(ImGuiMouseButton_Left)) - { - IsDragging = ClosestGizmoElementType != ECogEngine_GizmoElementType::MAX; - StartTransform = InTransform; - } - else if (ImGui::IsMouseReleased(ImGuiMouseButton_Left)) - { - IsDragging = false; - } - - if (IsDragging) - { - if (ImGui::IsMouseDragging(ImGuiMouseButton_Left, 4.0f)) - { - ImVec2 Delta = ImGui::GetMouseDragDelta(ImGuiMouseButton_Left); - FVector WorldOrigin, WorldDirection; - UGameplayStatics::DeprojectScreenToWorld(PlayerController, MousePos, WorldOrigin, WorldDirection); - } - } -} diff --git a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CollisionViewer.cpp b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CollisionViewer.cpp index 08a5743..ca99316 100644 --- a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CollisionViewer.cpp +++ b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CollisionViewer.cpp @@ -292,7 +292,7 @@ void FCogEngineWindow_CollisionViewer::RenderContent() if (AlreadyDrawnActors.Contains(Actor) == false) { FColor TextColor = Color.WithAlpha(255); - DrawDebugString(World, Actor->GetActorLocation(), GetNameSafe(Actor->GetClass()), nullptr, FColor::White, 0.0f, FCogDebugSettings::TextShadow, FCogDebugSettings::TextSize); + DrawDebugString(World, Actor->GetActorLocation(), GetNameSafe(Actor->GetClass()), nullptr, FColor::White, 0.0f, FCogDebugSettings::Data.TextShadow, FCogDebugSettings::Data.TextSize); AlreadyDrawnActors.Add(Actor); } } diff --git a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_DebugSettings.cpp b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_DebugSettings.cpp index f9d977d..bc9121f 100644 --- a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_DebugSettings.cpp +++ b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_DebugSettings.cpp @@ -21,22 +21,8 @@ void FCogEngineWindow_DebugSettings::Initialize() Config = GetConfig(); - FCogDebugSettings::Persistent = Config->Persistent; - FCogDebugSettings::TextShadow = Config->TextShadow; - FCogDebugSettings::Fade2D = Config->Fade2D; - FCogDebugSettings::Duration = Config->Duration; - FCogDebugSettings::DepthPriority = Config->DepthPriority; - FCogDebugSettings::Segments = Config->Segments; - FCogDebugSettings::Thickness = Config->Thickness; - FCogDebugSettings::ServerThickness = Config->ServerThickness; - FCogDebugSettings::ServerColorMultiplier = Config->ServerColorMultiplier; - FCogDebugSettings::ArrowSize = Config->ArrowSize; - FCogDebugSettings::AxesScale = Config->AxesScale; - FCogDebugSettings::GradientColorIntensity = Config->GradientColorIntensity; - FCogDebugSettings::GradientColorSpeed = Config->GradientColorSpeed; - FCogDebugSettings::TextSize = Config->TextSize; - - FCogDebugSettings::SetIsFilteringBySelection(GetWorld(), Config->bIsFilteringBySelection); + FCogDebugSettings::Data = Config->Data; + FCogDebugSettings::SetIsFilteringBySelection(GetWorld(), Config->Data.bIsFilteringBySelection); } //-------------------------------------------------------------------------------------------------------------------------- @@ -52,20 +38,7 @@ void FCogEngineWindow_DebugSettings::PreSaveConfig() { Super::PreSaveConfig(); - Config->Persistent = FCogDebugSettings::Persistent; - Config->TextShadow = FCogDebugSettings::TextShadow; - Config->Fade2D = FCogDebugSettings::Fade2D; - Config->Duration = FCogDebugSettings::Duration; - Config->DepthPriority = FCogDebugSettings::DepthPriority; - Config->Segments = FCogDebugSettings::Segments; - Config->Thickness = FCogDebugSettings::Thickness; - Config->ServerThickness = FCogDebugSettings::ServerThickness; - Config->ServerColorMultiplier = FCogDebugSettings::ServerColorMultiplier; - Config->ArrowSize = FCogDebugSettings::ArrowSize; - Config->AxesScale = FCogDebugSettings::AxesScale; - Config->GradientColorIntensity = FCogDebugSettings::GradientColorIntensity; - Config->GradientColorSpeed = FCogDebugSettings::GradientColorSpeed; - Config->TextSize = FCogDebugSettings::TextSize; + Config->Data = FCogDebugSettings::Data; } //-------------------------------------------------------------------------------------------------------------------------- @@ -75,117 +48,195 @@ void FCogEngineWindow_DebugSettings::RenderContent() if (ImGui::BeginMenuBar()) { - if (ImGui::MenuItem("Reset")) + if (ImGui::BeginMenu("Options")) { - FCogDebugSettings::Reset(); + if (ImGui::MenuItem("Reset")) + { + FCogDebugSettings::Reset(); + } + + ImGui::Checkbox("Show Advanced Settings", &Config->bShowAdvancedSettings); + + ImGui::EndMenu(); } ImGui::EndMenuBar(); } - Config->bIsFilteringBySelection = FCogDebugSettings::GetIsFilteringBySelection(); - if (ImGui::Checkbox("Filter by selection", &Config->bIsFilteringBySelection)) + Config->Data.bIsFilteringBySelection = FCogDebugSettings::GetIsFilteringBySelection(); + if (ImGui::Checkbox("Filter by selection", &Config->Data.bIsFilteringBySelection)) { - FCogDebugSettings::SetIsFilteringBySelection(GetWorld(), Config->bIsFilteringBySelection); + FCogDebugSettings::SetIsFilteringBySelection(GetWorld(), Config->Data.bIsFilteringBySelection); } if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) { ImGui::SetTooltip("If checked, only show the debug of the currently selected actor. Otherwise show the debug of all actors."); } - ImGui::Checkbox("Persistent", &FCogDebugSettings::Persistent); + FCogDebugData& Data = FCogDebugSettings::Data; + + ImGui::Checkbox("Persistent", &Data.Persistent); if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) { ImGui::SetTooltip("Make debug draw always persist"); } - ImGui::Checkbox("Text Shadow", &FCogDebugSettings::TextShadow); + ImGui::Checkbox("Text Shadow", &Data.TextShadow); if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) { ImGui::SetTooltip("Show a shadow below debug text."); } FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::Checkbox("Fade 2D", &FCogDebugSettings::Fade2D); + ImGui::Checkbox("Fade 2D", &Data.Fade2D); if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) { ImGui::SetTooltip("Does the 2D debug is fading out."); } FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Duration", &FCogDebugSettings::Duration, 0.01f, 0.0f, 100.0f, "%.1f"); + ImGui::DragFloat("Duration", &Data.Duration, 0.01f, 0.0f, 100.0f, "%.1f"); if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) { ImGui::SetTooltip("The duration of debug elements."); } FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Thickness", &FCogDebugSettings::Thickness, 0.05f, 0.0f, 5.0f, "%.1f"); + ImGui::DragFloat("Thickness", &Data.Thickness, 0.05f, 0.0f, 5.0f, "%.1f"); if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) { ImGui::SetTooltip("The thickness of debug lines."); } FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Server Thickness", &FCogDebugSettings::ServerThickness, 0.05f, 0.0f, 5.0f, "%.1f"); + ImGui::DragFloat("Server Thickness", &Data.ServerThickness, 0.05f, 0.0f, 5.0f, "%.1f"); if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) { ImGui::SetTooltip("The thickness the server debug lines."); } FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Server Color Mult", &FCogDebugSettings::ServerColorMultiplier, 0.01f, 0.0f, 1.0f, "%.1f"); + ImGui::DragFloat("Server Color Mult", &Data.ServerColorMultiplier, 0.01f, 0.0f, 1.0f, "%.1f"); if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) { ImGui::SetTooltip("The color multiplier applied to the server debug lines."); } FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragInt("Depth Priority", &FCogDebugSettings::DepthPriority, 0.1f, 0, 100); + ImGui::DragInt("Depth Priority", &Data.DepthPriority, 0.1f, 0, 100); if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) { ImGui::SetTooltip("The depth priority of debug elements."); } FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragInt("Segments", &FCogDebugSettings::Segments, 0.1f, 4, 20.0f); + ImGui::DragInt("Segments", &Data.Segments, 0.1f, 4, 20.0f); if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) { ImGui::SetTooltip("The number of segments used for circular shapes."); } FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Axes Scale", &FCogDebugSettings::AxesScale, 0.1f, 0, 10.0f, "%.1f"); + ImGui::DragFloat("Axes Scale", &Data.AxesScale, 0.1f, 0, 10.0f, "%.1f"); if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) { ImGui::SetTooltip("The scaling debug axis."); } FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Arrow Size", &FCogDebugSettings::ArrowSize, 1.0f, 0.0f, 200.0f, "%.0f"); + ImGui::DragFloat("Arrow Size", &Data.ArrowSize, 1.0f, 0.0f, 200.0f, "%.0f"); if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) { ImGui::SetTooltip("The size of debug arrows."); } FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Gradient Intensity", &FCogDebugSettings::GradientColorIntensity, 0.01f, 0.0f, 1.0f, "%.2f"); + ImGui::DragFloat("Gradient Intensity", &Data.GradientColorIntensity, 0.01f, 0.0f, 1.0f, "%.2f"); if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) { ImGui::SetTooltip("How much the debug elements color should be changed by a gradient color over time."); } FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Gradient Speed", &FCogDebugSettings::GradientColorSpeed, 0.1f, 0.0f, 10.0f, "%.1f"); + ImGui::DragFloat("Gradient Speed", &Data.GradientColorSpeed, 0.1f, 0.0f, 10.0f, "%.1f"); if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) { ImGui::SetTooltip("The speed of the gradient color change."); } FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Text Size", &FCogDebugSettings::TextSize, 0.1f, 0.1f, 5.0f, "%.1f"); + ImGui::DragFloat("Text Size", &Data.TextSize, 0.1f, 0.1f, 5.0f, "%.1f"); if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) { ImGui::SetTooltip("The size of the debug texts."); } + + if (Config->bShowAdvancedSettings) + { + ImGui::SeparatorText("Gizmo"); + } + + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragFloat("Gizmo Scale", &Data.GizmoScale, 0.1f, 0.1f, 10.0f, "%.1f"); + if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) + { + ImGui::SetTooltip("The scale of the gizmo."); + } + + if (Config->bShowAdvancedSettings) + { + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragFloat("Gizmo Axis Length", &Data.GizmoAxisLength, 0.1f, 0.1f, 500.0f, "%.1f"); + + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragInt("Gizmo Z Low", &Data.GizmoZLow, 0.5f, 0, 1000); + + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragInt("Gizmo Z High", &Data.GizmoZHigh, 0.5f, 0, 1000); + + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragFloat("Gizmo Thickness Z Low", &Data.GizmoThicknessZLow, 0.1f, 0.0f, 10.0f, "%.1f"); + + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragFloat("Gizmo Thickness Z High", &Data.GizmoThicknessZHigh, 0.1f, 0.0f, 10.0f, "%.1f"); + + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragFloat("Gizmo Mouse Max Distance", &Data.GizmoMouseMaxDistance, 0.1f, 0.0f, 50.0f, "%.1f"); + + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragFloat("Gizmo Plane Offset", &Data.GizmoPlaneOffset, 0.1f, 0.0f, 500.0f, "%.1f"); + + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragFloat("Gizmo Plane Extent", &Data.GizmoPlaneExtent, 0.1f, 0.0f, 100.0f, "%.1f"); + + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragFloat("Gizmo Scale Box Extent", &Data.GizmoScaleBoxExtent, 0.1f, 0.0f, 100.0f, "%.1f"); + + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragFloat("Gizmo Scale Speed", &Data.GizmoScaleSpeed, 0.1f, 0.0f, 100.0f, "%.1f"); + + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragFloat("Gizmo Scale Min", &Data.GizmoScaleMin, 0.001f, 0.001f, 1.0f, "%.3f"); + + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragFloat("Gizmo Rotation Radius", &Data.GizmoRotationRadius, 0.1f, 0.1f, 500.0f, "%.1f"); + + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragInt("Gizmo Rotation Segments", &Data.GizmoRotationSegments, 1.0f, 0, 64); + + FCogWindowWidgets::ColorEdit4("Gizmo Axis Colors ZLow X", Data.GizmoAxisColorsZLowX, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); + FCogWindowWidgets::ColorEdit4("Gizmo Axis Colors ZLow Y", Data.GizmoAxisColorsZLowY, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); + FCogWindowWidgets::ColorEdit4("Gizmo Axis Colors ZLow Z", Data.GizmoAxisColorsZLowZ, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); + FCogWindowWidgets::ColorEdit4("Gizmo Axis Colors ZLow W", Data.GizmoAxisColorsZLowW, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); + + FCogWindowWidgets::ColorEdit4("Gizmo Axis Colors ZHigh X", Data.GizmoAxisColorsZHighX, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); + FCogWindowWidgets::ColorEdit4("Gizmo Axis Colors ZHigh Y", Data.GizmoAxisColorsZHighY, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); + FCogWindowWidgets::ColorEdit4("Gizmo Axis Colors ZHigh Z", Data.GizmoAxisColorsZHighZ, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); + FCogWindowWidgets::ColorEdit4("Gizmo Axis Colors ZHigh W", Data.GizmoAxisColorsZHighW, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); + + FCogWindowWidgets::ColorEdit4("Gizmo Axis Colors Selection X", Data.GizmoAxisColorsSelectionX, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); + FCogWindowWidgets::ColorEdit4("Gizmo Axis Colors Selection Y", Data.GizmoAxisColorsSelectionY, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); + FCogWindowWidgets::ColorEdit4("Gizmo Axis Colors Selection Z", Data.GizmoAxisColorsSelectionZ, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); + FCogWindowWidgets::ColorEdit4("Gizmo Axis Colors Selection W", Data.GizmoAxisColorsSelectionW, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); + } } diff --git a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Skeleton.cpp b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Skeleton.cpp index c5d7854..72582b8 100644 --- a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Skeleton.cpp +++ b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Skeleton.cpp @@ -321,7 +321,7 @@ void FCogEngineWindow_Skeleton::DrawSkeleton() if (ShowNames || BoneInfo.ShowName || IsHovered) { - ::DrawDebugString(World, BoneLocation, BoneInfo.Name.ToString(), nullptr, IsHovered ? FColor::Red : FColor::White, 0.0f, true, FCogDebugSettings::TextSize); + ::DrawDebugString(World, BoneLocation, BoneInfo.Name.ToString(), nullptr, IsHovered ? FColor::Red : FColor::White, 0.0f, true, FCogDebugSettings::Data.TextSize); } if (ShowAxes || BoneInfo.ShowAxes) @@ -330,7 +330,7 @@ void FCogEngineWindow_Skeleton::DrawSkeleton() World, BoneLocation, BoneRotation, - 10.0f * FCogDebugSettings::AxesScale, + 10.0f * FCogDebugSettings::Data.AxesScale, false, 0.0f, 1, @@ -345,7 +345,7 @@ void FCogEngineWindow_Skeleton::DrawSkeleton() World, BoneLocation, BoneLocation + ParentBodyInstance->GetUnrealWorldVelocity() * World->GetDeltaSeconds(), - FCogDebugSettings::ArrowSize, + FCogDebugSettings::Data.ArrowSize, FCogDebugSettings::ModulateDebugColor(World, FColor::Cyan), FCogDebugSettings::GetDebugPersistent(true), FCogDebugSettings::GetDebugDuration(true), diff --git a/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_CollisionTester.h b/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_CollisionTester.h index 264bc97..b0994fd 100644 --- a/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_CollisionTester.h +++ b/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_CollisionTester.h @@ -1,6 +1,7 @@ #pragma once #include "CoreMinimal.h" +#include "CogDebugGizmo.h" #include "CogWindow.h" #include "CogWindowConfig.h" #include "Engine/HitResult.h" @@ -56,57 +57,6 @@ enum class ECogEngine_CollisionQueryShape : uint8 Capsule, }; -//-------------------------------------------------------------------------------------------------------------------------- -UENUM() -enum class ECogEngine_GizmoType : uint8 -{ - MoveAxis, - MovePlane, - Rotate, - ScaleAxis, - ScaleUniform, - MAX, -}; - -//-------------------------------------------------------------------------------------------------------------------------- -UENUM() -enum class ECogEngine_GizmoAxis : uint8 -{ - X, - Y, - Z, - MAX, -}; - -//-------------------------------------------------------------------------------------------------------------------------- -UENUM() -enum class ECogEngine_GizmoElementType : uint8 -{ - MoveX, - MoveY, - MoveZ, - MoveXY, - MoveXZ, - MoveYZ, - RotateX, - RotateY, - RotateZ, - ScaleXYZ, - ScaleX, - ScaleY, - ScaleZ, - MAX, -}; - -//-------------------------------------------------------------------------------------------------------------------------- -struct FCogEngine_GizmoElement -{ - ECogEngine_GizmoType Type; - ECogEngine_GizmoAxis Axis; - FQuat Rotation; - FVector Location; -}; - //-------------------------------------------------------------------------------------------------------------------------- class COGENGINE_API FCogEngineWindow_CollisionTester : public FCogWindow { @@ -132,7 +82,6 @@ protected: void DrawShape(const FCollisionShape& Shape, const FVector& Location, const FQuat& Rotation, const FVector& Scale, const FColor& Color, bool DrawSolid) const; - void DrawTransformGizmos(const UWorld* InWorld, FTransform& InTransform); struct FChannel { @@ -152,6 +101,9 @@ protected: bool IsDragging = false; + FCogDebug_Gizmo GizmoStart; + FCogDebug_Gizmo GizmoEnd; + FTransform StartTransform; }; @@ -176,6 +128,9 @@ public: UPROPERTY(Config) FRotator3f Rotation; + UPROPERTY(Config) + FRotator3f Scale; + UPROPERTY(Config) ECogEngine_CollisionQueryType Type; @@ -204,16 +159,7 @@ public: int32 ProfileIndex; UPROPERTY(Config) - float SphereRadius; - - UPROPERTY(Config) - FVector3f BoxExtent; - - UPROPERTY(Config) - float CapsuleRadius; - - UPROPERTY(Config) - float CapsuleHalfHeight; + FVector3f ShapeExtent; UPROPERTY(Config) int QueryTypeOld; @@ -272,10 +218,7 @@ public: Shape = ECogEngine_CollisionQueryShape::Sphere; MultiHits = false; TraceComplex = false; - SphereRadius = 50.0f; - BoxExtent = FVector3f(50.0f, 50.0f, 50.0f); - CapsuleRadius = 50.0f; - CapsuleHalfHeight = 50.0f; + ShapeExtent = FVector3f(50.0f, 50.0f, 50.0f); ObjectTypesToQuery = 0; ProfileIndex = 0; diff --git a/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_DebugSettings.h b/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_DebugSettings.h index 70d2368..fc0ef60 100644 --- a/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_DebugSettings.h +++ b/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_DebugSettings.h @@ -1,6 +1,7 @@ #pragma once #include "CoreMinimal.h" +#include "CogDebugSettings.h" #include "CogWindow.h" #include "CogWindowConfig.h" #include "CogEngineWindow_DebugSettings.generated.h" @@ -27,7 +28,6 @@ protected: private: TWeakObjectPtr Config = nullptr; - }; //-------------------------------------------------------------------------------------------------------------------------- @@ -39,68 +39,15 @@ class UCogEngineConfig_DebugSettings : public UCogWindowConfig public: UPROPERTY(Config) - bool bIsFilteringBySelection = true; + FCogDebugData Data; UPROPERTY(Config) - bool Persistent = false; - - UPROPERTY(Config) - bool TextShadow = true; - - UPROPERTY(Config) - bool Fade2D = true; - - UPROPERTY(Config) - float Duration = 3.0f; - - UPROPERTY(Config) - int DepthPriority = 0; - - UPROPERTY(Config) - int Segments = 12; - - UPROPERTY(Config) - float Thickness = 0.0f; - - UPROPERTY(Config) - float ServerThickness = 2.0f; - - UPROPERTY(Config) - float ServerColorMultiplier = 0.8f; - - UPROPERTY(Config) - float ArrowSize = 10.0f; - - UPROPERTY(Config) - float AxesScale = 1.0f; - - UPROPERTY(Config) - float GradientColorIntensity = 0.0f; - - UPROPERTY(Config) - float GradientColorSpeed = 2.0f; - - UPROPERTY(Config) - float TextSize = 1.0f; + bool bShowAdvancedSettings = false; virtual void Reset() override { Super::Reset(); - - bIsFilteringBySelection = true; - Persistent = false; - TextShadow = true; - Fade2D = true; - Duration = 3.0f; - DepthPriority = 0; - Segments = 12; - Thickness = 0.0f; - ServerThickness = 2.0f; - ServerColorMultiplier = 0.8f; - ArrowSize = 10.0f; - AxesScale = 1.0f; - GradientColorIntensity = 0.0f; - GradientColorSpeed = 2.0f; - TextSize = 1.0f; + Data = FCogDebugData(); + bShowAdvancedSettings = false; } }; \ No newline at end of file diff --git a/Plugins/Cog/Source/CogImgui/Private/CogImguiWidget.cpp b/Plugins/Cog/Source/CogImgui/Private/CogImguiWidget.cpp index 6d1f499..1e86d03 100644 --- a/Plugins/Cog/Source/CogImgui/Private/CogImguiWidget.cpp +++ b/Plugins/Cog/Source/CogImgui/Private/CogImguiWidget.cpp @@ -124,17 +124,17 @@ FReply SCogImguiWidget::OnKeyChar(const FGeometry& MyGeometry, const FCharacterE //-------------------------------------------------------------------------------------------------------------------------- FReply SCogImguiWidget::OnKeyDown(const FGeometry& MyGeometry, const FKeyEvent& KeyEvent) { - return HandleKeyEvent(MyGeometry, KeyEvent); + return HandleKeyEvent(MyGeometry, KeyEvent, true); } //-------------------------------------------------------------------------------------------------------------------------- FReply SCogImguiWidget::OnKeyUp(const FGeometry& MyGeometry, const FKeyEvent& KeyEvent) { - return HandleKeyEvent(MyGeometry, KeyEvent); + return HandleKeyEvent(MyGeometry, KeyEvent, false); } //-------------------------------------------------------------------------------------------------------------------------- -FReply SCogImguiWidget::HandleKeyEvent(const FGeometry& MyGeometry, const FKeyEvent& KeyEvent) +FReply SCogImguiWidget::HandleKeyEvent(const FGeometry& MyGeometry, const FKeyEvent& KeyEvent, bool Down) { if (Context->GetEnableInput() == false) { @@ -154,8 +154,9 @@ FReply SCogImguiWidget::HandleKeyEvent(const FGeometry& MyGeometry, const FKeyEv { return FReply::Unhandled(); } + ImGuiIO& IO = ImGui::GetIO(); - IO.AddKeyEvent(FCogImguiInputHelper::ToImKey(KeyEvent.GetKey()), false); + IO.AddKeyEvent(FCogImguiInputHelper::ToImKey(KeyEvent.GetKey()), Down); IO.AddKeyEvent(ImGuiMod_Ctrl, KeyEvent.IsControlDown()); IO.AddKeyEvent(ImGuiMod_Shift, KeyEvent.IsShiftDown()); IO.AddKeyEvent(ImGuiMod_Alt, KeyEvent.IsAltDown()); diff --git a/Plugins/Cog/Source/CogImgui/Public/CogImguiWidget.h b/Plugins/Cog/Source/CogImgui/Public/CogImguiWidget.h index 9a361e0..d443ab4 100644 --- a/Plugins/Cog/Source/CogImgui/Public/CogImguiWidget.h +++ b/Plugins/Cog/Source/CogImgui/Public/CogImguiWidget.h @@ -53,7 +53,7 @@ public: protected: - FReply HandleKeyEvent(const FGeometry& MyGeometry, const FKeyEvent& KeyEvent); + FReply HandleKeyEvent(const FGeometry& MyGeometry, const FKeyEvent& KeyEvent, bool Down); void RefreshVisibility(); diff --git a/Plugins/Cog/Source/CogWindow/Private/CogWindowWidgets.cpp b/Plugins/Cog/Source/CogWindow/Private/CogWindowWidgets.cpp index 02f3d4e..4febc36 100644 --- a/Plugins/Cog/Source/CogWindow/Private/CogWindowWidgets.cpp +++ b/Plugins/Cog/Source/CogWindow/Private/CogWindowWidgets.cpp @@ -611,4 +611,25 @@ bool FCogWindowWidgets::MultiChoiceButtonsFloat(TArray& Values, float& Va ImGui::PopStyleVar(3); return IsPressed; +} + +//-------------------------------------------------------------------------------------------------------------------------- +bool FCogWindowWidgets::DragFVector(const char* Label, FVector& Vector, float Speed, float Min, float Max, const char* Format, ImGuiSliderFlags Flags) +{ + return ImGui::DragScalarN(Label, ImGuiDataType_Double, &Vector.X, 3, Speed, &Min, &Max, Format, Flags); +} + +//-------------------------------------------------------------------------------------------------------------------------- +bool FCogWindowWidgets::DragFVector2D(const char* Label, FVector2D& Vector, float Speed, float Min, float Max, const char* Format, ImGuiSliderFlags Flags) +{ + return ImGui::DragScalarN(Label, ImGuiDataType_Double, &Vector.X, 2, Speed, &Min, &Max, Format, Flags); +} + +//-------------------------------------------------------------------------------------------------------------------------- +bool FCogWindowWidgets::ColorEdit4(const char* Label, FColor& Color, ImGuiColorEditFlags Flags) +{ + FLinearColor Linear(Color); + const bool Result = ImGui::ColorEdit4(Label, &Linear.R, Flags); + Color = Linear.ToFColor(true); + return Result; } \ No newline at end of file diff --git a/Plugins/Cog/Source/CogWindow/Public/CogWindowWidgets.h b/Plugins/Cog/Source/CogWindow/Public/CogWindowWidgets.h index 54995e0..dc2a095 100644 --- a/Plugins/Cog/Source/CogWindow/Public/CogWindowWidgets.h +++ b/Plugins/Cog/Source/CogWindow/Public/CogWindowWidgets.h @@ -20,6 +20,12 @@ public: static void EndTableTooltip(); + static bool DragFVector(const char* Label, FVector& Vector, float Speed = 1.0f, float Min = 0.0f, float Max = 0.0f, const char* Format = "%.3f", ImGuiSliderFlags Flags = 0); + + static bool DragFVector2D(const char* Label, FVector2D& Vector, float Speed = 1.0f, float Min = 0.0f, float Max = 0.0f, const char* Format = "%.3f", ImGuiSliderFlags Flags = 0); + + static bool ColorEdit4(const char* Label, FColor& Color, ImGuiColorEditFlags Flags = 0); + static void ProgressBarCentered(float Fraction, const ImVec2& Size, const char* Overlay); static bool ToggleMenuButton(bool* Value, const char* Text, const ImVec4& TrueColor); From 81fc6269ad2c91b444ac8c34d7f60130c9d3fd40 Mon Sep 17 00:00:00 2001 From: Arnaud Jamin Date: Fri, 29 Dec 2023 03:08:15 -0500 Subject: [PATCH 3/8] CogDebug: improving transform gizmos and collision tester (WIP) --- .../Cog/Source/CogCommon/Public/CogCommon.h | 4 +- .../{CogDebugSettings.cpp => CogDebug.cpp} | 80 ++-- .../Source/CogDebug/Private/CogDebugDraw.cpp | 188 ++++---- .../CogDebug/Private/CogDebugDrawHelper.cpp | 52 ++- .../Source/CogDebug/Private/CogDebugGizmo.cpp | 414 +++++++++++++----- .../CogDebug/Private/CogDebugLogBlueprint.cpp | 2 +- .../CogDebug/Private/CogDebugMetric.cpp | 4 +- .../Source/CogDebug/Private/CogDebugPlot.cpp | 2 +- .../CogDebug/Private/CogDebugReplicator.cpp | 4 +- .../Source/CogDebug/Private/CogDebugShape.cpp | 154 +++---- .../Public/{CogDebugSettings.h => CogDebug.h} | 30 +- .../CogDebug/Public/CogDebugDrawHelper.h | 2 + .../Source/CogDebug/Public/CogDebugGizmo.h | 21 +- .../CogEngineWindow_CollisionTester.cpp | 190 +++----- .../CogEngineWindow_CollisionViewer.cpp | 22 +- .../Private/CogEngineWindow_DebugSettings.cpp | 114 +++-- .../Private/CogEngineWindow_LogCategories.cpp | 6 +- .../Private/CogEngineWindow_Plots.cpp | 2 +- .../Private/CogEngineWindow_Selection.cpp | 12 +- .../Private/CogEngineWindow_Skeleton.cpp | 38 +- .../Public/CogEngineWindow_CollisionTester.h | 43 +- .../Public/CogEngineWindow_DebugSettings.h | 6 +- .../CogImgui/Private/CogImguiHelper.cpp | 35 +- .../CogImgui/Private/CogImguiWidget.cpp | 35 +- .../Source/CogImgui/Public/CogImguiHelper.h | 10 + .../Source/CogImgui/Public/CogImguiWidget.h | 4 +- .../Source/CogWindow/Private/CogWindow.cpp | 4 +- .../CogWindow/Private/CogWindowWidgets.cpp | 43 +- .../CogWindow/Public/CogWindowWidgets.h | 9 +- Source/CogSample/CogSampleAreaComponent.cpp | 2 +- Source/CogSample/CogSampleCharacter.cpp | 2 +- .../CogSampleCharacterMovementComponent.cpp | 4 +- Source/CogSample/CogSampleDefines.h | 4 +- Source/CogSample/CogSampleGameplayAbility.cpp | 2 +- 34 files changed, 889 insertions(+), 655 deletions(-) rename Plugins/Cog/Source/CogDebug/Private/{CogDebugSettings.cpp => CogDebug.cpp} (67%) rename Plugins/Cog/Source/CogDebug/Public/{CogDebugSettings.h => CogDebug.h} (86%) diff --git a/Plugins/Cog/Source/CogCommon/Public/CogCommon.h b/Plugins/Cog/Source/CogCommon/Public/CogCommon.h index e1d8b52..2a5eaf7 100644 --- a/Plugins/Cog/Source/CogCommon/Public/CogCommon.h +++ b/Plugins/Cog/Source/CogCommon/Public/CogCommon.h @@ -9,13 +9,13 @@ #if ENABLE_COG -#include "CogDebugSettings.h" +#include "CogDebug.h" #define IF_COG(expr) { expr; } #define COG_LOG_CATEGORY FLogCategoryBase //-------------------------------------------------------------------------------------------------------------------------- -#define COG_LOG_ACTIVE_FOR_OBJECT(Object) (FCogDebugSettings::IsDebugActiveForObject(Object)) +#define COG_LOG_ACTIVE_FOR_OBJECT(Object) (FCogDebug::IsDebugActiveForObject(Object)) //-------------------------------------------------------------------------------------------------------------------------- #define COG_LOG(LogCategory, Verbosity, Format, ...) \ diff --git a/Plugins/Cog/Source/CogDebug/Private/CogDebugSettings.cpp b/Plugins/Cog/Source/CogDebug/Private/CogDebug.cpp similarity index 67% rename from Plugins/Cog/Source/CogDebug/Private/CogDebugSettings.cpp rename to Plugins/Cog/Source/CogDebug/Private/CogDebug.cpp index 8e61ae8..08ce726 100644 --- a/Plugins/Cog/Source/CogDebug/Private/CogDebugSettings.cpp +++ b/Plugins/Cog/Source/CogDebug/Private/CogDebug.cpp @@ -1,4 +1,4 @@ -#include "CogDebugSettings.h" +#include "CogDebug.h" #include "CogCommonDebugFilteredActorInterface.h" #include "CogDebugReplicator.h" @@ -6,17 +6,17 @@ #include "Engine/Engine.h" //-------------------------------------------------------------------------------------------------------------------------- -TWeakObjectPtr FCogDebugSettings::Selection; -FCogDebugData FCogDebugSettings::Data = FCogDebugData(); +TWeakObjectPtr FCogDebug::Selection; +FCogDebugSettings FCogDebug::Settings = FCogDebugSettings(); //-------------------------------------------------------------------------------------------------------------------------- -void FCogDebugSettings::Reset() +void FCogDebug::Reset() { - Data = FCogDebugData(); + Settings = FCogDebugSettings(); } //-------------------------------------------------------------------------------------------------------------------------- -bool FCogDebugSettings::IsDebugActiveForObject(const UObject* WorldContextObject) +bool FCogDebug::IsDebugActiveForObject(const UObject* WorldContextObject) { UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::LogAndReturnNull); if (World == nullptr) @@ -29,19 +29,19 @@ bool FCogDebugSettings::IsDebugActiveForObject(const UObject* WorldContextObject return true; } - bool Result = IsDebugActiveForObject_Internal(WorldContextObject, Selection.Get(), Data.bIsFilteringBySelection); + bool Result = IsDebugActiveForObject_Internal(WorldContextObject, Selection.Get(), Settings.bIsFilteringBySelection); return Result; } //-------------------------------------------------------------------------------------------------------------------------- -bool FCogDebugSettings::IsReplicatedDebugActiveForObject(const UObject* WorldContextObject, const AActor* ServerSelection, bool IsServerFilteringBySelection) +bool FCogDebug::IsReplicatedDebugActiveForObject(const UObject* WorldContextObject, const AActor* ServerSelection, bool IsServerFilteringBySelection) { return IsDebugActiveForObject_Internal(WorldContextObject, ServerSelection, IsServerFilteringBySelection); } //-------------------------------------------------------------------------------------------------------------------------- -bool FCogDebugSettings::IsDebugActiveForObject_Internal(const UObject* WorldContextObject, const AActor* InSelection, bool InIsFilteringBySelection) +bool FCogDebug::IsDebugActiveForObject_Internal(const UObject* WorldContextObject, const AActor* InSelection, bool InIsFilteringBySelection) { if (InIsFilteringBySelection == false) { @@ -85,13 +85,13 @@ bool FCogDebugSettings::IsDebugActiveForObject_Internal(const UObject* WorldCont } //-------------------------------------------------------------------------------------------------------------------------- -AActor* FCogDebugSettings::GetSelection() +AActor* FCogDebug::GetSelection() { return Selection.Get(); } //-------------------------------------------------------------------------------------------------------------------------- -void FCogDebugSettings::SetSelection(UWorld* World, AActor* Value) +void FCogDebug::SetSelection(UWorld* World, AActor* Value) { Selection = Value; @@ -105,15 +105,15 @@ void FCogDebugSettings::SetSelection(UWorld* World, AActor* Value) } //-------------------------------------------------------------------------------------------------------------------------- -bool FCogDebugSettings::GetIsFilteringBySelection() +bool FCogDebug::GetIsFilteringBySelection() { - return Data.bIsFilteringBySelection; + return Settings.bIsFilteringBySelection; } //-------------------------------------------------------------------------------------------------------------------------- -void FCogDebugSettings::SetIsFilteringBySelection(UWorld* World, bool Value) +void FCogDebug::SetIsFilteringBySelection(UWorld* World, bool Value) { - Data.bIsFilteringBySelection = Value; + Settings.bIsFilteringBySelection = Value; if (World != nullptr && World->GetNetMode() == NM_Client) { @@ -125,23 +125,23 @@ void FCogDebugSettings::SetIsFilteringBySelection(UWorld* World, bool Value) } //-------------------------------------------------------------------------------------------------------------------------- -bool FCogDebugSettings::GetDebugPersistent(bool bPersistent) +bool FCogDebug::GetDebugPersistent(bool bPersistent) { - return Data.Persistent && bPersistent; + return Settings.Persistent && bPersistent; } //-------------------------------------------------------------------------------------------------------------------------- -float FCogDebugSettings::GetDebugDuration(bool bPersistent) +float FCogDebug::GetDebugDuration(bool bPersistent) { - return bPersistent == false ? 0.0f : Data.Duration; + return bPersistent == false ? 0.0f : Settings.Duration; } //-------------------------------------------------------------------------------------------------------------------------- -float FCogDebugSettings::GetDebugTextDuration(bool bPersistent) +float FCogDebug::GetDebugTextDuration(bool bPersistent) { if (bPersistent) { - return Data.Persistent ? 100 : Data.Duration; + return Settings.Persistent ? 100 : Settings.Duration; } else { @@ -150,37 +150,37 @@ float FCogDebugSettings::GetDebugTextDuration(bool bPersistent) } //-------------------------------------------------------------------------------------------------------------------------- -int FCogDebugSettings::GetDebugSegments() +int FCogDebug::GetDebugSegments() { - return Data.Segments; + return Settings.Segments; } //-------------------------------------------------------------------------------------------------------------------------- -int FCogDebugSettings::GetCircleSegments() +int FCogDebug::GetCircleSegments() { - return (Data.Segments * 2) + 2; // because DrawDebugCircle does Segments = FMath::Max((Segments - 2) / 2, 4) for some reason + return (Settings.Segments * 2) + 2; // because DrawDebugCircle does Segments = FMath::Max((Segments - 2) / 2, 4) for some reason } //-------------------------------------------------------------------------------------------------------------------------- -float FCogDebugSettings::GetDebugThickness(float InThickness) +float FCogDebug::GetDebugThickness(float InThickness) { - return (Data.Thickness + InThickness); + return (Settings.Thickness + InThickness); } //-------------------------------------------------------------------------------------------------------------------------- -float FCogDebugSettings::GetDebugServerThickness(float InThickness) +float FCogDebug::GetDebugServerThickness(float InThickness) { - return (Data.ServerThickness + InThickness); + return (Settings.ServerThickness + InThickness); } //-------------------------------------------------------------------------------------------------------------------------- -uint8 FCogDebugSettings::GetDebugDepthPriority(float InDepthPriority) +uint8 FCogDebug::GetDebugDepthPriority(float InDepthPriority) { - return (Data.DepthPriority + InDepthPriority); + return (Settings.DepthPriority + InDepthPriority); } //-------------------------------------------------------------------------------------------------------------------------- -FColor FCogDebugSettings::ModulateDebugColor(const UWorld* World, const FColor& Color, bool bPersistent) +FColor FCogDebug::ModulateDebugColor(const UWorld* World, const FColor& Color, bool bPersistent) { if (bPersistent == false) { @@ -199,30 +199,30 @@ FColor FCogDebugSettings::ModulateDebugColor(const UWorld* World, const FColor& ComplementaryColor = ComplementaryColor.HSVToLinearRGB(); - const FLinearColor GradientColor = FLinearColor::LerpUsingHSV(FLinearColor(Color), ComplementaryColor, FMath::Cos(Data.GradientColorSpeed * Time)); - const FLinearColor FBlendColor = BaseColor * (1.0f - Data.GradientColorIntensity) + GradientColor * Data.GradientColorIntensity; + const FLinearColor GradientColor = FLinearColor::LerpUsingHSV(FLinearColor(Color), ComplementaryColor, FMath::Cos(Settings.GradientColorSpeed * Time)); + const FLinearColor FBlendColor = BaseColor * (1.0f - Settings.GradientColorIntensity) + GradientColor * Settings.GradientColorIntensity; return FBlendColor.ToFColor(true); } //-------------------------------------------------------------------------------------------------------------------------- -FColor FCogDebugSettings::ModulateServerColor(const FColor& Color) +FColor FCogDebug::ModulateServerColor(const FColor& Color) { FColor ServerColor( - Color.R * Data.ServerColorMultiplier, - Color.G * Data.ServerColorMultiplier, - Color.B * Data.ServerColorMultiplier, + Color.R * Settings.ServerColorMultiplier, + Color.G * Settings.ServerColorMultiplier, + Color.B * Settings.ServerColorMultiplier, Color.A); return ServerColor; } //-------------------------------------------------------------------------------------------------------------------------- -bool FCogDebugSettings::IsSecondarySkeletonBone(FName BoneName) +bool FCogDebug::IsSecondarySkeletonBone(FName BoneName) { FString BoneString = BoneName.ToString().ToLower(); - for (const FString& Wildcard : Data.SecondaryBoneWildcards) + for (const FString& Wildcard : Settings.SecondaryBoneWildcards) { if (BoneString.MatchesWildcard(Wildcard)) { diff --git a/Plugins/Cog/Source/CogDebug/Private/CogDebugDraw.cpp b/Plugins/Cog/Source/CogDebug/Private/CogDebugDraw.cpp index b0f54cd..58d1496 100644 --- a/Plugins/Cog/Source/CogDebug/Private/CogDebugDraw.cpp +++ b/Plugins/Cog/Source/CogDebug/Private/CogDebugDraw.cpp @@ -6,7 +6,7 @@ #include "CogDebugLog.h" #include "CogDebugModule.h" #include "CogDebugReplicator.h" -#include "CogDebugSettings.h" +#include "CogDebug.h" #include "CogDebugShape.h" #include "CogImguiHelper.h" #include "Engine/Engine.h" @@ -32,8 +32,8 @@ void FCogDebugDraw::String2D(const FLogCategoryBase& LogCategory, const UObject* Text, FCogImguiHelper::ToImU32(Color), true, - FCogDebugSettings::GetDebugDuration(Persistent), - FCogDebugSettings::Data.Fade2D); + FCogDebug::GetDebugDuration(Persistent), + FCogDebug::Settings.Fade2D); } //-------------------------------------------------------------------------------------------------------------------------- @@ -48,9 +48,9 @@ void FCogDebugDraw::Segment2D(const FLogCategoryBase& LogCategory, const UObject FCogImguiHelper::ToImVec2(SegmentStart), FCogImguiHelper::ToImVec2(SegmentEnd), FCogImguiHelper::ToImU32(Color), - FCogDebugSettings::GetDebugThickness(0), - FCogDebugSettings::GetDebugDuration(Persistent), - FCogDebugSettings::Data.Fade2D); + FCogDebug::GetDebugThickness(0), + FCogDebug::GetDebugDuration(Persistent), + FCogDebug::Settings.Fade2D); } //-------------------------------------------------------------------------------------------------------------------------- @@ -65,10 +65,10 @@ void FCogDebugDraw::Circle2D(const FLogCategoryBase& LogCategory, const UObject* FCogImguiHelper::ToImVec2(Location), Radius, FCogImguiHelper::ToImU32(Color), - FCogDebugSettings::GetDebugSegments(), - FCogDebugSettings::GetDebugThickness(0), - FCogDebugSettings::GetDebugDuration(Persistent), - FCogDebugSettings::Data.Fade2D); + FCogDebug::GetDebugSegments(), + FCogDebug::GetDebugThickness(0), + FCogDebug::GetDebugDuration(Persistent), + FCogDebug::Settings.Fade2D); } //-------------------------------------------------------------------------------------------------------------------------- @@ -85,9 +85,9 @@ void FCogDebugDraw::Rect2D(const FLogCategoryBase& LogCategory, const UObject* W FCogImguiHelper::ToImVec2(Max), FCogImguiHelper::ToImU32(Color), 0.0f, - FCogDebugSettings::GetDebugThickness(0), - FCogDebugSettings::GetDebugDuration(Persistent), - FCogDebugSettings::Data.Fade2D); + FCogDebug::GetDebugThickness(0), + FCogDebug::GetDebugDuration(Persistent), + FCogDebug::Settings.Fade2D); } //-------------------------------------------------------------------------------------------------------------------------- @@ -104,7 +104,7 @@ void FCogDebugDraw::String(const FLogCategoryBase& LogCategory, const UObject* W return; } - const FColor NewColor = FCogDebugSettings::ModulateDebugColor(World, Color, Persistent); + const FColor NewColor = FCogDebug::ModulateDebugColor(World, Color, Persistent); UE_VLOG_LOCATION(WorldContextObject, LogCategory, Verbose, Location, 10.0f, NewColor, TEXT("%s"), *Text); ::DrawDebugString( @@ -113,9 +113,9 @@ void FCogDebugDraw::String(const FLogCategoryBase& LogCategory, const UObject* W *Text, nullptr, NewColor, - FCogDebugSettings::GetDebugTextDuration(Persistent), - FCogDebugSettings::Data.TextShadow, - FCogDebugSettings::Data.TextSize); + FCogDebug::GetDebugTextDuration(Persistent), + FCogDebug::Settings.TextShadow, + FCogDebug::Settings.TextSize); } //-------------------------------------------------------------------------------------------------------------------------- @@ -132,17 +132,17 @@ void FCogDebugDraw::Point(const FLogCategoryBase& LogCategory, const UObject* Wo return; } - const FColor NewColor = FCogDebugSettings::ModulateDebugColor(World, Color, Persistent); + const FColor NewColor = FCogDebug::ModulateDebugColor(World, Color, Persistent); ::DrawDebugPoint( World, Location, Size, NewColor, - FCogDebugSettings::GetDebugPersistent(Persistent), - FCogDebugSettings::GetDebugDuration(Persistent), - FCogDebugSettings::GetDebugDepthPriority(DepthPriority)); + FCogDebug::GetDebugPersistent(Persistent), + FCogDebug::GetDebugDuration(Persistent), + FCogDebug::GetDebugDepthPriority(DepthPriority)); - ReplicateShape(WorldContextObject, FCogDebugShape::MakePoint(Location, Size, NewColor, Persistent, FCogDebugSettings::Data.DepthPriority)); + ReplicateShape(WorldContextObject, FCogDebugShape::MakePoint(Location, Size, NewColor, Persistent, FCogDebug::Settings.DepthPriority)); } //-------------------------------------------------------------------------------------------------------------------------- @@ -159,7 +159,7 @@ void FCogDebugDraw::Segment(const FLogCategoryBase& LogCategory, const UObject* return; } - const FColor NewColor = FCogDebugSettings::ModulateDebugColor(World, Color, Persistent); + const FColor NewColor = FCogDebug::ModulateDebugColor(World, Color, Persistent); UE_VLOG_SEGMENT(WorldContextObject, LogCategory, Verbose, SegmentStart, SegmentEnd, NewColor, TEXT_EMPTY); ::DrawDebugLine( @@ -167,10 +167,10 @@ void FCogDebugDraw::Segment(const FLogCategoryBase& LogCategory, const UObject* SegmentStart, SegmentEnd, NewColor, - FCogDebugSettings::GetDebugPersistent(Persistent), - FCogDebugSettings::GetDebugDuration(Persistent), - FCogDebugSettings::GetDebugDepthPriority(DepthPriority), - FCogDebugSettings::GetDebugThickness(0)); + FCogDebug::GetDebugPersistent(Persistent), + FCogDebug::GetDebugDuration(Persistent), + FCogDebug::GetDebugDepthPriority(DepthPriority), + FCogDebug::GetDebugThickness(0)); ReplicateShape(WorldContextObject, FCogDebugShape::MakeSegment(SegmentStart, SegmentEnd, NewColor, 0.0f, Persistent, DepthPriority)); } @@ -189,7 +189,7 @@ void FCogDebugDraw::Bone(const FLogCategoryBase& LogCategory, const UObject* Wor return; } - const FColor NewColor = FCogDebugSettings::ModulateDebugColor(World, Color, Persistent); + const FColor NewColor = FCogDebug::ModulateDebugColor(World, Color, Persistent); UE_VLOG_SEGMENT(WorldContextObject, LogCategory, Verbose, BoneLocation, ParentLocation, NewColor, TEXT_EMPTY); ::DrawDebugLine( @@ -197,19 +197,19 @@ void FCogDebugDraw::Bone(const FLogCategoryBase& LogCategory, const UObject* Wor BoneLocation, ParentLocation, NewColor, - FCogDebugSettings::GetDebugPersistent(Persistent), - FCogDebugSettings::GetDebugDuration(Persistent), - FCogDebugSettings::GetDebugDepthPriority(DepthPriority), - FCogDebugSettings::GetDebugThickness(0)); + FCogDebug::GetDebugPersistent(Persistent), + FCogDebug::GetDebugDuration(Persistent), + FCogDebug::GetDebugDepthPriority(DepthPriority), + FCogDebug::GetDebugThickness(0)); ::DrawDebugPoint( World, BoneLocation, - FCogDebugSettings::GetDebugThickness(4.0f), + FCogDebug::GetDebugThickness(4.0f), NewColor, - FCogDebugSettings::GetDebugPersistent(Persistent), - FCogDebugSettings::GetDebugDuration(Persistent), - FCogDebugSettings::GetDebugDepthPriority(DepthPriority)); + FCogDebug::GetDebugPersistent(Persistent), + FCogDebug::GetDebugDuration(Persistent), + FCogDebug::GetDebugDepthPriority(DepthPriority)); ReplicateShape(WorldContextObject, FCogDebugShape::MakeBone(BoneLocation, ParentLocation, NewColor, 0.0f, Persistent, DepthPriority)); } @@ -228,21 +228,21 @@ void FCogDebugDraw::Arrow(const FLogCategoryBase& LogCategory, const UObject* Wo return; } - const FColor NewColor = FCogDebugSettings::ModulateDebugColor(World, Color, Persistent); + const FColor NewColor = FCogDebug::ModulateDebugColor(World, Color, Persistent); UE_VLOG_ARROW(WorldContextObject, LogCategory, Verbose, SegmentStart, SegmentEnd, NewColor, TEXT_EMPTY); ::DrawDebugDirectionalArrow( World, SegmentStart, SegmentEnd, - FCogDebugSettings::Data.ArrowSize, + FCogDebug::Settings.ArrowSize, NewColor, - FCogDebugSettings::GetDebugPersistent(Persistent), - FCogDebugSettings::GetDebugDuration(Persistent), - FCogDebugSettings::GetDebugDepthPriority(DepthPriority), - FCogDebugSettings::GetDebugThickness(0)); + FCogDebug::GetDebugPersistent(Persistent), + FCogDebug::GetDebugDuration(Persistent), + FCogDebug::GetDebugDepthPriority(DepthPriority), + FCogDebug::GetDebugThickness(0)); - ReplicateShape(WorldContextObject, FCogDebugShape::MakeArrow(SegmentStart, SegmentEnd, FCogDebugSettings::Data.ArrowSize, NewColor, 0.0f, Persistent, DepthPriority)); + ReplicateShape(WorldContextObject, FCogDebugShape::MakeArrow(SegmentStart, SegmentEnd, FCogDebug::Settings.ArrowSize, NewColor, 0.0f, Persistent, DepthPriority)); } //-------------------------------------------------------------------------------------------------------------------------- @@ -268,13 +268,13 @@ void FCogDebugDraw::Axis(const FLogCategoryBase& LogCategory, const UObject* Wor World, AxisLoc, AxisRot, - Scale * FCogDebugSettings::Data.AxesScale, - FCogDebugSettings::GetDebugPersistent(Persistent), - FCogDebugSettings::GetDebugDuration(Persistent), - FCogDebugSettings::GetDebugDepthPriority(DepthPriority), - FCogDebugSettings::GetDebugThickness(0)); + Scale * FCogDebug::Settings.AxesScale, + FCogDebug::GetDebugPersistent(Persistent), + FCogDebug::GetDebugDuration(Persistent), + FCogDebug::GetDebugDepthPriority(DepthPriority), + FCogDebug::GetDebugThickness(0)); - ReplicateShape(WorldContextObject, FCogDebugShape::MakeAxes(AxisLoc, AxisRot, FCogDebugSettings::Data.ArrowSize, FColor::Red, 0.0f, Persistent, DepthPriority)); + ReplicateShape(WorldContextObject, FCogDebugShape::MakeAxes(AxisLoc, AxisRot, FCogDebug::Settings.ArrowSize, FColor::Red, 0.0f, Persistent, DepthPriority)); } //-------------------------------------------------------------------------------------------------------------------------- @@ -291,7 +291,7 @@ void FCogDebugDraw::Circle(const FLogCategoryBase& LogCategory, const UObject* W return; } - const FColor NewColor = FCogDebugSettings::ModulateDebugColor(World, Color, Persistent); + const FColor NewColor = FCogDebug::ModulateDebugColor(World, Color, Persistent); const FVector Center = Matrix.GetOrigin(); const FVector UpVector = Matrix.GetUnitAxis(EAxis::X); UE_VLOG_CIRCLE(WorldContextObject, LogCategory, Verbose, Center, UpVector, Radius, NewColor, TEXT_EMPTY); @@ -300,12 +300,12 @@ void FCogDebugDraw::Circle(const FLogCategoryBase& LogCategory, const UObject* W World, Matrix, Radius, - FCogDebugSettings::GetCircleSegments(), + FCogDebug::GetCircleSegments(), NewColor, - FCogDebugSettings::GetDebugPersistent(Persistent), - FCogDebugSettings::GetDebugDuration(Persistent), - FCogDebugSettings::GetDebugDepthPriority(DepthPriority), - FCogDebugSettings::GetDebugThickness(0), + FCogDebug::GetDebugPersistent(Persistent), + FCogDebug::GetDebugDuration(Persistent), + FCogDebug::GetDebugDepthPriority(DepthPriority), + FCogDebug::GetDebugThickness(0), false); ReplicateShape(WorldContextObject, FCogDebugShape::MakeCircle(Center, Matrix.Rotator(), Radius, NewColor, 0.0f, Persistent, DepthPriority)); @@ -325,7 +325,7 @@ void FCogDebugDraw::CircleArc(const FLogCategoryBase& LogCategory, const UObject return; } - const FColor NewColor = FCogDebugSettings::ModulateDebugColor(World, Color, Persistent); + const FColor NewColor = FCogDebug::ModulateDebugColor(World, Color, Persistent); //TODO : Add VLOG @@ -335,12 +335,12 @@ void FCogDebugDraw::CircleArc(const FLogCategoryBase& LogCategory, const UObject InnerRadius, OuterRadius, Angle, - FCogDebugSettings::GetCircleSegments(), + FCogDebug::GetCircleSegments(), NewColor, - FCogDebugSettings::GetDebugPersistent(Persistent), - FCogDebugSettings::GetDebugDuration(Persistent), - FCogDebugSettings::GetDebugDepthPriority(DepthPriority), - FCogDebugSettings::GetDebugThickness(0)); + FCogDebug::GetDebugPersistent(Persistent), + FCogDebug::GetDebugDuration(Persistent), + FCogDebug::GetDebugDepthPriority(DepthPriority), + FCogDebug::GetDebugThickness(0)); ReplicateShape(WorldContextObject, FCogDebugShape::MakeCircleArc(Matrix.GetOrigin(), Matrix.Rotator(), InnerRadius, OuterRadius, Angle, NewColor, 0.0f, Persistent, DepthPriority)); } @@ -359,7 +359,7 @@ void FCogDebugDraw::FlatCapsule(const FLogCategoryBase& LogCategory, const UObje return; } - const FColor NewColor = FCogDebugSettings::ModulateDebugColor(World, Color, Persistent); + const FColor NewColor = FCogDebug::ModulateDebugColor(World, Color, Persistent); // TODO : Add VLOG FCogDebugDrawHelper::DrawFlatCapsule( @@ -368,12 +368,12 @@ void FCogDebugDraw::FlatCapsule(const FLogCategoryBase& LogCategory, const UObje End, Radius, Z, - FCogDebugSettings::GetCircleSegments(), + FCogDebug::GetCircleSegments(), NewColor, - FCogDebugSettings::GetDebugPersistent(Persistent), - FCogDebugSettings::GetDebugDuration(Persistent), - FCogDebugSettings::GetDebugDepthPriority(DepthPriority), - FCogDebugSettings::GetDebugThickness(0)); + FCogDebug::GetDebugPersistent(Persistent), + FCogDebug::GetDebugDuration(Persistent), + FCogDebug::GetDebugDepthPriority(DepthPriority), + FCogDebug::GetDebugThickness(0)); ReplicateShape(WorldContextObject, FCogDebugShape::MakeFlatCapsule(Start, End, Radius, Z, NewColor, 0.0f, Persistent, DepthPriority)); } @@ -392,19 +392,19 @@ void FCogDebugDraw::Sphere(const FLogCategoryBase& LogCategory, const UObject* W return; } - const FColor NewColor = FCogDebugSettings::ModulateDebugColor(World, Color, Persistent); + const FColor NewColor = FCogDebug::ModulateDebugColor(World, Color, Persistent); UE_VLOG_CAPSULE(WorldContextObject, LogCategory, Verbose, Location, 0.0f, Radius, FQuat::Identity, NewColor, TEXT_EMPTY); FCogDebugDrawHelper::DrawSphere( World, Location, Radius, - FCogDebugSettings::GetDebugSegments(), + FCogDebug::GetDebugSegments(), NewColor, - FCogDebugSettings::GetDebugPersistent(Persistent), - FCogDebugSettings::GetDebugDuration(Persistent), - FCogDebugSettings::GetDebugDepthPriority(DepthPriority), - FCogDebugSettings::GetDebugThickness(0)); + FCogDebug::GetDebugPersistent(Persistent), + FCogDebug::GetDebugDuration(Persistent), + FCogDebug::GetDebugDepthPriority(DepthPriority), + FCogDebug::GetDebugThickness(0)); ReplicateShape(WorldContextObject, FCogDebugShape::MakeCapsule(Location, FQuat::Identity, Radius, 0.0f, NewColor, 0.0f, Persistent, DepthPriority)); } @@ -423,7 +423,7 @@ void FCogDebugDraw::Box(const FLogCategoryBase& LogCategory, const UObject* Worl return; } - const FColor NewColor = FCogDebugSettings::ModulateDebugColor(World, Color, Persistent); + const FColor NewColor = FCogDebug::ModulateDebugColor(World, Color, Persistent); UE_VLOG_OBOX(WorldContextObject, LogCategory, Verbose, FBox(-Extent, Extent), FQuatRotationTranslationMatrix::Make(Rotation, Center), NewColor, TEXT_EMPTY); ::DrawDebugBox( @@ -432,10 +432,10 @@ void FCogDebugDraw::Box(const FLogCategoryBase& LogCategory, const UObject* Worl Extent, Rotation, NewColor, - FCogDebugSettings::GetDebugPersistent(Persistent), - FCogDebugSettings::GetDebugDuration(Persistent), - FCogDebugSettings::GetDebugDepthPriority(DepthPriority), - FCogDebugSettings::GetDebugThickness(0)); + FCogDebug::GetDebugPersistent(Persistent), + FCogDebug::GetDebugDuration(Persistent), + FCogDebug::GetDebugDepthPriority(DepthPriority), + FCogDebug::GetDebugThickness(0)); ReplicateShape(WorldContextObject, FCogDebugShape::MakeBox(Center, FRotator(Rotation), Extent, NewColor, 0.0f, Persistent, DepthPriority)); } @@ -454,7 +454,7 @@ void FCogDebugDraw::SolidBox(const FLogCategoryBase& LogCategory, const UObject* return; } - const FColor NewColor = FCogDebugSettings::ModulateDebugColor(World, Color, Persistent); + const FColor NewColor = FCogDebug::ModulateDebugColor(World, Color, Persistent); UE_VLOG_OBOX(WorldContextObject, LogCategory, Verbose, FBox(-Extent, Extent), FQuatRotationTranslationMatrix::Make(Rotation, Center), NewColor, TEXT_EMPTY); // If we make the Box Thick enough, it will be displayed as a filled box. @@ -467,9 +467,9 @@ void FCogDebugDraw::SolidBox(const FLogCategoryBase& LogCategory, const UObject* Extent, Rotation, NewColor, - FCogDebugSettings::GetDebugPersistent(Persistent), - FCogDebugSettings::GetDebugDuration(Persistent), - FCogDebugSettings::GetDebugDepthPriority(DepthPriority), + FCogDebug::GetDebugPersistent(Persistent), + FCogDebug::GetDebugDuration(Persistent), + FCogDebug::GetDebugDepthPriority(DepthPriority), NeededThickness); ReplicateShape(WorldContextObject, FCogDebugShape::MakeSolidBox(Center, FRotator(Rotation), Extent, NewColor, Persistent, DepthPriority)); @@ -489,7 +489,7 @@ void FCogDebugDraw::Frustrum(const FLogCategoryBase& LogCategory, const UObject* return; } - const FColor NewColor = FCogDebugSettings::ModulateDebugColor(World, Color, Persistent); + const FColor NewColor = FCogDebug::ModulateDebugColor(World, Color, Persistent); FCogDebugDrawHelper::DrawFrustum( World, @@ -499,10 +499,10 @@ void FCogDebugDraw::Frustrum(const FLogCategoryBase& LogCategory, const UObject* NearPlane, FarPlane, NewColor, - FCogDebugSettings::GetDebugPersistent(Persistent), - FCogDebugSettings::GetDebugDuration(Persistent), - FCogDebugSettings::GetDebugDepthPriority(DepthPriority), - FCogDebugSettings::GetDebugThickness(0)); + FCogDebug::GetDebugPersistent(Persistent), + FCogDebug::GetDebugDuration(Persistent), + FCogDebug::GetDebugDepthPriority(DepthPriority), + FCogDebug::GetDebugThickness(0)); // TODO: Replicate Shape } @@ -521,7 +521,7 @@ void FCogDebugDraw::Capsule(const FLogCategoryBase& LogCategory, const UObject* return; } - const FColor NewColor = FCogDebugSettings::ModulateDebugColor(World, Color, Persistent); + const FColor NewColor = FCogDebug::ModulateDebugColor(World, Color, Persistent); UE_VLOG_CAPSULE(WorldContextObject, LogCategory, Verbose, Center, HalfHeight, Radius, FQuat::Identity, NewColor, TEXT_EMPTY); DrawDebugCapsule( @@ -531,10 +531,10 @@ void FCogDebugDraw::Capsule(const FLogCategoryBase& LogCategory, const UObject* Radius, Rotation, NewColor, - FCogDebugSettings::GetDebugPersistent(Persistent), - FCogDebugSettings::GetDebugDuration(Persistent), - FCogDebugSettings::GetDebugDepthPriority(DepthPriority), - FCogDebugSettings::GetDebugThickness(0)); + FCogDebug::GetDebugPersistent(Persistent), + FCogDebug::GetDebugDuration(Persistent), + FCogDebug::GetDebugDepthPriority(DepthPriority), + FCogDebug::GetDebugThickness(0)); ReplicateShape(WorldContextObject, FCogDebugShape::MakeCapsule(Center, Rotation, Radius, HalfHeight, NewColor, 0.0f, Persistent, DepthPriority)); } @@ -615,7 +615,7 @@ void FCogDebugDraw::Skeleton(const FLogCategoryBase& LogCategory, const USkeleta if (DrawSecondaryBones == false) { FName BoneName = ReferenceSkeleton.GetBoneName(BoneIndex); - if (FCogDebugSettings::IsSecondarySkeletonBone(BoneName)) + if (FCogDebug::IsSecondarySkeletonBone(BoneName)) { continue; } @@ -666,7 +666,7 @@ void FCogDebugDraw::ReplicateShape(const UObject* WorldContextObject, const FCog continue; } - if (FCogDebugSettings::IsReplicatedDebugActiveForObject(WorldContextObject, Replicator->GetServerSelection(), Replicator->IsServerFilteringBySelection()) == false) + if (FCogDebug::IsReplicatedDebugActiveForObject(WorldContextObject, Replicator->GetServerSelection(), Replicator->IsServerFilteringBySelection()) == false) { continue; } diff --git a/Plugins/Cog/Source/CogDebug/Private/CogDebugDrawHelper.cpp b/Plugins/Cog/Source/CogDebug/Private/CogDebugDrawHelper.cpp index f8c1125..125b5cc 100644 --- a/Plugins/Cog/Source/CogDebug/Private/CogDebugDrawHelper.cpp +++ b/Plugins/Cog/Source/CogDebug/Private/CogDebugDrawHelper.cpp @@ -26,7 +26,8 @@ void FCogDebugDrawHelper::DrawArc( const FMatrix& Matrix, float InnerRadius, float OuterRadius, - float Angle, + float AngleStart, + float AngleEnd, int32 Segments, const FColor& Color, bool bPersistentLines, @@ -46,54 +47,52 @@ void FCogDebugDrawHelper::DrawArc( } const float LineLifeTime = GetLineLifeTime(LineBatcher, LifeTime, bPersistentLines); - - const float AngleRad = FMath::DegreesToRadians(Angle); + const float AngleStartRad = FMath::DegreesToRadians(AngleStart); + const float AngleEndRad = FMath::DegreesToRadians(AngleEnd); const FVector Center = Matrix.GetOrigin(); - const FVector Direction = Matrix.GetUnitAxis(EAxis::Z); // Need at least 4 segments Segments = FMath::Max(Segments, 4); - FVector AxisY, AxisZ; - FVector DirectionNorm = Direction.GetSafeNormal(); - DirectionNorm.FindBestAxisVectors(AxisZ, AxisY); + const FVector AxisY = Matrix.GetScaledAxis(EAxis::Y); + const FVector AxisZ = Matrix.GetScaledAxis(EAxis::Z); TArray Lines; Lines.Empty(Segments * 2 + 2); if (InnerRadius != OuterRadius) { - FVector P0 = Center + InnerRadius * (AxisY * -FMath::Sin(-AngleRad) + DirectionNorm * FMath::Cos(-AngleRad)); - FVector P1 = Center + OuterRadius * (AxisY * -FMath::Sin(-AngleRad) + DirectionNorm * FMath::Cos(-AngleRad)); + const FVector P0 = Center + InnerRadius * (AxisZ * FMath::Sin(AngleStartRad) + AxisY * FMath::Cos(AngleStartRad)); + const FVector P1 = Center + OuterRadius * (AxisZ * FMath::Sin(AngleStartRad) + AxisY * FMath::Cos(AngleStartRad)); Lines.Emplace(FBatchedLine(P0, P1, Color, LineLifeTime, Thickness, DepthPriority)); - FVector P2 = Center + InnerRadius * (AxisY * -FMath::Sin(AngleRad) + DirectionNorm * FMath::Cos(AngleRad)); - FVector P3 = Center + OuterRadius * (AxisY * -FMath::Sin(AngleRad) + DirectionNorm * FMath::Cos(AngleRad)); + const FVector P2 = Center + InnerRadius * (AxisZ * FMath::Sin(AngleEndRad) + AxisY * FMath::Cos(AngleEndRad)); + const FVector P3 = Center + OuterRadius * (AxisZ * FMath::Sin(AngleEndRad) + AxisY * FMath::Cos(AngleEndRad)); Lines.Emplace(FBatchedLine(P2, P3, Color, LineLifeTime, Thickness, DepthPriority)); } - float CurrentAngle = -AngleRad; - const float AngleStep = AngleRad / float(Segments) * 2.f; - FVector PrevVertex = Center + OuterRadius * (AxisY * -FMath::Sin(CurrentAngle) + DirectionNorm * FMath::Cos(CurrentAngle)); + float CurrentAngle = AngleStartRad; + const float AngleStep = (AngleEndRad - AngleStartRad) / float(Segments); + FVector PrevVertex = Center + OuterRadius * (AxisZ * FMath::Sin(CurrentAngle) + AxisY * FMath::Cos(CurrentAngle)); int32 Count = Segments; while (Count--) { CurrentAngle += AngleStep; - FVector NextVertex = Center + OuterRadius * (AxisY * -FMath::Sin(CurrentAngle) + DirectionNorm * FMath::Cos(CurrentAngle)); + const FVector NextVertex = Center + OuterRadius * (AxisZ * FMath::Sin(CurrentAngle) + AxisY * FMath::Cos(CurrentAngle)); Lines.Emplace(FBatchedLine(PrevVertex, NextVertex, Color, LineLifeTime, Thickness, DepthPriority)); PrevVertex = NextVertex; } if (InnerRadius != 0.0f) { - CurrentAngle = -AngleRad; - PrevVertex = Center + InnerRadius * (AxisY * -FMath::Sin(CurrentAngle) + DirectionNorm * FMath::Cos(CurrentAngle)); + CurrentAngle = AngleStartRad; + PrevVertex = Center + InnerRadius * (AxisZ * FMath::Sin(CurrentAngle) + AxisY * FMath::Cos(CurrentAngle)); Count = Segments; while (Segments--) { CurrentAngle += AngleStep; - FVector NextVertex = Center + InnerRadius * (AxisY * -FMath::Sin(CurrentAngle) + DirectionNorm * FMath::Cos(CurrentAngle)); + const FVector NextVertex = Center + InnerRadius * (AxisZ * FMath::Sin(CurrentAngle) + AxisY * FMath::Cos(CurrentAngle)); Lines.Emplace(FBatchedLine(PrevVertex, NextVertex, Color, LineLifeTime, Thickness, DepthPriority)); PrevVertex = NextVertex; } @@ -102,6 +101,23 @@ void FCogDebugDrawHelper::DrawArc( LineBatcher->DrawLines(Lines); } +//-------------------------------------------------------------------------------------------------------------------------- +void FCogDebugDrawHelper::DrawArc( + const UWorld* InWorld, + const FMatrix& Matrix, + float InnerRadius, + float OuterRadius, + float Angle, + int32 Segments, + const FColor& Color, + bool bPersistentLines, + float LifeTime, + uint8 DepthPriority, + float Thickness) +{ + DrawArc(InWorld, Matrix, InnerRadius, OuterRadius, -Angle / 2.0f, Angle / 2.0f, Segments, Color, bPersistentLines, LifeTime, DepthPriority, Thickness); +} + //-------------------------------------------------------------------------------------------------------------------------- void FCogDebugDrawHelper::DrawSphere( const UWorld* InWorld, diff --git a/Plugins/Cog/Source/CogDebug/Private/CogDebugGizmo.cpp b/Plugins/Cog/Source/CogDebug/Private/CogDebugGizmo.cpp index 40df81d..f221031 100644 --- a/Plugins/Cog/Source/CogDebug/Private/CogDebugGizmo.cpp +++ b/Plugins/Cog/Source/CogDebug/Private/CogDebugGizmo.cpp @@ -1,7 +1,7 @@ #include "CogDebugGizmo.h" +#include "CogDebug.h" #include "CogDebugDrawHelper.h" -#include "CogDebugSettings.h" #include "CogImGuiHelper.h" #include "Components/PrimitiveComponent.h" #include "Components/SceneComponent.h" @@ -10,7 +10,29 @@ #include "Kismet/GameplayStatics.h" //-------------------------------------------------------------------------------------------------------------------------- -float PointDistanceToQuad(const APlayerController& InPlayerController, const FVector2D& Point, const FVector& QuadPosition, const FQuat& QuadRotation, const FVector2D& QuadExtents) +float ScreenDistanceToLine(const APlayerController& InPlayerController, const FVector2D& Point2D, const FVector& P0, const FVector& P1) +{ + FVector2D ScreenP0, ScreenP1; + UGameplayStatics::ProjectWorldToScreen(&InPlayerController, P0, ScreenP0); + UGameplayStatics::ProjectWorldToScreen(&InPlayerController, P1, ScreenP1); + const FVector2D ClosestPoint = FMath::ClosestPointOnSegment2D(Point2D, ScreenP0, ScreenP1); + const float DistanceToMouse = (ClosestPoint - Point2D).Length(); + return DistanceToMouse; +} + +//-------------------------------------------------------------------------------------------------------------------------- +float ScreenDistanceToSphere(const APlayerController& InPlayerController, const FVector2D& Point2D, const FVector& SphereLocation, float Radius) +{ + FVector2D ElementLocation2D; + UGameplayStatics::ProjectWorldToScreen(&InPlayerController, SphereLocation, ElementLocation2D); + + //TODO : radius in 3D + const float Distance = FVector2D::Distance(ElementLocation2D, Point2D) - Radius; + return Distance; +} + +//-------------------------------------------------------------------------------------------------------------------------- +float ScreenDistanceToQuad(const APlayerController& InPlayerController, const FVector2D& Point2D, const FVector& QuadPosition, const FQuat& QuadRotation, const FVector2D& QuadExtents) { const FVector U = QuadRotation.GetAxisZ() * QuadExtents.X; const FVector V = QuadRotation.GetAxisY() * QuadExtents.Y; @@ -26,8 +48,8 @@ float PointDistanceToQuad(const APlayerController& InPlayerController, const FVe UGameplayStatics::ProjectWorldToScreen(&InPlayerController, V2, P2); UGameplayStatics::ProjectWorldToScreen(&InPlayerController, V3, P3); - const FVector B0 = FMath::GetBaryCentric2D(Point, P0, P1, P2); - const FVector B1 = FMath::GetBaryCentric2D(Point, P0, P2, P3); + const FVector B0 = FMath::GetBaryCentric2D(Point2D, P0, P1, P2); + const FVector B1 = FMath::GetBaryCentric2D(Point2D, P0, P2, P3); const bool Inside0 = B0.X > 0.0f && B0.Y > 0.0f && B0.Z > 0.0f; const bool Inside1 = B1.X > 0.0f && B1.Y > 0.0f && B1.Z > 0.0f; @@ -37,7 +59,90 @@ float PointDistanceToQuad(const APlayerController& InPlayerController, const FVe } //-------------------------------------------------------------------------------------------------------------------------- -void FCogDebug_Gizmo::Draw(const APlayerController& InPlayerController, FTransform& InOutTransform) +float ScreenDistanceToArc(const APlayerController& InPlayerController, const FVector2D& Point, const FMatrix& Matrix, const float Radius, const float AngleStart, const float AngleEnd, const int32 Segments) +{ + const float AngleStartRad = FMath::DegreesToRadians(AngleStart); + const float AngleEndRad = FMath::DegreesToRadians(AngleEnd); + const FVector Center = Matrix.GetOrigin(); + + // Need at least 4 segments + const int32 NumSegments = FMath::Max(Segments, 4); + + const FVector AxisY = Matrix.GetScaledAxis(EAxis::Y); + const FVector AxisZ = Matrix.GetScaledAxis(EAxis::Z); + + float CurrentAngle = AngleStartRad; + const float AngleStep = (AngleEndRad - AngleStartRad) / float(NumSegments); + + FVector P0 = Center + Radius * (AxisZ * FMath::Sin(CurrentAngle) + AxisY * FMath::Cos(CurrentAngle)); + + FVector2D ScreenP0; + UGameplayStatics::ProjectWorldToScreen(&InPlayerController, P0, ScreenP0); + + float MinDistanceSqr = FLT_MAX; + + int32 Count = NumSegments; + while (Count--) + { + CurrentAngle += AngleStep; + const FVector P1 = Center + Radius * (AxisZ * FMath::Sin(CurrentAngle) + AxisY * FMath::Cos(CurrentAngle)); + + FVector2D ScreenP1; + UGameplayStatics::ProjectWorldToScreen(&InPlayerController, P1, ScreenP1); + + const FVector2D ClosestPoint = FMath::ClosestPointOnSegment2D(Point, ScreenP0, ScreenP1); + const float ScreenDistanceSqr = (ClosestPoint - Point).SquaredLength(); + + if (ScreenDistanceSqr < MinDistanceSqr) + { + MinDistanceSqr = ScreenDistanceSqr; + } + + P0 = P1; + ScreenP0 = ScreenP1; + } + + return FMath::Sqrt(MinDistanceSqr); +} + +//-------------------------------------------------------------------------------------------------------------------------- +FVector GetMouseCursorOnLine(const APlayerController& InPlayerController, const FVector& LinePoint, const FVector& LineDirection, const FVector2D& MousePos) +{ + FVector MouseWorldOrigin, MouseWorldDirection; + UGameplayStatics::DeprojectScreenToWorld(&InPlayerController, MousePos, MouseWorldOrigin, MouseWorldDirection); + + FVector PointOnAxis; + FVector PointOnMouseRay; + + constexpr float LineLength = 10000; + FMath::SegmentDistToSegmentSafe(LinePoint - LineDirection * LineLength, LinePoint + LineDirection * LineLength, MouseWorldOrigin - MouseWorldDirection * LineLength, MouseWorldOrigin + MouseWorldDirection * LineLength, PointOnAxis, PointOnMouseRay); + + return PointOnAxis; +} + +//-------------------------------------------------------------------------------------------------------------------------- +FVector GetMouseCursorOnPlane(const APlayerController& InPlayerController, const FVector& PlanePoint, const FVector& PlaneNormal, const FVector2D& MousePos) +{ + FVector MouseWorldOrigin, MouseWorldDirection; + UGameplayStatics::DeprojectScreenToWorld(&InPlayerController, MousePos, MouseWorldOrigin, MouseWorldDirection); + + const FPlane Plane(PlanePoint, PlaneNormal); + const FVector PlaneIntersection = FMath::RayPlaneIntersection(MouseWorldOrigin, MouseWorldDirection, Plane); + return PlaneIntersection; +} + +//-------------------------------------------------------------------------------------------------------------------------- +FVector VectorMax(const FVector& Vector, const float MaxValue) +{ + FVector NewValue; + NewValue.X = FMath::Max(Vector.X, MaxValue); + NewValue.Y = FMath::Max(Vector.Y, MaxValue); + NewValue.Z = FMath::Max(Vector.Z, MaxValue); + return NewValue; +} + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogDebug_Gizmo::Draw(const char* Id, const APlayerController& InPlayerController, FTransform& InOutTransform, ECogDebug_GizmoFlags Flags) { UWorld* World = InPlayerController.GetWorld(); @@ -52,67 +157,98 @@ void FCogDebug_Gizmo::Draw(const APlayerController& InPlayerController, FTransfo FVector2D Center2D; if (UGameplayStatics::ProjectWorldToScreen(&InPlayerController, GizmoCenter, Center2D) == false) { + if (DraggedElementType != ECogDebug_GizmoElementType::MAX) + { + InOutTransform = InitialTransform; + } + return; } - const FCogDebugData& Debug = FCogDebugSettings::Data; + const ImGuiIO& IO = ImGui::GetIO(); + FCogDebugSettings& Settings = FCogDebug::Settings; - FVector CenterProjection, CenterDirection, AxisProjection, AxisDirection; - UGameplayStatics::DeprojectScreenToWorld(&InPlayerController, Center2D, CenterProjection, CenterDirection); + FVector ProjectedGizmoCenter, CenterDirection, AxisProjection, AxisDirection; + UGameplayStatics::DeprojectScreenToWorld(&InPlayerController, Center2D, ProjectedGizmoCenter, CenterDirection); UGameplayStatics::DeprojectScreenToWorld(&InPlayerController, Center2D + FVector2d(0, 1.0f), AxisProjection, AxisDirection); const FVector CameraLocation = InPlayerController.PlayerCameraManager->GetCameraLocation(); - const float Sc = FVector::Dist(AxisProjection, CenterProjection) * FVector::Dist(CameraLocation, GizmoCenter) / FVector::Dist(CameraLocation, CenterProjection); - const float Scale = Debug.GizmoScale * Sc; + const float CameraToProjectedGizmoCenter = FVector::Dist(CameraLocation, ProjectedGizmoCenter); + const float ScaleToKeepGizmoScreenSizeConstant = FMath::IsNearlyZero(CameraToProjectedGizmoCenter) ? 1.0f : FVector::Dist(AxisProjection, ProjectedGizmoCenter) * FVector::Dist(CameraLocation, GizmoCenter) / CameraToProjectedGizmoCenter; + const float GizmoScale = Settings.GizmoScale * ScaleToKeepGizmoScreenSizeConstant; - const FQuat RotX = InOutTransform.GetRotation(); - const FQuat RotY = RotX * FQuat(FVector(0.0f, 0.0f, 1.0f), UE_HALF_PI); + const FQuat RotX = UseLocalSpace ? 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 RotZ = RotX * FQuat(FVector(0.0f, 1.0f, 0.0f), UE_HALF_PI); - const FVector UnitAxisX = RotX.GetAxisX(); - const FVector UnitAxisY = RotX.GetAxisY(); - const FVector UnitAxisZ = RotX.GetAxisZ(); + const FVector UnitAxisX = UseLocalSpace ? RotX.GetAxisX() : FVector::XAxisVector; + const FVector UnitAxisY = UseLocalSpace ? RotX.GetAxisY() : FVector::YAxisVector; + const FVector UnitAxisZ = UseLocalSpace ? RotX.GetAxisZ() : FVector::ZAxisVector; - const FVector AxisX = GizmoCenter + UnitAxisX * Debug.GizmoAxisLength * Scale; - const FVector AxisY = GizmoCenter + UnitAxisY * Debug.GizmoAxisLength * Scale; - const FVector AxisZ = GizmoCenter + UnitAxisZ * Debug.GizmoAxisLength * Scale; + const FVector AxisX = GizmoCenter + UnitAxisX * Settings.GizmoAxisLength * GizmoScale; + const FVector AxisY = GizmoCenter + UnitAxisY * Settings.GizmoAxisLength * GizmoScale; + const FVector AxisZ = GizmoCenter + UnitAxisZ * Settings.GizmoAxisLength * GizmoScale; - const FVector PlaneXY = GizmoCenter + ((UnitAxisX + UnitAxisY) * Debug.GizmoPlaneOffset * Scale); - const FVector PlaneXZ = GizmoCenter + ((UnitAxisX + UnitAxisZ) * Debug.GizmoPlaneOffset * Scale); - const FVector PlaneYZ = GizmoCenter + ((UnitAxisY + UnitAxisZ) * Debug.GizmoPlaneOffset * Scale); + const FVector PlaneXY = GizmoCenter + ((UnitAxisX + UnitAxisY) * Settings.GizmoPlaneOffset * GizmoScale); + const FVector PlaneXZ = GizmoCenter + ((UnitAxisX + UnitAxisZ) * Settings.GizmoPlaneOffset * GizmoScale); + const FVector PlaneYZ = GizmoCenter + ((UnitAxisY + UnitAxisZ) * Settings.GizmoPlaneOffset * GizmoScale); - const float AdjustedScaleBoxExtent = Debug.GizmoScaleBoxExtent * Scale; - const float AdjustedPlaneExtent = Debug.GizmoPlaneExtent * Scale; - const float AdjustedThicknessZLow = Debug.GizmoThicknessZLow * Scale; - const float AdjustedThicknessZHigh = Debug.GizmoThicknessZHigh * Scale; + const float ScaleBoxExtent = Settings.GizmoScaleBoxExtent * GizmoScale; + const float PlaneExtent = Settings.GizmoPlaneExtent * GizmoScale; + const float ThicknessZLow = Settings.GizmoThicknessZLow * ScaleToKeepGizmoScreenSizeConstant; + const float ThicknessZHigh = Settings.GizmoThicknessZHigh * ScaleToKeepGizmoScreenSizeConstant; const ImVec2 ImMousePos = ImGui::GetMousePos() - Viewport->Pos; const FVector2D MousePos = FCogImguiHelper::ToFVector2D(ImMousePos); - const FColor GizmoAxisColorsZLow[] = { Debug.GizmoAxisColorsZLowX, Debug.GizmoAxisColorsZLowY, Debug.GizmoAxisColorsZLowZ, Debug.GizmoAxisColorsZLowW }; - const FColor GizmoAxisColorsZHigh[] = { Debug.GizmoAxisColorsZHighX, Debug.GizmoAxisColorsZHighY, Debug.GizmoAxisColorsZHighZ, Debug.GizmoAxisColorsZHighW }; - const FColor GizmoAxisColorsSelection[] = { Debug.GizmoAxisColorsSelectionX, Debug.GizmoAxisColorsSelectionY, Debug.GizmoAxisColorsSelectionZ, Debug.GizmoAxisColorsSelectionW }; + const FColor GizmoAxisColorsZLow[] = { Settings.GizmoAxisColorsZLowX, Settings.GizmoAxisColorsZLowY, Settings.GizmoAxisColorsZLowZ, Settings.GizmoAxisColorsZLowW }; + const FColor GizmoAxisColorsZHigh[] = { Settings.GizmoAxisColorsZHighX, Settings.GizmoAxisColorsZHighY, Settings.GizmoAxisColorsZHighZ, Settings.GizmoAxisColorsZHighW }; + const FColor GizmoAxisColorsSelection[] = { Settings.GizmoAxisColorsSelectionX, Settings.GizmoAxisColorsSelectionY, Settings.GizmoAxisColorsSelectionZ, Settings.GizmoAxisColorsSelectionW }; FCogDebug_GizmoElement GizmoElements[ECogDebug_GizmoElementType::MAX]; - GizmoElements[(uint8)ECogDebug_GizmoElementType::MoveX] = { ECogDebug_GizmoType::MoveAxis, ECogDebug_GizmoAxis::X, FVector::XAxisVector, UnitAxisX, FQuat::Identity, AxisX }; - GizmoElements[(uint8)ECogDebug_GizmoElementType::MoveY] = { ECogDebug_GizmoType::MoveAxis, ECogDebug_GizmoAxis::Y, FVector::YAxisVector, UnitAxisY, FQuat::Identity, AxisY }; - GizmoElements[(uint8)ECogDebug_GizmoElementType::MoveZ] = { ECogDebug_GizmoType::MoveAxis, ECogDebug_GizmoAxis::Z, FVector::ZAxisVector, UnitAxisZ, FQuat::Identity, AxisZ }; - GizmoElements[(uint8)ECogDebug_GizmoElementType::MoveXY] = { ECogDebug_GizmoType::MovePlane, ECogDebug_GizmoAxis::Z, FVector::ZAxisVector, UnitAxisZ, RotZ, PlaneXY }; - GizmoElements[(uint8)ECogDebug_GizmoElementType::MoveXZ] = { ECogDebug_GizmoType::MovePlane, ECogDebug_GizmoAxis::Y, FVector::YAxisVector, UnitAxisY, RotY, PlaneXZ }; - GizmoElements[(uint8)ECogDebug_GizmoElementType::MoveYZ] = { ECogDebug_GizmoType::MovePlane, ECogDebug_GizmoAxis::X, FVector::XAxisVector, UnitAxisX, RotX, PlaneYZ }; - GizmoElements[(uint8)ECogDebug_GizmoElementType::RotateX] = { ECogDebug_GizmoType::Rotate, ECogDebug_GizmoAxis::X, FVector::XAxisVector, UnitAxisX, RotX, AxisX }; - GizmoElements[(uint8)ECogDebug_GizmoElementType::RotateY] = { ECogDebug_GizmoType::Rotate, ECogDebug_GizmoAxis::Y, FVector::YAxisVector, UnitAxisY, RotY, AxisY }; - GizmoElements[(uint8)ECogDebug_GizmoElementType::RotateZ] = { ECogDebug_GizmoType::Rotate, ECogDebug_GizmoAxis::Z, FVector::ZAxisVector, UnitAxisZ, RotZ, AxisZ }; - GizmoElements[(uint8)ECogDebug_GizmoElementType::ScaleXYZ] = { ECogDebug_GizmoType::ScaleUniform, ECogDebug_GizmoAxis::MAX, FVector::OneVector, FVector::OneVector, RotX, GizmoCenter }; - GizmoElements[(uint8)ECogDebug_GizmoElementType::ScaleX] = { ECogDebug_GizmoType::ScaleAxis, ECogDebug_GizmoAxis::X, FVector::XAxisVector, UnitAxisX, RotX, AxisX }; - GizmoElements[(uint8)ECogDebug_GizmoElementType::ScaleY] = { ECogDebug_GizmoType::ScaleAxis, ECogDebug_GizmoAxis::Y, FVector::YAxisVector, UnitAxisY, RotY, AxisY }; - GizmoElements[(uint8)ECogDebug_GizmoElementType::ScaleZ] = { ECogDebug_GizmoType::ScaleAxis, ECogDebug_GizmoAxis::Z, FVector::ZAxisVector, UnitAxisZ, RotZ, AxisZ }; + for (FCogDebug_GizmoElement& GizmoElement : GizmoElements) + { + GizmoElement.Type = ECogDebug_GizmoType::MAX; + } + + if (EnumHasAnyFlags(Flags, ECogDebug_GizmoFlags::NoTranslationAxis) == false) + { + GizmoElements[(uint8)ECogDebug_GizmoElementType::MoveX] = { ECogDebug_GizmoType::MoveAxis, ECogDebug_GizmoAxis::X, FVector::XAxisVector, UnitAxisX, FQuat::Identity, AxisX }; + GizmoElements[(uint8)ECogDebug_GizmoElementType::MoveY] = { ECogDebug_GizmoType::MoveAxis, ECogDebug_GizmoAxis::Y, FVector::YAxisVector, UnitAxisY, FQuat::Identity, AxisY }; + GizmoElements[(uint8)ECogDebug_GizmoElementType::MoveZ] = { ECogDebug_GizmoType::MoveAxis, ECogDebug_GizmoAxis::Z, FVector::ZAxisVector, UnitAxisZ, FQuat::Identity, AxisZ }; + } + + if (EnumHasAnyFlags(Flags, ECogDebug_GizmoFlags::NoTranslationPlane) == false) + { + GizmoElements[(uint8)ECogDebug_GizmoElementType::MoveXY] = { ECogDebug_GizmoType::MovePlane, ECogDebug_GizmoAxis::Z, FVector::ZAxisVector, UnitAxisZ, RotZ, PlaneXY }; + GizmoElements[(uint8)ECogDebug_GizmoElementType::MoveXZ] = { ECogDebug_GizmoType::MovePlane, ECogDebug_GizmoAxis::Y, FVector::YAxisVector, UnitAxisY, RotY, PlaneXZ }; + GizmoElements[(uint8)ECogDebug_GizmoElementType::MoveYZ] = { ECogDebug_GizmoType::MovePlane, ECogDebug_GizmoAxis::X, FVector::XAxisVector, UnitAxisX, RotX, PlaneYZ }; + } + + if (EnumHasAnyFlags(Flags, ECogDebug_GizmoFlags::NoRotation) == false) + { + GizmoElements[(uint8)ECogDebug_GizmoElementType::RotateX] = { ECogDebug_GizmoType::Rotate, ECogDebug_GizmoAxis::X, FVector::XAxisVector, UnitAxisX, RotX, AxisX }; + GizmoElements[(uint8)ECogDebug_GizmoElementType::RotateY] = { ECogDebug_GizmoType::Rotate, ECogDebug_GizmoAxis::Y, FVector::YAxisVector, UnitAxisY, RotY, AxisY }; + GizmoElements[(uint8)ECogDebug_GizmoElementType::RotateZ] = { ECogDebug_GizmoType::Rotate, ECogDebug_GizmoAxis::Z, FVector::ZAxisVector, UnitAxisZ, RotZ, AxisZ }; + } + + if (EnumHasAnyFlags(Flags, ECogDebug_GizmoFlags::NoScaleUniform) == false) + { + GizmoElements[(uint8)ECogDebug_GizmoElementType::ScaleXYZ] = { ECogDebug_GizmoType::ScaleUniform, ECogDebug_GizmoAxis::MAX, FVector::OneVector, FVector::OneVector, RotX, GizmoCenter }; + } + + if (EnumHasAnyFlags(Flags, ECogDebug_GizmoFlags::NoScaleAxis) == false) + { + GizmoElements[(uint8)ECogDebug_GizmoElementType::ScaleX] = { ECogDebug_GizmoType::ScaleAxis, ECogDebug_GizmoAxis::X, FVector::XAxisVector, UnitAxisX, RotX, AxisX }; + GizmoElements[(uint8)ECogDebug_GizmoElementType::ScaleY] = { ECogDebug_GizmoType::ScaleAxis, ECogDebug_GizmoAxis::Y, FVector::YAxisVector, UnitAxisY, RotY, AxisY }; + GizmoElements[(uint8)ECogDebug_GizmoElementType::ScaleZ] = { ECogDebug_GizmoType::ScaleAxis, ECogDebug_GizmoAxis::Z, FVector::ZAxisVector, UnitAxisZ, RotZ, AxisZ }; + } ECogDebug_GizmoElementType HoveredElementType = ECogDebug_GizmoElementType::MAX; if (DraggedElementType != ECogDebug_GizmoElementType::MAX) { HoveredElementType = DraggedElementType; } - else + else if (IO.WantCaptureMouse == false) { float MinDistanceToMouse = FLT_MAX; for (uint8 i = (uint8)ECogDebug_GizmoElementType::MoveX; i < (uint8)ECogDebug_GizmoElementType::MAX; ++i) @@ -124,30 +260,35 @@ void FCogDebug_Gizmo::Draw(const APlayerController& InPlayerController, FTransfo { case ECogDebug_GizmoType::MoveAxis: { - FVector2D ElementLocation2D; - UGameplayStatics::ProjectWorldToScreen(&InPlayerController, Elm.Location, ElementLocation2D); - const FVector2D ClosestPoint = FMath::ClosestPointOnSegment2D(MousePos, Center2D, ElementLocation2D); - DistanceToMouse = (ClosestPoint - MousePos).Length(); + DistanceToMouse = ScreenDistanceToLine(InPlayerController, MousePos, GizmoCenter, Elm.Location); break; } case ECogDebug_GizmoType::MovePlane: { - DistanceToMouse = PointDistanceToQuad(InPlayerController, MousePos, Elm.Location, Elm.Rotation, FVector2D(AdjustedPlaneExtent, AdjustedPlaneExtent)); + DistanceToMouse = ScreenDistanceToQuad(InPlayerController, MousePos, Elm.Location, Elm.Rotation, FVector2D(PlaneExtent, PlaneExtent)); + break; + } + + case ECogDebug_GizmoType::Rotate: + { + FRotationTranslationMatrix Matrix(FRotator(Elm.Rotation), GizmoCenter); + const float RotationGizmoRadius = Settings.GizmoRotationRadius * GizmoScale; + DistanceToMouse = ScreenDistanceToArc(InPlayerController, MousePos, Matrix, RotationGizmoRadius, 0.0f, 90.0f, Settings.GizmoRotationSegments); break; } case ECogDebug_GizmoType::ScaleUniform: case ECogDebug_GizmoType::ScaleAxis: { - FVector2D ElementLocation2D; - UGameplayStatics::ProjectWorldToScreen(&InPlayerController, Elm.Location, ElementLocation2D); - DistanceToMouse = FVector2D::Distance(ElementLocation2D, MousePos) - Debug.GizmoScaleBoxExtent; + DistanceToMouse = ScreenDistanceToSphere(InPlayerController, MousePos, Elm.Location, Settings.GizmoScaleBoxExtent); break; } + + default:; } - if (DistanceToMouse < Debug.GizmoMouseMaxDistance && DistanceToMouse < MinDistanceToMouse) + if (DistanceToMouse < Settings.GizmoCursorSelectionThreshold && DistanceToMouse < MinDistanceToMouse) { HoveredElementType = (ECogDebug_GizmoElementType)i; MinDistanceToMouse = DistanceToMouse; @@ -167,90 +308,113 @@ void FCogDebug_Gizmo::Draw(const APlayerController& InPlayerController, FTransfo { case ECogDebug_GizmoType::MoveAxis: { - DrawDebugLine(World, GizmoCenter, Elm.Location, ZLowColor, false, 0.0f, Debug.GizmoZLow, AdjustedThicknessZLow); - DrawDebugLine(World, GizmoCenter, Elm.Location, ZHighColor, false, 0.0f, Debug.GizmoZHigh, Debug.GizmoThicknessZHigh); + DrawDebugLine(World, GizmoCenter, Elm.Location, ZLowColor, false, 0.0f, Settings.GizmoZLow, ThicknessZLow); + DrawDebugLine(World, GizmoCenter, Elm.Location, ZHighColor, false, 0.0f, Settings.GizmoZHigh, Settings.GizmoThicknessZHigh); break; } case ECogDebug_GizmoType::MovePlane: { - FCogDebugDrawHelper::DrawQuad(World, Elm.Location, Elm.Rotation, FVector2D(AdjustedPlaneExtent, AdjustedPlaneExtent), ZLowColor, false, 0.0f, Debug.GizmoZLow, AdjustedThicknessZLow); - FCogDebugDrawHelper::DrawQuad(World, Elm.Location, Elm.Rotation, FVector2D(AdjustedPlaneExtent, AdjustedPlaneExtent), ZHighColor, false, 0.0f, Debug.GizmoZHigh, AdjustedThicknessZHigh); - FCogDebugDrawHelper::DrawSolidQuad(World, Elm.Location, Elm.Rotation, FVector2D(AdjustedPlaneExtent, AdjustedPlaneExtent), ZLowColor, false, 0.0f, Debug.GizmoZLow); + FCogDebugDrawHelper::DrawQuad(World, Elm.Location, Elm.Rotation, FVector2D(PlaneExtent, PlaneExtent), ZLowColor, false, 0.0f, Settings.GizmoZLow, ThicknessZLow); + FCogDebugDrawHelper::DrawQuad(World, Elm.Location, Elm.Rotation, FVector2D(PlaneExtent, PlaneExtent), ZHighColor, false, 0.0f, Settings.GizmoZHigh, ThicknessZHigh); + FCogDebugDrawHelper::DrawSolidQuad(World, Elm.Location, Elm.Rotation, FVector2D(PlaneExtent, PlaneExtent), ZLowColor, false, 0.0f, Settings.GizmoZLow); break; } case ECogDebug_GizmoType::Rotate: { - FRotationTranslationMatrix Matrix(FRotator(Elm.Rotation), Elm.Location); - DrawDebugCircle(World, Matrix, Debug.GizmoRotationRadius, Debug.GizmoRotationSegments, ZLowColor, false, 0.0f, Debug.GizmoZLow, AdjustedThicknessZLow, false); - DrawDebugCircle(World, Matrix, Debug.GizmoRotationRadius, Debug.GizmoRotationSegments, ZHighColor, false, 0.0f, Debug.GizmoZHigh, AdjustedThicknessZHigh, false); + FRotationTranslationMatrix Matrix(FRotator(Elm.Rotation), GizmoCenter); + const float RotationGizmoRadius = Settings.GizmoRotationRadius * GizmoScale; + FCogDebugDrawHelper::DrawArc(World, Matrix, RotationGizmoRadius, RotationGizmoRadius, 0.0f, 90.0f, Settings.GizmoRotationSegments, ZLowColor, false, 0.0f, Settings.GizmoZLow, ThicknessZLow); + FCogDebugDrawHelper::DrawArc(World, Matrix, RotationGizmoRadius, RotationGizmoRadius, 0.0f, 90.0f, Settings.GizmoRotationSegments, ZHighColor, false, 0.0f, Settings.GizmoZHigh, ThicknessZHigh); break; } case ECogDebug_GizmoType::ScaleUniform: case ECogDebug_GizmoType::ScaleAxis: { - DrawDebugBox(World, Elm.Location, FVector::OneVector * AdjustedScaleBoxExtent, Elm.Rotation, ZLowColor, false, 0.0f, Debug.GizmoZLow, AdjustedThicknessZLow); - DrawDebugBox(World, Elm.Location, FVector::OneVector * AdjustedScaleBoxExtent, Elm.Rotation, ZHighColor, false, 0.0f, Debug.GizmoZHigh, AdjustedThicknessZHigh); - DrawDebugSolidBox(World, Elm.Location, FVector::OneVector * AdjustedScaleBoxExtent, Elm.Rotation, ZLowColor, false, 0.0f, Debug.GizmoZLow); + DrawDebugBox(World, Elm.Location, FVector::OneVector * ScaleBoxExtent, Elm.Rotation, ZLowColor, false, 0.0f, Settings.GizmoZLow, ThicknessZLow); + DrawDebugBox(World, Elm.Location, FVector::OneVector * ScaleBoxExtent, Elm.Rotation, ZHighColor, false, 0.0f, Settings.GizmoZHigh, ThicknessZHigh); + DrawDebugSolidBox(World, Elm.Location, FVector::OneVector * ScaleBoxExtent, Elm.Rotation, ZLowColor, false, 0.0f, Settings.GizmoZLow); break; } + + default: + break; } } + if (Settings.GizmoGroundRaycastLength > 0.0f) + { + FVector Bottom = GizmoCenter - FVector(0.0f, 0.0f, Settings.GizmoGroundRaycastLength); + FHitResult GroundHit; + if (World->LineTraceSingleByChannel(GroundHit, GizmoCenter, Bottom, Settings.GizmoGroundRaycastChannel)) + { + Bottom = 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); + } + DrawDebugLine(World, GizmoCenter, Bottom, Settings.GizmoGroundRaycastColor, false, 0.0f, Settings.GizmoZLow, ThicknessZLow); + } + if (ImGui::IsMouseReleased(ImGuiMouseButton_Left)) { DraggedElementType = ECogDebug_GizmoElementType::MAX; } else if (DraggedElementType != ECogDebug_GizmoElementType::MAX) { - if (ImGui::IsMouseDragging(ImGuiMouseButton_Left, 4.0f)) + if (ImGui::IsMouseClicked(ImGuiMouseButton_Right)) { - FVector MouseWorldOrigin, MouseWorldDirection; - UGameplayStatics::DeprojectScreenToWorld(&InPlayerController, MousePos - CursorOffset, MouseWorldOrigin, MouseWorldDirection); - - FCogDebug_GizmoElement& DraggedElement = GizmoElements[(uint8)DraggedElementType]; + InOutTransform = InitialTransform; + DraggedElementType = ECogDebug_GizmoElementType::MAX; + } + else if (ImGui::IsMouseDragging(ImGuiMouseButton_Left, Settings.GizmoCursorDraggingThreshold)) + { + const FCogDebug_GizmoElement& DraggedElement = GizmoElements[(uint8)DraggedElementType]; switch (DraggedElement.Type) { case ECogDebug_GizmoType::MoveAxis: { - FVector Pa, Pb; - FMath::SegmentDistToSegmentSafe( - GizmoCenter - DraggedElement.Direction * 10000, - GizmoCenter + DraggedElement.Direction * 10000, - MouseWorldOrigin - MouseWorldDirection * 10000, - MouseWorldOrigin + MouseWorldDirection * 10000, - Pa, Pb); - InOutTransform.SetLocation(Pa); + const FVector Point = GetMouseCursorOnLine(InPlayerController, InitialTransform.GetTranslation(), DraggedElement.Direction, MousePos - CursorOffset); + InOutTransform.SetLocation(Point); break; } case ECogDebug_GizmoType::MovePlane: { - const FPlane Plane(GizmoCenter, DraggedElement.Direction); - const FVector PlaneIntersection = FMath::RayPlaneIntersection(MouseWorldOrigin, MouseWorldDirection, Plane); - InOutTransform.SetLocation(PlaneIntersection); + const FVector Point = GetMouseCursorOnPlane(InPlayerController, InitialTransform.GetTranslation(), DraggedElement.Direction, MousePos - CursorOffset); + InOutTransform.SetLocation(Point); + break; + } + + case ECogDebug_GizmoType::Rotate: + { + const FVector2D DragDelta = FCogImguiHelper::ToFVector2D(ImGui::GetMouseDragDelta(ImGuiMouseButton_Left)); + const float DragAmount = DragDelta.X - DragDelta.Y; + const FQuat RotDelta(DraggedElement.Axis, DragAmount * Settings.GizmoScaleSpeed); + + FQuat NewRot; + if (UseLocalSpace) + { + NewRot = InitialTransform.GetRotation() * RotDelta; + + } + else + { + NewRot = RotDelta * InitialTransform.GetRotation(); + } + + InOutTransform.SetRotation(NewRot); break; } case ECogDebug_GizmoType::ScaleAxis: { - FVector Pa, Pb; - FMath::SegmentDistToSegmentSafe( - GizmoCenter - DraggedElement.Direction * 10000, - GizmoCenter + DraggedElement.Direction * 10000, - MouseWorldOrigin - MouseWorldDirection * 10000, - MouseWorldOrigin + MouseWorldDirection * 10000, - Pa, Pb); - - const float Sign = FMath::Sign(FVector::DotProduct(DraggedElement.Direction, Pa - GizmoCenter)); - const float Delta = (Pa - GizmoCenter).Length() * Sign; - FVector NewScale = InitialScale + (DraggedElement.Axis * Delta * Debug.GizmoScaleSpeed); - NewScale.X = FMath::Max(NewScale.X, Debug.GizmoScaleMin); - NewScale.Y = FMath::Max(NewScale.Y, Debug.GizmoScaleMin); - NewScale.Z = FMath::Max(NewScale.Z, Debug.GizmoScaleMin); + const FVector Point = GetMouseCursorOnLine(InPlayerController, GizmoCenter, DraggedElement.Direction, MousePos - CursorOffset); + const float Sign = FMath::Sign(FVector::DotProduct(DraggedElement.Direction, Point - GizmoCenter)); + const float Delta = (Point - GizmoCenter).Length() * Sign; + const FVector NewScale = VectorMax(InitialTransform.GetScale3D() + (DraggedElement.Axis * Delta * Settings.GizmoScaleSpeed), Settings.GizmoScaleMin); InOutTransform.SetScale3D(NewScale); break; } @@ -258,10 +422,8 @@ void FCogDebug_Gizmo::Draw(const APlayerController& InPlayerController, FTransfo case ECogDebug_GizmoType::ScaleUniform: { const FVector2D DragDelta = FCogImguiHelper::ToFVector2D(ImGui::GetMouseDragDelta(ImGuiMouseButton_Left)); - FVector NewScale = InitialScale + (DraggedElement.Axis * (DragDelta.X - DragDelta.Y) * Debug.GizmoScaleSpeed); - NewScale.X = FMath::Max(NewScale.X, Debug.GizmoScaleMin); - NewScale.Y = FMath::Max(NewScale.Y, Debug.GizmoScaleMin); - NewScale.Z = FMath::Max(NewScale.Z, Debug.GizmoScaleMin); + const float DragAmount = DragDelta.X - DragDelta.Y; + const FVector NewScale = VectorMax(InitialTransform.GetScale3D() + (DraggedElement.Axis * DragAmount * Settings.GizmoScaleSpeed), Settings.GizmoScaleMin); InOutTransform.SetScale3D(NewScale); break; } @@ -272,14 +434,64 @@ void FCogDebug_Gizmo::Draw(const APlayerController& InPlayerController, FTransfo } } - else if (ImGui::IsMouseDown(ImGuiMouseButton_Left)) + else if (HoveredElementType != ECogDebug_GizmoElementType::MAX) { - DraggedElementType = HoveredElementType; - - if (HoveredElementType != ECogDebug_GizmoElementType::MAX) + if (ImGui::IsMouseClicked(ImGuiMouseButton_Left)) { + DraggedElementType = HoveredElementType; CursorOffset = MousePos - Center2D; - InitialScale = InOutTransform.GetScale3D(); + InitialTransform = InOutTransform; + } + else if (ImGui::IsMouseClicked(ImGuiMouseButton_Right)) + { + ImGui::OpenPopup(Id); } } + + if (ImGui::BeginPopup(Id)) + { + ImGui::Checkbox("Local Space", &UseLocalSpace); + + ImGui::Separator(); + + FVector Translation = InOutTransform.GetTranslation(); + if (FCogImguiHelper::DragFVector("Translation", Translation, 1.0f, 0.0f, 0.0f, "%.1f")) + { + InOutTransform.SetTranslation(Translation); + } + + //if (ImGui::MenuItem("Reset Translation")) + //{ + // InOutTransform.SetTranslation(FVector::ZeroVector); + //} + + FRotator Rotation = FRotator(InOutTransform.GetRotation()); + if (FCogImguiHelper::DragFRotator("Rotation", Rotation, 1.0f, 0.0f, 0.0f, "%.1f")) + { + InOutTransform.SetRotation(Rotation.Quaternion()); + } + + //if (ImGui::MenuItem("Reset Rotation")) + //{ + // InOutTransform.SetRotation(FQuat::Identity); + //} + + FVector Scale = InOutTransform.GetScale3D(); + if (FCogImguiHelper::DragFVector("Scale", Scale, 1.0f, 0.0f, FLT_MAX, "%.1f")) + { + InOutTransform.SetScale3D(Scale); + } + + //if (ImGui::MenuItem("Reset Scale")) + //{ + // InOutTransform.SetScale3D(FVector::OneVector); + //} + + ImGui::Separator(); + + ImGui::DragFloat("Gizmo Scale", &Settings.GizmoScale, 0.1f, 0.1f, 10.0f, "%.1f"); + + ImGui::EndPopup(); + } + } diff --git a/Plugins/Cog/Source/CogDebug/Private/CogDebugLogBlueprint.cpp b/Plugins/Cog/Source/CogDebug/Private/CogDebugLogBlueprint.cpp index 9adb45a..e07d7a5 100644 --- a/Plugins/Cog/Source/CogDebug/Private/CogDebugLogBlueprint.cpp +++ b/Plugins/Cog/Source/CogDebug/Private/CogDebugLogBlueprint.cpp @@ -41,7 +41,7 @@ bool UCogDebugLogBlueprint::IsLogActive(const UObject* WorldContextObject, FCogL return false; } - if (FCogDebugSettings::IsDebugActiveForObject(WorldContextObject) == false) + if (FCogDebug::IsDebugActiveForObject(WorldContextObject) == false) { return false; } diff --git a/Plugins/Cog/Source/CogDebug/Private/CogDebugMetric.cpp b/Plugins/Cog/Source/CogDebug/Private/CogDebugMetric.cpp index 03c5ec6..e667a70 100644 --- a/Plugins/Cog/Source/CogDebug/Private/CogDebugMetric.cpp +++ b/Plugins/Cog/Source/CogDebug/Private/CogDebugMetric.cpp @@ -1,6 +1,6 @@ #include "CogDebugMetric.h" -#include "CogDebugSettings.h" +#include "CogDebug.h" //-------------------------------------------------------------------------------------------------------------------------- float FCogDebugMetric::MaxDurationSetting = 0.0f; @@ -13,7 +13,7 @@ TMap FCogDebugMetric::Metrics; //-------------------------------------------------------------------------------------------------------------------------- void FCogDebugMetric::AddMetric(const FCogDebugMetricParams& Params) { - if (FCogDebugSettings::IsDebugActiveForObject(Params.WorldContextObject) == false) + if (FCogDebug::IsDebugActiveForObject(Params.WorldContextObject) == false) { return; } diff --git a/Plugins/Cog/Source/CogDebug/Private/CogDebugPlot.cpp b/Plugins/Cog/Source/CogDebug/Private/CogDebugPlot.cpp index 4dbec06..a287b7d 100644 --- a/Plugins/Cog/Source/CogDebug/Private/CogDebugPlot.cpp +++ b/Plugins/Cog/Source/CogDebug/Private/CogDebugPlot.cpp @@ -425,7 +425,7 @@ FCogDebugPlotEntry* FCogDebugPlot::RegisterPlot(const UObject* WorldContextObjec return nullptr; } - if (FCogDebugSettings::IsDebugActiveForObject(WorldContextObject) == false) + if (FCogDebug::IsDebugActiveForObject(WorldContextObject) == false) { return nullptr; } diff --git a/Plugins/Cog/Source/CogDebug/Private/CogDebugReplicator.cpp b/Plugins/Cog/Source/CogDebug/Private/CogDebugReplicator.cpp index c297813..b0f0ba0 100644 --- a/Plugins/Cog/Source/CogDebug/Private/CogDebugReplicator.cpp +++ b/Plugins/Cog/Source/CogDebug/Private/CogDebugReplicator.cpp @@ -81,8 +81,8 @@ void ACogDebugReplicator::BeginPlay() if (OwnerPlayerController->IsLocalController()) { Server_RequestAllCategoriesVerbosity(); - Server_SetSelection(FCogDebugSettings::GetSelection()); - Server_SetIsFilteringBySelection(FCogDebugSettings::GetIsFilteringBySelection()); + Server_SetSelection(FCogDebug::GetSelection()); + Server_SetIsFilteringBySelection(FCogDebug::GetIsFilteringBySelection()); } } diff --git a/Plugins/Cog/Source/CogDebug/Private/CogDebugShape.cpp b/Plugins/Cog/Source/CogDebug/Private/CogDebugShape.cpp index aa2044c..aa03ba6 100644 --- a/Plugins/Cog/Source/CogDebug/Private/CogDebugShape.cpp +++ b/Plugins/Cog/Source/CogDebug/Private/CogDebugShape.cpp @@ -31,11 +31,11 @@ void FCogDebugShape::DrawPoint(UWorld* World) const DrawDebugPoint( World, ShapeData[0], - FCogDebugSettings::GetDebugServerThickness(Thickness), - FCogDebugSettings::ModulateServerColor(Color), - FCogDebugSettings::GetDebugPersistent(bPersistent), - FCogDebugSettings::GetDebugDuration(bPersistent), - FCogDebugSettings::GetDebugDepthPriority(DepthPriority)); + FCogDebug::GetDebugServerThickness(Thickness), + FCogDebug::ModulateServerColor(Color), + FCogDebug::GetDebugPersistent(bPersistent), + FCogDebug::GetDebugDuration(bPersistent), + FCogDebug::GetDebugDepthPriority(DepthPriority)); } #endif //ENABLE_COG @@ -70,11 +70,11 @@ void FCogDebugShape::DrawSegment(UWorld* World) const World, ShapeData[0], ShapeData[1], - FCogDebugSettings::ModulateServerColor(Color), - FCogDebugSettings::GetDebugPersistent(bPersistent), - FCogDebugSettings::GetDebugDuration(bPersistent), - FCogDebugSettings::GetDebugDepthPriority(DepthPriority), - FCogDebugSettings::GetDebugServerThickness(Thickness)); + FCogDebug::ModulateServerColor(Color), + FCogDebug::GetDebugPersistent(bPersistent), + FCogDebug::GetDebugDuration(bPersistent), + FCogDebug::GetDebugDepthPriority(DepthPriority), + FCogDebug::GetDebugServerThickness(Thickness)); } #endif //ENABLE_COG @@ -111,11 +111,11 @@ void FCogDebugShape::DrawArrow(UWorld* World) const ShapeData[0], ShapeData[1], ShapeData[2].X, - FCogDebugSettings::ModulateServerColor(Color), - FCogDebugSettings::GetDebugPersistent(bPersistent), - FCogDebugSettings::GetDebugDuration(bPersistent), - FCogDebugSettings::GetDebugDepthPriority(DepthPriority), - FCogDebugSettings::GetDebugServerThickness(Thickness)); + FCogDebug::ModulateServerColor(Color), + FCogDebug::GetDebugPersistent(bPersistent), + FCogDebug::GetDebugDuration(bPersistent), + FCogDebug::GetDebugDepthPriority(DepthPriority), + FCogDebug::GetDebugServerThickness(Thickness)); } #endif //ENABLE_COG @@ -152,10 +152,10 @@ void FCogDebugShape::DrawAxes(UWorld* World) const ShapeData[0], FRotator(ShapeData[1].X, ShapeData[1].Y, ShapeData[1].Z), ShapeData[2].X, - FCogDebugSettings::GetDebugPersistent(bPersistent), - FCogDebugSettings::GetDebugDuration(bPersistent), - FCogDebugSettings::GetDebugDepthPriority(DepthPriority), - FCogDebugSettings::GetDebugServerThickness(Thickness)); + FCogDebug::GetDebugPersistent(bPersistent), + FCogDebug::GetDebugDuration(bPersistent), + FCogDebug::GetDebugDepthPriority(DepthPriority), + FCogDebug::GetDebugServerThickness(Thickness)); } #endif //ENABLE_COG @@ -192,11 +192,11 @@ void FCogDebugShape::DrawBox(UWorld* World) const ShapeData[0], ShapeData[1], FQuat(FRotator(ShapeData[2].X, ShapeData[2].Y, ShapeData[2].Z)), - FCogDebugSettings::ModulateServerColor(Color), - FCogDebugSettings::GetDebugPersistent(bPersistent), - FCogDebugSettings::GetDebugDuration(bPersistent), - FCogDebugSettings::GetDebugDepthPriority(DepthPriority), - FCogDebugSettings::GetDebugServerThickness(Thickness)); + FCogDebug::ModulateServerColor(Color), + FCogDebug::GetDebugPersistent(bPersistent), + FCogDebug::GetDebugDuration(bPersistent), + FCogDebug::GetDebugDepthPriority(DepthPriority), + FCogDebug::GetDebugServerThickness(Thickness)); } #endif //ENABLE_COG @@ -231,10 +231,10 @@ void FCogDebugShape::DrawSolidBox(UWorld* World) const ShapeData[0], ShapeData[1], FQuat(FRotator(ShapeData[1].X, ShapeData[1].Y, ShapeData[1].Z)), - FCogDebugSettings::ModulateServerColor(Color), - FCogDebugSettings::GetDebugPersistent(bPersistent), - FCogDebugSettings::GetDebugDuration(bPersistent), - FCogDebugSettings::GetDebugDepthPriority(DepthPriority)); + FCogDebug::ModulateServerColor(Color), + FCogDebug::GetDebugPersistent(bPersistent), + FCogDebug::GetDebugDuration(bPersistent), + FCogDebug::GetDebugDepthPriority(DepthPriority)); } #endif //ENABLE_COG @@ -274,12 +274,12 @@ void FCogDebugShape::DrawCone(UWorld* World) const ShapeData[2].X, DefaultConeAngle, DefaultConeAngle, - FCogDebugSettings::GetCircleSegments(), - FCogDebugSettings::ModulateServerColor(Color), - FCogDebugSettings::GetDebugPersistent(bPersistent), - FCogDebugSettings::GetDebugDuration(bPersistent), - FCogDebugSettings::GetDebugDepthPriority(DepthPriority), - FCogDebugSettings::GetDebugServerThickness(Thickness)); + FCogDebug::GetCircleSegments(), + FCogDebug::ModulateServerColor(Color), + FCogDebug::GetDebugPersistent(bPersistent), + FCogDebug::GetDebugDuration(bPersistent), + FCogDebug::GetDebugDepthPriority(DepthPriority), + FCogDebug::GetDebugServerThickness(Thickness)); } #endif //ENABLE_COG @@ -314,12 +314,12 @@ void FCogDebugShape::DrawCylinder(UWorld* World) const ShapeData[0] - FVector(0, 0, ShapeData[1].Z), ShapeData[0] + FVector(0, 0, ShapeData[1].Z), ShapeData[1].X, - FCogDebugSettings::GetCircleSegments(), - FCogDebugSettings::ModulateServerColor(Color), - FCogDebugSettings::GetDebugPersistent(bPersistent), - FCogDebugSettings::GetDebugDuration(bPersistent), - FCogDebugSettings::GetDebugDepthPriority(DepthPriority), - FCogDebugSettings::GetDebugServerThickness(Thickness)); + FCogDebug::GetCircleSegments(), + FCogDebug::ModulateServerColor(Color), + FCogDebug::GetDebugPersistent(bPersistent), + FCogDebug::GetDebugDuration(bPersistent), + FCogDebug::GetDebugDepthPriority(DepthPriority), + FCogDebug::GetDebugServerThickness(Thickness)); } #endif //ENABLE_COG @@ -355,12 +355,12 @@ void FCogDebugShape::DrawCicle(UWorld* World) const World, FRotationTranslationMatrix(FRotator(ShapeData[1].X, ShapeData[1].Y, ShapeData[1].Z), ShapeData[0]), ShapeData[2].X, - FCogDebugSettings::GetCircleSegments(), - FCogDebugSettings::ModulateServerColor(Color), - FCogDebugSettings::GetDebugPersistent(bPersistent), - FCogDebugSettings::GetDebugDuration(bPersistent), - FCogDebugSettings::GetDebugDepthPriority(DepthPriority), - FCogDebugSettings::GetDebugServerThickness(Thickness), + FCogDebug::GetCircleSegments(), + FCogDebug::ModulateServerColor(Color), + FCogDebug::GetDebugPersistent(bPersistent), + FCogDebug::GetDebugDuration(bPersistent), + FCogDebug::GetDebugDepthPriority(DepthPriority), + FCogDebug::GetDebugServerThickness(Thickness), false); } @@ -399,12 +399,12 @@ void FCogDebugShape::DrawCicleArc(UWorld* World) const ShapeData[2].X, ShapeData[2].Y, ShapeData[2].Z, - FCogDebugSettings::GetDebugSegments(), - FCogDebugSettings::ModulateServerColor(Color), - FCogDebugSettings::GetDebugPersistent(bPersistent), - FCogDebugSettings::GetDebugDuration(bPersistent), - FCogDebugSettings::GetDebugDepthPriority(DepthPriority), - FCogDebugSettings::GetDebugServerThickness(Thickness)); + FCogDebug::GetDebugSegments(), + FCogDebug::ModulateServerColor(Color), + FCogDebug::GetDebugPersistent(bPersistent), + FCogDebug::GetDebugDuration(bPersistent), + FCogDebug::GetDebugDepthPriority(DepthPriority), + FCogDebug::GetDebugServerThickness(Thickness)); } #endif //ENABLE_COG @@ -442,11 +442,11 @@ void FCogDebugShape::DrawCapsule(UWorld* World) const ShapeData[1].Y, ShapeData[1].X, FQuat::MakeFromEuler(ShapeData[2]), - FCogDebugSettings::ModulateServerColor(Color), - FCogDebugSettings::GetDebugPersistent(bPersistent), - FCogDebugSettings::GetDebugDuration(bPersistent), - FCogDebugSettings::GetDebugDepthPriority(DepthPriority), - FCogDebugSettings::GetDebugServerThickness(Thickness)); + FCogDebug::ModulateServerColor(Color), + FCogDebug::GetDebugPersistent(bPersistent), + FCogDebug::GetDebugDuration(bPersistent), + FCogDebug::GetDebugDepthPriority(DepthPriority), + FCogDebug::GetDebugServerThickness(Thickness)); } #endif //ENABLE_COG @@ -484,12 +484,12 @@ void FCogDebugShape::DrawFlatCapsule(UWorld* World) const FVector2D(ShapeData[1].X, ShapeData[1].Y), ShapeData[2].X, ShapeData[2].Y, - FCogDebugSettings::GetCircleSegments(), - FCogDebugSettings::ModulateServerColor(Color), - FCogDebugSettings::GetDebugPersistent(bPersistent), - FCogDebugSettings::GetDebugDuration(bPersistent), - FCogDebugSettings::GetDebugDepthPriority(DepthPriority), - FCogDebugSettings::GetDebugServerThickness(Thickness)); + FCogDebug::GetCircleSegments(), + FCogDebug::ModulateServerColor(Color), + FCogDebug::GetDebugPersistent(bPersistent), + FCogDebug::GetDebugDuration(bPersistent), + FCogDebug::GetDebugDepthPriority(DepthPriority), + FCogDebug::GetDebugServerThickness(Thickness)); } #endif //ENABLE_COG @@ -524,20 +524,20 @@ void FCogDebugShape::DrawBone(UWorld* World) const World, ShapeData[0], ShapeData[1], - FCogDebugSettings::ModulateServerColor(Color), - FCogDebugSettings::GetDebugPersistent(bPersistent), - FCogDebugSettings::GetDebugDuration(bPersistent), - FCogDebugSettings::GetDebugDepthPriority(DepthPriority), - FCogDebugSettings::GetDebugServerThickness(Thickness)); + FCogDebug::ModulateServerColor(Color), + FCogDebug::GetDebugPersistent(bPersistent), + FCogDebug::GetDebugDuration(bPersistent), + FCogDebug::GetDebugDepthPriority(DepthPriority), + FCogDebug::GetDebugServerThickness(Thickness)); DrawDebugPoint( World, ShapeData[0], - FCogDebugSettings::GetDebugServerThickness(Thickness) + 4.0f, - FCogDebugSettings::ModulateServerColor(Color), - FCogDebugSettings::GetDebugPersistent(bPersistent), - FCogDebugSettings::GetDebugDuration(bPersistent), - FCogDebugSettings::GetDebugDepthPriority(DepthPriority)); + FCogDebug::GetDebugServerThickness(Thickness) + 4.0f, + FCogDebug::ModulateServerColor(Color), + FCogDebug::GetDebugPersistent(bPersistent), + FCogDebug::GetDebugDuration(bPersistent), + FCogDebug::GetDebugDepthPriority(DepthPriority)); } #endif //ENABLE_COG @@ -578,10 +578,10 @@ void FCogDebugShape::DrawPolygon(UWorld* World) const World, ShapeData, Indices, - FCogDebugSettings::ModulateServerColor(Color), - FCogDebugSettings::GetDebugPersistent(bPersistent), - FCogDebugSettings::GetDebugDuration(bPersistent), - FCogDebugSettings::GetDebugDepthPriority(DepthPriority)); + FCogDebug::ModulateServerColor(Color), + FCogDebug::GetDebugPersistent(bPersistent), + FCogDebug::GetDebugDuration(bPersistent), + FCogDebug::GetDebugDepthPriority(DepthPriority)); } #endif //ENABLE_COG diff --git a/Plugins/Cog/Source/CogDebug/Public/CogDebugSettings.h b/Plugins/Cog/Source/CogDebug/Public/CogDebug.h similarity index 86% rename from Plugins/Cog/Source/CogDebug/Public/CogDebugSettings.h rename to Plugins/Cog/Source/CogDebug/Public/CogDebug.h index 01e0f55..e0dbc5b 100644 --- a/Plugins/Cog/Source/CogDebug/Public/CogDebugSettings.h +++ b/Plugins/Cog/Source/CogDebug/Public/CogDebug.h @@ -2,14 +2,14 @@ #include "CoreMinimal.h" #include "UObject/WeakObjectPtrTemplates.h" -#include "CogDebugSettings.generated.h" +#include "CogDebug.generated.h" class UObject; class AActor; class UWorld; USTRUCT() -struct FCogDebugData +struct FCogDebugSettings { GENERATED_BODY() @@ -77,7 +77,10 @@ struct FCogDebugData float GizmoThicknessZHigh = 0.0f; UPROPERTY(Config) - float GizmoMouseMaxDistance = 5.0f; + float GizmoCursorDraggingThreshold = 4.0f; + + UPROPERTY(Config) + float GizmoCursorSelectionThreshold = 10.0f; UPROPERTY(Config) float GizmoPlaneOffset = 25.0f; @@ -98,7 +101,16 @@ struct FCogDebugData float GizmoRotationRadius = 15.0f; UPROPERTY(Config) - int GizmoRotationSegments = 32; + int GizmoRotationSegments = 12; + + UPROPERTY(Config) + float GizmoGroundRaycastLength = 100000.0f; + + UPROPERTY(Config) + TEnumAsByte GizmoGroundRaycastChannel = ECollisionChannel::ECC_WorldStatic; + + UPROPERTY(Config) + float GizmoGroundRaycastCircleRadius = 10.f; UPROPERTY(Config) FColor GizmoAxisColorsZHighX = FColor(255, 50, 50, 255); @@ -136,6 +148,12 @@ struct FCogDebugData UPROPERTY(Config) FColor GizmoAxisColorsSelectionW = FColor(255, 255, 0, 255); + UPROPERTY(Config) + FColor GizmoGroundRaycastColor = FColor(128, 128, 128, 255); + + UPROPERTY(Config) + FColor GizmoGroundRaycastCircleColor = FColor(128, 128, 128, 255); + UPROPERTY(Config) TArray SecondaryBoneWildcards = { "interaction", @@ -163,7 +181,7 @@ struct FCogDebugData }; }; -struct COGDEBUG_API FCogDebugSettings +struct COGDEBUG_API FCogDebug { public: @@ -204,7 +222,7 @@ public: static void Reset(); - static FCogDebugData Data; + static FCogDebugSettings Settings; private: diff --git a/Plugins/Cog/Source/CogDebug/Public/CogDebugDrawHelper.h b/Plugins/Cog/Source/CogDebug/Public/CogDebugDrawHelper.h index 5dcc8e8..194e6ef 100644 --- a/Plugins/Cog/Source/CogDebug/Public/CogDebugDrawHelper.h +++ b/Plugins/Cog/Source/CogDebug/Public/CogDebugDrawHelper.h @@ -12,6 +12,8 @@ class COGDEBUG_API FCogDebugDrawHelper { public: + static void DrawArc(const UWorld* InWorld, const FMatrix& Matrix, const float InnterRadius, const float OuterRadius, const float AngleStart, const float AngleEnd, const int32 Segments, const FColor& Color, const bool bPersistentLines = false, const float LifeTime = -1.f, const uint8 DepthPriority = 0U, const float Thickness = 0.0f); + static void DrawArc(const UWorld* InWorld, const FMatrix& Matrix, const float InnterRadius, const float OuterRadius, const float ArcAngle, const int32 Segments, const FColor& Color, const bool bPersistentLines = false, const float LifeTime = -1.f, const uint8 DepthPriority = 0U, const float Thickness = 0.0f); static void DrawSphere(const UWorld* InWorld, const FVector& Center, const float Radius, const int32 Segments, const FColor& Color, const bool bPersistentLines = false, const float LifeTime = -1.f, const uint8 DepthPriority = 0U, const float Thickness = 0.0f); diff --git a/Plugins/Cog/Source/CogDebug/Public/CogDebugGizmo.h b/Plugins/Cog/Source/CogDebug/Public/CogDebugGizmo.h index a8dee69..05a781a 100644 --- a/Plugins/Cog/Source/CogDebug/Public/CogDebugGizmo.h +++ b/Plugins/Cog/Source/CogDebug/Public/CogDebugGizmo.h @@ -3,6 +3,22 @@ #include "CoreMinimal.h" #include "CogDebugGizmo.generated.h" +//-------------------------------------------------------------------------------------------------------------------------- +UENUM(Flags) +enum class ECogDebug_GizmoFlags : uint8 +{ + None = 0, + NoTranslationAxis = 1 << 0, + NoTranslationPlane = 1 << 1, + NoRotation = 1 << 2, + NoScaleAxis = 1 << 3, + NoScaleUniform = 1 << 4, + + NoTranslation = NoTranslationAxis | NoTranslationPlane, + NoScale = NoScaleAxis | NoScaleUniform, +}; +ENUM_CLASS_FLAGS(ECogDebug_GizmoFlags); + //-------------------------------------------------------------------------------------------------------------------------- UENUM() enum class ECogDebug_GizmoType : uint8 @@ -59,9 +75,10 @@ struct FCogDebug_GizmoElement //-------------------------------------------------------------------------------------------------------------------------- struct COGDEBUG_API FCogDebug_Gizmo { - void Draw(const APlayerController& InPlayerController, FTransform& InOutTransform); + void Draw(const char* Id, const APlayerController& InPlayerController, FTransform& InOutTransform, ECogDebug_GizmoFlags Flags = ECogDebug_GizmoFlags::None); + bool UseLocalSpace = false; ECogDebug_GizmoElementType DraggedElementType = ECogDebug_GizmoElementType::MAX; FVector2D CursorOffset = FVector2D::ZeroVector; - FVector InitialScale = FVector::OneVector; + FTransform InitialTransform = FTransform::Identity; }; diff --git a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CollisionTester.cpp b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CollisionTester.cpp index f9ac217..3d29dd5 100644 --- a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CollisionTester.cpp +++ b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CollisionTester.cpp @@ -1,14 +1,13 @@ #include "CogEngineWindow_CollisionTester.h" #include "CogDebugDrawHelper.h" -#include "CogDebugSettings.h" +#include "CogDebug.h" #include "CogEngineDataAsset.h" #include "CogImGuiHelper.h" #include "CogWindowWidgets.h" #include "Components/PrimitiveComponent.h" #include "Components/SceneComponent.h" #include "imgui.h" -#include "Kismet/GameplayStatics.h" //-------------------------------------------------------------------------------------------------------------------------- void FCogEngineWindow_CollisionTester::Initialize() @@ -25,11 +24,7 @@ void FCogEngineWindow_CollisionTester::Initialize() //-------------------------------------------------------------------------------------------------------------------------- void FCogEngineWindow_CollisionTester::RenderHelp() { - ImGui::Text("This window is used to inspect collisions by performing a collision query with the selected channels. " - "The query can be configured in the options. " - "The displayed collision channels can be configured in the '%s' data asset. " - , TCHAR_TO_ANSI(*GetNameSafe(Asset.Get())) - ); + ImGui::Text("This window is used to test a collision query."); } //-------------------------------------------------------------------------------------------------------------------------- @@ -84,35 +79,6 @@ void FCogEngineWindow_CollisionTester::RenderContent() ImGui::EndMenuBar(); } - FCogWindowWidgets::SetNextItemToShortWidth(); - FCogWindowWidgets::ComboboxEnum("Placement", Config->Placement); - - if (Config->Placement == ECogEngine_CollisionQueryPlacement::Selection) - { - FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat3("Location", &Config->LocationStart.X, 1.0f, 0.0f, 0.0f, "%.1f"); - - FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat3("Rotation", &Config->Rotation.Pitch, 1.0f, 0.0f, 0.0f, "%.1f"); - } - else if (Config->Placement == ECogEngine_CollisionQueryPlacement::Transform) - { - FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat3("Start Location", &Config->LocationStart.X, 1.0f, 0.0f, 0.0f, "%.1f"); - - FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat3("End Location", &Config->LocationEnd.X, 1.0f, 0.0f, 0.0f, "%.1f"); - - FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat3("Rotation", &Config->Rotation.Pitch, 1.0f, 0.0f, 0.0f, "%.1f"); - } - - if (Config->Type == ECogEngine_CollisionQueryType::LineTrace || Config->Type == ECogEngine_CollisionQueryType::Sweep) - { - FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::SliderFloat("Distance", &Config->QueryLength, 0.0f, 20000.0f, "%0.f"); - } - FCogWindowWidgets::SetNextItemToShortWidth(); FCogWindowWidgets::ComboboxEnum("Type", Config->Type); @@ -124,31 +90,11 @@ void FCogEngineWindow_CollisionTester::RenderContent() //------------------------------------------------- if (Config->By == ECogEngine_CollisionQueryBy::Channel) { - const FName SelectedChannelName = CollisionProfile->ReturnChannelNameFromContainerIndex(Config->Channel); - FCogWindowWidgets::SetNextItemToShortWidth(); - if (ImGui::BeginCombo("Channel", TCHAR_TO_ANSI(*SelectedChannelName.ToString()), ImGuiComboFlags_HeightLarge)) + ECollisionChannel Channel = Config->Channel.GetValue(); + if (FCogWindowWidgets::ComboCollisionChannel("Channel", Channel)) { - for (int32 ChannelIndex = 0; ChannelIndex < (int32)ECC_MAX; ++ChannelIndex) - { - const FChannel& Channel = Channels[ChannelIndex]; - if (Channel.IsValid == false) - { - continue; - } - - ImGui::PushID(ChannelIndex); - - const FName ChannelName = CollisionProfile->ReturnChannelNameFromContainerIndex(ChannelIndex); - - if (ImGui::Selectable(TCHAR_TO_ANSI(*ChannelName.ToString()))) - { - Config->Channel = ChannelIndex; - } - - ImGui::PopID(); - } - ImGui::EndCombo(); + Config->Channel = Channel; } } //------------------------------------------------- @@ -225,9 +171,14 @@ void FCogEngineWindow_CollisionTester::RenderContent() } } + ImGui::Checkbox("Multi", &Config->MultiHits); + ImGui::Checkbox("Complex", &Config->TraceComplex); + //------------------------------------------------- // Shape //------------------------------------------------- + ImGui::Separator(); + if (Config->Type != ECogEngine_CollisionQueryType::LineTrace) { FCogWindowWidgets::SetNextItemToShortWidth(); @@ -238,33 +189,29 @@ void FCogEngineWindow_CollisionTester::RenderContent() case ECogEngine_CollisionQueryShape::Sphere: { FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Sphere Radius", &Config->ShapeExtent.X, 0.1f, 0, 100.0f, "%.1f"); + FCogImguiHelper::DragDouble("Sphere Radius", &Config->ShapeExtent.X, 0.1f, 0, FLT_MAX, "%.1f"); break; } case ECogEngine_CollisionQueryShape::Box: { FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat3("Box Extent", &Config->ShapeExtent.X, 0.1f, 0, 100.0f, "%.1f"); + FCogImguiHelper::DragFVector("Box Extent", Config->ShapeExtent, 0.1f, 0, FLT_MAX, "%.1f"); break; } case ECogEngine_CollisionQueryShape::Capsule: { FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Capsule Radius", &Config->ShapeExtent.X, 0.1f, 0, 100.0f, "%.1f"); + FCogImguiHelper::DragDouble("Capsule Radius", &Config->ShapeExtent.X, 0.1f, 0, FLT_MAX, "%.1f"); FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Capsule Half Height", &Config->ShapeExtent.Z, 0.1f, 0, 100.0f, "%.1f"); + FCogImguiHelper::DragDouble("Capsule Half Height", &Config->ShapeExtent.Z, 0.1f, 0, FLT_MAX, "%.1f"); break; } } - } - ImGui::Checkbox("Multi", &Config->MultiHits); - ImGui::Checkbox("Complex", &Config->TraceComplex); - Query(); } @@ -280,54 +227,13 @@ void FCogEngineWindow_CollisionTester::Query() return; } - FVector QueryStart = FVector::ZeroVector; - FVector QueryEnd = FVector::ZeroVector; - FQuat QueryRotation = FQuat::Identity; + FVector QueryStart = Config->LocationStart; + FVector QueryEnd = Config->LocationEnd; + FQuat QueryRotation = FQuat(Config->Rotation); TArray Hits; TArray Overlaps; bool HasHits = false; - - switch (Config->Placement) - { - case ECogEngine_CollisionQueryPlacement::Selection: - { - if (const AActor* Selection = GetSelection()) - { - QueryStart = Selection->GetActorLocation() + FVector(Config->LocationStart); - QueryRotation = Selection->GetActorQuat() * FQuat(FRotator(Config->Rotation)); - QueryEnd = QueryStart + Selection->GetActorQuat().GetForwardVector() * Config->QueryLength; - } - - break; - } - - case ECogEngine_CollisionQueryPlacement::View: - { - FRotator Rotation; - PlayerController->GetPlayerViewPoint(QueryStart, Rotation); - QueryRotation = FQuat(Rotation); - QueryEnd = QueryStart + QueryRotation.GetForwardVector() * Config->QueryLength; - break; - } - - case ECogEngine_CollisionQueryPlacement::Cursor: - { - FVector Direction; - const ImGuiViewport* Viewport = ImGui::GetMainViewport(); - const ImVec2 ViewportPos = Viewport != nullptr ? Viewport->Pos : ImVec2(0, 0); - UGameplayStatics::DeprojectScreenToWorld(PlayerController, FCogImguiHelper::ToFVector2D(ImGui::GetMousePos() - ViewportPos), QueryStart, Direction); - QueryEnd = QueryStart + Direction * Config->QueryLength; - break; - } - - case ECogEngine_CollisionQueryPlacement::Transform: - { - QueryStart = FVector(Config->LocationStart); - QueryEnd = FVector(Config->LocationEnd); - QueryRotation = FQuat(FRotator(Config->Rotation)); - break; - } - } + static const FName TraceTag(TEXT("FCogWindow_Collision")); FCollisionQueryParams QueryParams(TraceTag, SCENE_QUERY_STAT_ONLY(CogHitDetection), Config->TraceComplex); @@ -341,7 +247,7 @@ void FCogEngineWindow_CollisionTester::Query() { case ECogEngine_CollisionQueryShape::Sphere: QueryShape.SetSphere(Config->ShapeExtent.X); break; case ECogEngine_CollisionQueryShape::Capsule: QueryShape.SetCapsule(Config->ShapeExtent.X, Config->ShapeExtent.Z); break; - case ECogEngine_CollisionQueryShape::Box: QueryShape.SetBox(Config->ShapeExtent); break; + case ECogEngine_CollisionQueryShape::Box: QueryShape.SetBox(FVector3f(Config->ShapeExtent)); break; } } @@ -515,12 +421,12 @@ void FCogEngineWindow_CollisionTester::Query() GetWorld(), QueryStart, QueryEnd, - FCogDebugSettings::Data.ArrowSize, + FCogDebug::Settings.ArrowSize, Color, false, 0.0f, - FCogDebugSettings::GetDebugDepthPriority(0), - FCogDebugSettings::GetDebugThickness(0.0f)); + FCogDebug::GetDebugDepthPriority(0), + FCogDebug::GetDebugThickness(0.0f)); } if (bIsUsingShape) @@ -547,7 +453,7 @@ void FCogEngineWindow_CollisionTester::Query() Color, false, 0.0f, - FCogDebugSettings::GetDebugDepthPriority(0)); + FCogDebug::GetDebugDepthPriority(0)); } if (Config->DrawHitImpactPoints) @@ -559,7 +465,7 @@ void FCogEngineWindow_CollisionTester::Query() Color, false, 0.0f, - FCogDebugSettings::GetDebugDepthPriority(0)); + FCogDebug::GetDebugDepthPriority(0)); } if (bIsUsingShape && Config->DrawHitShapes) @@ -573,12 +479,12 @@ void FCogEngineWindow_CollisionTester::Query() GetWorld(), Hit.Location, Hit.Location + Hit.Normal * 20.0f, - FCogDebugSettings::Data.ArrowSize, + FCogDebug::Settings.ArrowSize, FLinearColor(Config->NormalColor).ToFColor(true), false, 0.0f, - FCogDebugSettings::GetDebugDepthPriority(0), - FCogDebugSettings::GetDebugThickness(0.0f)); + FCogDebug::GetDebugDepthPriority(0), + FCogDebug::GetDebugThickness(0.0f)); } if (Config->DrawHitImpactNormals) @@ -587,12 +493,12 @@ void FCogEngineWindow_CollisionTester::Query() GetWorld(), Hit.ImpactPoint, Hit.ImpactPoint + Hit.ImpactNormal * 20.0f, - FCogDebugSettings::Data.ArrowSize, + FCogDebug::Settings.ArrowSize, FLinearColor(Config->ImpactNormalColor).ToFColor(true), false, 0.0f, - FCogDebugSettings::GetDebugDepthPriority(0), - FCogDebugSettings::GetDebugThickness(0.0f)); + FCogDebug::GetDebugDepthPriority(0), + FCogDebug::GetDebugThickness(0.0f)); } if (Config->DrawHitPrimitives) @@ -605,15 +511,17 @@ void FCogEngineWindow_CollisionTester::Query() { FVector ScaleStart(Config->ShapeExtent); FTransform TransformStart(QueryRotation, QueryStart, ScaleStart); - GizmoStart.Draw(*LocalPlayerController, TransformStart); - Config->LocationStart = FVector3f(TransformStart.GetLocation()); - Config->ShapeExtent = FVector3f(TransformStart.GetScale3D()); + GizmoStart.Draw("Query Start", *LocalPlayerController, TransformStart); + Config->LocationStart = TransformStart.GetLocation(); + Config->Rotation = FRotator(TransformStart.GetRotation()); + Config->ShapeExtent = TransformStart.GetScale3D(); - FVector ScaleEnd(Config->ShapeExtent); - FTransform TransformEnd(QueryRotation, QueryEnd, ScaleEnd); - GizmoEnd.Draw(*LocalPlayerController, TransformEnd); - Config->LocationEnd = FVector3f(TransformEnd.GetLocation()); - Config->ShapeExtent = FVector3f(TransformEnd.GetScale3D()); + if (Config->Type != ECogEngine_CollisionQueryType::Overlap) + { + FTransform TransformEnd(FRotator::ZeroRotator, QueryEnd, FVector::OneVector); + GizmoEnd.Draw("Query End", *LocalPlayerController, TransformEnd, ECogDebug_GizmoFlags::NoRotation | ECogDebug_GizmoFlags::NoScale); + Config->LocationEnd = TransformEnd.GetLocation(); + } } } @@ -644,7 +552,7 @@ void FCogEngineWindow_CollisionTester::DrawPrimitive(const UPrimitiveComponent* if (AlreadyDrawnActors.Contains(Actor) == false) { FColor TextColor = Color.WithAlpha(255); - DrawDebugString(GetWorld(), Actor->GetActorLocation(), GetNameSafe(Actor->GetClass()), nullptr, FColor::White, 0.0f, FCogDebugSettings::Data.TextShadow, FCogDebugSettings::Data.TextSize); + DrawDebugString(GetWorld(), Actor->GetActorLocation(), GetNameSafe(Actor->GetClass()), nullptr, FColor::White, 0.0f, FCogDebug::Settings.TextShadow, FCogDebug::Settings.TextSize); AlreadyDrawnActors.Add(Actor); } } @@ -679,7 +587,7 @@ void FCogEngineWindow_CollisionTester::DrawShape(const FCollisionShape& Shape, c Color, false, 0.0f, - FCogDebugSettings::GetDebugDepthPriority(0)); + FCogDebug::GetDebugDepthPriority(0)); } DrawDebugBox( @@ -690,8 +598,8 @@ void FCogEngineWindow_CollisionTester::DrawShape(const FCollisionShape& Shape, c Color, false, 0.0f, - FCogDebugSettings::GetDebugDepthPriority(0), - FCogDebugSettings::GetDebugThickness(0.0f)); + FCogDebug::GetDebugDepthPriority(0), + FCogDebug::GetDebugThickness(0.0f)); break; } @@ -708,12 +616,12 @@ void FCogEngineWindow_CollisionTester::DrawShape(const FCollisionShape& Shape, c GetWorld(), Location, Radius, - FCogDebugSettings::GetCircleSegments(), + FCogDebug::GetCircleSegments(), Color, false, 0.0f, - FCogDebugSettings::GetDebugDepthPriority(0), - FCogDebugSettings::GetDebugThickness(0.0f)); + FCogDebug::GetDebugDepthPriority(0), + FCogDebug::GetDebugThickness(0.0f)); break; } @@ -734,8 +642,8 @@ void FCogEngineWindow_CollisionTester::DrawShape(const FCollisionShape& Shape, c Color, false, 0.0f, - FCogDebugSettings::GetDebugDepthPriority(0), - FCogDebugSettings::GetDebugThickness(0.0f)); + FCogDebug::GetDebugDepthPriority(0), + FCogDebug::GetDebugThickness(0.0f)); break; } } diff --git a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CollisionViewer.cpp b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CollisionViewer.cpp index ca99316..1e76459 100644 --- a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CollisionViewer.cpp +++ b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CollisionViewer.cpp @@ -1,7 +1,7 @@ #include "CogEngineWindow_CollisionViewer.h" #include "CogDebugDrawHelper.h" -#include "CogDebugSettings.h" +#include "CogDebug.h" #include "CogEngineDataAsset.h" #include "CogImguiHelper.h" #include "CogWindowHelper.h" @@ -260,7 +260,7 @@ void FCogEngineWindow_CollisionViewer::RenderContent() if (Config->ShowQuery) { - FCogDebugDrawHelper::DrawCapsuleCastMulti(World, QueryStart, QueryEnd, FQuat::Identity, 0.0f, QueryRadius, EDrawDebugTrace::ForOneFrame, false, QueryHits, FLinearColor::White, FLinearColor::Red, FCogDebugSettings::GetDebugDuration(true)); + FCogDebugDrawHelper::DrawCapsuleCastMulti(World, QueryStart, QueryEnd, FQuat::Identity, 0.0f, QueryRadius, EDrawDebugTrace::ForOneFrame, false, QueryHits, FLinearColor::White, FLinearColor::Red, FCogDebug::GetDebugDuration(true)); } TSet AlreadyDrawnActors; @@ -292,7 +292,7 @@ void FCogEngineWindow_CollisionViewer::RenderContent() if (AlreadyDrawnActors.Contains(Actor) == false) { FColor TextColor = Color.WithAlpha(255); - DrawDebugString(World, Actor->GetActorLocation(), GetNameSafe(Actor->GetClass()), nullptr, FColor::White, 0.0f, FCogDebugSettings::Data.TextShadow, FCogDebugSettings::Data.TextSize); + DrawDebugString(World, Actor->GetActorLocation(), GetNameSafe(Actor->GetClass()), nullptr, FColor::White, 0.0f, FCogDebug::Settings.TextShadow, FCogDebug::Settings.TextSize); AlreadyDrawnActors.Add(Actor); } } @@ -331,7 +331,7 @@ void FCogEngineWindow_CollisionViewer::RenderContent() Color, false, 0.0f, - FCogDebugSettings::GetDebugDepthPriority(0)); + FCogDebug::GetDebugDepthPriority(0)); DrawDebugBox( World, @@ -341,8 +341,8 @@ void FCogEngineWindow_CollisionViewer::RenderContent() Color, false, 0.0f, - FCogDebugSettings::GetDebugDepthPriority(0), - FCogDebugSettings::GetDebugThickness(0.0f)); + FCogDebug::GetDebugDepthPriority(0), + FCogDebug::GetDebugThickness(0.0f)); break; } @@ -355,12 +355,12 @@ void FCogEngineWindow_CollisionViewer::RenderContent() World, SphereComponent->GetComponentLocation(), SphereComponent->GetScaledSphereRadius(), - FCogDebugSettings::GetCircleSegments(), + FCogDebug::GetCircleSegments(), Color, false, 0.0f, - FCogDebugSettings::GetDebugDepthPriority(0), - FCogDebugSettings::GetDebugThickness(0.0f)); + FCogDebug::GetDebugDepthPriority(0), + FCogDebug::GetDebugThickness(0.0f)); } break; } @@ -377,8 +377,8 @@ void FCogEngineWindow_CollisionViewer::RenderContent() Color, false, 0.0f, - FCogDebugSettings::GetDebugDepthPriority(0), - FCogDebugSettings::GetDebugThickness(0.0f)); + FCogDebug::GetDebugDepthPriority(0), + FCogDebug::GetDebugThickness(0.0f)); } break; } diff --git a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_DebugSettings.cpp b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_DebugSettings.cpp index bc9121f..cdf6e94 100644 --- a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_DebugSettings.cpp +++ b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_DebugSettings.cpp @@ -1,7 +1,9 @@ #include "CogEngineWindow_DebugSettings.h" -#include "CogDebugSettings.h" +#include "CogDebug.h" +#include "CogImGuiHelper.h" #include "CogWindowWidgets.h" +#include "imgui_internal.h" //-------------------------------------------------------------------------------------------------------------------------- void FCogEngineWindow_DebugSettings::RenderHelp() @@ -21,8 +23,8 @@ void FCogEngineWindow_DebugSettings::Initialize() Config = GetConfig(); - FCogDebugSettings::Data = Config->Data; - FCogDebugSettings::SetIsFilteringBySelection(GetWorld(), Config->Data.bIsFilteringBySelection); + FCogDebug::Settings = Config->Data; + FCogDebug::SetIsFilteringBySelection(GetWorld(), Config->Data.bIsFilteringBySelection); } //-------------------------------------------------------------------------------------------------------------------------- @@ -38,7 +40,7 @@ void FCogEngineWindow_DebugSettings::PreSaveConfig() { Super::PreSaveConfig(); - Config->Data = FCogDebugSettings::Data; + Config->Data = FCogDebug::Settings; } //-------------------------------------------------------------------------------------------------------------------------- @@ -52,7 +54,7 @@ void FCogEngineWindow_DebugSettings::RenderContent() { if (ImGui::MenuItem("Reset")) { - FCogDebugSettings::Reset(); + FCogDebug::Reset(); } ImGui::Checkbox("Show Advanced Settings", &Config->bShowAdvancedSettings); @@ -63,109 +65,109 @@ void FCogEngineWindow_DebugSettings::RenderContent() ImGui::EndMenuBar(); } - Config->Data.bIsFilteringBySelection = FCogDebugSettings::GetIsFilteringBySelection(); + Config->Data.bIsFilteringBySelection = FCogDebug::GetIsFilteringBySelection(); if (ImGui::Checkbox("Filter by selection", &Config->Data.bIsFilteringBySelection)) { - FCogDebugSettings::SetIsFilteringBySelection(GetWorld(), Config->Data.bIsFilteringBySelection); + FCogDebug::SetIsFilteringBySelection(GetWorld(), Config->Data.bIsFilteringBySelection); } if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) { ImGui::SetTooltip("If checked, only show the debug of the currently selected actor. Otherwise show the debug of all actors."); } - FCogDebugData& Data = FCogDebugSettings::Data; + FCogDebugSettings& Settings = FCogDebug::Settings; - ImGui::Checkbox("Persistent", &Data.Persistent); + ImGui::Checkbox("Persistent", &Settings.Persistent); if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) { ImGui::SetTooltip("Make debug draw always persist"); } - ImGui::Checkbox("Text Shadow", &Data.TextShadow); + ImGui::Checkbox("Text Shadow", &Settings.TextShadow); if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) { ImGui::SetTooltip("Show a shadow below debug text."); } FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::Checkbox("Fade 2D", &Data.Fade2D); + ImGui::Checkbox("Fade 2D", &Settings.Fade2D); if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) { ImGui::SetTooltip("Does the 2D debug is fading out."); } FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Duration", &Data.Duration, 0.01f, 0.0f, 100.0f, "%.1f"); + ImGui::DragFloat("Duration", &Settings.Duration, 0.01f, 0.0f, 100.0f, "%.1f"); if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) { ImGui::SetTooltip("The duration of debug elements."); } FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Thickness", &Data.Thickness, 0.05f, 0.0f, 5.0f, "%.1f"); + ImGui::DragFloat("Thickness", &Settings.Thickness, 0.05f, 0.0f, 5.0f, "%.1f"); if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) { ImGui::SetTooltip("The thickness of debug lines."); } FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Server Thickness", &Data.ServerThickness, 0.05f, 0.0f, 5.0f, "%.1f"); + ImGui::DragFloat("Server Thickness", &Settings.ServerThickness, 0.05f, 0.0f, 5.0f, "%.1f"); if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) { ImGui::SetTooltip("The thickness the server debug lines."); } FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Server Color Mult", &Data.ServerColorMultiplier, 0.01f, 0.0f, 1.0f, "%.1f"); + ImGui::DragFloat("Server Color Mult", &Settings.ServerColorMultiplier, 0.01f, 0.0f, 1.0f, "%.1f"); if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) { ImGui::SetTooltip("The color multiplier applied to the server debug lines."); } FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragInt("Depth Priority", &Data.DepthPriority, 0.1f, 0, 100); + ImGui::DragInt("Depth Priority", &Settings.DepthPriority, 0.1f, 0, 100); if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) { ImGui::SetTooltip("The depth priority of debug elements."); } FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragInt("Segments", &Data.Segments, 0.1f, 4, 20.0f); + ImGui::DragInt("Segments", &Settings.Segments, 0.1f, 4, 20.0f); if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) { ImGui::SetTooltip("The number of segments used for circular shapes."); } FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Axes Scale", &Data.AxesScale, 0.1f, 0, 10.0f, "%.1f"); + ImGui::DragFloat("Axes Scale", &Settings.AxesScale, 0.1f, 0, 10.0f, "%.1f"); if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) { ImGui::SetTooltip("The scaling debug axis."); } FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Arrow Size", &Data.ArrowSize, 1.0f, 0.0f, 200.0f, "%.0f"); + ImGui::DragFloat("Arrow Size", &Settings.ArrowSize, 1.0f, 0.0f, 200.0f, "%.0f"); if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) { ImGui::SetTooltip("The size of debug arrows."); } FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Gradient Intensity", &Data.GradientColorIntensity, 0.01f, 0.0f, 1.0f, "%.2f"); + ImGui::DragFloat("Gradient Intensity", &Settings.GradientColorIntensity, 0.01f, 0.0f, 1.0f, "%.2f"); if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) { ImGui::SetTooltip("How much the debug elements color should be changed by a gradient color over time."); } FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Gradient Speed", &Data.GradientColorSpeed, 0.1f, 0.0f, 10.0f, "%.1f"); + ImGui::DragFloat("Gradient Speed", &Settings.GradientColorSpeed, 0.1f, 0.0f, 10.0f, "%.1f"); if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) { ImGui::SetTooltip("The speed of the gradient color change."); } FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Text Size", &Data.TextSize, 0.1f, 0.1f, 5.0f, "%.1f"); + ImGui::DragFloat("Text Size", &Settings.TextSize, 0.1f, 0.1f, 5.0f, "%.1f"); if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) { ImGui::SetTooltip("The size of the debug texts."); @@ -177,7 +179,7 @@ void FCogEngineWindow_DebugSettings::RenderContent() } FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Gizmo Scale", &Data.GizmoScale, 0.1f, 0.1f, 10.0f, "%.1f"); + ImGui::DragFloat("Gizmo Scale", &Settings.GizmoScale, 0.1f, 0.1f, 10.0f, "%.1f"); if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) { ImGui::SetTooltip("The scale of the gizmo."); @@ -186,57 +188,73 @@ void FCogEngineWindow_DebugSettings::RenderContent() if (Config->bShowAdvancedSettings) { FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Gizmo Axis Length", &Data.GizmoAxisLength, 0.1f, 0.1f, 500.0f, "%.1f"); + ImGui::DragFloat("Gizmo Axis Length", &Settings.GizmoAxisLength, 0.1f, 0.1f, 500.0f, "%.1f"); FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragInt("Gizmo Z Low", &Data.GizmoZLow, 0.5f, 0, 1000); + ImGui::DragInt("Gizmo Z Low", &Settings.GizmoZLow, 0.5f, 0, 1000); FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragInt("Gizmo Z High", &Data.GizmoZHigh, 0.5f, 0, 1000); + ImGui::DragInt("Gizmo Z High", &Settings.GizmoZHigh, 0.5f, 0, 1000); FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Gizmo Thickness Z Low", &Data.GizmoThicknessZLow, 0.1f, 0.0f, 10.0f, "%.1f"); + ImGui::DragFloat("Gizmo Thickness Z Low", &Settings.GizmoThicknessZLow, 0.1f, 0.0f, 10.0f, "%.1f"); FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Gizmo Thickness Z High", &Data.GizmoThicknessZHigh, 0.1f, 0.0f, 10.0f, "%.1f"); + ImGui::DragFloat("Gizmo Thickness Z High", &Settings.GizmoThicknessZHigh, 0.1f, 0.0f, 10.0f, "%.1f"); FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Gizmo Mouse Max Distance", &Data.GizmoMouseMaxDistance, 0.1f, 0.0f, 50.0f, "%.1f"); + ImGui::DragFloat("Gizmo Mouse Max Distance", &Settings.GizmoCursorSelectionThreshold, 0.1f, 0.0f, 50.0f, "%.1f"); FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Gizmo Plane Offset", &Data.GizmoPlaneOffset, 0.1f, 0.0f, 500.0f, "%.1f"); + ImGui::DragFloat("Gizmo Plane Offset", &Settings.GizmoPlaneOffset, 0.1f, 0.0f, 500.0f, "%.1f"); FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Gizmo Plane Extent", &Data.GizmoPlaneExtent, 0.1f, 0.0f, 100.0f, "%.1f"); + ImGui::DragFloat("Gizmo Plane Extent", &Settings.GizmoPlaneExtent, 0.1f, 0.0f, 100.0f, "%.1f"); FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Gizmo Scale Box Extent", &Data.GizmoScaleBoxExtent, 0.1f, 0.0f, 100.0f, "%.1f"); + ImGui::DragFloat("Gizmo Scale Box Extent", &Settings.GizmoScaleBoxExtent, 0.1f, 0.0f, 100.0f, "%.1f"); FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Gizmo Scale Speed", &Data.GizmoScaleSpeed, 0.1f, 0.0f, 100.0f, "%.1f"); + ImGui::DragFloat("Gizmo Scale Speed", &Settings.GizmoScaleSpeed, 0.01f, 0.01f, 100.0f, "%.2f"); FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Gizmo Scale Min", &Data.GizmoScaleMin, 0.001f, 0.001f, 1.0f, "%.3f"); + ImGui::DragFloat("Gizmo Scale Min", &Settings.GizmoScaleMin, 0.001f, 0.001f, 1.0f, "%.3f"); FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Gizmo Rotation Radius", &Data.GizmoRotationRadius, 0.1f, 0.1f, 500.0f, "%.1f"); + ImGui::DragFloat("Gizmo Rotation Radius", &Settings.GizmoRotationRadius, 0.1f, 0.1f, 500.0f, "%.1f"); FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragInt("Gizmo Rotation Segments", &Data.GizmoRotationSegments, 1.0f, 0, 64); + ImGui::DragInt("Gizmo Rotation Segments", &Settings.GizmoRotationSegments, 0.5f, 2, 12); - FCogWindowWidgets::ColorEdit4("Gizmo Axis Colors ZLow X", Data.GizmoAxisColorsZLowX, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); - FCogWindowWidgets::ColorEdit4("Gizmo Axis Colors ZLow Y", Data.GizmoAxisColorsZLowY, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); - FCogWindowWidgets::ColorEdit4("Gizmo Axis Colors ZLow Z", Data.GizmoAxisColorsZLowZ, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); - FCogWindowWidgets::ColorEdit4("Gizmo Axis Colors ZLow W", Data.GizmoAxisColorsZLowW, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragFloat("Gizmo Ground Raycast Length", &Settings.GizmoGroundRaycastLength, 10.0f, 0.0f, 1000000.0f, "%.0f"); - FCogWindowWidgets::ColorEdit4("Gizmo Axis Colors ZHigh X", Data.GizmoAxisColorsZHighX, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); - FCogWindowWidgets::ColorEdit4("Gizmo Axis Colors ZHigh Y", Data.GizmoAxisColorsZHighY, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); - FCogWindowWidgets::ColorEdit4("Gizmo Axis Colors ZHigh Z", Data.GizmoAxisColorsZHighZ, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); - FCogWindowWidgets::ColorEdit4("Gizmo Axis Colors ZHigh W", Data.GizmoAxisColorsZHighW, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); + FCogWindowWidgets::SetNextItemToShortWidth(); + ECollisionChannel Channel = Settings.GizmoGroundRaycastChannel.GetValue(); + if (FCogWindowWidgets::ComboCollisionChannel("Channel", Channel)) + { + Settings.GizmoGroundRaycastChannel = Channel; + } - FCogWindowWidgets::ColorEdit4("Gizmo Axis Colors Selection X", Data.GizmoAxisColorsSelectionX, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); - FCogWindowWidgets::ColorEdit4("Gizmo Axis Colors Selection Y", Data.GizmoAxisColorsSelectionY, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); - FCogWindowWidgets::ColorEdit4("Gizmo Axis Colors Selection Z", Data.GizmoAxisColorsSelectionZ, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); - FCogWindowWidgets::ColorEdit4("Gizmo Axis Colors Selection W", Data.GizmoAxisColorsSelectionW, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragFloat("Gizmo Ground Raycast Circle Radius", &Settings.GizmoGroundRaycastCircleRadius, 0.1f, 0.1f, 1000.0f, "%.1f"); + + FCogImguiHelper::ColorEdit4("Gizmo Axis Colors ZLow X", Settings.GizmoAxisColorsZLowX, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); + FCogImguiHelper::ColorEdit4("Gizmo Axis Colors ZLow Y", Settings.GizmoAxisColorsZLowY, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); + FCogImguiHelper::ColorEdit4("Gizmo Axis Colors ZLow Z", Settings.GizmoAxisColorsZLowZ, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); + FCogImguiHelper::ColorEdit4("Gizmo Axis Colors ZLow W", Settings.GizmoAxisColorsZLowW, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); + + FCogImguiHelper::ColorEdit4("Gizmo Axis Colors ZHigh X", Settings.GizmoAxisColorsZHighX, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); + FCogImguiHelper::ColorEdit4("Gizmo Axis Colors ZHigh Y", Settings.GizmoAxisColorsZHighY, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); + FCogImguiHelper::ColorEdit4("Gizmo Axis Colors ZHigh Z", Settings.GizmoAxisColorsZHighZ, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); + FCogImguiHelper::ColorEdit4("Gizmo Axis Colors ZHigh W", Settings.GizmoAxisColorsZHighW, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); + + FCogImguiHelper::ColorEdit4("Gizmo Axis Colors Selection X", Settings.GizmoAxisColorsSelectionX, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); + FCogImguiHelper::ColorEdit4("Gizmo Axis Colors Selection Y", Settings.GizmoAxisColorsSelectionY, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); + FCogImguiHelper::ColorEdit4("Gizmo Axis Colors Selection Z", Settings.GizmoAxisColorsSelectionZ, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); + FCogImguiHelper::ColorEdit4("Gizmo Axis Colors Selection W", Settings.GizmoAxisColorsSelectionW, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); + + FCogImguiHelper::ColorEdit4("Gizmo Ground Raycast Color", Settings.GizmoGroundRaycastColor, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); + FCogImguiHelper::ColorEdit4("Gizmo Ground Raycast Circle Color", Settings.GizmoGroundRaycastCircleColor, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); } } diff --git a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_LogCategories.cpp b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_LogCategories.cpp index 62e8ff4..7c13c02 100644 --- a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_LogCategories.cpp +++ b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_LogCategories.cpp @@ -1,7 +1,7 @@ #include "CogEngineWindow_LogCategories.h" #include "CogDebugHelper.h" -#include "CogDebugSettings.h" +#include "CogDebug.h" #include "CogWindowWidgets.h" #include "CogDebugLog.h" #include "DrawDebugHelpers.h" @@ -74,12 +74,12 @@ void FCogEngineWindow_LogCategories::RenderContent() ImGui::EndMenu(); } - bool bIsFilteringBySelection = FCogDebugSettings::GetIsFilteringBySelection(); + bool bIsFilteringBySelection = FCogDebug::GetIsFilteringBySelection(); ImGui::SetCursorPosY(ImGui::GetCursorPosY() + 2); FCogWindowWidgets::PushStyleCompact(); if (ImGui::Checkbox("Filter", &bIsFilteringBySelection)) { - FCogDebugSettings::SetIsFilteringBySelection(GetWorld(), bIsFilteringBySelection); + FCogDebug::SetIsFilteringBySelection(GetWorld(), bIsFilteringBySelection); } FCogWindowWidgets::PopStyleCompact(); diff --git a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Plots.cpp b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Plots.cpp index 2db6f41..f0749b1 100644 --- a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Plots.cpp +++ b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Plots.cpp @@ -82,7 +82,7 @@ void FCogEngineWindow_Plots::RenderMenu() { if (ImGui::BeginMenu("Options")) { - if (ImGui::MenuItem("Clear Data")) + if (ImGui::MenuItem("Clear Settings")) { FCogDebugPlot::Clear(); } diff --git a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Selection.cpp b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Selection.cpp index 61f8874..9165611 100644 --- a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Selection.cpp +++ b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Selection.cpp @@ -1,7 +1,7 @@ #include "CogEngineWindow_Selection.h" #include "CogDebugDraw.h" -#include "CogDebugSettings.h" +#include "CogDebug.h" #include "CogEngineReplicator.h" #include "CogImguiHelper.h" #include "CogImguiInputHelper.h" @@ -170,7 +170,7 @@ void FCogEngineWindow_Selection::RenderTick(float DeltaTime) { Super::RenderTick(DeltaTime); - if (FCogDebugSettings::GetSelection() == nullptr) + if (FCogDebug::GetSelection() == nullptr) { SetGlobalSelection(GetLocalPlayerPawn()); } @@ -265,7 +265,7 @@ bool FCogEngineWindow_Selection::DrawSelectionCombo() ImGui::PushStyleColor(ImGuiCol_Text, Actor == LocalPlayerPawn ? IM_COL32(255, 255, 0, 255) : IM_COL32(255, 255, 255, 255)); - bool bIsSelected = Actor == FCogDebugSettings::GetSelection(); + bool bIsSelected = Actor == FCogDebug::GetSelection(); if (ImGui::Selectable(TCHAR_TO_ANSI(*GetActorName(*Actor)), bIsSelected)) { SetGlobalSelection(Actor); @@ -417,7 +417,7 @@ void FCogEngineWindow_Selection::TickSelectionMode() // Prioritize another actor than the selected actor unless we only touch the selected actor. //-------------------------------------------------------------------------------------------------------- TArray IgnoreList; - IgnoreList.Add(FCogDebugSettings::GetSelection()); + IgnoreList.Add(FCogDebug::GetSelection()); FHitResult HitResult; for (int i = 0; i < 2; ++i) @@ -616,7 +616,7 @@ void FCogEngineWindow_Selection::RenderMainMenuWidget(int32 SubWidgetIndex, floa ImGui::EndPopup(); } - AActor* GlobalSelection = FCogDebugSettings::GetSelection(); + AActor* GlobalSelection = FCogDebug::GetSelection(); //----------------------------------- // Selection @@ -668,7 +668,7 @@ void FCogEngineWindow_Selection::RenderMainMenuWidget(int32 SubWidgetIndex, floa //-------------------------------------------------------------------------------------------------------------------------- void FCogEngineWindow_Selection::SetGlobalSelection(AActor* Value) const { - FCogDebugSettings::SetSelection(GetWorld(), Value); + FCogDebug::SetSelection(GetWorld(), Value); } //-------------------------------------------------------------------------------------------------------------------------- diff --git a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Skeleton.cpp b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Skeleton.cpp index 72582b8..99adaba 100644 --- a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Skeleton.cpp +++ b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Skeleton.cpp @@ -1,6 +1,6 @@ #include "CogEngineWindow_Skeleton.h" -#include "CogDebugSettings.h" +#include "CogDebug.h" #include "CogWindowWidgets.h" #include "Components/LineBatchComponent.h" #include "Components/SkeletalMeshComponent.h" @@ -80,7 +80,7 @@ void FCogEngineWindow_Skeleton::RefreshSkeleton() CurrentBoneInfo.Name = ReferenceSkeleton.GetBoneName(BoneIndex); const FTransform Transform = ComponentSpaceTransforms[BoneIndex] * WorldTransform; CurrentBoneInfo.LastLocation = Transform.GetLocation(); - CurrentBoneInfo.IsSecondaryBone = FCogDebugSettings::IsSecondarySkeletonBone(CurrentBoneInfo.Name); + CurrentBoneInfo.IsSecondaryBone = FCogDebug::IsSecondarySkeletonBone(CurrentBoneInfo.Name); CurrentBoneInfo.ShowBone = !(HideSecondaryBones && CurrentBoneInfo.IsSecondaryBone); const int32 ParentIndex = ReferenceSkeleton.GetParentIndex(BoneIndex); @@ -315,13 +315,13 @@ void FCogEngineWindow_Skeleton::DrawSkeleton() if (ShowBones) { - ::DrawDebugLine(World, ParentLocation, BoneLocation, IsHovered ? FColor::Red : FColor::White, false, 0.0f, 1, FCogDebugSettings::GetDebugThickness(IsHovered ? 0.5f : 0.0f)); - ::DrawDebugPoint(World, BoneLocation, FCogDebugSettings::GetDebugThickness(IsHovered ? 6.0f : 4.0f), IsHovered ? FColor::Red : FColor::White, false, 0.0f, 1); + ::DrawDebugLine(World, ParentLocation, BoneLocation, IsHovered ? FColor::Red : FColor::White, false, 0.0f, 1, FCogDebug::GetDebugThickness(IsHovered ? 0.5f : 0.0f)); + ::DrawDebugPoint(World, BoneLocation, FCogDebug::GetDebugThickness(IsHovered ? 6.0f : 4.0f), IsHovered ? FColor::Red : FColor::White, false, 0.0f, 1); } if (ShowNames || BoneInfo.ShowName || IsHovered) { - ::DrawDebugString(World, BoneLocation, BoneInfo.Name.ToString(), nullptr, IsHovered ? FColor::Red : FColor::White, 0.0f, true, FCogDebugSettings::Data.TextSize); + ::DrawDebugString(World, BoneLocation, BoneInfo.Name.ToString(), nullptr, IsHovered ? FColor::Red : FColor::White, 0.0f, true, FCogDebug::Settings.TextSize); } if (ShowAxes || BoneInfo.ShowAxes) @@ -330,11 +330,11 @@ void FCogEngineWindow_Skeleton::DrawSkeleton() World, BoneLocation, BoneRotation, - 10.0f * FCogDebugSettings::Data.AxesScale, + 10.0f * FCogDebug::Settings.AxesScale, false, 0.0f, 1, - FCogDebugSettings::GetDebugThickness(0.0f)); + FCogDebug::GetDebugThickness(0.0f)); } if (ShowVelocities || BoneInfo.ShowLocalVelocity) @@ -345,35 +345,35 @@ void FCogEngineWindow_Skeleton::DrawSkeleton() World, BoneLocation, BoneLocation + ParentBodyInstance->GetUnrealWorldVelocity() * World->GetDeltaSeconds(), - FCogDebugSettings::Data.ArrowSize, - FCogDebugSettings::ModulateDebugColor(World, FColor::Cyan), - FCogDebugSettings::GetDebugPersistent(true), - FCogDebugSettings::GetDebugDuration(true), + FCogDebug::Settings.ArrowSize, + FCogDebug::ModulateDebugColor(World, FColor::Cyan), + FCogDebug::GetDebugPersistent(true), + FCogDebug::GetDebugDuration(true), 0, - FCogDebugSettings::GetDebugThickness(0.0f)); + FCogDebug::GetDebugThickness(0.0f)); } } if (ShowTrajectories || BoneInfo.ShowTrajectory) { - const FColor Color = FCogDebugSettings::ModulateDebugColor(World, FColor::Yellow); + const FColor Color = FCogDebug::ModulateDebugColor(World, FColor::Yellow); DrawDebugLine( World, BoneInfo.LastLocation, BoneLocation, Color, - FCogDebugSettings::GetDebugPersistent(true), - FCogDebugSettings::GetDebugDuration(true), + FCogDebug::GetDebugPersistent(true), + FCogDebug::GetDebugDuration(true), 0, - FCogDebugSettings::GetDebugThickness(0.0f)); + FCogDebug::GetDebugThickness(0.0f)); DrawDebugPoint( World, BoneLocation, - FCogDebugSettings::GetDebugThickness(2.0f), + FCogDebug::GetDebugThickness(2.0f), Color, - FCogDebugSettings::GetDebugPersistent(true), - FCogDebugSettings::GetDebugDuration(true), + FCogDebug::GetDebugPersistent(true), + FCogDebug::GetDebugDuration(true), 0); } diff --git a/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_CollisionTester.h b/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_CollisionTester.h index b0994fd..9af2da4 100644 --- a/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_CollisionTester.h +++ b/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_CollisionTester.h @@ -12,16 +12,6 @@ class UCogEngineDataAsset; class UPrimitiveComponent; struct FCollisionShape; -//-------------------------------------------------------------------------------------------------------------------------- -UENUM() -enum class ECogEngine_CollisionQueryPlacement : uint8 -{ - Selection, - View, - Cursor, - Transform, -}; - //-------------------------------------------------------------------------------------------------------------------------- UENUM() enum class ECogEngine_CollisionQueryType : uint8 @@ -57,6 +47,9 @@ enum class ECogEngine_CollisionQueryShape : uint8 Capsule, }; + +enum class ECogDebug_GizmoTransformSpace : uint8; + //-------------------------------------------------------------------------------------------------------------------------- class COGENGINE_API FCogEngineWindow_CollisionTester : public FCogWindow { @@ -69,6 +62,7 @@ public: protected: virtual void ResetConfig() override; + void DoWork(const UCollisionProfile* CollisionProfile); virtual void RenderHelp() override; @@ -117,19 +111,16 @@ class UCogEngineConfig_CollisionTester : public UCogWindowConfig public: UPROPERTY(Config) - ECogEngine_CollisionQueryPlacement Placement; + FVector LocationStart; UPROPERTY(Config) - FVector3f LocationStart; + FVector LocationEnd; UPROPERTY(Config) - FVector3f LocationEnd; + FRotator Rotation; UPROPERTY(Config) - FRotator3f Rotation; - - UPROPERTY(Config) - FRotator3f Scale; + FVector Scale; UPROPERTY(Config) ECogEngine_CollisionQueryType Type; @@ -153,19 +144,13 @@ public: FName Profile; UPROPERTY(Config) - int32 Channel; + TEnumAsByte Channel; UPROPERTY(Config) int32 ProfileIndex; UPROPERTY(Config) - FVector3f ShapeExtent; - - UPROPERTY(Config) - int QueryTypeOld; - - UPROPERTY(Config) - float QueryLength; + FVector ShapeExtent; UPROPERTY(Config) bool DrawHitLocations; @@ -212,18 +197,16 @@ public: { Super::Reset(); - Placement = ECogEngine_CollisionQueryPlacement::Selection; Type = ECogEngine_CollisionQueryType::LineTrace; By = ECogEngine_CollisionQueryBy::Channel; - Shape = ECogEngine_CollisionQueryShape::Sphere; + Channel = ECC_WorldStatic; MultiHits = false; TraceComplex = false; - ShapeExtent = FVector3f(50.0f, 50.0f, 50.0f); + Shape = ECogEngine_CollisionQueryShape::Sphere; + ShapeExtent = FVector(50.0f, 50.0f, 50.0f); ObjectTypesToQuery = 0; ProfileIndex = 0; - QueryTypeOld = 0; - QueryLength = 5000.0f; DrawHitLocations = true; DrawHitImpactPoints = true; DrawHitShapes = true; diff --git a/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_DebugSettings.h b/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_DebugSettings.h index fc0ef60..7659803 100644 --- a/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_DebugSettings.h +++ b/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_DebugSettings.h @@ -1,7 +1,7 @@ #pragma once #include "CoreMinimal.h" -#include "CogDebugSettings.h" +#include "CogDebug.h" #include "CogWindow.h" #include "CogWindowConfig.h" #include "CogEngineWindow_DebugSettings.generated.h" @@ -39,7 +39,7 @@ class UCogEngineConfig_DebugSettings : public UCogWindowConfig public: UPROPERTY(Config) - FCogDebugData Data; + FCogDebugSettings Data; UPROPERTY(Config) bool bShowAdvancedSettings = false; @@ -47,7 +47,7 @@ public: virtual void Reset() override { Super::Reset(); - Data = FCogDebugData(); + Data = FCogDebugSettings(); bShowAdvancedSettings = false; } }; \ No newline at end of file diff --git a/Plugins/Cog/Source/CogImgui/Private/CogImguiHelper.cpp b/Plugins/Cog/Source/CogImgui/Private/CogImguiHelper.cpp index 89b7a10..6cd7440 100644 --- a/Plugins/Cog/Source/CogImgui/Private/CogImguiHelper.cpp +++ b/Plugins/Cog/Source/CogImgui/Private/CogImguiHelper.cpp @@ -145,4 +145,37 @@ void FCogImguiHelper::SetFlags(int32& Value, int32 Flags, bool EnableFlags) { Value &= ~Flags; } -} \ No newline at end of file +} + +//-------------------------------------------------------------------------------------------------------------------------- +bool FCogImguiHelper::DragDouble(const char* Label, double* Value, float Speed, double Min, double Max, const char* Format, ImGuiSliderFlags Flags) +{ + return ImGui::DragScalar(Label, ImGuiDataType_Double, Value, Speed, &Min, &Max, Format, Flags); +} + +//-------------------------------------------------------------------------------------------------------------------------- +bool FCogImguiHelper::DragFVector(const char* Label, FVector& Vector, float Speed, double Min, double Max, const char* Format, ImGuiSliderFlags Flags) +{ + return ImGui::DragScalarN(Label, ImGuiDataType_Double, &Vector.X, 3, Speed, &Min, &Max, Format, Flags); +} + +//-------------------------------------------------------------------------------------------------------------------------- +bool FCogImguiHelper::DragFRotator(const char* Label, FRotator& Rotator, float Speed, double Min, double Max, const char* Format, ImGuiSliderFlags Flags) +{ + return ImGui::DragScalarN(Label, ImGuiDataType_Double, &Rotator.Pitch, 3, Speed, &Min, &Max, Format, Flags); +} + +//-------------------------------------------------------------------------------------------------------------------------- +bool FCogImguiHelper::DragFVector2D(const char* Label, FVector2D& Vector, float Speed, double Min, double Max, const char* Format, ImGuiSliderFlags Flags) +{ + return ImGui::DragScalarN(Label, ImGuiDataType_Double, &Vector.X, 2, Speed, &Min, &Max, Format, Flags); +} + +//-------------------------------------------------------------------------------------------------------------------------- +bool FCogImguiHelper::ColorEdit4(const char* Label, FColor& Color, ImGuiColorEditFlags Flags) +{ + FLinearColor Linear(Color); + const bool Result = ImGui::ColorEdit4(Label, &Linear.R, Flags); + Color = Linear.ToFColor(true); + return Result; +} diff --git a/Plugins/Cog/Source/CogImgui/Private/CogImguiWidget.cpp b/Plugins/Cog/Source/CogImgui/Private/CogImguiWidget.cpp index 1e86d03..67b0643 100644 --- a/Plugins/Cog/Source/CogImgui/Private/CogImguiWidget.cpp +++ b/Plugins/Cog/Source/CogImgui/Private/CogImguiWidget.cpp @@ -124,17 +124,17 @@ FReply SCogImguiWidget::OnKeyChar(const FGeometry& MyGeometry, const FCharacterE //-------------------------------------------------------------------------------------------------------------------------- FReply SCogImguiWidget::OnKeyDown(const FGeometry& MyGeometry, const FKeyEvent& KeyEvent) { - return HandleKeyEvent(MyGeometry, KeyEvent, true); + return HandleKeyEvent(KeyEvent, true); } //-------------------------------------------------------------------------------------------------------------------------- FReply SCogImguiWidget::OnKeyUp(const FGeometry& MyGeometry, const FKeyEvent& KeyEvent) { - return HandleKeyEvent(MyGeometry, KeyEvent, false); + return HandleKeyEvent(KeyEvent, false); } //-------------------------------------------------------------------------------------------------------------------------- -FReply SCogImguiWidget::HandleKeyEvent(const FGeometry& MyGeometry, const FKeyEvent& KeyEvent, bool Down) +FReply SCogImguiWidget::HandleKeyEvent(const FKeyEvent& KeyEvent, bool Down) { if (Context->GetEnableInput() == false) { @@ -189,31 +189,34 @@ FReply SCogImguiWidget::OnAnalogValueChanged(const FGeometry& MyGeometry, const //-------------------------------------------------------------------------------------------------------------------------- FReply SCogImguiWidget::OnMouseButtonDown(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) { - if (Context->GetEnableInput() == false) - { - UE_LOG(LogCogImGui, VeryVerbose, TEXT("SCogImguiWidget::OnMouseButtonDown | %s | Unhandled | EnableInput == false"), Window.IsValid() ? *Window->GetTitle().ToString() : *FString("None")); - return FReply::Unhandled(); - } - const uint32 MouseButton = FCogImguiInputHelper::ToImGuiMouseButton(MouseEvent.GetEffectingButton()); - ImGui::GetIO().AddMouseSourceEvent(ImGuiMouseSource_Mouse); - ImGui::GetIO().AddMouseButtonEvent(MouseButton, true); + return HandleMouseButtonEvent(MouseEvent, true); +} - UE_LOG(LogCogImGui, VeryVerbose, TEXT("SCogImguiWidget::OnMouseButtonDown | Window:%s | Handled"), Window.IsValid() ? *Window->GetTitle().ToString() : *FString("None")); - return FReply::Handled(); +//-------------------------------------------------------------------------------------------------------------------------- +FReply SCogImguiWidget::OnMouseButtonDoubleClick(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) +{ + return HandleMouseButtonEvent(MouseEvent, true); } //-------------------------------------------------------------------------------------------------------------------------- FReply SCogImguiWidget::OnMouseButtonUp(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) +{ + return HandleMouseButtonEvent(MouseEvent, false); +} + +//-------------------------------------------------------------------------------------------------------------------------- +FReply SCogImguiWidget::HandleMouseButtonEvent(const FPointerEvent& MouseEvent, bool Down) { if (Context->GetEnableInput() == false) { - UE_LOG(LogCogImGui, VeryVerbose, TEXT("SCogImguiWidget::OnMouseButtonUp | Window:%s | Unhandled | EnableInput == false"), Window.IsValid() ? *Window->GetTitle().ToString() : *FString("None")); + UE_LOG(LogCogImGui, VeryVerbose, TEXT("SCogImguiWidget::HandleMouseButtonEvent | %s | Unhandled | EnableInput == false | Down:%d"), Window.IsValid() ? *Window->GetTitle().ToString() : *FString("None"), Down); return FReply::Unhandled(); } const uint32 MouseButton = FCogImguiInputHelper::ToImGuiMouseButton(MouseEvent.GetEffectingButton()); ImGui::GetIO().AddMouseSourceEvent(ImGuiMouseSource_Mouse); - ImGui::GetIO().AddMouseButtonEvent(MouseButton, false); - UE_LOG(LogCogImGui, VeryVerbose, TEXT("SCogImguiWidget::OnMouseButtonUp | Window:%s | Handled"), Window.IsValid() ? *Window->GetTitle().ToString() : *FString("None")); + ImGui::GetIO().AddMouseButtonEvent(MouseButton, Down); + + UE_LOG(LogCogImGui, VeryVerbose, TEXT("SCogImguiWidget::HandleMouseButtonEvent | Window:%s | Handled | Down:%d"), Window.IsValid() ? *Window->GetTitle().ToString() : *FString("None"), Down); return FReply::Handled(); } diff --git a/Plugins/Cog/Source/CogImgui/Public/CogImguiHelper.h b/Plugins/Cog/Source/CogImgui/Public/CogImguiHelper.h index 49f9c24..d360cee 100644 --- a/Plugins/Cog/Source/CogImgui/Public/CogImguiHelper.h +++ b/Plugins/Cog/Source/CogImgui/Public/CogImguiHelper.h @@ -57,4 +57,14 @@ public: static FSlateRenderTransform RoundTranslation(const FSlateRenderTransform& Transform); static void SetFlags(int32& Value, int32 Flags, bool EnableFlags); + + static bool DragDouble(const char* Label, double* Value, float Speed = 1.0f, double Min = 0.0f, double Max = 0.0f, const char* Format = "%.3f", ImGuiSliderFlags Flags = 0); + + static bool DragFVector(const char* Label, FVector& Vector, float Speed = 1.0f, double Min = 0.0f, double Max = 0.0f, const char* Format = "%.3f", ImGuiSliderFlags Flags = 0); + + static bool DragFRotator(const char* Label, FRotator& Rotator, float Speed = 1.0f, double Min = 0.0f, double Max = 0.0f, const char* Format = "%.3f", ImGuiSliderFlags Flags = 0); + + static bool DragFVector2D(const char* Label, FVector2D& Vector, float Speed = 1.0f, double Min = 0.0f, double Max = 0.0f, const char* Format = "%.3f", ImGuiSliderFlags Flags = 0); + + static bool ColorEdit4(const char* Label, FColor& Color, ImGuiColorEditFlags Flags = 0); }; diff --git a/Plugins/Cog/Source/CogImgui/Public/CogImguiWidget.h b/Plugins/Cog/Source/CogImgui/Public/CogImguiWidget.h index d443ab4..3079b7f 100644 --- a/Plugins/Cog/Source/CogImgui/Public/CogImguiWidget.h +++ b/Plugins/Cog/Source/CogImgui/Public/CogImguiWidget.h @@ -40,6 +40,7 @@ public: virtual FReply OnKeyUp(const FGeometry& MyGeometry, const FKeyEvent& KeyEvent) override; virtual FReply OnAnalogValueChanged(const FGeometry& MyGeometry, const FAnalogInputEvent& AnalogInputEvent) override; virtual FReply OnMouseButtonDown(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override; + virtual FReply OnMouseButtonDoubleClick(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override; virtual FReply OnMouseButtonUp(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override; virtual FReply OnMouseWheel(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override; virtual FReply OnMouseMove(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override; @@ -53,7 +54,8 @@ public: protected: - FReply HandleKeyEvent(const FGeometry& MyGeometry, const FKeyEvent& KeyEvent, bool Down); + FReply HandleKeyEvent(const FKeyEvent& KeyEvent, bool Down); + FReply HandleMouseButtonEvent(const FPointerEvent& MouseEvent, bool Down); void RefreshVisibility(); diff --git a/Plugins/Cog/Source/CogWindow/Private/CogWindow.cpp b/Plugins/Cog/Source/CogWindow/Private/CogWindow.cpp index 33fb22a..7637102 100644 --- a/Plugins/Cog/Source/CogWindow/Private/CogWindow.cpp +++ b/Plugins/Cog/Source/CogWindow/Private/CogWindow.cpp @@ -1,7 +1,7 @@ #include "CogWindow.h" #include "CogDebugDraw.h" -#include "CogDebugSettings.h" +#include "CogDebug.h" #include "CogWindow_Settings.h" #include "CogWindowManager.h" #include "CogWindowWidgets.h" @@ -137,7 +137,7 @@ void FCogWindow::RenderHelp() //-------------------------------------------------------------------------------------------------------------------------- void FCogWindow::RenderTick(float DeltaTime) { - SetSelection(FCogDebugSettings::GetSelection()); + SetSelection(FCogDebug::GetSelection()); } //-------------------------------------------------------------------------------------------------------------------------- diff --git a/Plugins/Cog/Source/CogWindow/Private/CogWindowWidgets.cpp b/Plugins/Cog/Source/CogWindow/Private/CogWindowWidgets.cpp index 4febc36..8c41b15 100644 --- a/Plugins/Cog/Source/CogWindow/Private/CogWindowWidgets.cpp +++ b/Plugins/Cog/Source/CogWindow/Private/CogWindowWidgets.cpp @@ -614,22 +614,37 @@ bool FCogWindowWidgets::MultiChoiceButtonsFloat(TArray& Values, float& Va } //-------------------------------------------------------------------------------------------------------------------------- -bool FCogWindowWidgets::DragFVector(const char* Label, FVector& Vector, float Speed, float Min, float Max, const char* Format, ImGuiSliderFlags Flags) +bool FCogWindowWidgets::ComboCollisionChannel(const char* Label, ECollisionChannel& Channel) { - return ImGui::DragScalarN(Label, ImGuiDataType_Double, &Vector.X, 3, Speed, &Min, &Max, Format, Flags); -} + FName SelectedChannelName; + const UCollisionProfile* CollisionProfile = UCollisionProfile::Get(); + if (CollisionProfile != nullptr) + { + SelectedChannelName = CollisionProfile->ReturnChannelNameFromContainerIndex(Channel); + } -//-------------------------------------------------------------------------------------------------------------------------- -bool FCogWindowWidgets::DragFVector2D(const char* Label, FVector2D& Vector, float Speed, float Min, float Max, const char* Format, ImGuiSliderFlags Flags) -{ - return ImGui::DragScalarN(Label, ImGuiDataType_Double, &Vector.X, 2, Speed, &Min, &Max, Format, Flags); -} + bool Result = false; + if (ImGui::BeginCombo(Label, TCHAR_TO_ANSI(*SelectedChannelName.ToString()), ImGuiComboFlags_HeightLarge)) + { + for (int32 ChannelIndex = 0; ChannelIndex < (int32)ECC_MAX; ++ChannelIndex) + { + ImGui::PushID(ChannelIndex); + + const FName ChannelName = CollisionProfile->ReturnChannelNameFromContainerIndex(ChannelIndex); + + if (ChannelName.IsValid()) + { + if (ImGui::Selectable(TCHAR_TO_ANSI(*ChannelName.ToString()))) + { + Channel = (ECollisionChannel)ChannelIndex; + Result = true; + } + } + + ImGui::PopID(); + } + ImGui::EndCombo(); + } -//-------------------------------------------------------------------------------------------------------------------------- -bool FCogWindowWidgets::ColorEdit4(const char* Label, FColor& Color, ImGuiColorEditFlags Flags) -{ - FLinearColor Linear(Color); - const bool Result = ImGui::ColorEdit4(Label, &Linear.R, Flags); - Color = Linear.ToFColor(true); return Result; } \ No newline at end of file diff --git a/Plugins/Cog/Source/CogWindow/Public/CogWindowWidgets.h b/Plugins/Cog/Source/CogWindow/Public/CogWindowWidgets.h index dc2a095..c167ab7 100644 --- a/Plugins/Cog/Source/CogWindow/Public/CogWindowWidgets.h +++ b/Plugins/Cog/Source/CogWindow/Public/CogWindowWidgets.h @@ -20,12 +20,6 @@ public: static void EndTableTooltip(); - static bool DragFVector(const char* Label, FVector& Vector, float Speed = 1.0f, float Min = 0.0f, float Max = 0.0f, const char* Format = "%.3f", ImGuiSliderFlags Flags = 0); - - static bool DragFVector2D(const char* Label, FVector2D& Vector, float Speed = 1.0f, float Min = 0.0f, float Max = 0.0f, const char* Format = "%.3f", ImGuiSliderFlags Flags = 0); - - static bool ColorEdit4(const char* Label, FColor& Color, ImGuiColorEditFlags Flags = 0); - static void ProgressBarCentered(float Fraction, const ImVec2& Size, const char* Overlay); static bool ToggleMenuButton(bool* Value, const char* Text, const ImVec4& TrueColor); @@ -86,6 +80,9 @@ public: static bool DeleteArrayItemButton(); + static bool ComboCollisionChannel(const char* Label, ECollisionChannel& Channel); + + }; template diff --git a/Source/CogSample/CogSampleAreaComponent.cpp b/Source/CogSample/CogSampleAreaComponent.cpp index caf0dcc..5eb2955 100644 --- a/Source/CogSample/CogSampleAreaComponent.cpp +++ b/Source/CogSample/CogSampleAreaComponent.cpp @@ -154,7 +154,7 @@ void UCogSampleAreaComponent::TickComponent(float DeltaTime, enum ELevelTick Tic #if ENABLE_COG const AActor* AreaInstigator = UCogSampleFunctionLibrary_Gameplay::GetInstigator(GetOwner()); - if (FCogDebugLog::IsLogCategoryActive(LogCogArea) && FCogDebugSettings::IsDebugActiveForObject(AreaInstigator)) + if (FCogDebugLog::IsLogCategoryActive(LogCogArea) && FCogDebug::IsDebugActiveForObject(AreaInstigator)) { TArray> Components; GetOwner()->GetComponents(Components); diff --git a/Source/CogSample/CogSampleCharacter.cpp b/Source/CogSample/CogSampleCharacter.cpp index 1f1fe62..db0627f 100644 --- a/Source/CogSample/CogSampleCharacter.cpp +++ b/Source/CogSample/CogSampleCharacter.cpp @@ -677,7 +677,7 @@ void ACogSampleCharacter::OnGhostTagNewOrRemoved(const FGameplayTag InTag, int32 void ACogSampleCharacter::OnScaleAttributeChanged(const FOnAttributeChangeData& Data) { //---------------------------------------------------------------------------------- - // 'Data.NewValue' is not used because it seems to only corresponds to the changes + // 'Settings.NewValue' is not used because it seems to only corresponds to the changes // of the BaseValue which do not account for the temporary modifiers. //---------------------------------------------------------------------------------- diff --git a/Source/CogSample/CogSampleCharacterMovementComponent.cpp b/Source/CogSample/CogSampleCharacterMovementComponent.cpp index 116faac..0faf51a 100644 --- a/Source/CogSample/CogSampleCharacterMovementComponent.cpp +++ b/Source/CogSample/CogSampleCharacterMovementComponent.cpp @@ -224,7 +224,7 @@ void UCogSampleCharacterMovementComponent::TickComponent(float DeltaTime, enum E const ACharacter* Character = GetCharacterOwner(); const UCapsuleComponent* CapsuleComponent = Character->GetCapsuleComponent(); - if (FCogDebugSettings::IsDebugActiveForObject(GetPawnOwner())) + if (FCogDebug::IsDebugActiveForObject(GetPawnOwner())) { FCogDebugPlot::PlotValue(GetPawnOwner(), "Move Input X", GetPendingInputVector().X); FCogDebugPlot::PlotValue(GetPawnOwner(), "Move Input Y", GetPendingInputVector().Y); @@ -241,7 +241,7 @@ void UCogSampleCharacterMovementComponent::TickComponent(float DeltaTime, enum E const FVector DebugLocation = Character->GetActorLocation(); const FVector DebugBottomLocation = DebugLocation - FVector::UpVector * CapsuleComponent->GetScaledCapsuleHalfHeight(); - if (FCogDebugSettings::IsDebugActiveForObject(GetPawnOwner())) + if (FCogDebug::IsDebugActiveForObject(GetPawnOwner())) { const FRotator Rotation = Character->GetActorRotation(); const FVector Forward = Character->GetActorForwardVector(); diff --git a/Source/CogSample/CogSampleDefines.h b/Source/CogSample/CogSampleDefines.h index b0c560a..1fe07fe 100644 --- a/Source/CogSample/CogSampleDefines.h +++ b/Source/CogSample/CogSampleDefines.h @@ -5,13 +5,13 @@ #if ENABLE_COG -#include "CogDebugSettings.h" +#include "CogDebug.h" #define COG_LOG_ABILITY(Verbosity, Ability, Format, ...) \ if (Ability != nullptr) \ { \ AActor* Actor = Ability->GetAvatarActorFromActorInfo(); \ - if (FCogDebugSettings::IsDebugActiveForObject(Actor) || (int32)Verbosity <= (int32)ELogVerbosity::Warning) \ + if (FCogDebug::IsDebugActiveForObject(Actor) || (int32)Verbosity <= (int32)ELogVerbosity::Warning) \ { \ COG_LOG(LogCogAbility, Verbosity, TEXT("%s - %s - %s - %s"), \ *GetNameSafe(Actor), \ diff --git a/Source/CogSample/CogSampleGameplayAbility.cpp b/Source/CogSample/CogSampleGameplayAbility.cpp index 538f748..c238d36 100644 --- a/Source/CogSample/CogSampleGameplayAbility.cpp +++ b/Source/CogSample/CogSampleGameplayAbility.cpp @@ -197,7 +197,7 @@ bool UCogSampleGameplayAbility::IsCostGameplayEffectIsZero(const UGameplayEffect const float CostValue = ModSpec.GetEvaluatedMagnitude(); //---------------------------------------------------------------------------------------------- - // The Cost in the Data is positive, but UCogSampleModifierCalculation_Cost negates it. + // The Cost in the Settings is positive, but UCogSampleModifierCalculation_Cost negates it. // Therefore a cost less than zero is an actual cost, and a cost of 0 or greater can be ignored //---------------------------------------------------------------------------------------------- if (CostValue < 0) From dd20cff959f08b0f1f0b200c7774dcbcf566c351 Mon Sep 17 00:00:00 2001 From: Arnaud Jamin Date: Sat, 30 Dec 2023 01:28:01 -0500 Subject: [PATCH 4/8] CogEngine: improve collision tester --- Config/DefaultEngine.ini | 29 +- Plugins/Cog/Source/CogDebug/Public/CogDebug.h | 2 +- .../CogEngineWindow_CollisionTester.cpp | 393 +++++++++++------- .../CogEngine/Public/CogEngineDataAsset.h | 2 +- .../Public/CogEngineWindow_CollisionTester.h | 15 +- .../CogWindow/Private/CogWindowWidgets.cpp | 39 ++ .../CogWindow/Public/CogWindowWidgets.h | 3 + 7 files changed, 318 insertions(+), 165 deletions(-) diff --git a/Config/DefaultEngine.ini b/Config/DefaultEngine.ini index b6b8052..baf6d99 100644 --- a/Config/DefaultEngine.ini +++ b/Config/DefaultEngine.ini @@ -88,35 +88,37 @@ ManualIPAddress= -Profiles=(Name="Vehicle",CollisionEnabled=QueryAndPhysics,ObjectTypeName="Vehicle",CustomResponses=,HelpMessage="Vehicle object that blocks Vehicle, WorldStatic, and WorldDynamic. All other channels will be set to default.",bCanModify=False) -Profiles=(Name="UI",CollisionEnabled=QueryOnly,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="WorldStatic",Response=ECR_Overlap),(Channel="Pawn",Response=ECR_Overlap),(Channel="Visibility",Response=ECR_Block),(Channel="WorldDynamic",Response=ECR_Overlap),(Channel="Camera",Response=ECR_Overlap),(Channel="PhysicsBody",Response=ECR_Overlap),(Channel="Vehicle",Response=ECR_Overlap),(Channel="Destructible",Response=ECR_Overlap)),HelpMessage="WorldStatic object that overlaps all actors by default. All new custom channels will use its own default response. ",bCanModify=False) +Profiles=(Name="NoCollision",CollisionEnabled=NoCollision,bCanModify=False,ObjectTypeName="WorldStatic",CustomResponses=((Channel="Visibility",Response=ECR_Ignore),(Channel="Camera",Response=ECR_Ignore)),HelpMessage="No collision") -+Profiles=(Name="BlockAll",CollisionEnabled=QueryAndPhysics,bCanModify=False,ObjectTypeName="WorldStatic",CustomResponses=,HelpMessage="WorldStatic object that blocks all actors by default. All new custom channels will use its own default response. ") -+Profiles=(Name="OverlapAll",CollisionEnabled=QueryOnly,bCanModify=False,ObjectTypeName="WorldStatic",CustomResponses=((Channel="WorldStatic",Response=ECR_Overlap),(Channel="Pawn",Response=ECR_Overlap),(Channel="Visibility",Response=ECR_Overlap),(Channel="WorldDynamic",Response=ECR_Overlap),(Channel="Camera",Response=ECR_Overlap),(Channel="PhysicsBody",Response=ECR_Overlap),(Channel="Vehicle",Response=ECR_Overlap),(Channel="Destructible",Response=ECR_Overlap)),HelpMessage="WorldStatic object that overlaps all actors by default. All new custom channels will use its own default response. ") -+Profiles=(Name="BlockAllDynamic",CollisionEnabled=QueryAndPhysics,bCanModify=False,ObjectTypeName="WorldDynamic",CustomResponses=,HelpMessage="WorldDynamic object that blocks all actors by default. All new custom channels will use its own default response. ") -+Profiles=(Name="OverlapAllDynamic",CollisionEnabled=QueryOnly,bCanModify=False,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="WorldStatic",Response=ECR_Overlap),(Channel="Pawn",Response=ECR_Overlap),(Channel="Visibility",Response=ECR_Overlap),(Channel="WorldDynamic",Response=ECR_Overlap),(Channel="Camera",Response=ECR_Overlap),(Channel="PhysicsBody",Response=ECR_Overlap),(Channel="Vehicle",Response=ECR_Overlap),(Channel="Destructible",Response=ECR_Overlap)),HelpMessage="WorldDynamic object that overlaps all actors by default. All new custom channels will use its own default response. ") -+Profiles=(Name="IgnoreOnlyPawn",CollisionEnabled=QueryOnly,bCanModify=False,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="Pawn",Response=ECR_Ignore),(Channel="Vehicle",Response=ECR_Ignore)),HelpMessage="WorldDynamic object that ignores Pawn and Vehicle. All other channels will be set to default.") -+Profiles=(Name="OverlapOnlyPawn",CollisionEnabled=QueryOnly,bCanModify=False,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="Pawn",Response=ECR_Overlap),(Channel="Vehicle",Response=ECR_Overlap),(Channel="Camera",Response=ECR_Ignore)),HelpMessage="WorldDynamic object that overlaps Pawn, Camera, and Vehicle. All other channels will be set to default. ") -+Profiles=(Name="Pawn",CollisionEnabled=QueryAndPhysics,bCanModify=False,ObjectTypeName="Pawn",CustomResponses=((Channel="Visibility",Response=ECR_Ignore)),HelpMessage="Pawn object. Can be used for capsule of any playerable character or AI. ") -+Profiles=(Name="Spectator",CollisionEnabled=QueryOnly,bCanModify=False,ObjectTypeName="Pawn",CustomResponses=((Channel="WorldStatic"),(Channel="Pawn",Response=ECR_Ignore),(Channel="Visibility",Response=ECR_Ignore),(Channel="WorldDynamic",Response=ECR_Ignore),(Channel="Camera",Response=ECR_Ignore),(Channel="PhysicsBody",Response=ECR_Ignore),(Channel="Vehicle",Response=ECR_Ignore),(Channel="Destructible",Response=ECR_Ignore)),HelpMessage="Pawn object that ignores all other actors except WorldStatic.") -+Profiles=(Name="CharacterMesh",CollisionEnabled=QueryOnly,bCanModify=False,ObjectTypeName="CharacterMesh",CustomResponses=((Channel="Pawn",Response=ECR_Ignore),(Channel="Vehicle",Response=ECR_Ignore),(Channel="Visibility",Response=ECR_Ignore)),HelpMessage="Pawn object that is used for Character Mesh. All other channels will be set to default.") ++Profiles=(Name="BlockAll",CollisionEnabled=QueryAndPhysics,bCanModify=False,ObjectTypeName="WorldStatic",CustomResponses=((Channel="Projectile")),HelpMessage="WorldStatic object that blocks all actors by default. All new custom channels will use its own default response. ") ++Profiles=(Name="OverlapAll",CollisionEnabled=QueryOnly,bCanModify=False,ObjectTypeName="WorldStatic",CustomResponses=((Channel="WorldStatic",Response=ECR_Overlap),(Channel="WorldDynamic",Response=ECR_Overlap),(Channel="Pawn",Response=ECR_Overlap),(Channel="Visibility",Response=ECR_Overlap),(Channel="Camera",Response=ECR_Overlap),(Channel="PhysicsBody",Response=ECR_Overlap),(Channel="Vehicle",Response=ECR_Overlap),(Channel="Destructible",Response=ECR_Overlap),(Channel="Projectile",Response=ECR_Overlap)),HelpMessage="WorldStatic object that overlaps all actors by default. All new custom channels will use its own default response. ") ++Profiles=(Name="BlockAllDynamic",CollisionEnabled=QueryAndPhysics,bCanModify=False,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="Projectile")),HelpMessage="WorldDynamic object that blocks all actors by default. All new custom channels will use its own default response. ") ++Profiles=(Name="OverlapAllDynamic",CollisionEnabled=QueryOnly,bCanModify=False,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="WorldStatic",Response=ECR_Overlap),(Channel="WorldDynamic",Response=ECR_Overlap),(Channel="Pawn",Response=ECR_Overlap),(Channel="Visibility",Response=ECR_Overlap),(Channel="Camera",Response=ECR_Overlap),(Channel="PhysicsBody",Response=ECR_Overlap),(Channel="Vehicle",Response=ECR_Overlap),(Channel="Destructible",Response=ECR_Overlap),(Channel="Projectile",Response=ECR_Overlap)),HelpMessage="WorldDynamic object that overlaps all actors by default. All new custom channels will use its own default response. ") ++Profiles=(Name="IgnoreOnlyPawn",CollisionEnabled=QueryOnly,bCanModify=False,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="Pawn",Response=ECR_Ignore),(Channel="Vehicle",Response=ECR_Ignore),(Channel="Projectile")),HelpMessage="WorldDynamic object that ignores Pawn and Vehicle. All other channels will be set to default.") ++Profiles=(Name="OverlapOnlyPawn",CollisionEnabled=QueryOnly,bCanModify=False,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="Pawn",Response=ECR_Overlap),(Channel="Camera",Response=ECR_Ignore),(Channel="Vehicle",Response=ECR_Overlap),(Channel="Projectile")),HelpMessage="WorldDynamic object that overlaps Pawn, Camera, and Vehicle. All other channels will be set to default. ") ++Profiles=(Name="Pawn",CollisionEnabled=QueryAndPhysics,bCanModify=False,ObjectTypeName="Pawn",CustomResponses=((Channel="Visibility",Response=ECR_Ignore),(Channel="Camera",Response=ECR_Ignore)),HelpMessage="Pawn object. Can be used for capsule of any playerable character or AI. ") ++Profiles=(Name="Spectator",CollisionEnabled=QueryOnly,bCanModify=False,ObjectTypeName="Pawn",CustomResponses=((Channel="WorldDynamic",Response=ECR_Ignore),(Channel="Pawn",Response=ECR_Ignore),(Channel="Visibility",Response=ECR_Ignore),(Channel="Camera",Response=ECR_Ignore),(Channel="PhysicsBody",Response=ECR_Ignore),(Channel="Vehicle",Response=ECR_Ignore),(Channel="Destructible",Response=ECR_Ignore)),HelpMessage="Pawn object that ignores all other actors except WorldStatic.") ++Profiles=(Name="CharacterMesh",CollisionEnabled=QueryOnly,bCanModify=False,ObjectTypeName="CharacterMesh",CustomResponses=((Channel="Pawn",Response=ECR_Ignore),(Channel="Visibility",Response=ECR_Ignore),(Channel="Camera",Response=ECR_Ignore),(Channel="Vehicle",Response=ECR_Ignore),(Channel="Projectile",Response=ECR_Overlap)),HelpMessage="Pawn object that is used for Character Mesh. All other channels will be set to default.") +Profiles=(Name="PhysicsActor",CollisionEnabled=QueryAndPhysics,bCanModify=False,ObjectTypeName="PhysicsBody",CustomResponses=,HelpMessage="Simulating actors") +Profiles=(Name="Destructible",CollisionEnabled=QueryAndPhysics,bCanModify=False,ObjectTypeName="Destructible",CustomResponses=,HelpMessage="Destructible actors") +Profiles=(Name="InvisibleWall",CollisionEnabled=QueryAndPhysics,bCanModify=False,ObjectTypeName="WorldStatic",CustomResponses=((Channel="Visibility",Response=ECR_Ignore)),HelpMessage="WorldStatic object that is invisible.") +Profiles=(Name="InvisibleWallDynamic",CollisionEnabled=QueryAndPhysics,bCanModify=False,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="Visibility",Response=ECR_Ignore)),HelpMessage="WorldDynamic object that is invisible.") -+Profiles=(Name="Trigger",CollisionEnabled=QueryOnly,bCanModify=False,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="WorldStatic",Response=ECR_Overlap),(Channel="Pawn",Response=ECR_Overlap),(Channel="Visibility",Response=ECR_Ignore),(Channel="WorldDynamic",Response=ECR_Overlap),(Channel="Camera",Response=ECR_Overlap),(Channel="PhysicsBody",Response=ECR_Overlap),(Channel="Vehicle",Response=ECR_Overlap),(Channel="Destructible",Response=ECR_Overlap)),HelpMessage="WorldDynamic object that is used for trigger. All other channels will be set to default.") ++Profiles=(Name="Trigger",CollisionEnabled=QueryOnly,bCanModify=False,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="WorldStatic",Response=ECR_Overlap),(Channel="WorldDynamic",Response=ECR_Overlap),(Channel="Pawn",Response=ECR_Overlap),(Channel="Visibility",Response=ECR_Ignore),(Channel="Camera",Response=ECR_Overlap),(Channel="PhysicsBody",Response=ECR_Overlap),(Channel="Vehicle",Response=ECR_Overlap),(Channel="Destructible",Response=ECR_Overlap)),HelpMessage="WorldDynamic object that is used for trigger. All other channels will be set to default.") +Profiles=(Name="Ragdoll",CollisionEnabled=QueryAndPhysics,bCanModify=False,ObjectTypeName="PhysicsBody",CustomResponses=((Channel="Pawn",Response=ECR_Ignore),(Channel="Visibility",Response=ECR_Ignore)),HelpMessage="Simulating Skeletal Mesh Component. All other channels will be set to default.") +Profiles=(Name="Vehicle",CollisionEnabled=QueryAndPhysics,bCanModify=False,ObjectTypeName="Vehicle",CustomResponses=,HelpMessage="Vehicle object that blocks Vehicle, WorldStatic, and WorldDynamic. All other channels will be set to default.") -+Profiles=(Name="UI",CollisionEnabled=QueryOnly,bCanModify=False,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="WorldStatic",Response=ECR_Overlap),(Channel="Pawn",Response=ECR_Overlap),(Channel="Visibility"),(Channel="WorldDynamic",Response=ECR_Overlap),(Channel="Camera",Response=ECR_Overlap),(Channel="PhysicsBody",Response=ECR_Overlap),(Channel="Vehicle",Response=ECR_Overlap),(Channel="Destructible",Response=ECR_Overlap)),HelpMessage="WorldStatic object that overlaps all actors by default. All new custom channels will use its own default response. ") ++Profiles=(Name="UI",CollisionEnabled=QueryOnly,bCanModify=False,ObjectTypeName="WorldDynamic",CustomResponses=((Channel="WorldStatic",Response=ECR_Overlap),(Channel="WorldDynamic",Response=ECR_Overlap),(Channel="Pawn",Response=ECR_Overlap),(Channel="Camera",Response=ECR_Overlap),(Channel="PhysicsBody",Response=ECR_Overlap),(Channel="Vehicle",Response=ECR_Overlap),(Channel="Destructible",Response=ECR_Overlap)),HelpMessage="WorldStatic object that overlaps all actors by default. All new custom channels will use its own default response. ") +Profiles=(Name="ProjectileCollision",CollisionEnabled=QueryOnly,bCanModify=True,ObjectTypeName="Projectile",CustomResponses=((Channel="WorldStatic",Response=ECR_Overlap),(Channel="WorldDynamic",Response=ECR_Overlap),(Channel="Pawn",Response=ECR_Ignore),(Channel="Visibility",Response=ECR_Ignore),(Channel="Camera",Response=ECR_Ignore),(Channel="PhysicsBody",Response=ECR_Ignore),(Channel="Vehicle",Response=ECR_Ignore),(Channel="Destructible",Response=ECR_Ignore),(Channel="CharacterMesh",Response=ECR_Overlap)),HelpMessage="Needs description") +Profiles=(Name="ProjectileAssistance",CollisionEnabled=QueryOnly,bCanModify=True,ObjectTypeName="Projectile",CustomResponses=((Channel="WorldStatic",Response=ECR_Ignore),(Channel="WorldDynamic",Response=ECR_Ignore),(Channel="Pawn",Response=ECR_Ignore),(Channel="Visibility",Response=ECR_Ignore),(Channel="Camera",Response=ECR_Ignore),(Channel="PhysicsBody",Response=ECR_Ignore),(Channel="Vehicle",Response=ECR_Ignore),(Channel="Destructible",Response=ECR_Ignore),(Channel="CharacterMesh",Response=ECR_Overlap)),HelpMessage="Needs description") +DefaultChannelResponses=(Channel=ECC_GameTraceChannel1,DefaultResponse=ECR_Ignore,bTraceType=False,bStaticObject=False,Name="CharacterMesh") +DefaultChannelResponses=(Channel=ECC_GameTraceChannel2,DefaultResponse=ECR_Ignore,bTraceType=False,bStaticObject=False,Name="Projectile") -+EditProfiles=(Name="Pawn",CustomResponses=((Channel="Camera",Response=ECR_Ignore),(Channel="Projectile",Response=ECR_Ignore))) -+EditProfiles=(Name="CharacterMesh",CustomResponses=((Channel="Camera",Response=ECR_Ignore),(Channel="Projectile",Response=ECR_Overlap))) ++DefaultChannelResponses=(Channel=ECC_GameTraceChannel3,DefaultResponse=ECR_Ignore,bTraceType=True,bStaticObject=False,Name="TraceCustom") ++EditProfiles=(Name="Pawn",CustomResponses=((Channel="Camera",Response=ECR_Ignore),(Channel="Projectile",Response=ECR_Ignore),(Channel="TraceCustom"))) ++EditProfiles=(Name="CharacterMesh",CustomResponses=((Channel="Camera",Response=ECR_Ignore),(Channel="Projectile",Response=ECR_Overlap),(Channel="TraceCustom",Response=ECR_Ignore))) +EditProfiles=(Name="BlockAll",CustomResponses=((Channel="Projectile"))) +EditProfiles=(Name="OverlapAll",CustomResponses=((Channel="Projectile",Response=ECR_Overlap))) +EditProfiles=(Name="BlockAllDynamic",CustomResponses=((Channel="Projectile"))) +EditProfiles=(Name="OverlapAllDynamic",CustomResponses=((Channel="Projectile",Response=ECR_Overlap))) +EditProfiles=(Name="IgnoreOnlyPawn",CustomResponses=((Channel="Projectile"))) +EditProfiles=(Name="OverlapOnlyPawn",CustomResponses=((Channel="Projectile"))) ++EditProfiles=(Name="Spectator",CustomResponses=((Channel="TraceCustom",Response=ECR_Ignore))) -ProfileRedirects=(OldName="BlockingVolume",NewName="InvisibleWall") -ProfileRedirects=(OldName="InterpActor",NewName="IgnoreOnlyPawn") -ProfileRedirects=(OldName="StaticMeshComponent",NewName="BlockAllDynamic") @@ -135,4 +137,5 @@ ManualIPAddress= +CollisionChannelRedirects=(OldName="Dynamic",NewName="WorldDynamic") +CollisionChannelRedirects=(OldName="VehicleMovement",NewName="Vehicle") +CollisionChannelRedirects=(OldName="PawnMovement",NewName="Pawn") ++CollisionChannelRedirects=(OldName="Test",NewName="TraceCustom") diff --git a/Plugins/Cog/Source/CogDebug/Public/CogDebug.h b/Plugins/Cog/Source/CogDebug/Public/CogDebug.h index e0dbc5b..7126c5e 100644 --- a/Plugins/Cog/Source/CogDebug/Public/CogDebug.h +++ b/Plugins/Cog/Source/CogDebug/Public/CogDebug.h @@ -110,7 +110,7 @@ struct FCogDebugSettings TEnumAsByte GizmoGroundRaycastChannel = ECollisionChannel::ECC_WorldStatic; UPROPERTY(Config) - float GizmoGroundRaycastCircleRadius = 10.f; + float GizmoGroundRaycastCircleRadius = 5.0f; UPROPERTY(Config) FColor GizmoAxisColorsZHighX = FColor(255, 50, 50, 255); diff --git a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CollisionTester.cpp b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CollisionTester.cpp index 3d29dd5..8915ca8 100644 --- a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CollisionTester.cpp +++ b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CollisionTester.cpp @@ -35,6 +35,75 @@ void FCogEngineWindow_CollisionTester::ResetConfig() Config->Reset(); } +//-------------------------------------------------------------------------------------------------------------------------- +bool RenderCollisionProfileChannels(const UCollisionProfile& CollisionProfileChannels, int32& Channels, const TArray& ChannelsConfig) +{ + bool Result = false; + + for (const FCogCollisionChannel& ChannelConfig : ChannelsConfig) + { + const ECollisionChannel Channel = ChannelConfig.Channel.GetValue(); + ImGui::PushID(Channel); + + ImColor Color = FCogImguiHelper::ToImColor(ChannelConfig.Color); + ImGui::ColorEdit4("Color", (float*)&Color.Value, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel); + ImGui::SameLine(); + + bool IsCollisionActive = (Channels & ECC_TO_BITFIELD(Channel)) > 0; + const FName ChannelName = CollisionProfileChannels.ReturnChannelNameFromContainerIndex(Channel); + if (ImGui::Checkbox(TCHAR_TO_ANSI(*ChannelName.ToString()), &IsCollisionActive)) + { + Result = true; + + if (IsCollisionActive) + { + Channels |= ECC_TO_BITFIELD(Channel); + } + else + { + Channels &= ~ECC_TO_BITFIELD(Channel); + } + } + + ImGui::PopID(); + } + + return Result; +} + +//-------------------------------------------------------------------------------------------------------------------------- +bool RenderComboCollisionChannel(const char* Label, const UCollisionProfile& CollisionProfile, ECollisionChannel& SelectedChannel, const TArray& ChannelsConfig) +{ + const FName SelectedChannelName = CollisionProfile.ReturnChannelNameFromContainerIndex(SelectedChannel); + + bool Result = false; + if (ImGui::BeginCombo(Label, TCHAR_TO_ANSI(*SelectedChannelName.ToString()), ImGuiComboFlags_HeightLarge)) + { + for (const FCogCollisionChannel& ChannelConfig : ChannelsConfig) + { + const ECollisionChannel Channel = ChannelConfig.Channel.GetValue(); + ImGui::PushID(Channel); + + const FName ChannelName = CollisionProfile.ReturnChannelNameFromContainerIndex(Channel); + + ImColor Color = FCogImguiHelper::ToImColor(ChannelConfig.Color); + ImGui::ColorEdit4("Color", (float*)&Color.Value, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel); + ImGui::SameLine(); + + if (ImGui::Selectable(TCHAR_TO_ANSI(*ChannelName.ToString()))) + { + SelectedChannel = Channel; + Result = true; + } + + ImGui::PopID(); + } + ImGui::EndCombo(); + } + + return Result; +} + //-------------------------------------------------------------------------------------------------------------------------- void FCogEngineWindow_CollisionTester::RenderContent() { @@ -82,6 +151,9 @@ void FCogEngineWindow_CollisionTester::RenderContent() FCogWindowWidgets::SetNextItemToShortWidth(); FCogWindowWidgets::ComboboxEnum("Type", Config->Type); + FCogWindowWidgets::SetNextItemToShortWidth(); + FCogWindowWidgets::ComboboxEnum("Mode", Config->Mode); + FCogWindowWidgets::SetNextItemToShortWidth(); FCogWindowWidgets::ComboboxEnum("By", Config->By); @@ -92,7 +164,7 @@ void FCogEngineWindow_CollisionTester::RenderContent() { FCogWindowWidgets::SetNextItemToShortWidth(); ECollisionChannel Channel = Config->Channel.GetValue(); - if (FCogWindowWidgets::ComboCollisionChannel("Channel", Channel)) + if (RenderComboCollisionChannel("Channel", *CollisionProfile, Channel, Asset->Channels)) { Config->Channel = Channel; } @@ -103,7 +175,7 @@ void FCogEngineWindow_CollisionTester::RenderContent() else if (Config->By == ECogEngine_CollisionQueryBy::Profile) { const FCollisionResponseTemplate* SelectedProfile = CollisionProfile->GetProfileByIndex(Config->ProfileIndex); - FName SelectedProfileName = SelectedProfile != nullptr ? SelectedProfile->Name : FName("Custom"); + const FName SelectedProfileName = SelectedProfile != nullptr ? SelectedProfile->Name : FName("Custom"); FCogWindowWidgets::SetNextItemToShortWidth(); if (ImGui::BeginCombo("Profile", TCHAR_TO_ANSI(*SelectedProfileName.ToString()), ImGuiComboFlags_HeightLargest)) @@ -121,7 +193,7 @@ void FCogEngineWindow_CollisionTester::RenderContent() { for (int j = 0; j < ECC_MAX; ++j) { - ECollisionResponse Response = Profile->ResponseToChannels.GetResponse((ECollisionChannel)j); + const ECollisionResponse Response = Profile->ResponseToChannels.GetResponse((ECollisionChannel)j); if (Response != ECR_Ignore) { Config->ObjectTypesToQuery |= ECC_TO_BITFIELD(j); @@ -132,52 +204,13 @@ void FCogEngineWindow_CollisionTester::RenderContent() } ImGui::EndCombo(); } - ImGui::Separator(); - - //------------------------------------------------- - // Query Filtering - //------------------------------------------------- - for (int ChannelIndex = 0; ChannelIndex < (int32)ECC_MAX; ++ChannelIndex) - { - const FChannel& Channel = Channels[ChannelIndex]; - if (Channel.IsValid == false) - { - continue; - } - - ImGui::PushID(ChannelIndex); - - ImColor Color = FCogImguiHelper::ToImColor(Channel.Color); - ImGui::ColorEdit4("Color", (float*)&Color.Value, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel); - ImGui::SameLine(); - - bool IsCollisionActive = (Config->ObjectTypesToQuery & ECC_TO_BITFIELD(ChannelIndex)) > 0; - const FName ChannelName = CollisionProfile->ReturnChannelNameFromContainerIndex(ChannelIndex); - if (ImGui::Checkbox(TCHAR_TO_ANSI(*ChannelName.ToString()), &IsCollisionActive)) - { - if (IsCollisionActive) - { - Config->ObjectTypesToQuery |= ECC_TO_BITFIELD(ChannelIndex); - Config->ProfileIndex = INDEX_NONE; - } - else - { - Config->ObjectTypesToQuery &= ~ECC_TO_BITFIELD(ChannelIndex); - Config->ProfileIndex = INDEX_NONE; - } - } - - ImGui::PopID(); - } } - ImGui::Checkbox("Multi", &Config->MultiHits); ImGui::Checkbox("Complex", &Config->TraceComplex); //------------------------------------------------- // Shape //------------------------------------------------- - ImGui::Separator(); if (Config->Type != ECogEngine_CollisionQueryType::LineTrace) { @@ -186,32 +219,49 @@ void FCogEngineWindow_CollisionTester::RenderContent() switch (Config->Shape) { - case ECogEngine_CollisionQueryShape::Sphere: - { - FCogWindowWidgets::SetNextItemToShortWidth(); - FCogImguiHelper::DragDouble("Sphere Radius", &Config->ShapeExtent.X, 0.1f, 0, FLT_MAX, "%.1f"); - break; - } + case ECogEngine_CollisionQueryShape::Sphere: + { + FCogWindowWidgets::SetNextItemToShortWidth(); + FCogImguiHelper::DragDouble("Sphere Radius", &Config->ShapeExtent.X, 0.1f, 0, FLT_MAX, "%.1f"); + break; + } - case ECogEngine_CollisionQueryShape::Box: - { - FCogWindowWidgets::SetNextItemToShortWidth(); - FCogImguiHelper::DragFVector("Box Extent", Config->ShapeExtent, 0.1f, 0, FLT_MAX, "%.1f"); - break; - } + case ECogEngine_CollisionQueryShape::Box: + { + FCogWindowWidgets::SetNextItemToShortWidth(); + FCogImguiHelper::DragFVector("Box Extent", Config->ShapeExtent, 0.1f, 0, FLT_MAX, "%.1f"); + break; + } - case ECogEngine_CollisionQueryShape::Capsule: - { - FCogWindowWidgets::SetNextItemToShortWidth(); - FCogImguiHelper::DragDouble("Capsule Radius", &Config->ShapeExtent.X, 0.1f, 0, FLT_MAX, "%.1f"); + case ECogEngine_CollisionQueryShape::Capsule: + { + FCogWindowWidgets::SetNextItemToShortWidth(); + FCogImguiHelper::DragDouble("Capsule Radius", &Config->ShapeExtent.X, 0.1f, 0, FLT_MAX, "%.1f"); - FCogWindowWidgets::SetNextItemToShortWidth(); - FCogImguiHelper::DragDouble("Capsule Half Height", &Config->ShapeExtent.Z, 0.1f, 0, FLT_MAX, "%.1f"); - break; - } + FCogWindowWidgets::SetNextItemToShortWidth(); + FCogImguiHelper::DragDouble("Capsule Half Height", &Config->ShapeExtent.Z, 0.1f, 0, FLT_MAX, "%.1f"); + break; + } } } + ImGui::Separator(); + + //------------------------------------------------- + // Channels + //------------------------------------------------- + if (Config->By == ECogEngine_CollisionQueryBy::Profile) + { + ImGui::BeginDisabled(); + RenderCollisionProfileChannels(*CollisionProfile, Config->ObjectTypesToQuery, Asset->Channels); + ImGui::EndDisabled(); + } + else if (Config->By == ECogEngine_CollisionQueryBy::ObjectType) + { + RenderCollisionProfileChannels(*CollisionProfile, Config->ObjectTypesToQuery, Asset->Channels); + } + + Query(); } @@ -236,7 +286,10 @@ void FCogEngineWindow_CollisionTester::Query() static const FName TraceTag(TEXT("FCogWindow_Collision")); - FCollisionQueryParams QueryParams(TraceTag, SCENE_QUERY_STAT_ONLY(CogHitDetection), Config->TraceComplex); + const FCollisionQueryParams QueryParams(TraceTag, SCENE_QUERY_STAT_ONLY(CogHitDetection), Config->TraceComplex); + + const FCollisionResponseTemplate* Profile = UCollisionProfile::Get()->GetProfileByIndex(Config->ProfileIndex); + const FName ProfileName = Profile != nullptr ? Profile->Name : FName(); FCollisionShape QueryShape; @@ -257,25 +310,25 @@ void FCogEngineWindow_CollisionTester::Query() { switch (Config->By) { - case ECogEngine_CollisionQueryBy::Channel: - { - HasHits = GetWorld()->OverlapMultiByChannel(Overlaps, QueryStart, QueryRotation, (ECollisionChannel)Config->Channel, QueryShape, QueryParams); - break; - } + case ECogEngine_CollisionQueryBy::Channel: + { + HasHits = GetWorld()->OverlapMultiByChannel(Overlaps, QueryStart, QueryRotation, Config->Channel, QueryShape, QueryParams); + break; + } - case ECogEngine_CollisionQueryBy::ObjectType: - { - FCollisionObjectQueryParams QueryObjectParams; - QueryObjectParams.ObjectTypesToQuery = Config->ObjectTypesToQuery; - HasHits = GetWorld()->OverlapMultiByObjectType(Overlaps, QueryStart, QueryRotation, QueryObjectParams, QueryShape, QueryParams); - break; - } + case ECogEngine_CollisionQueryBy::ObjectType: + { + FCollisionObjectQueryParams QueryObjectParams; + QueryObjectParams.ObjectTypesToQuery = Config->ObjectTypesToQuery; + HasHits = GetWorld()->OverlapMultiByObjectType(Overlaps, QueryStart, QueryRotation, QueryObjectParams, QueryShape, QueryParams); + break; + } - case ECogEngine_CollisionQueryBy::Profile: - { - HasHits = GetWorld()->OverlapMultiByProfile(Overlaps, QueryStart, QueryRotation, Config->Profile, QueryShape, QueryParams); - break; - } + case ECogEngine_CollisionQueryBy::Profile: + { + HasHits = GetWorld()->OverlapMultiByProfile(Overlaps, QueryStart, QueryRotation, ProfileName, QueryShape, QueryParams); + break; + } } break; @@ -285,62 +338,93 @@ void FCogEngineWindow_CollisionTester::Query() { switch (Config->By) { - case ECogEngine_CollisionQueryBy::Channel: + case ECogEngine_CollisionQueryBy::Channel: + { + switch (Config->Mode) { - if (Config->MultiHits) + case ECogEngine_CollisionQueryMode::Single: + { + FHitResult Hit; + HasHits = GetWorld()->LineTraceSingleByChannel(Hit, QueryStart, QueryEnd, Config->Channel, QueryParams); + if (HasHits) { - HasHits = GetWorld()->LineTraceMultiByChannel(Hits, QueryStart, QueryEnd, (ECollisionChannel)Config->Channel, QueryParams); - } - else - { - FHitResult Hit; - HasHits = GetWorld()->LineTraceSingleByChannel(Hit, QueryStart, QueryEnd, (ECollisionChannel)Config->Channel, QueryParams); - if (HasHits) - { - Hits.Add(Hit); - } + Hits.Add(Hit); } break; } - - case ECogEngine_CollisionQueryBy::ObjectType: + case ECogEngine_CollisionQueryMode::Multi: { - FCollisionObjectQueryParams QueryObjectParams; - QueryObjectParams.ObjectTypesToQuery = Config->ObjectTypesToQuery; + HasHits = GetWorld()->LineTraceMultiByChannel(Hits, QueryStart, QueryEnd, Config->Channel, QueryParams); + break; + } + case ECogEngine_CollisionQueryMode::Test: + { + HasHits = GetWorld()->LineTraceTestByChannel(QueryStart, QueryEnd, Config->Channel, QueryParams); + break; + } + } - if (Config->MultiHits) + break; + } + + case ECogEngine_CollisionQueryBy::ObjectType: + { + FCollisionObjectQueryParams QueryObjectParams; + QueryObjectParams.ObjectTypesToQuery = Config->ObjectTypesToQuery; + + switch (Config->Mode) + { + case ECogEngine_CollisionQueryMode::Single: + { + FHitResult Hit; + HasHits = GetWorld()->LineTraceSingleByObjectType(Hit, QueryStart, QueryEnd, QueryObjectParams, QueryParams); + if (HasHits) { - HasHits = GetWorld()->LineTraceMultiByObjectType(Hits, QueryStart, QueryEnd, QueryObjectParams, QueryParams); - } - else - { - FHitResult Hit; - HasHits = GetWorld()->LineTraceSingleByObjectType(Hit, QueryStart, QueryEnd, QueryObjectParams, QueryParams); - if (HasHits) - { - Hits.Add(Hit); - } + Hits.Add(Hit); } break; } - - case ECogEngine_CollisionQueryBy::Profile: + case ECogEngine_CollisionQueryMode::Multi: { - if (Config->MultiHits) + 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: + { + switch (Config->Mode) + { + case ECogEngine_CollisionQueryMode::Single: + { + FHitResult Hit; + HasHits = GetWorld()->LineTraceSingleByProfile(Hit, QueryStart, QueryEnd, ProfileName, QueryParams); + if (HasHits) { - GetWorld()->LineTraceMultiByProfile(Hits, QueryStart, QueryEnd, Config->Profile, QueryParams); - } - else - { - FHitResult Hit; - HasHits = GetWorld()->LineTraceSingleByProfile(Hit, QueryStart, QueryEnd, Config->Profile, QueryParams); - if (HasHits) - { - Hits.Add(Hit); - } + 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; + } } break; } @@ -351,59 +435,87 @@ void FCogEngineWindow_CollisionTester::Query() { case ECogEngine_CollisionQueryBy::Channel: { - if (Config->MultiHits) + switch (Config->Mode) { - HasHits = GetWorld()->SweepMultiByChannel(Hits, QueryStart, QueryEnd, QueryRotation, (ECollisionChannel)Config->Channel, QueryShape, QueryParams); - } - else + case ECogEngine_CollisionQueryMode::Single: { FHitResult Hit; - HasHits = GetWorld()->SweepSingleByChannel(Hit, QueryStart, QueryEnd, QueryRotation, (ECollisionChannel)Config->Channel, QueryShape, QueryParams); + HasHits = GetWorld()->SweepSingleByChannel(Hit, QueryStart, QueryEnd, QueryRotation, Config->Channel, QueryShape, QueryParams); if (HasHits) { Hits.Add(Hit); } + break; + } + case ECogEngine_CollisionQueryMode::Multi: + { + HasHits = GetWorld()->SweepMultiByChannel(Hits, QueryStart, QueryEnd, QueryRotation, Config->Channel, QueryShape, QueryParams); + break; + } + case ECogEngine_CollisionQueryMode::Test: + { + HasHits = GetWorld()->SweepTestByChannel(QueryStart, QueryEnd, QueryRotation, Config->Channel, QueryShape, QueryParams); + break; + } } break; } case ECogEngine_CollisionQueryBy::ObjectType: { - if (Config->MultiHits) - { - FCollisionObjectQueryParams QueryObjectParams; - QueryObjectParams.ObjectTypesToQuery = Config->ObjectTypesToQuery; - HasHits = GetWorld()->SweepMultiByObjectType(Hits, QueryStart, QueryEnd, QueryRotation, QueryObjectParams, QueryShape, QueryParams); - } - else - { - FCollisionObjectQueryParams QueryObjectParams; - QueryObjectParams.ObjectTypesToQuery = Config->ObjectTypesToQuery; + FCollisionObjectQueryParams QueryObjectParams; + QueryObjectParams.ObjectTypesToQuery = Config->ObjectTypesToQuery; + switch (Config->Mode) + { + case ECogEngine_CollisionQueryMode::Single: + { 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: { - if (Config->MultiHits) + switch (Config->Mode) { - HasHits = GetWorld()->SweepMultiByProfile(Hits, QueryStart, QueryEnd, QueryRotation, Config->Profile, QueryShape, QueryParams); - } - else + case ECogEngine_CollisionQueryMode::Single: { FHitResult Hit; - HasHits = GetWorld()->SweepSingleByProfile(Hit, QueryStart, QueryEnd, QueryRotation, Config->Profile, QueryShape, QueryParams); + HasHits = GetWorld()->SweepSingleByProfile(Hit, QueryStart, QueryEnd, QueryRotation, ProfileName, QueryShape, QueryParams); if (HasHits) { Hits.Add(Hit); } + break; + } + case ECogEngine_CollisionQueryMode::Multi: + { + HasHits = GetWorld()->SweepMultiByProfile(Hits, QueryStart, QueryEnd, QueryRotation, ProfileName, QueryShape, QueryParams); + break; + } + case ECogEngine_CollisionQueryMode::Test: + { + HasHits = GetWorld()->SweepTestByProfile(QueryStart, QueryEnd, QueryRotation, ProfileName, QueryShape, QueryParams); + break; + } } break; } @@ -413,7 +525,6 @@ void FCogEngineWindow_CollisionTester::Query() } const FColor Color = HasHits ? FLinearColor(Config->HitColor).ToFColor(true) : FLinearColor(Config->NoHitColor).ToFColor(true); - const bool bUseTrace = Config->Type == ECogEngine_CollisionQueryType::LineTrace || Config->Type == ECogEngine_CollisionQueryType::Sweep; if (bUseTrace) { diff --git a/Plugins/Cog/Source/CogEngine/Public/CogEngineDataAsset.h b/Plugins/Cog/Source/CogEngine/Public/CogEngineDataAsset.h index a53e4c9..5fc6933 100644 --- a/Plugins/Cog/Source/CogEngine/Public/CogEngineDataAsset.h +++ b/Plugins/Cog/Source/CogEngine/Public/CogEngineDataAsset.h @@ -12,7 +12,7 @@ struct COGENGINE_API FCogCollisionChannel GENERATED_BODY() UPROPERTY(EditAnywhere) - TEnumAsByte Channel = ECollisionChannel::ECC_WorldStatic; + TEnumAsByte Channel = ECC_WorldStatic; UPROPERTY(EditAnywhere) FLinearColor Color = FLinearColor(0.5f, 0.5f, 0.5f, 1.0f); diff --git a/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_CollisionTester.h b/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_CollisionTester.h index 9af2da4..4aa99a9 100644 --- a/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_CollisionTester.h +++ b/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_CollisionTester.h @@ -23,10 +23,11 @@ enum class ECogEngine_CollisionQueryType : uint8 //-------------------------------------------------------------------------------------------------------------------------- UENUM() -enum class ECogEngine_CollisionQueryCount : uint8 +enum class ECogEngine_CollisionQueryMode : uint8 { Single, Multi, + Test, }; //-------------------------------------------------------------------------------------------------------------------------- @@ -62,7 +63,6 @@ public: protected: virtual void ResetConfig() override; - void DoWork(const UCollisionProfile* CollisionProfile); virtual void RenderHelp() override; @@ -125,24 +125,21 @@ public: UPROPERTY(Config) ECogEngine_CollisionQueryType Type; + UPROPERTY(Config) + ECogEngine_CollisionQueryMode Mode; + UPROPERTY(Config) ECogEngine_CollisionQueryBy By; UPROPERTY(Config) ECogEngine_CollisionQueryShape Shape; - UPROPERTY(Config) - bool MultiHits; - UPROPERTY(Config) bool TraceComplex; UPROPERTY(Config) int32 ObjectTypesToQuery; - UPROPERTY(Config) - FName Profile; - UPROPERTY(Config) TEnumAsByte Channel; @@ -199,8 +196,8 @@ public: Type = ECogEngine_CollisionQueryType::LineTrace; By = ECogEngine_CollisionQueryBy::Channel; + Mode = ECogEngine_CollisionQueryMode::Multi; Channel = ECC_WorldStatic; - MultiHits = false; TraceComplex = false; Shape = ECogEngine_CollisionQueryShape::Sphere; ShapeExtent = FVector(50.0f, 50.0f, 50.0f); diff --git a/Plugins/Cog/Source/CogWindow/Private/CogWindowWidgets.cpp b/Plugins/Cog/Source/CogWindow/Private/CogWindowWidgets.cpp index 8c41b15..79897e9 100644 --- a/Plugins/Cog/Source/CogWindow/Private/CogWindowWidgets.cpp +++ b/Plugins/Cog/Source/CogWindow/Private/CogWindowWidgets.cpp @@ -646,5 +646,44 @@ bool FCogWindowWidgets::ComboCollisionChannel(const char* Label, ECollisionChann ImGui::EndCombo(); } + return Result; +} + +//-------------------------------------------------------------------------------------------------------------------------- +bool FCogWindowWidgets::CollisionProfileChannel(const UCollisionProfile& CollisionProfile, const int32 ChannelIndex, int32& Channels) +{ + bool Result = false; + + bool IsCollisionActive = (Channels & ECC_TO_BITFIELD(ChannelIndex)) > 0; + const FName ChannelName = CollisionProfile.ReturnChannelNameFromContainerIndex(ChannelIndex); + if (ImGui::Checkbox(TCHAR_TO_ANSI(*ChannelName.ToString()), &IsCollisionActive)) + { + Result = true; + + if (IsCollisionActive) + { + Channels |= ECC_TO_BITFIELD(ChannelIndex); + } + else + { + Channels &= ~ECC_TO_BITFIELD(ChannelIndex); + } + } + + return Result; +} + +//-------------------------------------------------------------------------------------------------------------------------- +bool FCogWindowWidgets::CollisionProfileChannels(const UCollisionProfile& CollisionProfile, int32& Channels) +{ + bool Result = false; + + for (int32 ChannelIndex = 0; ChannelIndex < (int32)ECC_MAX; ++ChannelIndex) + { + ImGui::PushID(ChannelIndex); + Result |= CollisionProfileChannel(CollisionProfile, ChannelIndex, Channels); + ImGui::PopID(); + } + return Result; } \ No newline at end of file diff --git a/Plugins/Cog/Source/CogWindow/Public/CogWindowWidgets.h b/Plugins/Cog/Source/CogWindow/Public/CogWindowWidgets.h index c167ab7..f15622a 100644 --- a/Plugins/Cog/Source/CogWindow/Public/CogWindowWidgets.h +++ b/Plugins/Cog/Source/CogWindow/Public/CogWindowWidgets.h @@ -82,6 +82,9 @@ public: static bool ComboCollisionChannel(const char* Label, ECollisionChannel& Channel); + static bool CollisionProfileChannel(const UCollisionProfile& CollisionProfile, int32 ChannelIndex, int32& Channels); + + static bool CollisionProfileChannels(const UCollisionProfile& CollisionProfile, int32& Channels); }; From 65bd2150de40d26786627e376911db70116f238a Mon Sep 17 00:00:00 2001 From: Arnaud Jamin Date: Sun, 31 Dec 2023 03:13:10 -0500 Subject: [PATCH 5/8] CogDebug: improve gizmo --- .../CogDebug/Private/CogDebugDrawImGui.cpp | 26 +- .../Source/CogDebug/Private/CogDebugGizmo.cpp | 253 ++++++++++++------ Plugins/Cog/Source/CogDebug/Public/CogDebug.h | 48 +++- .../Source/CogDebug/Public/CogDebugGizmo.h | 1 - .../Private/CogEngineWindow_DebugSettings.cpp | 55 ++-- .../CogImgui/Private/CogImguiHelper.cpp | 50 ++++ .../Source/CogImgui/Public/CogImguiHelper.h | 4 + 7 files changed, 319 insertions(+), 118 deletions(-) diff --git a/Plugins/Cog/Source/CogDebug/Private/CogDebugDrawImGui.cpp b/Plugins/Cog/Source/CogDebug/Private/CogDebugDrawImGui.cpp index 28d829f..d26b4dd 100644 --- a/Plugins/Cog/Source/CogDebug/Private/CogDebugDrawImGui.cpp +++ b/Plugins/Cog/Source/CogDebug/Private/CogDebugDrawImGui.cpp @@ -153,19 +153,6 @@ void FCogDebugDrawImGui::AddCircleFilled(const ImVec2& Center, float Radius, ImU //-------------------------------------------------------------------------------------------------------------------------- void FCogDebugDrawImGui::AddText(const ImVec2& Pos, const FString& Text, ImU32 Color, bool AddShadow /*= false*/, float Duration/* = 0.0f*/, bool FadeColor /*= false*/) { - if (AddShadow) - { - FText ShadowTextElement; - ShadowTextElement.Pos = Pos + ImVec2(1, 1); - ShadowTextElement.Text = Text; - float Alpha = ImGui::ColorConvertU32ToFloat4(Color).w; // Keep original Alpha and set to black - ShadowTextElement.Color = ImGui::ColorConvertFloat4ToU32(ImVec4(0, 0, 0, Alpha)); - ShadowTextElement.Time = ImGui::GetCurrentContext()->Time; - ShadowTextElement.Duration = Duration; - ShadowTextElement.FadeColor = FadeColor; - Texts.Add_GetRef(ShadowTextElement); - } - FText TextElement; TextElement.Pos = Pos; TextElement.Text = Text; @@ -174,6 +161,19 @@ void FCogDebugDrawImGui::AddText(const ImVec2& Pos, const FString& Text, ImU32 C TextElement.Duration = Duration; TextElement.FadeColor = FadeColor; Texts.Add_GetRef(TextElement); + + if (AddShadow) + { + FText ShadowTextElement; + ShadowTextElement.Pos = Pos + ImVec2(1, 1); + ShadowTextElement.Text = Text; + const float Alpha = ImGui::ColorConvertU32ToFloat4(Color).w; // Keep original Alpha and set to black + ShadowTextElement.Color = ImGui::ColorConvertFloat4ToU32(ImVec4(0, 0, 0, Alpha)); + ShadowTextElement.Time = ImGui::GetCurrentContext()->Time; + ShadowTextElement.Duration = Duration; + ShadowTextElement.FadeColor = FadeColor; + Texts.Add_GetRef(ShadowTextElement); + } } diff --git a/Plugins/Cog/Source/CogDebug/Private/CogDebugGizmo.cpp b/Plugins/Cog/Source/CogDebug/Private/CogDebugGizmo.cpp index f221031..ef1ba4f 100644 --- a/Plugins/Cog/Source/CogDebug/Private/CogDebugGizmo.cpp +++ b/Plugins/Cog/Source/CogDebug/Private/CogDebugGizmo.cpp @@ -1,12 +1,17 @@ #include "CogDebugGizmo.h" #include "CogDebug.h" +#include "CogDebugDraw.h" #include "CogDebugDrawHelper.h" +#include "CogDebugDrawImGui.h" #include "CogImGuiHelper.h" +#include "CogWindowWidgets.h" +#include "CogWindowWidgets.h" #include "Components/PrimitiveComponent.h" #include "Components/SceneComponent.h" #include "GameFramework/PlayerController.h" #include "imgui.h" +#include "../../ThirdParty/ImGui/imgui.h" #include "Kismet/GameplayStatics.h" //-------------------------------------------------------------------------------------------------------------------------- @@ -141,6 +146,51 @@ FVector VectorMax(const FVector& Vector, const float MaxValue) return NewValue; } +//-------------------------------------------------------------------------------------------------------------------------- +void DrawGizmoText(const ImVec2& Position, ImU32 Color, const char* Text) +{ + ImGuiViewport* Viewport = ImGui::GetMainViewport(); + if (Viewport == nullptr) + { + return; + } + + ImDrawList* DrawList = ImGui::GetBackgroundDrawList(Viewport); + + const float Alpha = ImGui::ColorConvertU32ToFloat4(Color).w; + DrawList->AddText(Viewport->Pos + Position + ImVec2(1.0f, 1.0f), ImGui::ColorConvertFloat4ToU32(ImVec4(0, 0, 0, Alpha)), Text, nullptr); + DrawList->AddText(Viewport->Pos + Position, Color, Text, nullptr); +} + +//-------------------------------------------------------------------------------------------------------------------------- +bool AddTransformComponent(const char* Label, double* Value, double Reset) +{ + ImGui::TableNextColumn(); + ImGui::PushItemWidth(-1); + bool Result = FCogImguiHelper::DragDouble(Label, Value, 0.1f, 0.0f, 0.0f, "%.1f"); + if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) + { + *Value = Reset; + Result = true; + } + ImGui::PopItemWidth(); + return Result; +} + +//-------------------------------------------------------------------------------------------------------------------------- +void AddTransformSnap(bool* SnapEnable, float* Snap) +{ + ImGui::TableNextColumn(); + ImGui::PushItemWidth(-1); + ImGui::Checkbox("Snap", SnapEnable); + ImGui::PopItemWidth(); + + ImGui::TableNextColumn(); + ImGui::PushItemWidth(-1); + ImGui::DragFloat("##SnapValue", Snap, 0.1f, 0.1f, 1000.0f, "%.1f"); + ImGui::PopItemWidth(); +} + //-------------------------------------------------------------------------------------------------------------------------- void FCogDebug_Gizmo::Draw(const char* Id, const APlayerController& InPlayerController, FTransform& InOutTransform, ECogDebug_GizmoFlags Flags) { @@ -176,24 +226,16 @@ void FCogDebug_Gizmo::Draw(const char* Id, const APlayerController& InPlayerCont const float ScaleToKeepGizmoScreenSizeConstant = FMath::IsNearlyZero(CameraToProjectedGizmoCenter) ? 1.0f : FVector::Dist(AxisProjection, ProjectedGizmoCenter) * FVector::Dist(CameraLocation, GizmoCenter) / CameraToProjectedGizmoCenter; const float GizmoScale = Settings.GizmoScale * ScaleToKeepGizmoScreenSizeConstant; - const FQuat RotX = UseLocalSpace ? 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 RotZ = RotX * FQuat(FVector(0.0f, 1.0f, 0.0f), UE_HALF_PI); - const FVector UnitAxisX = UseLocalSpace ? RotX.GetAxisX() : FVector::XAxisVector; - const FVector UnitAxisY = UseLocalSpace ? RotX.GetAxisY() : FVector::YAxisVector; - const FVector UnitAxisZ = UseLocalSpace ? RotX.GetAxisZ() : FVector::ZAxisVector; - - const FVector AxisX = GizmoCenter + UnitAxisX * Settings.GizmoAxisLength * GizmoScale; - const FVector AxisY = GizmoCenter + UnitAxisY * Settings.GizmoAxisLength * GizmoScale; - const FVector AxisZ = GizmoCenter + UnitAxisZ * Settings.GizmoAxisLength * GizmoScale; - - const FVector PlaneXY = GizmoCenter + ((UnitAxisX + UnitAxisY) * Settings.GizmoPlaneOffset * GizmoScale); - const FVector PlaneXZ = GizmoCenter + ((UnitAxisX + UnitAxisZ) * Settings.GizmoPlaneOffset * GizmoScale); - const FVector PlaneYZ = GizmoCenter + ((UnitAxisY + UnitAxisZ) * Settings.GizmoPlaneOffset * GizmoScale); + const FVector UnitAxisX = Settings.GizmoUseLocalSpace ? RotX.GetAxisX() : FVector::XAxisVector; + const FVector UnitAxisY = Settings.GizmoUseLocalSpace ? RotX.GetAxisY() : FVector::YAxisVector; + const FVector UnitAxisZ = Settings.GizmoUseLocalSpace ? RotX.GetAxisZ() : FVector::ZAxisVector; const float ScaleBoxExtent = Settings.GizmoScaleBoxExtent * GizmoScale; - const float PlaneExtent = Settings.GizmoPlaneExtent * GizmoScale; + const float PlaneExtent = Settings.GizmoTranslationPlaneExtent * GizmoScale; const float ThicknessZLow = Settings.GizmoThicknessZLow * ScaleToKeepGizmoScreenSizeConstant; const float ThicknessZHigh = Settings.GizmoThicknessZHigh * ScaleToKeepGizmoScreenSizeConstant; @@ -212,23 +254,23 @@ void FCogDebug_Gizmo::Draw(const char* Id, const APlayerController& InPlayerCont if (EnumHasAnyFlags(Flags, ECogDebug_GizmoFlags::NoTranslationAxis) == false) { - GizmoElements[(uint8)ECogDebug_GizmoElementType::MoveX] = { ECogDebug_GizmoType::MoveAxis, ECogDebug_GizmoAxis::X, FVector::XAxisVector, UnitAxisX, FQuat::Identity, AxisX }; - GizmoElements[(uint8)ECogDebug_GizmoElementType::MoveY] = { ECogDebug_GizmoType::MoveAxis, ECogDebug_GizmoAxis::Y, FVector::YAxisVector, UnitAxisY, FQuat::Identity, AxisY }; - GizmoElements[(uint8)ECogDebug_GizmoElementType::MoveZ] = { ECogDebug_GizmoType::MoveAxis, ECogDebug_GizmoAxis::Z, FVector::ZAxisVector, UnitAxisZ, FQuat::Identity, AxisZ }; + GizmoElements[(uint8)ECogDebug_GizmoElementType::MoveX] = { ECogDebug_GizmoType::MoveAxis, ECogDebug_GizmoAxis::X, FVector::XAxisVector, UnitAxisX, RotX, GizmoCenter + UnitAxisX * Settings.GizmoTranslationAxisLength * GizmoScale }; + GizmoElements[(uint8)ECogDebug_GizmoElementType::MoveY] = { ECogDebug_GizmoType::MoveAxis, ECogDebug_GizmoAxis::Y, FVector::YAxisVector, UnitAxisY, RotY, GizmoCenter + UnitAxisY * Settings.GizmoTranslationAxisLength * GizmoScale }; + GizmoElements[(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) { - GizmoElements[(uint8)ECogDebug_GizmoElementType::MoveXY] = { ECogDebug_GizmoType::MovePlane, ECogDebug_GizmoAxis::Z, FVector::ZAxisVector, UnitAxisZ, RotZ, PlaneXY }; - GizmoElements[(uint8)ECogDebug_GizmoElementType::MoveXZ] = { ECogDebug_GizmoType::MovePlane, ECogDebug_GizmoAxis::Y, FVector::YAxisVector, UnitAxisY, RotY, PlaneXZ }; - GizmoElements[(uint8)ECogDebug_GizmoElementType::MoveYZ] = { ECogDebug_GizmoType::MovePlane, ECogDebug_GizmoAxis::X, FVector::XAxisVector, UnitAxisX, RotX, PlaneYZ }; + GizmoElements[(uint8)ECogDebug_GizmoElementType::MoveXY] = { ECogDebug_GizmoType::MovePlane, ECogDebug_GizmoAxis::Z, FVector::ZAxisVector, UnitAxisZ, RotZ, GizmoCenter + ((UnitAxisX + UnitAxisY) * Settings.GizmoTranslationPlaneOffset * GizmoScale) }; + GizmoElements[(uint8)ECogDebug_GizmoElementType::MoveXZ] = { ECogDebug_GizmoType::MovePlane, ECogDebug_GizmoAxis::Y, FVector::YAxisVector, UnitAxisY, RotY, GizmoCenter + ((UnitAxisX + UnitAxisZ) * Settings.GizmoTranslationPlaneOffset * GizmoScale) }; + GizmoElements[(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) { - GizmoElements[(uint8)ECogDebug_GizmoElementType::RotateX] = { ECogDebug_GizmoType::Rotate, ECogDebug_GizmoAxis::X, FVector::XAxisVector, UnitAxisX, RotX, AxisX }; - GizmoElements[(uint8)ECogDebug_GizmoElementType::RotateY] = { ECogDebug_GizmoType::Rotate, ECogDebug_GizmoAxis::Y, FVector::YAxisVector, UnitAxisY, RotY, AxisY }; - GizmoElements[(uint8)ECogDebug_GizmoElementType::RotateZ] = { ECogDebug_GizmoType::Rotate, ECogDebug_GizmoAxis::Z, FVector::ZAxisVector, UnitAxisZ, RotZ, AxisZ }; + GizmoElements[(uint8)ECogDebug_GizmoElementType::RotateX] = { ECogDebug_GizmoType::Rotate, ECogDebug_GizmoAxis::X, FVector::XAxisVector, UnitAxisX, RotX, FVector::ZeroVector }; + GizmoElements[(uint8)ECogDebug_GizmoElementType::RotateY] = { ECogDebug_GizmoType::Rotate, ECogDebug_GizmoAxis::Y, FVector::YAxisVector, UnitAxisY, RotY, FVector::ZeroVector }; + GizmoElements[(uint8)ECogDebug_GizmoElementType::RotateZ] = { ECogDebug_GizmoType::Rotate, ECogDebug_GizmoAxis::Z, FVector::ZAxisVector, UnitAxisZ, RotZ, FVector::ZeroVector }; } if (EnumHasAnyFlags(Flags, ECogDebug_GizmoFlags::NoScaleUniform) == false) @@ -238,9 +280,9 @@ void FCogDebug_Gizmo::Draw(const char* Id, const APlayerController& InPlayerCont if (EnumHasAnyFlags(Flags, ECogDebug_GizmoFlags::NoScaleAxis) == false) { - GizmoElements[(uint8)ECogDebug_GizmoElementType::ScaleX] = { ECogDebug_GizmoType::ScaleAxis, ECogDebug_GizmoAxis::X, FVector::XAxisVector, UnitAxisX, RotX, AxisX }; - GizmoElements[(uint8)ECogDebug_GizmoElementType::ScaleY] = { ECogDebug_GizmoType::ScaleAxis, ECogDebug_GizmoAxis::Y, FVector::YAxisVector, UnitAxisY, RotY, AxisY }; - GizmoElements[(uint8)ECogDebug_GizmoElementType::ScaleZ] = { ECogDebug_GizmoType::ScaleAxis, ECogDebug_GizmoAxis::Z, FVector::ZAxisVector, UnitAxisZ, RotZ, AxisZ }; + GizmoElements[(uint8)ECogDebug_GizmoElementType::ScaleX] = { ECogDebug_GizmoType::ScaleAxis, ECogDebug_GizmoAxis::X, FVector::XAxisVector, UnitAxisX, RotX, GizmoCenter + UnitAxisX * Settings.GizmoScaleBoxOffset * GizmoScale }; + GizmoElements[(uint8)ECogDebug_GizmoElementType::ScaleY] = { ECogDebug_GizmoType::ScaleAxis, ECogDebug_GizmoAxis::Y, FVector::YAxisVector, UnitAxisY, RotY, GizmoCenter + UnitAxisY * Settings.GizmoScaleBoxOffset * GizmoScale }; + GizmoElements[(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; @@ -272,7 +314,7 @@ void FCogDebug_Gizmo::Draw(const char* Id, const APlayerController& InPlayerCont case ECogDebug_GizmoType::Rotate: { - FRotationTranslationMatrix Matrix(FRotator(Elm.Rotation), GizmoCenter); + const FRotationTranslationMatrix Matrix(FRotator(Elm.Rotation), GizmoCenter); const float RotationGizmoRadius = Settings.GizmoRotationRadius * GizmoScale; DistanceToMouse = ScreenDistanceToArc(InPlayerController, MousePos, Matrix, RotationGizmoRadius, 0.0f, 90.0f, Settings.GizmoRotationSegments); break; @@ -376,15 +418,48 @@ void FCogDebug_Gizmo::Draw(const char* Id, const APlayerController& InPlayerCont { case ECogDebug_GizmoType::MoveAxis: { - const FVector Point = GetMouseCursorOnLine(InPlayerController, InitialTransform.GetTranslation(), DraggedElement.Direction, MousePos - CursorOffset); - InOutTransform.SetLocation(Point); + const FVector CursorOnLine = GetMouseCursorOnLine(InPlayerController, InitialTransform.GetTranslation(), DraggedElement.Direction, MousePos - CursorOffset); + const float Delta = FVector::DotProduct(DraggedElement.Direction, CursorOnLine - InitialTransform.GetTranslation()); + const float SnappedDelta = FMath::GridSnap(Delta, Settings.GizmoTranslationSnapEnable ? Settings.GizmoTranslationSnap : 0.0f); + const FVector NewLocation = InitialTransform.GetTranslation() + DraggedElement.Direction * SnappedDelta; + InOutTransform.SetLocation(NewLocation); + + const FString Text = FString::Printf(TEXT("%0.1f"), SnappedDelta); + DrawGizmoText(FCogImguiHelper::ToImVec2(Center2D), FCogImguiHelper::ToImU32(Settings.GizmoTextColor), StringCast(*Text).Get()); + + //DrawDebugPoint(World, InitialTransform.GetTranslation(), 5.0f, FColor::White); + //DrawDebugLine(World, InitialTransform.GetTranslation(), InitialTransform.GetTranslation() + DraggedElement.Direction * SnappedDelta, FColor::White); + //const FVector TextLocation = InitialTransform.GetTranslation() + DraggedElement.Direction * SnappedDelta * 0.5f; + //UGameplayStatics::DeprojectScreenToWorld(&InPlayerController, Center2D + FVector2d(0, 1.0f), AxisProjection, AxisDirection); + //FVector2D TextLocation2D; + //if (UGameplayStatics::ProjectWorldToScreen(&InPlayerController, TextLocation, TextLocation2D)) + //{ + // FCogDebugDrawImGui::AddText(FCogImguiHelper::ToImVec2(TextLocation2D), FString::Printf(TEXT("%0.1f"), SnappedDelta), IM_COL32(255, 255, 255, 255), true); + //} break; } case ECogDebug_GizmoType::MovePlane: { - const FVector Point = GetMouseCursorOnPlane(InPlayerController, InitialTransform.GetTranslation(), DraggedElement.Direction, MousePos - CursorOffset); - InOutTransform.SetLocation(Point); + const FVector CursorOnPlane = GetMouseCursorOnPlane(InPlayerController, InitialTransform.GetTranslation(), DraggedElement.Direction, MousePos - CursorOffset); + const FVector U = DraggedElement.Rotation.GetAxisZ(); + const FVector V = DraggedElement.Rotation.GetAxisY(); + const float DeltaU = FVector::DotProduct(U, CursorOnPlane - InitialTransform.GetTranslation()); + const float DeltaV = FVector::DotProduct(V, CursorOnPlane - InitialTransform.GetTranslation()); + const float SnappedDeltaU = FMath::GridSnap(DeltaU, Settings.GizmoTranslationSnapEnable ? Settings.GizmoTranslationSnap : 0.0f); + const float SnappedDeltaV = FMath::GridSnap(DeltaV, Settings.GizmoTranslationSnapEnable ? Settings.GizmoTranslationSnap : 0.0f); + const FVector WorldDeltaU = U * SnappedDeltaU; + const FVector WorldDeltaV = V * SnappedDeltaV; + const FVector NewLocation = InitialTransform.GetTranslation() + WorldDeltaU + WorldDeltaV; + InOutTransform.SetLocation(NewLocation); + + const FString Text = FString::Printf(TEXT("%0.1f %0.1f"), SnappedDeltaU, SnappedDeltaV); + DrawGizmoText(FCogImguiHelper::ToImVec2(Center2D), FCogImguiHelper::ToImU32(Settings.GizmoTextColor), StringCast(*Text).Get()); + + //DrawDebugPoint(World, InitialTransform.GetTranslation(), 5.0f, FColor::White); + //DrawDebugLine(World, InitialTransform.GetTranslation(), InitialTransform.GetTranslation() + WorldDeltaU, FColor::White); + //DrawDebugLine(World, InitialTransform.GetTranslation() + WorldDeltaU, InitialTransform.GetTranslation() + WorldDeltaU + WorldDeltaV, FColor::White); + break; } @@ -392,20 +467,15 @@ void FCogDebug_Gizmo::Draw(const char* Id, const APlayerController& InPlayerCont { const FVector2D DragDelta = FCogImguiHelper::ToFVector2D(ImGui::GetMouseDragDelta(ImGuiMouseButton_Left)); const float DragAmount = DragDelta.X - DragDelta.Y; - const FQuat RotDelta(DraggedElement.Axis, DragAmount * Settings.GizmoScaleSpeed); - - FQuat NewRot; - if (UseLocalSpace) - { - NewRot = InitialTransform.GetRotation() * RotDelta; - - } - else - { - NewRot = RotDelta * InitialTransform.GetRotation(); - } - + const float NormalizedAngle = FRotator::NormalizeAxis(DragAmount * Settings.GizmoRotationSpeed); + const float SnappedAngle = FMath::GridSnap(NormalizedAngle, Settings.GizmoRotationSnapEnable ? Settings.GizmoRotationSnap : 0.0f); + const FQuat RotDelta(-DraggedElement.Axis, FMath::DegreesToRadians(SnappedAngle)); + const FQuat NewRot = (Settings.GizmoUseLocalSpace) ? InitialTransform.GetRotation() * RotDelta : RotDelta * InitialTransform.GetRotation(); InOutTransform.SetRotation(NewRot); + + const FString Text = FString::Printf(TEXT("%0.1f"), SnappedAngle); + DrawGizmoText(FCogImguiHelper::ToImVec2(Center2D), FCogImguiHelper::ToImU32(Settings.GizmoTextColor), StringCast(*Text).Get()); + break; } @@ -414,17 +484,27 @@ void FCogDebug_Gizmo::Draw(const char* Id, const APlayerController& InPlayerCont const FVector Point = GetMouseCursorOnLine(InPlayerController, GizmoCenter, DraggedElement.Direction, MousePos - CursorOffset); const float Sign = FMath::Sign(FVector::DotProduct(DraggedElement.Direction, Point - GizmoCenter)); const float Delta = (Point - GizmoCenter).Length() * Sign; - const FVector NewScale = VectorMax(InitialTransform.GetScale3D() + (DraggedElement.Axis * Delta * Settings.GizmoScaleSpeed), Settings.GizmoScaleMin); + const float SnappedDelta = FMath::GridSnap(Delta, Settings.GizmoScaleSnapEnable ? Settings.GizmoScaleSnap : 0.0f); + const FVector NewScale = VectorMax(InitialTransform.GetScale3D() + (DraggedElement.Axis * SnappedDelta * Settings.GizmoScaleSpeed), Settings.GizmoScaleMin); InOutTransform.SetScale3D(NewScale); + + const FString Text = FString::Printf(TEXT("%0.1f"), SnappedDelta); + DrawGizmoText(FCogImguiHelper::ToImVec2(Center2D), FCogImguiHelper::ToImU32(Settings.GizmoTextColor), StringCast(*Text).Get()); + break; } case ECogDebug_GizmoType::ScaleUniform: { const FVector2D DragDelta = FCogImguiHelper::ToFVector2D(ImGui::GetMouseDragDelta(ImGuiMouseButton_Left)); - const float DragAmount = DragDelta.X - DragDelta.Y; - const FVector NewScale = VectorMax(InitialTransform.GetScale3D() + (DraggedElement.Axis * DragAmount * Settings.GizmoScaleSpeed), Settings.GizmoScaleMin); + const float Delta = DragDelta.X - DragDelta.Y; + const float SnappedDelta = FMath::GridSnap(Delta, Settings.GizmoScaleSnapEnable ? Settings.GizmoScaleSnap : 0.0f); + const FVector NewScale = VectorMax(InitialTransform.GetScale3D() + (DraggedElement.Axis * SnappedDelta * Settings.GizmoScaleSpeed), Settings.GizmoScaleMin); InOutTransform.SetScale3D(NewScale); + + const FString Text = FString::Printf(TEXT("%0.1f"), SnappedDelta); + DrawGizmoText(FCogImguiHelper::ToImVec2(Center2D), FCogImguiHelper::ToImU32(Settings.GizmoTextColor), StringCast(*Text).Get()); + break; } @@ -450,46 +530,59 @@ void FCogDebug_Gizmo::Draw(const char* Id, const APlayerController& InPlayerCont if (ImGui::BeginPopup(Id)) { - ImGui::Checkbox("Local Space", &UseLocalSpace); - - ImGui::Separator(); - FVector Translation = InOutTransform.GetTranslation(); - if (FCogImguiHelper::DragFVector("Translation", Translation, 1.0f, 0.0f, 0.0f, "%.1f")) - { - InOutTransform.SetTranslation(Translation); - } - - //if (ImGui::MenuItem("Reset Translation")) - //{ - // InOutTransform.SetTranslation(FVector::ZeroVector); - //} - - FRotator Rotation = FRotator(InOutTransform.GetRotation()); - if (FCogImguiHelper::DragFRotator("Rotation", Rotation, 1.0f, 0.0f, 0.0f, "%.1f")) - { - InOutTransform.SetRotation(Rotation.Quaternion()); - } - - //if (ImGui::MenuItem("Reset Rotation")) - //{ - // InOutTransform.SetRotation(FQuat::Identity); - //} - + FRotator Rotation = InOutTransform.GetRotation().Rotator(); FVector Scale = InOutTransform.GetScale3D(); - if (FCogImguiHelper::DragFVector("Scale", Scale, 1.0f, 0.0f, FLT_MAX, "%.1f")) - { - InOutTransform.SetScale3D(Scale); - } - //if (ImGui::MenuItem("Reset Scale")) - //{ - // InOutTransform.SetScale3D(FVector::OneVector); - //} + ImGui::Checkbox("Local Space", &Settings.GizmoUseLocalSpace); ImGui::Separator(); - ImGui::DragFloat("Gizmo Scale", &Settings.GizmoScale, 0.1f, 0.1f, 10.0f, "%.1f"); + ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2(1.0f, 1.0f)); + + if (ImGui::BeginTable("Pools", 6, ImGuiTableFlags_SizingFixedFit)) + { + ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthFixed, ImGui::GetFontSize() * 5); + ImGui::TableSetupColumn("X", ImGuiTableColumnFlags_WidthFixed, ImGui::GetFontSize() * 4); + ImGui::TableSetupColumn("Y", ImGuiTableColumnFlags_WidthFixed, ImGui::GetFontSize() * 4); + ImGui::TableSetupColumn("Z", ImGuiTableColumnFlags_WidthFixed, ImGui::GetFontSize() * 4); + ImGui::TableSetupColumn("SnapEnable", ImGuiTableColumnFlags_WidthFixed, ImGui::GetFontSize() * 4); + ImGui::TableSetupColumn("Snap", ImGuiTableColumnFlags_WidthFixed, ImGui::GetFontSize() * 3); + + ImGui::PushID("Location"); + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + ImGui::Text("Location"); + if (AddTransformComponent("##X", &Translation.X, 0.0)) { InOutTransform.SetTranslation(Translation); } + if (AddTransformComponent("##Y", &Translation.Y, 0.0)) { InOutTransform.SetTranslation(Translation); } + if (AddTransformComponent("##Z", &Translation.Z, 0.0)) { InOutTransform.SetTranslation(Translation); } + AddTransformSnap(&Settings.GizmoTranslationSnapEnable, &Settings.GizmoTranslationSnap); + ImGui::PopID(); + + ImGui::PushID("Rotation"); + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + ImGui::Text("Rotation"); + if (AddTransformComponent("##X", &Rotation.Yaw, 0.0)) { InOutTransform.SetRotation(Rotation.Quaternion()); } + if (AddTransformComponent("##Y", &Rotation.Pitch, 0.0)) { InOutTransform.SetRotation(Rotation.Quaternion()); } + if (AddTransformComponent("##Z", &Rotation.Roll, 0.0)) { InOutTransform.SetRotation(Rotation.Quaternion()); } + AddTransformSnap(&Settings.GizmoRotationSnapEnable, &Settings.GizmoRotationSnap); + ImGui::PopID(); + + ImGui::PushID("Scale"); + ImGui::TableNextRow(); + ImGui::TableNextColumn(); + ImGui::Text("Scale"); + if (AddTransformComponent("##X", &Scale.X, 0.0)) { InOutTransform.SetScale3D(Scale); } + if (AddTransformComponent("##Y", &Scale.Y, 0.0)) { InOutTransform.SetScale3D(Scale); } + if (AddTransformComponent("##Z", &Scale.Z, 0.0)) { InOutTransform.SetScale3D(Scale); } + AddTransformSnap(&Settings.GizmoScaleSnapEnable, &Settings.GizmoScaleSnap); + ImGui::PopID(); + + ImGui::EndTable(); + } + + ImGui::PopStyleVar(); ImGui::EndPopup(); } diff --git a/Plugins/Cog/Source/CogDebug/Public/CogDebug.h b/Plugins/Cog/Source/CogDebug/Public/CogDebug.h index 7126c5e..395968c 100644 --- a/Plugins/Cog/Source/CogDebug/Public/CogDebug.h +++ b/Plugins/Cog/Source/CogDebug/Public/CogDebug.h @@ -62,7 +62,7 @@ struct FCogDebugSettings float GizmoScale = 1.0f; UPROPERTY(Config) - float GizmoAxisLength = 50.0f; + bool GizmoUseLocalSpace = false; UPROPERTY(Config) int GizmoZLow = 0; @@ -83,10 +83,43 @@ struct FCogDebugSettings float GizmoCursorSelectionThreshold = 10.0f; UPROPERTY(Config) - float GizmoPlaneOffset = 25.0f; + float GizmoTranslationAxisLength = 50.0f; UPROPERTY(Config) - float GizmoPlaneExtent = 5.0f; + bool GizmoTranslationSnapEnable = true; + + UPROPERTY(Config) + float GizmoTranslationSnap = 10.0f; + + UPROPERTY(Config) + float GizmoTranslationPlaneOffset = 25.0f; + + UPROPERTY(Config) + float GizmoTranslationPlaneExtent = 5.0f; + + UPROPERTY(Config) + bool GizmoRotationSnapEnable = true; + + UPROPERTY(Config) + float GizmoRotationSnap = 10.0f; + + UPROPERTY(Config) + float GizmoRotationSpeed = 0.01f; + + UPROPERTY(Config) + float GizmoRotationRadius = 15.0f; + + UPROPERTY(Config) + int GizmoRotationSegments = 12; + + UPROPERTY(Config) + bool GizmoScaleSnapEnable = true; + + UPROPERTY(Config) + float GizmoScaleSnap = 1.0f; + + UPROPERTY(Config) + float GizmoScaleBoxOffset = 50.0f; UPROPERTY(Config) float GizmoScaleBoxExtent = 2.0f; @@ -97,12 +130,6 @@ struct FCogDebugSettings UPROPERTY(Config) float GizmoScaleMin = 0.001f; - UPROPERTY(Config) - float GizmoRotationRadius = 15.0f; - - UPROPERTY(Config) - int GizmoRotationSegments = 12; - UPROPERTY(Config) float GizmoGroundRaycastLength = 100000.0f; @@ -154,6 +181,9 @@ struct FCogDebugSettings UPROPERTY(Config) FColor GizmoGroundRaycastCircleColor = FColor(128, 128, 128, 255); + UPROPERTY(Config) + FColor GizmoTextColor = FColor(255, 255, 255, 255); + UPROPERTY(Config) TArray SecondaryBoneWildcards = { "interaction", diff --git a/Plugins/Cog/Source/CogDebug/Public/CogDebugGizmo.h b/Plugins/Cog/Source/CogDebug/Public/CogDebugGizmo.h index 05a781a..215e8a5 100644 --- a/Plugins/Cog/Source/CogDebug/Public/CogDebugGizmo.h +++ b/Plugins/Cog/Source/CogDebug/Public/CogDebugGizmo.h @@ -77,7 +77,6 @@ struct COGDEBUG_API FCogDebug_Gizmo { void Draw(const char* Id, const APlayerController& InPlayerController, FTransform& InOutTransform, ECogDebug_GizmoFlags Flags = ECogDebug_GizmoFlags::None); - bool UseLocalSpace = false; ECogDebug_GizmoElementType DraggedElementType = ECogDebug_GizmoElementType::MAX; FVector2D CursorOffset = FVector2D::ZeroVector; FTransform InitialTransform = FTransform::Identity; diff --git a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_DebugSettings.cpp b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_DebugSettings.cpp index cdf6e94..e657c61 100644 --- a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_DebugSettings.cpp +++ b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_DebugSettings.cpp @@ -173,10 +173,9 @@ void FCogEngineWindow_DebugSettings::RenderContent() ImGui::SetTooltip("The size of the debug texts."); } - if (Config->bShowAdvancedSettings) - { - ImGui::SeparatorText("Gizmo"); - } + ImGui::SeparatorText("Gizmo"); + + ImGui::Checkbox("Gizmo Use Local Space", &Settings.GizmoUseLocalSpace); FCogWindowWidgets::SetNextItemToShortWidth(); ImGui::DragFloat("Gizmo Scale", &Settings.GizmoScale, 0.1f, 0.1f, 10.0f, "%.1f"); @@ -187,9 +186,6 @@ void FCogEngineWindow_DebugSettings::RenderContent() if (Config->bShowAdvancedSettings) { - FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Gizmo Axis Length", &Settings.GizmoAxisLength, 0.1f, 0.1f, 500.0f, "%.1f"); - FCogWindowWidgets::SetNextItemToShortWidth(); ImGui::DragInt("Gizmo Z Low", &Settings.GizmoZLow, 0.5f, 0, 1000); @@ -206,10 +202,43 @@ void FCogEngineWindow_DebugSettings::RenderContent() ImGui::DragFloat("Gizmo Mouse Max Distance", &Settings.GizmoCursorSelectionThreshold, 0.1f, 0.0f, 50.0f, "%.1f"); FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Gizmo Plane Offset", &Settings.GizmoPlaneOffset, 0.1f, 0.0f, 500.0f, "%.1f"); + ImGui::Checkbox("Gizmo Translation Snap Enable", &Settings.GizmoTranslationSnapEnable); FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Gizmo Plane Extent", &Settings.GizmoPlaneExtent, 0.1f, 0.0f, 100.0f, "%.1f"); + ImGui::DragFloat("Gizmo Translation Snap", &Settings.GizmoTranslationSnap, 0.1f, 0.0f, 1000.0f, "%.1f"); + + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragFloat("Gizmo Translation Axis Length", &Settings.GizmoTranslationAxisLength, 0.1f, 0.1f, 500.0f, "%.1f"); + + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragFloat("Gizmo Translation Plane Offset", &Settings.GizmoTranslationPlaneOffset, 0.1f, 0.0f, 500.0f, "%.1f"); + + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragFloat("Gizmo Translation Plane Extent", &Settings.GizmoTranslationPlaneExtent, 0.1f, 0.0f, 100.0f, "%.1f"); + + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::Checkbox("Gizmo Rotation Snap Enable", &Settings.GizmoRotationSnapEnable); + + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragFloat("Gizmo Rotation Snap", &Settings.GizmoRotationSnap, 0.1f, 0.0f, 360.0f, "%.1f"); + + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragFloat("Gizmo Rotation Speed", &Settings.GizmoRotationSpeed, 0.01f, 0.01f, 100.0f, "%.2f"); + + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragFloat("Gizmo Rotation Radius", &Settings.GizmoRotationRadius, 0.1f, 0.1f, 500.0f, "%.1f"); + + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragInt("Gizmo Rotation Segments", &Settings.GizmoRotationSegments, 0.5f, 2, 12); + + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::Checkbox("Gizmo Scale Snap Enable", &Settings.GizmoScaleSnapEnable); + + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragFloat("Gizmo Scale Snap", &Settings.GizmoScaleSnap, 0.1f, 0.0f, 10.0f, "%.1f"); + + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragFloat("Gizmo Scale Box Offset", &Settings.GizmoScaleBoxOffset, 0.0f, 0.0f, 500.0f, "%.1f"); FCogWindowWidgets::SetNextItemToShortWidth(); ImGui::DragFloat("Gizmo Scale Box Extent", &Settings.GizmoScaleBoxExtent, 0.1f, 0.0f, 100.0f, "%.1f"); @@ -220,12 +249,6 @@ void FCogEngineWindow_DebugSettings::RenderContent() FCogWindowWidgets::SetNextItemToShortWidth(); ImGui::DragFloat("Gizmo Scale Min", &Settings.GizmoScaleMin, 0.001f, 0.001f, 1.0f, "%.3f"); - FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Gizmo Rotation Radius", &Settings.GizmoRotationRadius, 0.1f, 0.1f, 500.0f, "%.1f"); - - FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragInt("Gizmo Rotation Segments", &Settings.GizmoRotationSegments, 0.5f, 2, 12); - FCogWindowWidgets::SetNextItemToShortWidth(); ImGui::DragFloat("Gizmo Ground Raycast Length", &Settings.GizmoGroundRaycastLength, 10.0f, 0.0f, 1000000.0f, "%.0f"); @@ -254,6 +277,8 @@ void FCogEngineWindow_DebugSettings::RenderContent() FCogImguiHelper::ColorEdit4("Gizmo Axis Colors Selection Z", Settings.GizmoAxisColorsSelectionZ, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); FCogImguiHelper::ColorEdit4("Gizmo Axis Colors Selection W", Settings.GizmoAxisColorsSelectionW, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); + FCogImguiHelper::ColorEdit4("Gizmo Text Color", Settings.GizmoTextColor, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); + FCogImguiHelper::ColorEdit4("Gizmo Ground Raycast Color", Settings.GizmoGroundRaycastColor, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); FCogImguiHelper::ColorEdit4("Gizmo Ground Raycast Circle Color", Settings.GizmoGroundRaycastCircleColor, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); } diff --git a/Plugins/Cog/Source/CogImgui/Private/CogImguiHelper.cpp b/Plugins/Cog/Source/CogImgui/Private/CogImguiHelper.cpp index 6cd7440..ef2ac81 100644 --- a/Plugins/Cog/Source/CogImgui/Private/CogImguiHelper.cpp +++ b/Plugins/Cog/Source/CogImgui/Private/CogImguiHelper.cpp @@ -159,12 +159,62 @@ bool FCogImguiHelper::DragFVector(const char* Label, FVector& Vector, float Spee return ImGui::DragScalarN(Label, ImGuiDataType_Double, &Vector.X, 3, Speed, &Min, &Max, Format, Flags); } +//-------------------------------------------------------------------------------------------------------------------------- +bool FCogImguiHelper::DragFVector(const char* Label, FVector& Vector, const FVector& ResetVector, float Speed, double Min, double Max, const char* Format, ImGuiSliderFlags Flags) +{ + bool Result = ImGui::DragScalarN(Label, ImGuiDataType_Double, &Vector.X, 3, Speed, &Min, &Max, Format, Flags); + + if (ImGui::BeginPopupContextItem(Label)) + { + if (ImGui::Button("Reset")) + { + Vector = ResetVector; + Result = true; + + if (ImGuiWindow* Window = GetCurrentWindow()) + { + const ImGuiID ID = Window->GetID(Label); + ImGui::MarkItemEdited(ID); + } + } + + ImGui::EndPopup(); + } + + return Result; +} + //-------------------------------------------------------------------------------------------------------------------------- bool FCogImguiHelper::DragFRotator(const char* Label, FRotator& Rotator, float Speed, double Min, double Max, const char* Format, ImGuiSliderFlags Flags) { return ImGui::DragScalarN(Label, ImGuiDataType_Double, &Rotator.Pitch, 3, Speed, &Min, &Max, Format, Flags); } +//-------------------------------------------------------------------------------------------------------------------------- +bool FCogImguiHelper::DragFRotator(const char* Label, FRotator& Rotator, const FRotator& ResetRotator, float Speed, double Min, double Max, const char* Format, ImGuiSliderFlags Flags) +{ + bool Result = ImGui::DragScalarN(Label, ImGuiDataType_Double, &Rotator.Pitch, 3, Speed, &Min, &Max, Format, Flags); + + if (ImGui::BeginPopupContextItem(Label)) + { + if (ImGui::Button("Reset")) + { + Rotator = ResetRotator; + Result = true; + + if (ImGuiWindow* Window = GetCurrentWindow()) + { + const ImGuiID ID = Window->GetID(Label); + ImGui::MarkItemEdited(ID); + } + } + + ImGui::EndPopup(); + } + + return Result; +} + //-------------------------------------------------------------------------------------------------------------------------- bool FCogImguiHelper::DragFVector2D(const char* Label, FVector2D& Vector, float Speed, double Min, double Max, const char* Format, ImGuiSliderFlags Flags) { diff --git a/Plugins/Cog/Source/CogImgui/Public/CogImguiHelper.h b/Plugins/Cog/Source/CogImgui/Public/CogImguiHelper.h index d360cee..8b7ac16 100644 --- a/Plugins/Cog/Source/CogImgui/Public/CogImguiHelper.h +++ b/Plugins/Cog/Source/CogImgui/Public/CogImguiHelper.h @@ -62,8 +62,12 @@ public: static bool DragFVector(const char* Label, FVector& Vector, float Speed = 1.0f, double Min = 0.0f, double Max = 0.0f, const char* Format = "%.3f", ImGuiSliderFlags Flags = 0); + static bool DragFVector(const char* Label, FVector& Vector, const FVector& ResetVector, float Speed = 1.0f, double Min = 0.0f, double Max = 0.0f, const char* Format = "%.3f", ImGuiSliderFlags Flags = 0); + static bool DragFRotator(const char* Label, FRotator& Rotator, float Speed = 1.0f, double Min = 0.0f, double Max = 0.0f, const char* Format = "%.3f", ImGuiSliderFlags Flags = 0); + static bool DragFRotator(const char* Label, FRotator& Rotator, const FRotator& ResetRotator, float Speed = 1.0f, double Min = 0.0f, double Max = 0.0f, const char* Format = "%.3f", ImGuiSliderFlags Flags = 0); + static bool DragFVector2D(const char* Label, FVector2D& Vector, float Speed = 1.0f, double Min = 0.0f, double Max = 0.0f, const char* Format = "%.3f", ImGuiSliderFlags Flags = 0); static bool ColorEdit4(const char* Label, FColor& Color, ImGuiColorEditFlags Flags = 0); From 7dd4922b01093f49593f2617398cec09afb00443 Mon Sep 17 00:00:00 2001 From: Arnaud Jamin Date: Tue, 2 Jan 2024 00:57:02 -0500 Subject: [PATCH 6/8] CogEngine: move CollisionTester logic inside an actor --- .../Source/CogDebug/Private/CogDebugGizmo.cpp | 140 +++-- Plugins/Cog/Source/CogDebug/Public/CogDebug.h | 6 +- .../Source/CogDebug/Public/CogDebugGizmo.h | 2 +- .../Cog/Source/CogEngine/CogEngine.Build.cs | 4 +- .../Private/CogEngineCollisionTester.cpp | 509 +++++++++++++++ .../CogEngineWindow_CollisionTester.cpp | 590 ++---------------- .../Private/CogEngineWindow_DebugSettings.cpp | 6 +- .../Private/CogEngineWindow_Transform.cpp | 256 ++++++++ .../Public/CogEngineCollisionTester.h | 140 +++++ .../Public/CogEngineWindow_CollisionTester.h | 57 +- .../Public/CogEngineWindow_Transform.h | 72 +++ Source/CogSample/CogSampleGameState.cpp | 3 + 12 files changed, 1118 insertions(+), 667 deletions(-) create mode 100644 Plugins/Cog/Source/CogEngine/Private/CogEngineCollisionTester.cpp create mode 100644 Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Transform.cpp create mode 100644 Plugins/Cog/Source/CogEngine/Public/CogEngineCollisionTester.h create mode 100644 Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_Transform.h diff --git a/Plugins/Cog/Source/CogDebug/Private/CogDebugGizmo.cpp b/Plugins/Cog/Source/CogDebug/Private/CogDebugGizmo.cpp index ef1ba4f..8a1f4cd 100644 --- a/Plugins/Cog/Source/CogDebug/Private/CogDebugGizmo.cpp +++ b/Plugins/Cog/Source/CogDebug/Private/CogDebugGizmo.cpp @@ -1,17 +1,12 @@ #include "CogDebugGizmo.h" #include "CogDebug.h" -#include "CogDebugDraw.h" #include "CogDebugDrawHelper.h" -#include "CogDebugDrawImGui.h" #include "CogImGuiHelper.h" -#include "CogWindowWidgets.h" -#include "CogWindowWidgets.h" #include "Components/PrimitiveComponent.h" #include "Components/SceneComponent.h" #include "GameFramework/PlayerController.h" #include "imgui.h" -#include "../../ThirdParty/ImGui/imgui.h" #include "Kismet/GameplayStatics.h" //-------------------------------------------------------------------------------------------------------------------------- @@ -163,7 +158,7 @@ void DrawGizmoText(const ImVec2& Position, ImU32 Color, const char* Text) } //-------------------------------------------------------------------------------------------------------------------------- -bool AddTransformComponent(const char* Label, double* Value, double Reset) +bool RenderComponent(const char* Label, double* Value, double Reset) { ImGui::TableNextColumn(); ImGui::PushItemWidth(-1); @@ -178,7 +173,7 @@ bool AddTransformComponent(const char* Label, double* Value, double Reset) } //-------------------------------------------------------------------------------------------------------------------------- -void AddTransformSnap(bool* SnapEnable, float* Snap) +void RenderSnap(bool* SnapEnable, float* Snap) { ImGui::TableNextColumn(); ImGui::PushItemWidth(-1); @@ -192,14 +187,14 @@ void AddTransformSnap(bool* SnapEnable, float* Snap) } //-------------------------------------------------------------------------------------------------------------------------- -void FCogDebug_Gizmo::Draw(const char* Id, const APlayerController& InPlayerController, FTransform& InOutTransform, ECogDebug_GizmoFlags Flags) +bool FCogDebug_Gizmo::Draw(const char* Id, const APlayerController& InPlayerController, FTransform& InOutTransform, ECogDebug_GizmoFlags Flags) { UWorld* World = InPlayerController.GetWorld(); const ImGuiViewport* Viewport = ImGui::GetMainViewport(); if (Viewport == nullptr) { - return; + return false; } const FVector GizmoCenter = InOutTransform.GetTranslation(); @@ -210,11 +205,14 @@ void FCogDebug_Gizmo::Draw(const char* Id, const APlayerController& InPlayerCont if (DraggedElementType != ECogDebug_GizmoElementType::MAX) { InOutTransform = InitialTransform; + return true; } - return; + return false; } + bool Result = false; + const ImGuiIO& IO = ImGui::GetIO(); FCogDebugSettings& Settings = FCogDebug::Settings; @@ -420,9 +418,10 @@ void FCogDebug_Gizmo::Draw(const char* Id, const APlayerController& InPlayerCont { const FVector CursorOnLine = GetMouseCursorOnLine(InPlayerController, InitialTransform.GetTranslation(), DraggedElement.Direction, MousePos - CursorOffset); const float Delta = FVector::DotProduct(DraggedElement.Direction, CursorOnLine - InitialTransform.GetTranslation()); - const float SnappedDelta = FMath::GridSnap(Delta, Settings.GizmoTranslationSnapEnable ? Settings.GizmoTranslationSnap : 0.0f); + const float SnappedDelta = FMath::GridSnap(Delta, Settings.GizmoTranslationSnapEnable ? Settings.GizmoTranslationSnapValue : 0.0f); const FVector NewLocation = InitialTransform.GetTranslation() + DraggedElement.Direction * SnappedDelta; InOutTransform.SetLocation(NewLocation); + Result = true; const FString Text = FString::Printf(TEXT("%0.1f"), SnappedDelta); DrawGizmoText(FCogImguiHelper::ToImVec2(Center2D), FCogImguiHelper::ToImU32(Settings.GizmoTextColor), StringCast(*Text).Get()); @@ -446,12 +445,13 @@ void FCogDebug_Gizmo::Draw(const char* Id, const APlayerController& InPlayerCont const FVector V = DraggedElement.Rotation.GetAxisY(); const float DeltaU = FVector::DotProduct(U, CursorOnPlane - InitialTransform.GetTranslation()); const float DeltaV = FVector::DotProduct(V, CursorOnPlane - InitialTransform.GetTranslation()); - const float SnappedDeltaU = FMath::GridSnap(DeltaU, Settings.GizmoTranslationSnapEnable ? Settings.GizmoTranslationSnap : 0.0f); - const float SnappedDeltaV = FMath::GridSnap(DeltaV, Settings.GizmoTranslationSnapEnable ? Settings.GizmoTranslationSnap : 0.0f); + const float SnappedDeltaU = FMath::GridSnap(DeltaU, Settings.GizmoTranslationSnapEnable ? Settings.GizmoTranslationSnapValue : 0.0f); + const float SnappedDeltaV = FMath::GridSnap(DeltaV, Settings.GizmoTranslationSnapEnable ? Settings.GizmoTranslationSnapValue : 0.0f); const FVector WorldDeltaU = U * SnappedDeltaU; const FVector WorldDeltaV = V * SnappedDeltaV; const FVector NewLocation = InitialTransform.GetTranslation() + WorldDeltaU + WorldDeltaV; InOutTransform.SetLocation(NewLocation); + Result = true; const FString Text = FString::Printf(TEXT("%0.1f %0.1f"), SnappedDeltaU, SnappedDeltaV); DrawGizmoText(FCogImguiHelper::ToImVec2(Center2D), FCogImguiHelper::ToImU32(Settings.GizmoTextColor), StringCast(*Text).Get()); @@ -468,10 +468,11 @@ void FCogDebug_Gizmo::Draw(const char* Id, const APlayerController& InPlayerCont const FVector2D DragDelta = FCogImguiHelper::ToFVector2D(ImGui::GetMouseDragDelta(ImGuiMouseButton_Left)); const float DragAmount = DragDelta.X - DragDelta.Y; const float NormalizedAngle = FRotator::NormalizeAxis(DragAmount * Settings.GizmoRotationSpeed); - const float SnappedAngle = FMath::GridSnap(NormalizedAngle, Settings.GizmoRotationSnapEnable ? Settings.GizmoRotationSnap : 0.0f); + const float SnappedAngle = FMath::GridSnap(NormalizedAngle, Settings.GizmoRotationSnapEnable ? Settings.GizmoRotationSnapValue : 0.0f); const FQuat RotDelta(-DraggedElement.Axis, FMath::DegreesToRadians(SnappedAngle)); const FQuat NewRot = (Settings.GizmoUseLocalSpace) ? InitialTransform.GetRotation() * RotDelta : RotDelta * InitialTransform.GetRotation(); InOutTransform.SetRotation(NewRot); + Result = true; const FString Text = FString::Printf(TEXT("%0.1f"), SnappedAngle); DrawGizmoText(FCogImguiHelper::ToImVec2(Center2D), FCogImguiHelper::ToImU32(Settings.GizmoTextColor), StringCast(*Text).Get()); @@ -484,9 +485,10 @@ void FCogDebug_Gizmo::Draw(const char* Id, const APlayerController& InPlayerCont const FVector Point = GetMouseCursorOnLine(InPlayerController, GizmoCenter, DraggedElement.Direction, MousePos - CursorOffset); const float Sign = FMath::Sign(FVector::DotProduct(DraggedElement.Direction, Point - GizmoCenter)); const float Delta = (Point - GizmoCenter).Length() * Sign; - const float SnappedDelta = FMath::GridSnap(Delta, Settings.GizmoScaleSnapEnable ? Settings.GizmoScaleSnap : 0.0f); + const float SnappedDelta = FMath::GridSnap(Delta, Settings.GizmoScaleSnapEnable ? Settings.GizmoScaleSnapValue : 0.0f); const FVector NewScale = VectorMax(InitialTransform.GetScale3D() + (DraggedElement.Axis * SnappedDelta * Settings.GizmoScaleSpeed), Settings.GizmoScaleMin); InOutTransform.SetScale3D(NewScale); + Result = true; const FString Text = FString::Printf(TEXT("%0.1f"), SnappedDelta); DrawGizmoText(FCogImguiHelper::ToImVec2(Center2D), FCogImguiHelper::ToImU32(Settings.GizmoTextColor), StringCast(*Text).Get()); @@ -498,9 +500,10 @@ void FCogDebug_Gizmo::Draw(const char* Id, const APlayerController& InPlayerCont { const FVector2D DragDelta = FCogImguiHelper::ToFVector2D(ImGui::GetMouseDragDelta(ImGuiMouseButton_Left)); const float Delta = DragDelta.X - DragDelta.Y; - const float SnappedDelta = FMath::GridSnap(Delta, Settings.GizmoScaleSnapEnable ? Settings.GizmoScaleSnap : 0.0f); + const float SnappedDelta = FMath::GridSnap(Delta, Settings.GizmoScaleSnapEnable ? Settings.GizmoScaleSnapValue : 0.0f); const FVector NewScale = VectorMax(InitialTransform.GetScale3D() + (DraggedElement.Axis * SnappedDelta * Settings.GizmoScaleSpeed), Settings.GizmoScaleMin); InOutTransform.SetScale3D(NewScale); + Result = true; const FString Text = FString::Printf(TEXT("%0.1f"), SnappedDelta); DrawGizmoText(FCogImguiHelper::ToImVec2(Center2D), FCogImguiHelper::ToImU32(Settings.GizmoTextColor), StringCast(*Text).Get()); @@ -522,69 +525,70 @@ void FCogDebug_Gizmo::Draw(const char* Id, const APlayerController& InPlayerCont CursorOffset = MousePos - Center2D; InitialTransform = InOutTransform; } - else if (ImGui::IsMouseClicked(ImGuiMouseButton_Right)) - { - ImGui::OpenPopup(Id); - } + //else if (ImGui::IsMouseClicked(ImGuiMouseButton_Right)) + //{ + // ImGui::OpenPopup(Id); + //} } - if (ImGui::BeginPopup(Id)) - { - FVector Translation = InOutTransform.GetTranslation(); - FRotator Rotation = InOutTransform.GetRotation().Rotator(); - FVector Scale = InOutTransform.GetScale3D(); + //if (ImGui::BeginPopup(Id)) + //{ + // 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)) - { - ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthFixed, ImGui::GetFontSize() * 5); - ImGui::TableSetupColumn("X", ImGuiTableColumnFlags_WidthFixed, ImGui::GetFontSize() * 4); - ImGui::TableSetupColumn("Y", ImGuiTableColumnFlags_WidthFixed, ImGui::GetFontSize() * 4); - ImGui::TableSetupColumn("Z", ImGuiTableColumnFlags_WidthFixed, ImGui::GetFontSize() * 4); - ImGui::TableSetupColumn("SnapEnable", ImGuiTableColumnFlags_WidthFixed, ImGui::GetFontSize() * 4); - ImGui::TableSetupColumn("Snap", ImGuiTableColumnFlags_WidthFixed, ImGui::GetFontSize() * 3); + // if (ImGui::BeginTable("Pools", 6, ImGuiTableFlags_SizingFixedFit)) + // { + // ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthFixed, ImGui::GetFontSize() * 5); + // ImGui::TableSetupColumn("X", ImGuiTableColumnFlags_WidthFixed, ImGui::GetFontSize() * 4); + // ImGui::TableSetupColumn("Y", ImGuiTableColumnFlags_WidthFixed, ImGui::GetFontSize() * 4); + // ImGui::TableSetupColumn("Z", ImGuiTableColumnFlags_WidthFixed, ImGui::GetFontSize() * 4); + // ImGui::TableSetupColumn("SnapEnable", ImGuiTableColumnFlags_WidthFixed, ImGui::GetFontSize() * 4); + // ImGui::TableSetupColumn("Snap", ImGuiTableColumnFlags_WidthFixed, ImGui::GetFontSize() * 3); - ImGui::PushID("Location"); - ImGui::TableNextRow(); - ImGui::TableNextColumn(); - ImGui::Text("Location"); - if (AddTransformComponent("##X", &Translation.X, 0.0)) { InOutTransform.SetTranslation(Translation); } - if (AddTransformComponent("##Y", &Translation.Y, 0.0)) { InOutTransform.SetTranslation(Translation); } - if (AddTransformComponent("##Z", &Translation.Z, 0.0)) { InOutTransform.SetTranslation(Translation); } - AddTransformSnap(&Settings.GizmoTranslationSnapEnable, &Settings.GizmoTranslationSnap); - ImGui::PopID(); + // ImGui::PushID("Location"); + // ImGui::TableNextRow(); + // ImGui::TableNextColumn(); + // ImGui::Text("Location"); + // if (RenderComponent("##X", &Translation.X, 0.0)) { InOutTransform.SetTranslation(Translation); } + // if (RenderComponent("##Y", &Translation.Y, 0.0)) { InOutTransform.SetTranslation(Translation); } + // if (RenderComponent("##Z", &Translation.Z, 0.0)) { InOutTransform.SetTranslation(Translation); } + // RenderSnap(&Settings.GizmoTranslationSnapEnable, &Settings.GizmoTranslationSnapValue); + // ImGui::PopID(); - ImGui::PushID("Rotation"); - ImGui::TableNextRow(); - ImGui::TableNextColumn(); - ImGui::Text("Rotation"); - if (AddTransformComponent("##X", &Rotation.Yaw, 0.0)) { InOutTransform.SetRotation(Rotation.Quaternion()); } - if (AddTransformComponent("##Y", &Rotation.Pitch, 0.0)) { InOutTransform.SetRotation(Rotation.Quaternion()); } - if (AddTransformComponent("##Z", &Rotation.Roll, 0.0)) { InOutTransform.SetRotation(Rotation.Quaternion()); } - AddTransformSnap(&Settings.GizmoRotationSnapEnable, &Settings.GizmoRotationSnap); - ImGui::PopID(); + // ImGui::PushID("Rotation"); + // ImGui::TableNextRow(); + // ImGui::TableNextColumn(); + // 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"); - ImGui::TableNextRow(); - ImGui::TableNextColumn(); - ImGui::Text("Scale"); - if (AddTransformComponent("##X", &Scale.X, 0.0)) { InOutTransform.SetScale3D(Scale); } - if (AddTransformComponent("##Y", &Scale.Y, 0.0)) { InOutTransform.SetScale3D(Scale); } - if (AddTransformComponent("##Z", &Scale.Z, 0.0)) { InOutTransform.SetScale3D(Scale); } - AddTransformSnap(&Settings.GizmoScaleSnapEnable, &Settings.GizmoScaleSnap); - ImGui::PopID(); + // ImGui::PushID("Scale"); + // ImGui::TableNextRow(); + // ImGui::TableNextColumn(); + // ImGui::Text("Scale"); + // 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(); - } + // ImGui::EndTable(); + // } - ImGui::PopStyleVar(); + // ImGui::PopStyleVar(); - ImGui::EndPopup(); - } + // ImGui::EndPopup(); + //} + return Result; } diff --git a/Plugins/Cog/Source/CogDebug/Public/CogDebug.h b/Plugins/Cog/Source/CogDebug/Public/CogDebug.h index 395968c..a2875a3 100644 --- a/Plugins/Cog/Source/CogDebug/Public/CogDebug.h +++ b/Plugins/Cog/Source/CogDebug/Public/CogDebug.h @@ -89,7 +89,7 @@ struct FCogDebugSettings bool GizmoTranslationSnapEnable = true; UPROPERTY(Config) - float GizmoTranslationSnap = 10.0f; + float GizmoTranslationSnapValue = 10.0f; UPROPERTY(Config) float GizmoTranslationPlaneOffset = 25.0f; @@ -101,7 +101,7 @@ struct FCogDebugSettings bool GizmoRotationSnapEnable = true; UPROPERTY(Config) - float GizmoRotationSnap = 10.0f; + float GizmoRotationSnapValue = 10.0f; UPROPERTY(Config) float GizmoRotationSpeed = 0.01f; @@ -116,7 +116,7 @@ struct FCogDebugSettings bool GizmoScaleSnapEnable = true; UPROPERTY(Config) - float GizmoScaleSnap = 1.0f; + float GizmoScaleSnapValue = 1.0f; UPROPERTY(Config) float GizmoScaleBoxOffset = 50.0f; diff --git a/Plugins/Cog/Source/CogDebug/Public/CogDebugGizmo.h b/Plugins/Cog/Source/CogDebug/Public/CogDebugGizmo.h index 215e8a5..f418b49 100644 --- a/Plugins/Cog/Source/CogDebug/Public/CogDebugGizmo.h +++ b/Plugins/Cog/Source/CogDebug/Public/CogDebugGizmo.h @@ -75,7 +75,7 @@ struct FCogDebug_GizmoElement //-------------------------------------------------------------------------------------------------------------------------- struct COGDEBUG_API FCogDebug_Gizmo { - void Draw(const char* Id, const APlayerController& InPlayerController, FTransform& InOutTransform, ECogDebug_GizmoFlags Flags = ECogDebug_GizmoFlags::None); + bool Draw(const char* Id, const APlayerController& InPlayerController, FTransform& InOutTransform, ECogDebug_GizmoFlags Flags = ECogDebug_GizmoFlags::None); ECogDebug_GizmoElementType DraggedElementType = ECogDebug_GizmoElementType::MAX; FVector2D CursorOffset = FVector2D::ZeroVector; diff --git a/Plugins/Cog/Source/CogEngine/CogEngine.Build.cs b/Plugins/Cog/Source/CogEngine/CogEngine.Build.cs index 9109015..38b9ffa 100644 --- a/Plugins/Cog/Source/CogEngine/CogEngine.Build.cs +++ b/Plugins/Cog/Source/CogEngine/CogEngine.Build.cs @@ -23,15 +23,15 @@ public class CogEngine : ModuleRules PublicDependencyModuleNames.AddRange( new string[] { + "CogDebug", } - ); + ); PrivateDependencyModuleNames.AddRange( new string[] { "CogCommon", - "CogDebug", "CogImgui", "CogWindow", "Core", diff --git a/Plugins/Cog/Source/CogEngine/Private/CogEngineCollisionTester.cpp b/Plugins/Cog/Source/CogEngine/Private/CogEngineCollisionTester.cpp new file mode 100644 index 0000000..7e7172a --- /dev/null +++ b/Plugins/Cog/Source/CogEngine/Private/CogEngineCollisionTester.cpp @@ -0,0 +1,509 @@ +#include "CogEngineCollisionTester.h" + +#include "CogDebugDrawHelper.h" +#include "CogDebug.h" +#include "Components/PrimitiveComponent.h" +#include "Components/SceneComponent.h" + +//-------------------------------------------------------------------------------------------------------------------------- +ACogEngineCollisionTester::ACogEngineCollisionTester(const FObjectInitializer& ObjectInitializer) + : Super(ObjectInitializer) +{ + PrimaryActorTick.bCanEverTick = true; + PrimaryActorTick.bStartWithTickEnabled = true; + + StartComponent = CreateDefaultSubobject(TEXT("Start")); + RootComponent = StartComponent; + + EndComponent = CreateDefaultSubobject(TEXT("End")); + EndComponent->SetupAttachment(RootComponent); + EndComponent->SetRelativeLocation(FVector(1000, 0, 0)); +} + +//-------------------------------------------------------------------------------------------------------------------------- +bool ACogEngineCollisionTester::ShouldTickIfViewportsOnly() const +{ + if (GetWorld() != nullptr && GetWorld()->WorldType == EWorldType::Editor && TickInEditor) + { + return true; + } + + return false; +} + +//-------------------------------------------------------------------------------------------------------------------------- +void ACogEngineCollisionTester::Tick(float DeltaSeconds) +{ + Query(); +} + +//-------------------------------------------------------------------------------------------------------------------------- +void ACogEngineCollisionTester::Query() +{ + AlreadyDrawnActors.Empty(); + AlreadyDrawnComponents.Empty(); + + FVector QueryStart = StartComponent->GetComponentLocation(); + FVector QueryEnd = EndComponent->GetComponentLocation(); + FQuat QueryRotation = StartComponent->GetComponentQuat(); + TArray Hits; + TArray Overlaps; + bool HasHits = false; + + static const FName TraceTag(TEXT("FCogWindow_Collision")); + const FCollisionQueryParams QueryParams(TraceTag, SCENE_QUERY_STAT_ONLY(CogHitDetection), TraceComplex); + + const FCollisionResponseTemplate* Profile = UCollisionProfile::Get()->GetProfileByIndex(ProfileIndex); + const FName ProfileName = Profile != nullptr ? Profile->Name : FName(); + + FCollisionShape QueryShape; + + const bool bIsUsingShape = Type == ECogEngine_CollisionQueryType::Overlap || Type == ECogEngine_CollisionQueryType::Sweep; + if (bIsUsingShape) + { + switch (Shape) + { + case ECogEngine_CollisionQueryShape::Sphere: QueryShape.SetSphere(ShapeExtent.X); break; + case ECogEngine_CollisionQueryShape::Capsule: QueryShape.SetCapsule(ShapeExtent.X, ShapeExtent.Z); break; + case ECogEngine_CollisionQueryShape::Box: QueryShape.SetBox(FVector3f(ShapeExtent)); break; + } + } + + switch (Type) + { + case ECogEngine_CollisionQueryType::Overlap: + { + switch (By) + { + case ECogEngine_CollisionQueryBy::Channel: + { + HasHits = GetWorld()->OverlapMultiByChannel(Overlaps, QueryStart, QueryRotation, Channel, QueryShape, QueryParams); + break; + } + + case ECogEngine_CollisionQueryBy::ObjectType: + { + FCollisionObjectQueryParams QueryObjectParams; + QueryObjectParams.ObjectTypesToQuery = ObjectTypesToQuery; + HasHits = GetWorld()->OverlapMultiByObjectType(Overlaps, QueryStart, QueryRotation, QueryObjectParams, QueryShape, QueryParams); + break; + } + + case ECogEngine_CollisionQueryBy::Profile: + { + HasHits = GetWorld()->OverlapMultiByProfile(Overlaps, QueryStart, QueryRotation, ProfileName, QueryShape, QueryParams); + break; + } + } + + break; + } + + case ECogEngine_CollisionQueryType::LineTrace: + { + switch (By) + { + 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_CollisionQueryBy::ObjectType: + { + FCollisionObjectQueryParams QueryObjectParams; + QueryObjectParams.ObjectTypesToQuery = ObjectTypesToQuery; + + switch (Mode) + { + case ECogEngine_CollisionQueryMode::Single: + { + FHitResult Hit; + HasHits = GetWorld()->LineTraceSingleByObjectType(Hit, QueryStart, QueryEnd, QueryObjectParams, QueryParams); + if (HasHits) + { + 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: + { + switch (Mode) + { + 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; + } + } + break; + } + + case ECogEngine_CollisionQueryType::Sweep: + { + switch (By) + { + 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: + { + FCollisionObjectQueryParams QueryObjectParams; + QueryObjectParams.ObjectTypesToQuery = ObjectTypesToQuery; + + switch (Mode) + { + case ECogEngine_CollisionQueryMode::Single: + { + 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 (Mode) + { + case ECogEngine_CollisionQueryMode::Single: + { + FHitResult Hit; + HasHits = GetWorld()->SweepSingleByProfile(Hit, QueryStart, QueryEnd, QueryRotation, ProfileName, QueryShape, QueryParams); + if (HasHits) + { + Hits.Add(Hit); + } + break; + } + case ECogEngine_CollisionQueryMode::Multi: + { + HasHits = GetWorld()->SweepMultiByProfile(Hits, QueryStart, QueryEnd, QueryRotation, ProfileName, QueryShape, QueryParams); + break; + } + case ECogEngine_CollisionQueryMode::Test: + { + HasHits = GetWorld()->SweepTestByProfile(QueryStart, QueryEnd, QueryRotation, ProfileName, QueryShape, QueryParams); + break; + } + } + break; + } + } + break; + } + } + + const FColor Color = HasHits ? FLinearColor(HitColor).ToFColor(true) : FLinearColor(NoHitColor).ToFColor(true); + const bool bUseTrace = Type == ECogEngine_CollisionQueryType::LineTrace || Type == ECogEngine_CollisionQueryType::Sweep; + if (bUseTrace) + { + DrawDebugDirectionalArrow( + GetWorld(), + QueryStart, + QueryEnd, + FCogDebug::Settings.ArrowSize, + Color, + false, + 0.0f, + FCogDebug::GetDebugDepthPriority(0), + FCogDebug::GetDebugThickness(0.0f)); + } + + if (bIsUsingShape) + { + DrawShape(QueryShape, QueryStart, QueryRotation, FVector::OneVector, Color, false); + } + + for (const FOverlapResult& Overlap : Overlaps) + { + if (DrawHitPrimitives) + { + DrawPrimitive(Overlap.GetComponent()); + } + } + + for (const FHitResult& Hit : Hits) + { + if (DrawHitLocations) + { + DrawDebugPoint( + GetWorld(), + Hit.Location, + HitPointSize, + Color, + false, + 0.0f, + FCogDebug::GetDebugDepthPriority(0)); + } + + if (DrawHitImpactPoints) + { + DrawDebugPoint( + GetWorld(), + Hit.ImpactPoint, + HitPointSize, + Color, + false, + 0.0f, + FCogDebug::GetDebugDepthPriority(0)); + } + + if (bIsUsingShape && DrawHitShapes) + { + DrawShape(QueryShape, Hit.Location, QueryRotation, FVector::OneVector, Color, false); + } + + if (DrawHitNormals) + { + DrawDebugDirectionalArrow( + GetWorld(), + Hit.Location, + Hit.Location + Hit.Normal * 20.0f, + FCogDebug::Settings.ArrowSize, + FLinearColor(NormalColor).ToFColor(true), + false, + 0.0f, + FCogDebug::GetDebugDepthPriority(0), + FCogDebug::GetDebugThickness(0.0f)); + } + + if (DrawHitImpactNormals) + { + DrawDebugDirectionalArrow( + GetWorld(), + Hit.ImpactPoint, + Hit.ImpactPoint + Hit.ImpactNormal * 20.0f, + FCogDebug::Settings.ArrowSize, + FLinearColor(ImpactNormalColor).ToFColor(true), + false, + 0.0f, + FCogDebug::GetDebugDepthPriority(0), + FCogDebug::GetDebugThickness(0.0f)); + } + + if (DrawHitPrimitives) + { + DrawPrimitive(Hit.GetComponent()); + } + } +} + +//-------------------------------------------------------------------------------------------------------------------------- +void ACogEngineCollisionTester::DrawPrimitive(const UPrimitiveComponent* PrimitiveComponent) +{ + //------------------------------------------------------- + // Don't draw same primitives multiple times (for bones) + //------------------------------------------------------- + if (AlreadyDrawnComponents.Contains(PrimitiveComponent)) + { + return; + } + + AlreadyDrawnComponents.Add(PrimitiveComponent); + + ECollisionChannel CollisionObjectType = PrimitiveComponent->GetCollisionObjectType(); + FColor Color = FColor::Green; // Channels[CollisionObjectType].Color; + + //------------------------------------------------------- + // Draw Name + //------------------------------------------------------- + if (DrawHitActorsNames) + { + const AActor* Actor = PrimitiveComponent->GetOwner(); + if (Actor != nullptr) + { + if (AlreadyDrawnActors.Contains(Actor) == false) + { + FColor TextColor = Color.WithAlpha(255); + DrawDebugString(GetWorld(), Actor->GetActorLocation(), GetNameSafe(Actor->GetClass()), nullptr, FColor::White, 0.0f, FCogDebug::Settings.TextShadow, FCogDebug::Settings.TextSize); + AlreadyDrawnActors.Add(Actor); + } + } + } + + const FVector Location = PrimitiveComponent->GetComponentLocation(); + const FQuat Rotation = PrimitiveComponent->GetComponentQuat(); + const FVector Scale = PrimitiveComponent->GetComponentScale(); + const FCollisionShape PrimitiveShape = PrimitiveComponent->GetCollisionShape(); + DrawShape(PrimitiveShape, Location, Rotation, Scale, Color, true); +} + +//-------------------------------------------------------------------------------------------------------------------------- +void ACogEngineCollisionTester::DrawShape(const FCollisionShape& InShape, const FVector& InLocation, const FQuat& InRotation, const FVector& InScale, const FColor& InColor, bool InDrawSolid) const +{ + switch (InShape.ShapeType) + { + case ECollisionShape::Box: + { + //-------------------------------------------------- + // see UBoxComponent::GetScaledBoxExtent() + //-------------------------------------------------- + const FVector HalfExtent(InShape.Box.HalfExtentX * InScale.X, InShape.Box.HalfExtentY * InScale.Y, InShape.Box.HalfExtentZ * InScale.Z); + + if (InDrawSolid) + { + DrawDebugSolidBox( + GetWorld(), + InLocation, + HalfExtent, + InRotation, + InColor, + false, + 0.0f, + FCogDebug::GetDebugDepthPriority(0)); + } + + DrawDebugBox( + GetWorld(), + InLocation, + HalfExtent, + InRotation, + InColor, + false, + 0.0f, + FCogDebug::GetDebugDepthPriority(0), + FCogDebug::GetDebugThickness(0.0f)); + + break; + } + + case ECollisionShape::Sphere: + { + //-------------------------------------------------- + // see USphereComponent::GetScaledSphereRadius() + //-------------------------------------------------- + const float RadiusScale = FMath::Min(InScale.X, FMath::Min(InScale.Y, InScale.Z)); + const float Radius = InShape.Sphere.Radius * RadiusScale; + + FCogDebugDrawHelper::DrawSphere( + GetWorld(), + InLocation, + Radius, + FCogDebug::GetCircleSegments(), + InColor, + false, + 0.0f, + FCogDebug::GetDebugDepthPriority(0), + FCogDebug::GetDebugThickness(0.0f)); + break; + } + + case ECollisionShape::Capsule: + { + //-------------------------------------------------- + // see UCapsuleComponent::GetScaledCapsuleRadius() + //-------------------------------------------------- + const float Radius = InShape.Capsule.Radius * FMath::Min(InScale.X, InScale.Y); + const float HalfHeight = InShape.Capsule.HalfHeight * UE_REAL_TO_FLOAT(InScale.Z); + + DrawDebugCapsule( + GetWorld(), + InLocation, + HalfHeight, + Radius, + InRotation, + InColor, + false, + 0.0f, + FCogDebug::GetDebugDepthPriority(0), + FCogDebug::GetDebugThickness(0.0f)); + break; + } + } +} diff --git a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CollisionTester.cpp b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CollisionTester.cpp index 8915ca8..988fc7b 100644 --- a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CollisionTester.cpp +++ b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CollisionTester.cpp @@ -1,6 +1,5 @@ #include "CogEngineWindow_CollisionTester.h" -#include "CogDebugDrawHelper.h" #include "CogDebug.h" #include "CogEngineDataAsset.h" #include "CogImGuiHelper.h" @@ -109,16 +108,6 @@ void FCogEngineWindow_CollisionTester::RenderContent() { Super::RenderContent(); - //------------------------------------------------- - // Query Profile - //------------------------------------------------- - - const UCollisionProfile* CollisionProfile = UCollisionProfile::Get(); - if (CollisionProfile == nullptr) - { - return; - } - //------------------------------------------------- // Menu //------------------------------------------------- @@ -148,33 +137,63 @@ void FCogEngineWindow_CollisionTester::RenderContent() ImGui::EndMenuBar(); } - FCogWindowWidgets::SetNextItemToShortWidth(); - FCogWindowWidgets::ComboboxEnum("Type", Config->Type); + if (ImGui::Button("Spawn Collision Tester", ImVec2(-1, 0))) + { + const FActorSpawnParameters SpawnInfo; + ACogEngineCollisionTester* Actor = GetWorld()->SpawnActor(SpawnInfo); + FCogDebug::SetSelection(GetWorld(), Actor); + } + + ACogEngineCollisionTester* CollisionTester = Cast(GetSelection()); + if (CollisionTester == nullptr) + { + ImGui::TextDisabled("Spawn or select a Collision Tester actor"); + return; + } + + const UCollisionProfile* CollisionProfile = UCollisionProfile::Get(); + if (CollisionProfile == nullptr) + { + ImGui::TextDisabled("No CollisionProfile"); + return; + } + + if (const APlayerController* LocalPlayerController = GetLocalPlayerController()) + { + FTransform Transform = CollisionTester->EndComponent->GetComponentTransform(); + if (EndGizmo.Draw("CollisionTesterEndGizmo", *LocalPlayerController, Transform, ECogDebug_GizmoFlags::NoRotation | ECogDebug_GizmoFlags::NoScale)) + { + CollisionTester->EndComponent->SetWorldTransform(Transform); + } + } FCogWindowWidgets::SetNextItemToShortWidth(); - FCogWindowWidgets::ComboboxEnum("Mode", Config->Mode); + FCogWindowWidgets::ComboboxEnum("Type", CollisionTester->Type); FCogWindowWidgets::SetNextItemToShortWidth(); - FCogWindowWidgets::ComboboxEnum("By", Config->By); + FCogWindowWidgets::ComboboxEnum("Mode", CollisionTester->Mode); + + FCogWindowWidgets::SetNextItemToShortWidth(); + FCogWindowWidgets::ComboboxEnum("By", CollisionTester->By); //------------------------------------------------- // Channel //------------------------------------------------- - if (Config->By == ECogEngine_CollisionQueryBy::Channel) + if (CollisionTester->By == ECogEngine_CollisionQueryBy::Channel) { FCogWindowWidgets::SetNextItemToShortWidth(); - ECollisionChannel Channel = Config->Channel.GetValue(); + ECollisionChannel Channel = CollisionTester->Channel.GetValue(); if (RenderComboCollisionChannel("Channel", *CollisionProfile, Channel, Asset->Channels)) { - Config->Channel = Channel; + CollisionTester->Channel = Channel; } } //------------------------------------------------- // Profile //------------------------------------------------- - else if (Config->By == ECogEngine_CollisionQueryBy::Profile) + else if (CollisionTester->By == ECogEngine_CollisionQueryBy::Profile) { - const FCollisionResponseTemplate* SelectedProfile = CollisionProfile->GetProfileByIndex(Config->ProfileIndex); + const FCollisionResponseTemplate* SelectedProfile = CollisionProfile->GetProfileByIndex(CollisionTester->ProfileIndex); const FName SelectedProfileName = SelectedProfile != nullptr ? SelectedProfile->Name : FName("Custom"); FCogWindowWidgets::SetNextItemToShortWidth(); @@ -185,9 +204,9 @@ void FCogEngineWindow_CollisionTester::RenderContent() const FCollisionResponseTemplate* Profile = CollisionProfile->GetProfileByIndex(i); if (ImGui::Selectable(TCHAR_TO_ANSI(*Profile->Name.ToString()), false)) { - Config->ProfileIndex = i; - Config->ObjectTypesToQuery = 0; - SelectedProfile = CollisionProfile->GetProfileByIndex(Config->ProfileIndex); + CollisionTester->ProfileIndex = i; + CollisionTester->ObjectTypesToQuery = 0; + SelectedProfile = CollisionProfile->GetProfileByIndex(CollisionTester->ProfileIndex); if (Profile->CollisionEnabled != ECollisionEnabled::NoCollision) { @@ -196,7 +215,7 @@ void FCogEngineWindow_CollisionTester::RenderContent() const ECollisionResponse Response = Profile->ResponseToChannels.GetResponse((ECollisionChannel)j); if (Response != ECR_Ignore) { - Config->ObjectTypesToQuery |= ECC_TO_BITFIELD(j); + CollisionTester->ObjectTypesToQuery |= ECC_TO_BITFIELD(j); } } } @@ -206,40 +225,40 @@ void FCogEngineWindow_CollisionTester::RenderContent() } } - ImGui::Checkbox("Complex", &Config->TraceComplex); + ImGui::Checkbox("Complex", &CollisionTester->TraceComplex); //------------------------------------------------- // Shape //------------------------------------------------- - if (Config->Type != ECogEngine_CollisionQueryType::LineTrace) + if (CollisionTester->Type != ECogEngine_CollisionQueryType::LineTrace) { FCogWindowWidgets::SetNextItemToShortWidth(); - FCogWindowWidgets::ComboboxEnum("Shape", Config->Shape); + FCogWindowWidgets::ComboboxEnum("Shape", CollisionTester->Shape); - switch (Config->Shape) + switch (CollisionTester->Shape) { case ECogEngine_CollisionQueryShape::Sphere: { FCogWindowWidgets::SetNextItemToShortWidth(); - FCogImguiHelper::DragDouble("Sphere Radius", &Config->ShapeExtent.X, 0.1f, 0, FLT_MAX, "%.1f"); + FCogImguiHelper::DragDouble("Sphere Radius", &CollisionTester->ShapeExtent.X, 0.1f, 0, FLT_MAX, "%.1f"); break; } case ECogEngine_CollisionQueryShape::Box: { FCogWindowWidgets::SetNextItemToShortWidth(); - FCogImguiHelper::DragFVector("Box Extent", Config->ShapeExtent, 0.1f, 0, FLT_MAX, "%.1f"); + FCogImguiHelper::DragFVector("Box Extent", CollisionTester->ShapeExtent, 0.1f, 0, FLT_MAX, "%.1f"); break; } case ECogEngine_CollisionQueryShape::Capsule: { FCogWindowWidgets::SetNextItemToShortWidth(); - FCogImguiHelper::DragDouble("Capsule Radius", &Config->ShapeExtent.X, 0.1f, 0, FLT_MAX, "%.1f"); + FCogImguiHelper::DragDouble("Capsule Radius", &CollisionTester->ShapeExtent.X, 0.1f, 0, FLT_MAX, "%.1f"); FCogWindowWidgets::SetNextItemToShortWidth(); - FCogImguiHelper::DragDouble("Capsule Half Height", &Config->ShapeExtent.Z, 0.1f, 0, FLT_MAX, "%.1f"); + FCogImguiHelper::DragDouble("Capsule Half Height", &CollisionTester->ShapeExtent.Z, 0.1f, 0, FLT_MAX, "%.1f"); break; } } @@ -250,517 +269,18 @@ void FCogEngineWindow_CollisionTester::RenderContent() //------------------------------------------------- // Channels //------------------------------------------------- - if (Config->By == ECogEngine_CollisionQueryBy::Profile) + if (CollisionTester->By == ECogEngine_CollisionQueryBy::Profile) { ImGui::BeginDisabled(); - RenderCollisionProfileChannels(*CollisionProfile, Config->ObjectTypesToQuery, Asset->Channels); + RenderCollisionProfileChannels(*CollisionProfile, CollisionTester->ObjectTypesToQuery, Asset->Channels); ImGui::EndDisabled(); } - else if (Config->By == ECogEngine_CollisionQueryBy::ObjectType) + else if (CollisionTester->By == ECogEngine_CollisionQueryBy::ObjectType) { - RenderCollisionProfileChannels(*CollisionProfile, Config->ObjectTypesToQuery, Asset->Channels); - } - - - Query(); -} - -//-------------------------------------------------------------------------------------------------------------------------- -void FCogEngineWindow_CollisionTester::Query() -{ - AlreadyDrawnActors.Empty(); - AlreadyDrawnComponents.Empty(); - - const APlayerController* PlayerController = GetLocalPlayerController(); - if (PlayerController == nullptr) - { - return; - } - - FVector QueryStart = Config->LocationStart; - FVector QueryEnd = Config->LocationEnd; - FQuat QueryRotation = FQuat(Config->Rotation); - TArray Hits; - TArray Overlaps; - bool HasHits = false; - - - static const FName TraceTag(TEXT("FCogWindow_Collision")); - const FCollisionQueryParams QueryParams(TraceTag, SCENE_QUERY_STAT_ONLY(CogHitDetection), Config->TraceComplex); - - const FCollisionResponseTemplate* Profile = UCollisionProfile::Get()->GetProfileByIndex(Config->ProfileIndex); - const FName ProfileName = Profile != nullptr ? Profile->Name : FName(); - - FCollisionShape QueryShape; - - const bool bIsUsingShape = Config->Type == ECogEngine_CollisionQueryType::Overlap || Config->Type == ECogEngine_CollisionQueryType::Sweep; - if (bIsUsingShape) - { - switch (Config->Shape) - { - case ECogEngine_CollisionQueryShape::Sphere: QueryShape.SetSphere(Config->ShapeExtent.X); break; - case ECogEngine_CollisionQueryShape::Capsule: QueryShape.SetCapsule(Config->ShapeExtent.X, Config->ShapeExtent.Z); break; - case ECogEngine_CollisionQueryShape::Box: QueryShape.SetBox(FVector3f(Config->ShapeExtent)); break; - } - } - - switch (Config->Type) - { - case ECogEngine_CollisionQueryType::Overlap: - { - switch (Config->By) - { - case ECogEngine_CollisionQueryBy::Channel: - { - HasHits = GetWorld()->OverlapMultiByChannel(Overlaps, QueryStart, QueryRotation, Config->Channel, QueryShape, QueryParams); - break; - } - - case ECogEngine_CollisionQueryBy::ObjectType: - { - FCollisionObjectQueryParams QueryObjectParams; - QueryObjectParams.ObjectTypesToQuery = Config->ObjectTypesToQuery; - HasHits = GetWorld()->OverlapMultiByObjectType(Overlaps, QueryStart, QueryRotation, QueryObjectParams, QueryShape, QueryParams); - break; - } - - case ECogEngine_CollisionQueryBy::Profile: - { - HasHits = GetWorld()->OverlapMultiByProfile(Overlaps, QueryStart, QueryRotation, ProfileName, QueryShape, QueryParams); - break; - } - } - - break; - } - - case ECogEngine_CollisionQueryType::LineTrace: - { - switch (Config->By) - { - case ECogEngine_CollisionQueryBy::Channel: - { - switch (Config->Mode) - { - case ECogEngine_CollisionQueryMode::Single: - { - FHitResult Hit; - HasHits = GetWorld()->LineTraceSingleByChannel(Hit, QueryStart, QueryEnd, Config->Channel, QueryParams); - if (HasHits) - { - Hits.Add(Hit); - } - break; - } - case ECogEngine_CollisionQueryMode::Multi: - { - HasHits = GetWorld()->LineTraceMultiByChannel(Hits, QueryStart, QueryEnd, Config->Channel, QueryParams); - break; - } - case ECogEngine_CollisionQueryMode::Test: - { - HasHits = GetWorld()->LineTraceTestByChannel(QueryStart, QueryEnd, Config->Channel, QueryParams); - break; - } - } - - break; - } - - case ECogEngine_CollisionQueryBy::ObjectType: - { - FCollisionObjectQueryParams QueryObjectParams; - QueryObjectParams.ObjectTypesToQuery = Config->ObjectTypesToQuery; - - switch (Config->Mode) - { - case ECogEngine_CollisionQueryMode::Single: - { - FHitResult Hit; - HasHits = GetWorld()->LineTraceSingleByObjectType(Hit, QueryStart, QueryEnd, QueryObjectParams, QueryParams); - if (HasHits) - { - 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: - { - switch (Config->Mode) - { - 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; - } - } - break; - } - - case ECogEngine_CollisionQueryType::Sweep: - { - switch (Config->By) - { - case ECogEngine_CollisionQueryBy::Channel: - { - switch (Config->Mode) - { - case ECogEngine_CollisionQueryMode::Single: - { - FHitResult Hit; - HasHits = GetWorld()->SweepSingleByChannel(Hit, QueryStart, QueryEnd, QueryRotation, Config->Channel, QueryShape, QueryParams); - if (HasHits) - { - Hits.Add(Hit); - } - break; - } - case ECogEngine_CollisionQueryMode::Multi: - { - HasHits = GetWorld()->SweepMultiByChannel(Hits, QueryStart, QueryEnd, QueryRotation, Config->Channel, QueryShape, QueryParams); - break; - } - case ECogEngine_CollisionQueryMode::Test: - { - HasHits = GetWorld()->SweepTestByChannel(QueryStart, QueryEnd, QueryRotation, Config->Channel, QueryShape, QueryParams); - break; - } - } - break; - } - - case ECogEngine_CollisionQueryBy::ObjectType: - { - FCollisionObjectQueryParams QueryObjectParams; - QueryObjectParams.ObjectTypesToQuery = Config->ObjectTypesToQuery; - - switch (Config->Mode) - { - case ECogEngine_CollisionQueryMode::Single: - { - 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 (Config->Mode) - { - case ECogEngine_CollisionQueryMode::Single: - { - FHitResult Hit; - HasHits = GetWorld()->SweepSingleByProfile(Hit, QueryStart, QueryEnd, QueryRotation, ProfileName, QueryShape, QueryParams); - if (HasHits) - { - Hits.Add(Hit); - } - break; - } - case ECogEngine_CollisionQueryMode::Multi: - { - HasHits = GetWorld()->SweepMultiByProfile(Hits, QueryStart, QueryEnd, QueryRotation, ProfileName, QueryShape, QueryParams); - break; - } - case ECogEngine_CollisionQueryMode::Test: - { - HasHits = GetWorld()->SweepTestByProfile(QueryStart, QueryEnd, QueryRotation, ProfileName, QueryShape, QueryParams); - break; - } - } - break; - } - } - break; - } - } - - const FColor Color = HasHits ? FLinearColor(Config->HitColor).ToFColor(true) : FLinearColor(Config->NoHitColor).ToFColor(true); - const bool bUseTrace = Config->Type == ECogEngine_CollisionQueryType::LineTrace || Config->Type == ECogEngine_CollisionQueryType::Sweep; - if (bUseTrace) - { - DrawDebugDirectionalArrow( - GetWorld(), - QueryStart, - QueryEnd, - FCogDebug::Settings.ArrowSize, - Color, - false, - 0.0f, - FCogDebug::GetDebugDepthPriority(0), - FCogDebug::GetDebugThickness(0.0f)); - } - - if (bIsUsingShape) - { - DrawShape(QueryShape, QueryStart, QueryRotation, FVector::OneVector, Color, false); - } - - for (const FOverlapResult& Overlap : Overlaps) - { - if (Config->DrawHitPrimitives) - { - DrawPrimitive(Overlap.GetComponent()); - } - } - - for (const FHitResult& Hit : Hits) - { - if (Config->DrawHitLocations) - { - DrawDebugPoint( - GetWorld(), - Hit.Location, - Config->HitPointSize, - Color, - false, - 0.0f, - FCogDebug::GetDebugDepthPriority(0)); - } - - if (Config->DrawHitImpactPoints) - { - DrawDebugPoint( - GetWorld(), - Hit.ImpactPoint, - Config->HitPointSize, - Color, - false, - 0.0f, - FCogDebug::GetDebugDepthPriority(0)); - } - - if (bIsUsingShape && Config->DrawHitShapes) - { - DrawShape(QueryShape, Hit.Location, QueryRotation, FVector::OneVector, Color, false); - } - - if (Config->DrawHitNormals) - { - DrawDebugDirectionalArrow( - GetWorld(), - Hit.Location, - Hit.Location + Hit.Normal * 20.0f, - FCogDebug::Settings.ArrowSize, - FLinearColor(Config->NormalColor).ToFColor(true), - false, - 0.0f, - FCogDebug::GetDebugDepthPriority(0), - FCogDebug::GetDebugThickness(0.0f)); - } - - if (Config->DrawHitImpactNormals) - { - DrawDebugDirectionalArrow( - GetWorld(), - Hit.ImpactPoint, - Hit.ImpactPoint + Hit.ImpactNormal * 20.0f, - FCogDebug::Settings.ArrowSize, - FLinearColor(Config->ImpactNormalColor).ToFColor(true), - false, - 0.0f, - FCogDebug::GetDebugDepthPriority(0), - FCogDebug::GetDebugThickness(0.0f)); - } - - if (Config->DrawHitPrimitives) - { - DrawPrimitive(Hit.GetComponent()); - } - } - - if (const APlayerController* LocalPlayerController = GetLocalPlayerController()) - { - FVector ScaleStart(Config->ShapeExtent); - FTransform TransformStart(QueryRotation, QueryStart, ScaleStart); - GizmoStart.Draw("Query Start", *LocalPlayerController, TransformStart); - Config->LocationStart = TransformStart.GetLocation(); - Config->Rotation = FRotator(TransformStart.GetRotation()); - Config->ShapeExtent = TransformStart.GetScale3D(); - - if (Config->Type != ECogEngine_CollisionQueryType::Overlap) - { - FTransform TransformEnd(FRotator::ZeroRotator, QueryEnd, FVector::OneVector); - GizmoEnd.Draw("Query End", *LocalPlayerController, TransformEnd, ECogDebug_GizmoFlags::NoRotation | ECogDebug_GizmoFlags::NoScale); - Config->LocationEnd = TransformEnd.GetLocation(); - } + RenderCollisionProfileChannels(*CollisionProfile, CollisionTester->ObjectTypesToQuery, Asset->Channels); } } -//-------------------------------------------------------------------------------------------------------------------------- -void FCogEngineWindow_CollisionTester::DrawPrimitive(const UPrimitiveComponent* PrimitiveComponent) -{ - //------------------------------------------------------- - // Don't draw same primitives multiple times (for bones) - //------------------------------------------------------- - if (AlreadyDrawnComponents.Contains(PrimitiveComponent)) - { - return; - } - - AlreadyDrawnComponents.Add(PrimitiveComponent); - - ECollisionChannel CollisionObjectType = PrimitiveComponent->GetCollisionObjectType(); - FColor Color = Channels[CollisionObjectType].Color; - - //------------------------------------------------------- - // Draw Name - //------------------------------------------------------- - if (Config->DrawHitActorsNames) - { - const AActor* Actor = PrimitiveComponent->GetOwner(); - if (Actor != nullptr) - { - if (AlreadyDrawnActors.Contains(Actor) == false) - { - FColor TextColor = Color.WithAlpha(255); - DrawDebugString(GetWorld(), Actor->GetActorLocation(), GetNameSafe(Actor->GetClass()), nullptr, FColor::White, 0.0f, FCogDebug::Settings.TextShadow, FCogDebug::Settings.TextSize); - AlreadyDrawnActors.Add(Actor); - } - } - } - - const FVector Location = PrimitiveComponent->GetComponentLocation(); - const FQuat Rotation = PrimitiveComponent->GetComponentQuat(); - const FVector Scale = PrimitiveComponent->GetComponentScale(); - const FCollisionShape Shape = PrimitiveComponent->GetCollisionShape(); - DrawShape(Shape, Location, Rotation, Scale, Color, true); -} - -//-------------------------------------------------------------------------------------------------------------------------- -void FCogEngineWindow_CollisionTester::DrawShape(const FCollisionShape& Shape, const FVector& Location, const FQuat& Rotation, const FVector& Scale, const FColor& Color, bool DrawSolid) const -{ - switch (Shape.ShapeType) - { - case ECollisionShape::Box: - { - //-------------------------------------------------- - // see UBoxComponent::GetScaledBoxExtent() - //-------------------------------------------------- - const FVector HalfExtent(Shape.Box.HalfExtentX * Scale.X, Shape.Box.HalfExtentY * Scale.Y, Shape.Box.HalfExtentZ * Scale.Z); - - if (DrawSolid) - { - DrawDebugSolidBox( - GetWorld(), - Location, - HalfExtent, - Rotation, - Color, - false, - 0.0f, - FCogDebug::GetDebugDepthPriority(0)); - } - - DrawDebugBox( - GetWorld(), - Location, - HalfExtent, - Rotation, - Color, - false, - 0.0f, - FCogDebug::GetDebugDepthPriority(0), - FCogDebug::GetDebugThickness(0.0f)); - - break; - } - - case ECollisionShape::Sphere: - { - //-------------------------------------------------- - // see USphereComponent::GetScaledSphereRadius() - //-------------------------------------------------- - const float RadiusScale = FMath::Min(Scale.X, FMath::Min(Scale.Y, Scale.Z)); - const float Radius = Shape.Sphere.Radius * RadiusScale; - - FCogDebugDrawHelper::DrawSphere( - GetWorld(), - Location, - Radius, - FCogDebug::GetCircleSegments(), - Color, - false, - 0.0f, - FCogDebug::GetDebugDepthPriority(0), - FCogDebug::GetDebugThickness(0.0f)); - break; - } - - case ECollisionShape::Capsule: - { - //-------------------------------------------------- - // see UCapsuleComponent::GetScaledCapsuleRadius() - //-------------------------------------------------- - const float Radius = Shape.Capsule.Radius * FMath::Min(Scale.X, Scale.Y); - const float HalfHeight = Shape.Capsule.HalfHeight * UE_REAL_TO_FLOAT(Scale.Z); - - DrawDebugCapsule( - GetWorld(), - Location, - HalfHeight, - Radius, - Rotation, - Color, - false, - 0.0f, - FCogDebug::GetDebugDepthPriority(0), - FCogDebug::GetDebugThickness(0.0f)); - break; - } - } -} - - //-------------------------------------------------------------------------------------------------------------------------- void FCogEngineWindow_CollisionTester::SetAsset(const UCogEngineDataAsset* Value) { diff --git a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_DebugSettings.cpp b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_DebugSettings.cpp index e657c61..f1ccf3b 100644 --- a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_DebugSettings.cpp +++ b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_DebugSettings.cpp @@ -205,7 +205,7 @@ void FCogEngineWindow_DebugSettings::RenderContent() ImGui::Checkbox("Gizmo Translation Snap Enable", &Settings.GizmoTranslationSnapEnable); FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Gizmo Translation Snap", &Settings.GizmoTranslationSnap, 0.1f, 0.0f, 1000.0f, "%.1f"); + ImGui::DragFloat("Gizmo Translation Snap", &Settings.GizmoTranslationSnapValue, 0.1f, 0.0f, 1000.0f, "%.1f"); FCogWindowWidgets::SetNextItemToShortWidth(); ImGui::DragFloat("Gizmo Translation Axis Length", &Settings.GizmoTranslationAxisLength, 0.1f, 0.1f, 500.0f, "%.1f"); @@ -220,7 +220,7 @@ void FCogEngineWindow_DebugSettings::RenderContent() ImGui::Checkbox("Gizmo Rotation Snap Enable", &Settings.GizmoRotationSnapEnable); FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Gizmo Rotation Snap", &Settings.GizmoRotationSnap, 0.1f, 0.0f, 360.0f, "%.1f"); + ImGui::DragFloat("Gizmo Rotation Snap", &Settings.GizmoRotationSnapValue, 0.1f, 0.0f, 360.0f, "%.1f"); FCogWindowWidgets::SetNextItemToShortWidth(); ImGui::DragFloat("Gizmo Rotation Speed", &Settings.GizmoRotationSpeed, 0.01f, 0.01f, 100.0f, "%.2f"); @@ -235,7 +235,7 @@ void FCogEngineWindow_DebugSettings::RenderContent() ImGui::Checkbox("Gizmo Scale Snap Enable", &Settings.GizmoScaleSnapEnable); FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Gizmo Scale Snap", &Settings.GizmoScaleSnap, 0.1f, 0.0f, 10.0f, "%.1f"); + ImGui::DragFloat("Gizmo Scale Snap", &Settings.GizmoScaleSnapValue, 0.1f, 0.0f, 10.0f, "%.1f"); FCogWindowWidgets::SetNextItemToShortWidth(); ImGui::DragFloat("Gizmo Scale Box Offset", &Settings.GizmoScaleBoxOffset, 0.0f, 0.0f, 500.0f, "%.1f"); diff --git a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Transform.cpp b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Transform.cpp new file mode 100644 index 0000000..635442d --- /dev/null +++ b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Transform.cpp @@ -0,0 +1,256 @@ +#include "CogEngineWindow_Transform.h" + +#include "CogDebug.h" +#include "CogImGuiHelper.h" +#include "CogWindowWidgets.h" +#include "imgui.h" +#include "imgui_internal.h" + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogEngineWindow_Transform::Initialize() +{ + Super::Initialize(); + Config = GetConfig(); + bHasMenu = true; +} + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogEngineWindow_Transform::RenderHelp() +{ + ImGui::Text( + "This window can be used to modify the transform of the selected actor." + ); +} + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogEngineWindow_Transform::RenderContent() +{ + Super::RenderContent(); + + AActor* Selection = GetSelection(); + if (Selection == nullptr) + { + ImGui::TextDisabled("No Selection"); + return; + } + + if (ImGui::BeginMenuBar()) + { + if (ImGui::BeginMenu("Options")) + { + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragFloat("Drag Speed Location", &Config->LocationSpeed, 0.1f, 0.1f, 100.0f); + + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragFloat("Drag Speed Rotation", &Config->RotationSpeed, 0.1f, 0.1f, 100.0f); + + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragFloat("Drag Speed Scale", &Config->ScaleSpeed, 0.1f, 0.1f, 100.0f); + + ImGui::SeparatorText("Gizmo"); + FCogDebugSettings& Settings = FCogDebug::Settings; + ImGui::Checkbox("Local Space Gizmo", &Settings.GizmoUseLocalSpace); + RenderSnap("##Location", "Snap Location", &Settings.GizmoTranslationSnapEnable, &Settings.GizmoTranslationSnapValue); + RenderSnap("##Rotation", "Snap Rotation", &Settings.GizmoRotationSnapEnable, &Settings.GizmoRotationSnapValue); + RenderSnap("##Scale", "Snap Scale", &Settings.GizmoScaleSnapEnable, &Settings.GizmoScaleSnapValue); + + ImGui::EndMenu(); + } + + ImGui::EndMenuBar(); + } + + FTransform Transform = Selection->GetActorTransform(); + if (RenderTransform(Transform)) + { + Selection->SetActorTransform(Transform); + } + + if (const APlayerController* LocalPlayerController = GetLocalPlayerController()) + { + if (Gizmo.Draw("Transform", *LocalPlayerController, Transform)) + { + Selection->SetActorTransform(Transform); + } + } + + ImGui::PopStyleVar(); +} + + +//-------------------------------------------------------------------------------------------------------------------------- +bool FCogEngineWindow_Transform::RenderComponent(const char* Label, double* Value, float Speed, double Min, double Max, double Reset) +{ + ImGui::PushItemWidth(-1); + bool Result = FCogImguiHelper::DragDouble(Label, Value, Speed, Min, Max, "%.2f"); + + if (ImGui::IsItemActive() && ImGui::TempInputIsActive(ImGui::GetActiveID())) + { + Result = false; + } + + if (ImGui::BeginItemTooltip()) + { + ImGui::Text("%.2f", *Value); + ImGui::TextDisabled("Reset [RMB]"); + ImGui::EndTooltip(); + } + + if (ImGui::IsItemClicked(ImGuiMouseButton_Right)) + { + *Value = Reset; + Result = true; + } + + ImGui::PopItemWidth(); + return Result; +} + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogEngineWindow_Transform::RenderSnap(const char* CheckboxLabel, const char* InputLabel, bool* SnapEnable, float* Snap) +{ + ImGui::Checkbox(CheckboxLabel, SnapEnable); + + ImGui::SameLine(); + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragFloat(InputLabel, Snap, 0.1f, 0.1f, 1000.0f, "%.1f"); +} + +//-------------------------------------------------------------------------------------------------------------------------- +bool FCogEngineWindow_Transform::RenderLocation(FTransform& InOutTransform) +{ + ImGui::PushID("Location"); + ImGui::TableNextRow(); + + ImGui::TableNextColumn(); + ImGui::Text("Location"); + + FVector Location = InOutTransform.GetTranslation(); + bool Result = false; + + ImGui::TableNextColumn(); + if (RenderComponent("##X", &Location.X, Config->LocationSpeed, 0.0, 0.0, 0.0)) + { + InOutTransform.SetTranslation(Location); + Result = true; + } + + ImGui::TableNextColumn(); + if (RenderComponent("##Y", &Location.Y, Config->LocationSpeed, 0.0, 0.0, 0.0)) + { + InOutTransform.SetTranslation(Location); + Result = true; + } + + ImGui::TableNextColumn(); + if (RenderComponent("##Z", &Location.Z, Config->LocationSpeed, 0.0, 0.0, 0.0)) + { + InOutTransform.SetTranslation(Location); + Result = true; + } + + ImGui::PopID(); + + return Result; +} + +//-------------------------------------------------------------------------------------------------------------------------- +bool FCogEngineWindow_Transform::RenderRotation(FTransform& InOutTransform) +{ + ImGui::PushID("Rotation"); + ImGui::TableNextRow(); + + ImGui::TableNextColumn(); + ImGui::Text("Rotation"); + + FRotator Rotation = InOutTransform.GetRotation().Rotator(); + bool Result = false; + + ImGui::TableNextColumn(); + if (RenderComponent("##X", &Rotation.Yaw, Config->RotationSpeed, 0.0, 0.0, 0.0)) + { + InOutTransform.SetRotation(Rotation.Quaternion()); + Result = true; + } + + ImGui::TableNextColumn(); + if (RenderComponent("##Y", &Rotation.Pitch, Config->RotationSpeed, 0.0, 0.0, 0.0)) + { + InOutTransform.SetRotation(Rotation.Quaternion()); + Result = true; + } + + ImGui::TableNextColumn(); + if (RenderComponent("##Z", &Rotation.Roll, Config->RotationSpeed, 0.0, 0.0, 0.0)) + { + InOutTransform.SetRotation(Rotation.Quaternion()); + Result = true; + } + + + ImGui::PopID(); + + return Result; +} + +//-------------------------------------------------------------------------------------------------------------------------- +bool FCogEngineWindow_Transform::RenderScale(FTransform& InOutTransform) +{ + ImGui::PushID("Scale"); + ImGui::TableNextRow(); + + ImGui::TableNextColumn(); + ImGui::Text("Scale"); + + FVector Scale = InOutTransform.GetScale3D(); + bool Result = false; + + ImGui::TableNextColumn(); + if (RenderComponent("##X", &Scale.X, Config->ScaleSpeed, 0.01, 1000.0, 1.0)) + { + InOutTransform.SetScale3D(Scale); + Result = true; + } + + ImGui::TableNextColumn(); + if (RenderComponent("##Y", &Scale.Y, Config->ScaleSpeed, 0.01, 1000.0, 1.0)) + { + InOutTransform.SetScale3D(Scale); + Result = true; + } + + ImGui::TableNextColumn(); + if (RenderComponent("##Z", &Scale.Z, Config->ScaleSpeed, 0.01, 1000.0, 1.0)) + { + InOutTransform.SetScale3D(Scale); + Result = true; + } + + ImGui::PopID(); + + return Result; +} + +//-------------------------------------------------------------------------------------------------------------------------- +bool FCogEngineWindow_Transform::RenderTransform(FTransform& InOutTransform) +{ + ImGui::PushStyleVar(ImGuiStyleVar_CellPadding, ImVec2(1.0f, 1.0f)); + + bool Result = false; + + if (ImGui::BeginTable("Pools", 4, ImGuiTableFlags_SizingFixedFit)) + { + ImGui::TableSetupColumn("Name", ImGuiTableColumnFlags_WidthFixed, ImGui::GetFontSize() * 5); + ImGui::TableSetupColumn("X", ImGuiTableColumnFlags_WidthStretch); + ImGui::TableSetupColumn("Y", ImGuiTableColumnFlags_WidthStretch); + ImGui::TableSetupColumn("Z", ImGuiTableColumnFlags_WidthStretch); + + Result |= RenderLocation(InOutTransform); + Result |= RenderRotation(InOutTransform); + Result |= RenderScale(InOutTransform); + + ImGui::EndTable(); + } + + return Result; +} diff --git a/Plugins/Cog/Source/CogEngine/Public/CogEngineCollisionTester.h b/Plugins/Cog/Source/CogEngine/Public/CogEngineCollisionTester.h new file mode 100644 index 0000000..0610053 --- /dev/null +++ b/Plugins/Cog/Source/CogEngine/Public/CogEngineCollisionTester.h @@ -0,0 +1,140 @@ +#pragma once + +#include "CoreMinimal.h" +#include "Engine/HitResult.h" +#include "CogEngineCollisionTester.generated.h" + +class UCogEngineEditAnywhere_CollisionViewer; +class UCogEngineDataAsset; +class UPrimitiveComponent; +struct FCollisionShape; + +//-------------------------------------------------------------------------------------------------------------------------- +UENUM() +enum class ECogEngine_CollisionQueryType : uint8 +{ + Overlap, + LineTrace, + Sweep, +}; + +//-------------------------------------------------------------------------------------------------------------------------- +UENUM() +enum class ECogEngine_CollisionQueryMode : uint8 +{ + Single, + Multi, + Test, +}; + +//-------------------------------------------------------------------------------------------------------------------------- +UENUM() +enum class ECogEngine_CollisionQueryBy : uint8 +{ + Channel, + ObjectType, + Profile, +}; + +//-------------------------------------------------------------------------------------------------------------------------- +UENUM() +enum class ECogEngine_CollisionQueryShape : uint8 +{ + Sphere, + Box, + Capsule, +}; + +//-------------------------------------------------------------------------------------------------------------------------- +UCLASS() +class COGENGINE_API ACogEngineCollisionTester : public AActor +{ + GENERATED_BODY() + +public: + ACogEngineCollisionTester(const FObjectInitializer& ObjectInitializer); + + virtual void Tick(float DeltaSeconds) override; + virtual bool ShouldTickIfViewportsOnly() const override; + + void Query(); + void DrawPrimitive(const UPrimitiveComponent* PrimitiveComponent); + void DrawShape(const FCollisionShape& Shape, const FVector& InLocation, const FQuat& InRotation, const FVector& InScale, + const FColor& InColor, bool InDrawSolid) const; + + UPROPERTY(EditAnywhere) + bool TickInEditor = false; + + UPROPERTY(EditAnywhere) + ECogEngine_CollisionQueryType Type = ECogEngine_CollisionQueryType::LineTrace; + + UPROPERTY(EditAnywhere) + ECogEngine_CollisionQueryMode Mode = ECogEngine_CollisionQueryMode::Multi; + + UPROPERTY(EditAnywhere) + ECogEngine_CollisionQueryBy By = ECogEngine_CollisionQueryBy::Channel; + + UPROPERTY(EditAnywhere) + ECogEngine_CollisionQueryShape Shape = ECogEngine_CollisionQueryShape::Sphere; + + UPROPERTY(EditAnywhere) + bool TraceComplex = false; + + UPROPERTY() + int32 ObjectTypesToQuery = 0; + + UPROPERTY(EditAnywhere) + TEnumAsByte Channel = ECC_WorldStatic; + + UPROPERTY() + int32 ProfileIndex = 0; + + UPROPERTY(EditAnywhere) + FVector ShapeExtent = FVector::One(); + + UPROPERTY(EditAnywhere) + bool DrawHitLocations = true; + + UPROPERTY(EditAnywhere) + bool DrawHitImpactPoints = true; + + UPROPERTY(EditAnywhere) + bool DrawHitShapes = true; + + UPROPERTY(EditAnywhere) + bool DrawHitNormals = true; + + UPROPERTY(EditAnywhere) + bool DrawHitImpactNormals = true; + + UPROPERTY(EditAnywhere) + bool DrawHitPrimitives = true; + + UPROPERTY(EditAnywhere) + bool DrawHitActorsNames = false; + + UPROPERTY(EditAnywhere) + float HitPointSize = 5.0f; + + UPROPERTY(EditAnywhere) + FColor NoHitColor = FColor::Red; + + UPROPERTY(EditAnywhere) + FColor HitColor = FColor::Green; + + UPROPERTY(EditAnywhere) + FColor NormalColor = FColor::Yellow; + + UPROPERTY(EditAnywhere) + FColor ImpactNormalColor = FColor::Cyan; + + TSet AlreadyDrawnActors; + + TSet AlreadyDrawnComponents; + + UPROPERTY(EditAnywhere) + USceneComponent* StartComponent = nullptr; + + UPROPERTY(EditAnywhere) + USceneComponent* EndComponent = nullptr; +}; diff --git a/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_CollisionTester.h b/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_CollisionTester.h index 4aa99a9..a4636cc 100644 --- a/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_CollisionTester.h +++ b/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_CollisionTester.h @@ -5,6 +5,7 @@ #include "CogWindow.h" #include "CogWindowConfig.h" #include "Engine/HitResult.h" +#include "CogEngineCollisionTester.h" #include "CogEngineWindow_CollisionTester.generated.h" class UCogEngineConfig_CollisionViewer; @@ -12,43 +13,6 @@ class UCogEngineDataAsset; class UPrimitiveComponent; struct FCollisionShape; -//-------------------------------------------------------------------------------------------------------------------------- -UENUM() -enum class ECogEngine_CollisionQueryType : uint8 -{ - Overlap, - LineTrace, - Sweep, -}; - -//-------------------------------------------------------------------------------------------------------------------------- -UENUM() -enum class ECogEngine_CollisionQueryMode : uint8 -{ - Single, - Multi, - Test, -}; - -//-------------------------------------------------------------------------------------------------------------------------- -UENUM() -enum class ECogEngine_CollisionQueryBy : uint8 -{ - Channel, - ObjectType, - Profile, -}; - -//-------------------------------------------------------------------------------------------------------------------------- -UENUM() -enum class ECogEngine_CollisionQueryShape : uint8 -{ - Sphere, - Box, - Capsule, -}; - - enum class ECogDebug_GizmoTransformSpace : uint8; //-------------------------------------------------------------------------------------------------------------------------- @@ -70,13 +34,6 @@ protected: virtual void SetAsset(const UCogEngineDataAsset* Value); - void Query(); - - void DrawPrimitive(const UPrimitiveComponent* PrimitiveComponent); - - void DrawShape(const FCollisionShape& Shape, const FVector& Location, const FQuat& Rotation, const FVector& Scale, const FColor& Color, bool DrawSolid) const; - - struct FChannel { bool IsValid = false; @@ -89,17 +46,7 @@ protected: TObjectPtr Config = nullptr; - TSet AlreadyDrawnActors; - - TSet AlreadyDrawnComponents; - - bool IsDragging = false; - - FCogDebug_Gizmo GizmoStart; - FCogDebug_Gizmo GizmoEnd; - - FTransform StartTransform; - + FCogDebug_Gizmo EndGizmo; }; //-------------------------------------------------------------------------------------------------------------------------- diff --git a/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_Transform.h b/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_Transform.h new file mode 100644 index 0000000..c0ad37b --- /dev/null +++ b/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_Transform.h @@ -0,0 +1,72 @@ +#pragma once + +#include "CoreMinimal.h" +#include "CogDebugGizmo.h" +#include "CogWindow.h" +#include "CogWindowConfig.h" +#include "CogEngineWindow_Transform.generated.h" + +class UCogEngineConfig_Transform; + +class COGENGINE_API FCogEngineWindow_Transform : public FCogWindow +{ + typedef FCogWindow Super; + +public: + + virtual void Initialize() override; + +protected: + + virtual void RenderHelp() override; + + virtual void RenderContent() override; + + bool RenderComponent(const char* Label, double* Value, float Speed, double Min, double Max, double Reset); + + void RenderSnap(const char* CheckboxLabel, const char* InputLabel, bool* SnapEnable, float* Snap); + + bool RenderLocation(FTransform& InOutTransform); + + bool RenderRotation(FTransform& InOutTransform); + + bool RenderScale(FTransform& InOutTransform); + + bool RenderTransform(FTransform& InOutTransform); + +private: + + FCogDebug_Gizmo Gizmo; + + TWeakObjectPtr Config = nullptr; +}; + +//-------------------------------------------------------------------------------------------------------------------------- +UCLASS(Config = Cog) +class UCogEngineConfig_Transform : public UCogWindowConfig +{ + GENERATED_BODY() + +public: + + UPROPERTY(Config) + bool ShowGizmo = true; + + UPROPERTY(Config) + float LocationSpeed = 10.0f; + + UPROPERTY(Config) + float RotationSpeed = 1.0f; + + UPROPERTY(Config) + float ScaleSpeed = 0.1f; + + virtual void Reset() override + { + Super::Reset(); + ShowGizmo = true; + LocationSpeed = 10.0f; + RotationSpeed = 1.0f; + ScaleSpeed = 0.1f; + } +}; \ No newline at end of file diff --git a/Source/CogSample/CogSampleGameState.cpp b/Source/CogSample/CogSampleGameState.cpp index 2b2ab61..41bfb4d 100644 --- a/Source/CogSample/CogSampleGameState.cpp +++ b/Source/CogSample/CogSampleGameState.cpp @@ -41,6 +41,7 @@ #include "CogEngineWindow_Spawns.h" #include "CogEngineWindow_Stats.h" #include "CogEngineWindow_TimeScale.h" +#include "CogEngineWindow_Transform.h" #include "CogImguiModule.h" #include "CogInputDataAsset.h" #include "CogInputWindow_Actions.h" @@ -174,6 +175,8 @@ void ACogSampleGameState::InitializeCog() CogWindowManager->AddWindow("Engine.Time Scale"); + CogWindowManager->AddWindow("Engine.Transform"); + //--------------------------------------- // Abilities //--------------------------------------- From 11022f7311dc3ad071c71c0afe2b19cc8c192fa4 Mon Sep 17 00:00:00 2001 From: Arnaud Jamin Date: Wed, 3 Jan 2024 03:56:47 -0500 Subject: [PATCH 7/8] CogEngine: Improve collision tester and viewer Replace usage of engine asset by debug config for the colors of collision channels --- .../Cog/Source/CogDebug/Private/CogDebug.cpp | 77 +++ .../CogDebug/Private/CogDebugDrawHelper.cpp | 584 +++++++++------- Plugins/Cog/Source/CogDebug/Public/CogDebug.h | 167 ++++- .../CogDebug/Public/CogDebugDrawHelper.h | 73 +- .../Private/CogEngineCollisionTester.cpp | 647 ++++++------------ .../CogEngineWindow_CollisionTester.cpp | 187 ++--- .../CogEngineWindow_CollisionViewer.cpp | 214 +----- .../Private/CogEngineWindow_DebugSettings.cpp | 391 ++++++----- .../Public/CogEngineCollisionTester.h | 18 +- .../CogEngine/Public/CogEngineDataAsset.h | 16 - .../Public/CogEngineWindow_CollisionTester.h | 53 -- .../Public/CogEngineWindow_CollisionViewer.h | 10 - .../Public/CogEngineWindow_DebugSettings.h | 4 - .../CogWindow/Private/CogWindowWidgets.cpp | 41 +- .../CogWindow/Public/CogWindowWidgets.h | 4 +- 15 files changed, 1205 insertions(+), 1281 deletions(-) diff --git a/Plugins/Cog/Source/CogDebug/Private/CogDebug.cpp b/Plugins/Cog/Source/CogDebug/Private/CogDebug.cpp index 08ce726..034e08a 100644 --- a/Plugins/Cog/Source/CogDebug/Private/CogDebug.cpp +++ b/Plugins/Cog/Source/CogDebug/Private/CogDebug.cpp @@ -1,6 +1,7 @@ #include "CogDebug.h" #include "CogCommonDebugFilteredActorInterface.h" +#include "CogDebugDrawHelper.h" #include "CogDebugReplicator.h" #include "Engine/World.h" #include "Engine/Engine.h" @@ -232,3 +233,79 @@ bool FCogDebug::IsSecondarySkeletonBone(FName BoneName) return false; } + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogDebug::GetDebugChannelColors(FColor ChannelColors[ECC_MAX]) +{ + ChannelColors[ECC_WorldStatic] = Settings.ChannelColorWorldStatic; + ChannelColors[ECC_WorldDynamic] = Settings.ChannelColorWorldDynamic; + ChannelColors[ECC_Pawn] = Settings.ChannelColorPawn; + ChannelColors[ECC_Visibility] = Settings.ChannelColorVisibility; + ChannelColors[ECC_Camera] = Settings.ChannelColorCamera; + ChannelColors[ECC_PhysicsBody] = Settings.ChannelColorPhysicsBody; + ChannelColors[ECC_Vehicle] = Settings.ChannelColorVehicle; + 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_GameTraceChannel2] = Settings.ChannelColorGameTraceChannel2; + ChannelColors[ECC_GameTraceChannel3] = Settings.ChannelColorGameTraceChannel3; + ChannelColors[ECC_GameTraceChannel4] = Settings.ChannelColorGameTraceChannel4; + ChannelColors[ECC_GameTraceChannel5] = Settings.ChannelColorGameTraceChannel5; + ChannelColors[ECC_GameTraceChannel6] = Settings.ChannelColorGameTraceChannel6; + ChannelColors[ECC_GameTraceChannel7] = Settings.ChannelColorGameTraceChannel7; + ChannelColors[ECC_GameTraceChannel8] = Settings.ChannelColorGameTraceChannel8; + ChannelColors[ECC_GameTraceChannel9] = Settings.ChannelColorGameTraceChannel9; + ChannelColors[ECC_GameTraceChannel10] = Settings.ChannelColorGameTraceChannel10; + ChannelColors[ECC_GameTraceChannel11] = Settings.ChannelColorGameTraceChannel11; + ChannelColors[ECC_GameTraceChannel12] = Settings.ChannelColorGameTraceChannel12; + ChannelColors[ECC_GameTraceChannel13] = Settings.ChannelColorGameTraceChannel13; + ChannelColors[ECC_GameTraceChannel14] = Settings.ChannelColorGameTraceChannel14; + ChannelColors[ECC_GameTraceChannel15] = Settings.ChannelColorGameTraceChannel15; + ChannelColors[ECC_GameTraceChannel16] = Settings.ChannelColorGameTraceChannel16; + ChannelColors[ECC_GameTraceChannel17] = Settings.ChannelColorGameTraceChannel17; + ChannelColors[ECC_GameTraceChannel18] = Settings.ChannelColorGameTraceChannel18; +} + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogDebug::GetDebugDrawOverlapSettings(FCogDebugDrawOverlapParams& Params) +{ + Params.HitColor = Settings.CollisionQueryHitColor; + Params.NoHitColor = Settings.CollisionQueryNoHitColor; + Params.DrawHitPrimitives = Settings.CollisionQueryDrawHitPrimitives; + Params.DrawHitPrimitiveActorsName = Settings.CollisionQueryDrawHitPrimitiveActorsName; + Params.HitPrimitiveActorsNameShadow = Settings.CollisionQueryHitPrimitiveActorsNameShadow; + Params.HitPrimitiveActorsNameSize = Settings.CollisionQueryHitPrimitiveActorsNameSize; + Params.Persistent = false; + Params.LifeTime = 0.0f; + Params.DepthPriority = Settings.DepthPriority; + Params.Thickness = Settings.Thickness; + + GetDebugChannelColors(Params.ChannelColors); +} + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogDebug::GetDebugDrawLineTraceSettings(FCogDebugDrawLineTraceParams& Params) +{ + GetDebugDrawOverlapSettings(Params); + + Params.DrawHitLocation = Settings.CollisionQueryDrawHitLocation; + Params.DrawHitImpactPoints = Settings.CollisionQueryDrawHitImpactPoints; + Params.DrawHitNormals = Settings.CollisionQueryDrawHitNormals; + Params.DrawHitImpactNormals = Settings.CollisionQueryDrawHitImpactNormals; + Params.HitPointSize = Settings.CollisionQueryHitPointSize; + Params.NormalColor = Settings.CollisionQueryNormalColor; + Params.ImpactNormalColor = Settings.CollisionQueryImpactNormalColor; +} + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogDebug::GetDebugDrawSweepSettings(FCogDebugDrawSweepParams& Params) +{ + GetDebugDrawLineTraceSettings(Params); + + Params.DrawHitShapes = Settings.CollisionQueryDrawHitShapes; +} \ No newline at end of file diff --git a/Plugins/Cog/Source/CogDebug/Private/CogDebugDrawHelper.cpp b/Plugins/Cog/Source/CogDebug/Private/CogDebugDrawHelper.cpp index 125b5cc..7457b99 100644 --- a/Plugins/Cog/Source/CogDebug/Private/CogDebugDrawHelper.cpp +++ b/Plugins/Cog/Source/CogDebug/Private/CogDebugDrawHelper.cpp @@ -1,9 +1,11 @@ #include "CogDebugDrawHelper.h" +#include "CogDebug.h" #include "Components/LineBatchComponent.h" #include "Kismet/KismetSystemLibrary.h" #include "Engine/Engine.h" #include "DrawDebugHelpers.h" +#include "Components/BoxComponent.h" namespace { @@ -161,237 +163,6 @@ void FCogDebugDrawHelper::DrawFlatCapsule( ::DrawDebugCircle(InWorld, FRotationTranslationMatrix(FRotator(90, 0, 0), FVector(End, Z)), Radius, Segments, Color, bPersistentLines, LifeTime, DepthPriority, Thickness, false); } -//-------------------------------------------------------------------------------------------------------------------------- -void FCogDebugDrawHelper::DrawRaycastSingle( - const UWorld* World, - const FVector& Start, - const FVector& End, - const EDrawDebugTrace::Type DrawType, - const bool bHit, - const FHitResult& Hit, - const float HitSize, - const FLinearColor DrawColor, - const FLinearColor DrawHitColor, - const float DrawDuration, - const uint8 DepthPriority /*= 0*/ -) -{ - if (DrawType != EDrawDebugTrace::None) - { - bool DrawPersistent = DrawType == EDrawDebugTrace::Persistent; - float DrawTime = (DrawType == EDrawDebugTrace::ForDuration) ? DrawDuration : 0.f; - - if (bHit && Hit.bBlockingHit) - { - ::DrawDebugLine(World, Start, Hit.ImpactPoint, DrawColor.ToFColor(true), DrawPersistent, DrawTime); - ::DrawDebugLine(World, Hit.ImpactPoint, End, DrawHitColor.ToFColor(true), DrawPersistent, DrawTime); - - DrawHitResult(World, Hit, 0, DrawType, false, HitSize, DrawHitColor, DrawTime, DepthPriority); - } - else - { - ::DrawDebugLine(World, Start, End, DrawColor.ToFColor(true), DrawPersistent, DrawTime); - } - } -} - -//-------------------------------------------------------------------------------------------------------------------------- -void FCogDebugDrawHelper::DrawSphereOverlapMulti( - const UWorld* World, - const FVector& Position, - const float Radius, - const EDrawDebugTrace::Type DrawType, - const bool bOverlap, - const TArray& OutActors, - const FLinearColor DrawColor, - const FLinearColor DrawHitColor, - const float DrawDuration /*= 0*/ -) -{ - if (DrawType == EDrawDebugTrace::None) - return; - - const bool DrawPersistent = DrawType == EDrawDebugTrace::Persistent; - const float DrawTime = (DrawType == EDrawDebugTrace::ForDuration) ? DrawDuration : 0.f; - - DrawSphereOverlapSingle(World, Position, Radius, DrawColor.ToFColor(true), DrawPersistent, DrawTime); -} - -//-------------------------------------------------------------------------------------------------------------------------- -void FCogDebugDrawHelper::DrawSphereOverlapSingle( - const UWorld* World, - const FVector& Position, - const float Radius, - const FColor& DrawColor, - const bool DrawPersistent, - const float DrawTime /*= -1.f*/, - const uint8 DepthPriority /*= 0*/ -) -{ - ::DrawDebugSphere(World, Position, Radius, 16, DrawColor, DrawPersistent, DrawTime, DepthPriority); -} - -//-------------------------------------------------------------------------------------------------------------------------- -void FCogDebugDrawHelper::DrawCapsuleCastMulti(const UWorld* World, const FVector& Start, const FVector& End, const FQuat& Rotation, const float HalfHeight, const float Radius, const EDrawDebugTrace::Type DrawType, const bool bHit, const TArray& OutHits, const FLinearColor DrawColor, const FLinearColor DrawHitColor, const float DrawDuration /*= 0*/) -{ - if (DrawType == EDrawDebugTrace::None) - return; - - const bool DrawPersistent = DrawType == EDrawDebugTrace::Persistent; - const float DrawTime = (DrawType == EDrawDebugTrace::ForDuration) ? DrawDuration : 0.f; - - if (bHit && OutHits.Last().bBlockingHit) - { - FVector const BlockingHitPoint = OutHits.Last().Location; - - DrawCapsuleCastSingle(World, Start, BlockingHitPoint, Rotation, HalfHeight, Radius, DrawHitColor.ToFColor(true), DrawPersistent, DrawTime); - DrawCapsuleCastSingle(World, Start, End, Rotation, HalfHeight, Radius, DrawColor.ToFColor(true), DrawPersistent, DrawTime); - } - else - { - DrawCapsuleCastSingle(World, Start, End, Rotation, HalfHeight, Radius, DrawColor.ToFColor(true), DrawPersistent, DrawTime); - } -} - -//-------------------------------------------------------------------------------------------------------------------------- -void FCogDebugDrawHelper::DrawCapsuleCastSingle(const UWorld* World, const FVector& Start, const FVector& End, const FQuat& Rotation, const float HalfHeight, const float Radius, const FColor& DrawColor, const bool DrawPersistent, const float DrawDuration /*= -1.f*/, const uint8 DepthPriority /*= 0*/) -{ - ::DrawDebugCapsule(World, Start, HalfHeight, Radius, Rotation, DrawColor, DrawPersistent, DrawDuration, DepthPriority); - ::DrawDebugLine(World, Start, End, DrawColor, DrawPersistent, DrawDuration, DepthPriority, 0.5f); - ::DrawDebugCapsule(World, End, HalfHeight, Radius, Rotation, DrawColor, DrawPersistent, DrawDuration, DepthPriority); -} - -//-------------------------------------------------------------------------------------------------------------------------- -void FCogDebugDrawHelper::DrawSphereCastMulti( - const UWorld* World, - const FVector& Start, - const FVector& End, - const float Radius, - const EDrawDebugTrace::Type DrawType, - const bool bHit, - const TArray& OutHits, - const FLinearColor DrawColor, - const FLinearColor DrawHitColor, - const float DrawDuration /*= 0*/ -) -{ - if (DrawType == EDrawDebugTrace::None) - return; - - const bool DrawPersistent = DrawType == EDrawDebugTrace::Persistent; - const float DrawTime = (DrawType == EDrawDebugTrace::ForDuration) ? DrawDuration : 0.f; - - if (bHit && OutHits.Last().bBlockingHit) - { - FVector const BlockingHitPoint = OutHits.Last().Location; - DrawSphereCastSingle(World, Start, BlockingHitPoint, Radius, DrawColor.ToFColor(true), DrawPersistent, DrawTime); - DrawSphereCastSingle(World, BlockingHitPoint, End, Radius, DrawHitColor.ToFColor(true), DrawPersistent, DrawTime); - } - else - { - DrawSphereCastSingle(World, Start, End, Radius, DrawColor.ToFColor(true), DrawPersistent, DrawTime); - } -} - - -//-------------------------------------------------------------------------------------------------------------------------- -void FCogDebugDrawHelper::DrawSphereCastSingle( - const UWorld* World, - const FVector& Start, - const FVector& End, - const float Radius, - const FColor& DrawColor, - const bool DrawPersistent, - const float DrawDuration /*= -1.f*/, - const uint8 DepthPriority /*= 0*/ -) -{ - FVector const TraceVec = End - Start; - float const Dist = TraceVec.Size(); - - FVector const Center = Start + TraceVec * 0.5f; - float const HalfHeight = (Dist * 0.5f) + Radius; - - FQuat const CapsuleRot = FRotationMatrix::MakeFromZ(TraceVec).ToQuat(); - ::DrawDebugCapsule(World, Center, HalfHeight, Radius, CapsuleRot, DrawColor, DrawPersistent, DrawDuration, DepthPriority); -} - - -//-------------------------------------------------------------------------------------------------------------------------- -void FCogDebugDrawHelper::DrawHitResults( - const UWorld* World, - const TArray& OutHits, - const EDrawDebugTrace::Type DrawType, - const bool ShowHitIndex, - const float HitSize, - const FLinearColor HitColor, - const float DrawDuration, - const uint8 DepthPriority /*= 0*/ -) -{ - if (DrawType == EDrawDebugTrace::None) - return; - - for (int32 i = 0; i < OutHits.Num(); ++i) - { - DrawHitResult(World, OutHits[i], i, DrawType, ShowHitIndex, HitSize, HitColor, DrawDuration, DepthPriority); - } -} - -//-------------------------------------------------------------------------------------------------------------------------- -void FCogDebugDrawHelper::DrawHitResultsDiscarded( - const UWorld* World, - const TArray& AllHits, - const TArray& KeptHits, - const EDrawDebugTrace::Type DrawType, - const float HitSize, - const FLinearColor DrawColor, - const float DrawDuration, - const uint8 DepthPriority /*= 0*/ -) -{ - if (DrawType == EDrawDebugTrace::None) - return; - - for (int32 i = 0; i < AllHits.Num(); ++i) - { - const FHitResult& PhysicHit = AllHits[i]; - if (!KeptHits.ContainsByPredicate([&](const FHitResult& Hit) - { - return Hit.GetActor() == PhysicHit.GetActor() && Hit.Component == PhysicHit.Component && Hit.Distance == PhysicHit.Distance; - })) - { - DrawHitResult(World, PhysicHit, i, DrawType, false, HitSize, DrawColor, DrawDuration, DepthPriority); - } - } -} - -//-------------------------------------------------------------------------------------------------------------------------- -void FCogDebugDrawHelper::DrawHitResult( - const UWorld* World, - const FHitResult& Hit, - const int HitIndex, - const EDrawDebugTrace::Type DrawType, - const bool ShowHitIndex, - const float HitSize, - const FLinearColor HitColor, - const float DrawDuration, - const uint8 DepthPriority /*= 0*/ -) -{ - if (DrawType == EDrawDebugTrace::None) - return; - - const bool DrawPersistent = DrawType == EDrawDebugTrace::Persistent; - const float DrawTime = (DrawType == EDrawDebugTrace::ForDuration) ? DrawDuration : 0.f; - - ::DrawDebugSphere(World, Hit.ImpactPoint, HitSize, 12, HitColor.ToFColor(true), DrawPersistent, DrawTime, DepthPriority); - if (ShowHitIndex) - { - ::DrawDebugString(World, Hit.ImpactPoint, FString::Printf(TEXT("%d"), HitIndex), nullptr, HitColor.ToFColor(true), DrawTime, true, 1.0f); - } -} - //-------------------------------------------------------------------------------------------------------------------------- void FCogDebugDrawHelper::DrawFrustum( const UWorld* World, @@ -406,9 +177,9 @@ void FCogDebugDrawHelper::DrawFrustum( const uint8 DepthPriority, const float Thickness) { - FVector Direction(1, 0, 0); - FVector LeftVector(0, 1, 0); - FVector UpVector(0, 0, 1); + const FVector Direction(1, 0, 0); + const FVector LeftVector(0, 1, 0); + const FVector UpVector(0, 0, 1); FVector Verts[8]; @@ -519,4 +290,347 @@ void FCogDebugDrawHelper::DrawSolidQuad(const UWorld* World, const FVector& Posi Indices[5] = 3; DrawDebugMesh(World, Verts, Indices, Color, bPersistent, LifeTime, DepthPriority); -} \ No newline at end of file +} + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogDebugDrawHelper::DrawHitResult( + const UWorld* World, + const FHitResult& HitResult, + const FCogDebugDrawLineTraceParams& Settings) +{ + +} + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogDebugDrawHelper::DrawHitResults( + const UWorld* World, + const TArray& HitResults, + const FCogDebugDrawLineTraceParams& Settings) +{ + TSet AlreadyDrawnPrimitives; + TSet AlreadyDrawnActors; + + for (const FHitResult& HitResult : HitResults) + { + const FColor& HitColor = Settings.HitColor; + + if (Settings.DrawHitLocation) + { + DrawDebugPoint( + World, + HitResult.Location, + Settings.HitPointSize, + HitColor, + Settings.Persistent, + Settings.LifeTime, + Settings.DepthPriority); + } + + if (Settings.DrawHitImpactPoints) + { + DrawDebugPoint( + World, + HitResult.ImpactPoint, + Settings.HitPointSize, + HitColor, + Settings.Persistent, + Settings.LifeTime, + Settings.DepthPriority); + } + + if (Settings.DrawHitNormals) + { + DrawDebugDirectionalArrow( + World, + HitResult.Location, + HitResult.Location + HitResult.Normal * 20.0f, + FCogDebug::Settings.ArrowSize, + Settings.NormalColor, + Settings.Persistent, + Settings.LifeTime, + Settings.DepthPriority, + Settings.Thickness); + } + + if (Settings.DrawHitImpactNormals) + { + DrawDebugDirectionalArrow( + World, + HitResult.ImpactPoint, + HitResult.ImpactPoint + HitResult.ImpactNormal * 20.0f, + FCogDebug::Settings.ArrowSize, + Settings.ImpactNormalColor, + Settings.Persistent, + Settings.LifeTime, + Settings.DepthPriority, + Settings.Thickness); + } + + if (Settings.DrawHitPrimitives) + { + const UPrimitiveComponent* PrimitiveComponent = HitResult.GetComponent(); + if (PrimitiveComponent == nullptr) + { + continue; + } + + if (AlreadyDrawnPrimitives.Contains(PrimitiveComponent)) + { + continue; + } + + AlreadyDrawnPrimitives.Add(PrimitiveComponent); + const ECollisionChannel CollisionObjectType = PrimitiveComponent->GetCollisionObjectType(); + const FColor PrimitiveColor = Settings.ChannelColors[CollisionObjectType]; + DrawPrimitiveComponent(*PrimitiveComponent, PrimitiveColor, Settings.Persistent, Settings.LifeTime, Settings.DepthPriority, Settings.Thickness); + + if (Settings.DrawHitPrimitiveActorsName) + { + const AActor* Actor = PrimitiveComponent->GetOwner(); + if (Actor == nullptr) + { + continue; + } + + if (AlreadyDrawnActors.Contains(Actor)) + { + continue; + } + + AlreadyDrawnActors.Add(Actor); + const FColor TextColor = PrimitiveColor.WithAlpha(255); + DrawDebugString(World, Actor->GetActorLocation(), GetNameSafe(Actor->GetClass()), nullptr, TextColor, 0.0f, Settings.HitPrimitiveActorsNameShadow, Settings.HitPrimitiveActorsNameSize); + } + } + } +} + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogDebugDrawHelper::DrawLineTrace( + const UWorld* World, + const FVector& Start, + const FVector& End, + const bool HasHits, + TArray& HitResults, + const FCogDebugDrawLineTraceParams& Settings +) +{ + DrawDebugDirectionalArrow( + World, + Start, + End, + FCogDebug::Settings.ArrowSize, + HasHits ? Settings.HitColor : Settings.NoHitColor, + false, + 0.0f, + FCogDebug::GetDebugDepthPriority(0), + FCogDebug::GetDebugThickness(0.0f)); + + DrawHitResults(World, HitResults, Settings); +} + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogDebugDrawHelper::DrawSweep( + const UWorld* World, + const FCollisionShape& Shape, + const FVector& Start, + const FVector& End, + const FQuat& Rotation, + const bool HasHits, + TArray& HitResults, + const FCogDebugDrawSweepParams& Settings +) +{ + const FColor Color = HasHits ? Settings.HitColor : Settings.NoHitColor; + + DrawDebugDirectionalArrow( + World, + Start, + End, + FCogDebug::Settings.ArrowSize, + Color, + false, + 0.0f, + FCogDebug::GetDebugDepthPriority(0), + FCogDebug::GetDebugThickness(0.0f)); + + DrawShape(World, Shape, Start, Rotation, FVector::OneVector, Color, Settings.Persistent, Settings.LifeTime, Settings.DepthPriority, Settings.Thickness); + + DrawHitResults(World, HitResults, Settings); + + for (const FHitResult& Hit : HitResults) + { + if (Settings.DrawHitShapes) + { + DrawShape(World, Shape, Hit.Location, Rotation, FVector::OneVector, Color, Settings.Persistent, Settings.LifeTime, Settings.DepthPriority, Settings.Thickness); + } + } +} + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogDebugDrawHelper::DrawOverlap( + const UWorld* World, + const FCollisionShape& Shape, + const FVector& Location, + const FQuat& Rotation, + TArray& OverlapResults, + const FCogDebugDrawOverlapParams& Settings +) +{ + const FColor Color = OverlapResults.Num() > 0 ? Settings.HitColor : Settings.NoHitColor; + DrawShape(World, Shape, Location, Rotation, FVector::OneVector, Color, Settings.Persistent, Settings.LifeTime, Settings.DepthPriority, Settings.Thickness); + + if (Settings.DrawHitPrimitives) + { + for (const FOverlapResult& OverlapResult : OverlapResults) + { + if (const UPrimitiveComponent* PrimitiveComponent = OverlapResult.GetComponent()) + { + const ECollisionChannel CollisionObjectType = PrimitiveComponent->GetCollisionObjectType(); + const FColor PrimitiveColor = Settings.ChannelColors[CollisionObjectType]; + DrawPrimitiveComponent(*PrimitiveComponent, PrimitiveColor, Settings.Persistent, Settings.LifeTime, Settings.DepthPriority, Settings.Thickness); + } + } + } +} + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogDebugDrawHelper::DrawPrimitiveComponent( + const UPrimitiveComponent& PrimitiveComponent, + const FColor& Color, + const bool Persistent, + const float LifeTime, + const uint8 DepthPriority, + const float Thickness) +{ + const UWorld* World = PrimitiveComponent.GetWorld(); + if (World == nullptr) + { + return; + } + + const UBoxComponent* BoxComponent = Cast(&PrimitiveComponent);; + const FCollisionShape Shape = PrimitiveComponent.GetCollisionShape(); + + if (Shape.ShapeType == ECollisionShape::Box && BoxComponent == nullptr) + { + FVector Location; + FVector Extent; + PrimitiveComponent.Bounds.GetBox().GetCenterAndExtents(Location, Extent); + + // TODO: this adds padding to prevent Z fight. Maybe add this as a parameter. + Extent += FVector::OneVector; + + DrawDebugSolidBox( + World, + Location, + Extent, + FQuat::Identity, + Color, + Persistent, + LifeTime, + DepthPriority); + + DrawDebugBox( + World, + Location, + Extent, + FQuat::Identity, + Color, + Persistent, + LifeTime, + DepthPriority, + Thickness); + } + else + { + const FVector Location = PrimitiveComponent.GetComponentLocation(); + const FQuat Rotation = PrimitiveComponent.GetComponentQuat(); + const FVector Scale = PrimitiveComponent.GetComponentScale(); + DrawShape(World, Shape, Location, Rotation, Scale, Color, Persistent, LifeTime, DepthPriority, Thickness); + } +} + +//-------------------------------------------------------------------------------------------------------------------------- +void FCogDebugDrawHelper::DrawShape( + const UWorld* World, + const FCollisionShape& InShape, + const FVector& Location, + const FQuat& Rotation, + const FVector& Scale, + const FColor& Color, + const bool Persistent, + const float LifeTime, + const uint8 DepthPriority, + const float Thickness) +{ + switch (InShape.ShapeType) + { + case ECollisionShape::Box: + { + //-------------------------------------------------- + // see UBoxComponent::GetScaledBoxExtent() + //-------------------------------------------------- + const FVector HalfExtent(InShape.Box.HalfExtentX * Scale.X, InShape.Box.HalfExtentY * Scale.Y, InShape.Box.HalfExtentZ * Scale.Z); + + DrawDebugBox( + World, + Location, + HalfExtent, + Rotation, + Color, + Persistent, + LifeTime, + DepthPriority, + Thickness); + + break; + } + + case ECollisionShape::Sphere: + { + //-------------------------------------------------- + // see USphereComponent::GetScaledSphereRadius() + //-------------------------------------------------- + const float RadiusScale = FMath::Min(Scale.X, FMath::Min(Scale.Y, Scale.Z)); + const float Radius = InShape.Sphere.Radius * RadiusScale; + + DrawSphere( + World, + Location, + Radius, + FCogDebug::GetCircleSegments(), + Color, + Persistent, + LifeTime, + DepthPriority, + Thickness); + break; + } + + case ECollisionShape::Capsule: + { + //-------------------------------------------------- + // see UCapsuleComponent::GetScaledCapsuleRadius() + //-------------------------------------------------- + const float Radius = InShape.Capsule.Radius * FMath::Min(Scale.X, Scale.Y); + const float HalfHeight = InShape.Capsule.HalfHeight * UE_REAL_TO_FLOAT(Scale.Z); + + DrawDebugCapsule( + World, + Location, + HalfHeight, + Radius, + Rotation, + Color, + Persistent, + LifeTime, + DepthPriority, + Thickness); + break; + } + + default: + break; + } +} diff --git a/Plugins/Cog/Source/CogDebug/Public/CogDebug.h b/Plugins/Cog/Source/CogDebug/Public/CogDebug.h index a2875a3..e61f8e9 100644 --- a/Plugins/Cog/Source/CogDebug/Public/CogDebug.h +++ b/Plugins/Cog/Source/CogDebug/Public/CogDebug.h @@ -4,6 +4,9 @@ #include "UObject/WeakObjectPtrTemplates.h" #include "CogDebug.generated.h" +struct FCogDebugDrawSweepParams; +struct FCogDebugDrawLineTraceParams; +struct FCogDebugDrawOverlapParams; class UObject; class AActor; class UWorld; @@ -86,34 +89,34 @@ struct FCogDebugSettings float GizmoTranslationAxisLength = 50.0f; UPROPERTY(Config) - bool GizmoTranslationSnapEnable = true; + bool GizmoTranslationSnapEnable = false; UPROPERTY(Config) float GizmoTranslationSnapValue = 10.0f; UPROPERTY(Config) - float GizmoTranslationPlaneOffset = 25.0f; + float GizmoTranslationPlaneOffset = 18.0f; UPROPERTY(Config) float GizmoTranslationPlaneExtent = 5.0f; UPROPERTY(Config) - bool GizmoRotationSnapEnable = true; + bool GizmoRotationSnapEnable = false; UPROPERTY(Config) float GizmoRotationSnapValue = 10.0f; UPROPERTY(Config) - float GizmoRotationSpeed = 0.01f; + float GizmoRotationSpeed = 1.0f; UPROPERTY(Config) - float GizmoRotationRadius = 15.0f; + float GizmoRotationRadius = 40.0f; UPROPERTY(Config) - int GizmoRotationSegments = 12; + int GizmoRotationSegments = 8; UPROPERTY(Config) - bool GizmoScaleSnapEnable = true; + bool GizmoScaleSnapEnable = false; UPROPERTY(Config) float GizmoScaleSnapValue = 1.0f; @@ -125,7 +128,7 @@ struct FCogDebugSettings float GizmoScaleBoxExtent = 2.0f; UPROPERTY(Config) - float GizmoScaleSpeed = 0.5f; + float GizmoScaleSpeed = 0.01f; UPROPERTY(Config) float GizmoScaleMin = 0.001f; @@ -136,7 +139,7 @@ struct FCogDebugSettings UPROPERTY(Config) TEnumAsByte GizmoGroundRaycastChannel = ECollisionChannel::ECC_WorldStatic; - UPROPERTY(Config) + UPROPERTY(Config) float GizmoGroundRaycastCircleRadius = 5.0f; UPROPERTY(Config) @@ -184,6 +187,144 @@ struct FCogDebugSettings UPROPERTY(Config) FColor GizmoTextColor = FColor(255, 255, 255, 255); + UPROPERTY(Config) + FColor CollisionQueryHitColor = FColor::Green; + + UPROPERTY(Config) + FColor CollisionQueryNoHitColor = FColor::Red; + + UPROPERTY(Config) + bool CollisionQueryDrawHitPrimitives = true; + + UPROPERTY(Config) + bool CollisionQueryDrawHitPrimitiveActorsName = false; + + UPROPERTY(Config) + bool CollisionQueryHitPrimitiveActorsNameShadow = true; + + UPROPERTY(Config) + float CollisionQueryHitPrimitiveActorsNameSize = 1.0f; + + UPROPERTY(Config) + bool CollisionQueryDrawHitLocation = true; + + UPROPERTY(Config) + bool CollisionQueryDrawHitImpactPoints = true; + + UPROPERTY(Config) + bool CollisionQueryDrawHitNormals = true; + + UPROPERTY(Config) + bool CollisionQueryDrawHitImpactNormals = true; + + UPROPERTY(Config) + float CollisionQueryHitPointSize = 5.0f; + + UPROPERTY(Config) + FColor CollisionQueryNormalColor = FColor::Yellow; + + UPROPERTY(Config) + FColor CollisionQueryImpactNormalColor = FColor::Cyan; + + UPROPERTY(Config) + bool CollisionQueryDrawHitShapes = true; + + UPROPERTY(Config) + FColor ChannelColorWorldStatic = FColor(255, 0, 0, 5); + + UPROPERTY(Config) + FColor ChannelColorWorldDynamic = FColor(255, 0, 188, 5); + + UPROPERTY(Config) + FColor ChannelColorPawn = FColor(105, 0, 255, 5); + + UPROPERTY(Config) + FColor ChannelColorVisibility = FColor(0, 15, 255, 5); + + UPROPERTY(Config) + FColor ChannelColorCamera = FColor(0, 105, 255, 5); + + UPROPERTY(Config) + FColor ChannelColorPhysicsBody = FColor(0, 255, 208, 5); + + UPROPERTY(Config) + FColor ChannelColorVehicle = FColor(52, 255, 0, 5); + + UPROPERTY(Config) + FColor ChannelColorDestructible = FColor(255, 255, 0, 0); + + UPROPERTY(Config) + FColor ChannelColorEngineTraceChannel1 = FColor(0, 0, 0, 0); + + UPROPERTY(Config) + FColor ChannelColorEngineTraceChannel2 = FColor(0, 0, 0, 0); + + UPROPERTY(Config) + FColor ChannelColorEngineTraceChannel3 = FColor(0, 0, 0, 0); + + UPROPERTY(Config) + FColor ChannelColorEngineTraceChannel4 = FColor(0, 0, 0, 0); + + UPROPERTY(Config) + FColor ChannelColorEngineTraceChannel5 = FColor(0, 0, 0, 0); + + UPROPERTY(Config) + FColor ChannelColorEngineTraceChannel6 = FColor(0, 0, 0, 0); + + UPROPERTY(Config) + FColor ChannelColorGameTraceChannel1 = FColor(255, 105, 0, 5); + + UPROPERTY(Config) + FColor ChannelColorGameTraceChannel2 = FColor(255, 30, 0, 5); + + UPROPERTY(Config) + FColor ChannelColorGameTraceChannel3 = FColor(0, 0, 0, 0); + + UPROPERTY(Config) + FColor ChannelColorGameTraceChannel4 = FColor(0, 0, 0, 0); + + UPROPERTY(Config) + FColor ChannelColorGameTraceChannel5 = FColor(0, 0, 0, 0); + + UPROPERTY(Config) + FColor ChannelColorGameTraceChannel6 = FColor(0, 0, 0, 0); + + UPROPERTY(Config) + FColor ChannelColorGameTraceChannel7 = FColor(0, 0, 0, 0); + + UPROPERTY(Config) + FColor ChannelColorGameTraceChannel8 = FColor(0, 0, 0, 0); + + UPROPERTY(Config) + FColor ChannelColorGameTraceChannel9 = FColor(0, 0, 0, 0); + + UPROPERTY(Config) + FColor ChannelColorGameTraceChannel10 = FColor(0, 0, 0, 0); + + UPROPERTY(Config) + FColor ChannelColorGameTraceChannel11 = FColor(0, 0, 0, 0); + + UPROPERTY(Config) + FColor ChannelColorGameTraceChannel12 = FColor(0, 0, 0, 0); + + 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) TArray SecondaryBoneWildcards = { "interaction", @@ -252,6 +393,14 @@ public: static void Reset(); + static void GetDebugChannelColors(FColor ChannelColors[ECC_MAX]); + + static void GetDebugDrawOverlapSettings(FCogDebugDrawOverlapParams& Params); + + static void GetDebugDrawLineTraceSettings(FCogDebugDrawLineTraceParams& Params); + + static void GetDebugDrawSweepSettings(FCogDebugDrawSweepParams& Params); + static FCogDebugSettings Settings; private: diff --git a/Plugins/Cog/Source/CogDebug/Public/CogDebugDrawHelper.h b/Plugins/Cog/Source/CogDebug/Public/CogDebugDrawHelper.h index 194e6ef..776b1d8 100644 --- a/Plugins/Cog/Source/CogDebug/Public/CogDebugDrawHelper.h +++ b/Plugins/Cog/Source/CogDebug/Public/CogDebugDrawHelper.h @@ -8,42 +8,67 @@ class UWorld; struct FHitResult; class AActor; +struct FCogDebugDrawOverlapParams +{ + FColor HitColor = FColor::Green; + FColor NoHitColor = FColor::Red; + bool DrawHitPrimitives = true; + bool DrawHitPrimitiveActorsName = false; + bool HitPrimitiveActorsNameShadow = true; + float HitPrimitiveActorsNameSize = 1.0f; + bool Persistent = false; + float LifeTime = 0.0f; + uint8 DepthPriority = 0; + float Thickness = 0.0f; + FColor ChannelColors[ECC_MAX]; +}; + +struct FCogDebugDrawLineTraceParams : public FCogDebugDrawOverlapParams +{ + bool DrawHitLocation = true; + bool DrawHitImpactPoints = true; + bool DrawHitNormals = true; + bool DrawHitImpactNormals = true; + float HitPointSize = 5.0f; + FColor NormalColor = FColor::Yellow; + FColor ImpactNormalColor = FColor::Cyan; +}; + +struct FCogDebugDrawSweepParams : public FCogDebugDrawLineTraceParams +{ + bool DrawHitShapes = true; +}; + class COGDEBUG_API FCogDebugDrawHelper { public: - static void DrawArc(const UWorld* InWorld, const FMatrix& Matrix, const float InnterRadius, const float OuterRadius, const float AngleStart, const float AngleEnd, const int32 Segments, const FColor& Color, const bool bPersistentLines = false, const float LifeTime = -1.f, const uint8 DepthPriority = 0U, const float Thickness = 0.0f); + static void DrawArc(const UWorld* World, const FMatrix& Matrix, const float InnterRadius, const float OuterRadius, const float AngleStart, const float AngleEnd, const int32 Segments, const FColor& Color, const bool bPersistentLines = false, const float LifeTime = -1.f, const uint8 DepthPriority = 0U, const float Thickness = 0.0f); - static void DrawArc(const UWorld* InWorld, const FMatrix& Matrix, const float InnterRadius, const float OuterRadius, const float ArcAngle, const int32 Segments, const FColor& Color, const bool bPersistentLines = false, const float LifeTime = -1.f, const uint8 DepthPriority = 0U, const float Thickness = 0.0f); + static void DrawArc(const UWorld* World, const FMatrix& Matrix, const float InnterRadius, const float OuterRadius, const float ArcAngle, const int32 Segments, const FColor& Color, const bool bPersistentLines = false, const float LifeTime = -1.f, const uint8 DepthPriority = 0U, const float Thickness = 0.0f); - static void DrawSphere(const UWorld* InWorld, const FVector& Center, const float Radius, const int32 Segments, const FColor& Color, const bool bPersistentLines = false, const float LifeTime = -1.f, const uint8 DepthPriority = 0U, const float Thickness = 0.0f); + static void DrawSphere(const UWorld* World, const FVector& Center, const float Radius, const int32 Segments, const FColor& Color, const bool bPersistentLines = false, const float LifeTime = -1.f, const uint8 DepthPriority = 0U, const float Thickness = 0.0f); static void DrawFrustum(const UWorld* World, const FMatrix& Matrix, const float Angle, const float AspectRatio, const float NearPlane, const float FarPlane, const FColor& Color, const bool bPersistentLines = false, const float LifeTime = -1.f, const uint8 DepthPriority = 0U, const float Thickness = 0.0f); - static void DrawFlatCapsule(const UWorld* InWorld, const FVector2D& Start, const FVector2D& End, const float Radius, const float Z, const float Segments, const FColor& Color, const bool bPersistentLines = false, const float LifeTime = -1.0f, const uint8 DepthPriority = 0, const float Thickness = 0.0f); + static void DrawFlatCapsule(const UWorld* World, const FVector2D& Start, const FVector2D& End, const float Radius, const float Z, const float Segments, const FColor& Color, const bool bPersistentLines = false, const float LifeTime = -1.0f, const uint8 DepthPriority = 0, const float Thickness = 0.0f); - static void DrawRaycastSingle(const UWorld* World, const FVector& Start, const FVector& End, const EDrawDebugTrace::Type DrawType, const bool bHit, const FHitResult& Hit, const float HitSize, const FLinearColor DrawColor, const FLinearColor DrawHitColor, const float DrawDuration, const uint8 DepthPriority = 0); - - static void DrawSphereOverlapMulti(const UWorld* World, const FVector& Position, const float Radius, const EDrawDebugTrace::Type DrawType, const bool bOverlap, const TArray& OutActors, const FLinearColor DrawColor, const FLinearColor DrawHitColor, const float DrawDuration = 0); - - static void DrawSphereOverlapSingle(const UWorld* World, const FVector& Position, const float Radius, const FColor& DrawColor, const bool DrawPersistent, const float DrawDuration = -1.f, const uint8 DepthPriority = 0); - - static void DrawCapsuleCastMulti(const UWorld* World, const FVector& Start, const FVector& End, const FQuat& Rotation, const float HalfHeight, const float Radius, const EDrawDebugTrace::Type DrawType, const bool bHit, const TArray& OutHits, const FLinearColor DrawColor, const FLinearColor DrawHitColor, const float DrawDuration = 0); - - static void DrawCapsuleCastSingle(const UWorld* World, const FVector& Start, const FVector& End, const FQuat& Rotation, const float HalfHeight, const float Radius, const FColor& DrawColor, const bool DrawPersistent, const float DrawDuration = -1.f, const uint8 DepthPriority = 0); - - static void DrawSphereCastMulti(const UWorld* World, const FVector& Start, const FVector& End, const float Radius, const EDrawDebugTrace::Type DrawType, const bool bHit, const TArray& OutHits, const FLinearColor DrawColor, const FLinearColor DrawHitColor, const float DrawDuration = 0); - - static void DrawSphereCastSingle(const UWorld* World, const FVector& Start, const FVector& End, const float Radius, const FColor& DrawColor, const bool DrawPersistent, const float LifeTime = -1.f, const uint8 DepthPriority = 0); - - static void DrawHitResults(const UWorld* World, const TArray& OutHits, const EDrawDebugTrace::Type DrawType, const bool ShowHitIndex, const float HitSize, const FLinearColor HitColor, const float DrawDuration, const uint8 DepthPriority = 0); - - static void DrawHitResultsDiscarded(const UWorld* World, const TArray& AllHits, const TArray& KeptHits, const EDrawDebugTrace::Type DrawType, const float HitSize, const FLinearColor DrawColor, const float DrawDuration, const uint8 DepthPriority = 0); - - static void DrawHitResult(const UWorld* World, const FHitResult& Hit, const int HitIndex, const EDrawDebugTrace::Type DrawType, const bool ShowHitIndex, const float HitSize, const FLinearColor HitColor, const float DrawDuration, const uint8 DepthPriority = 0); - static void DrawQuad(const UWorld* World, const FVector& Position, const FQuat& Rotation, const FVector2D& Extents, const FColor& Color, bool bPersistent = false, float LifeTime = -1, uint8 DepthPriority = 0, const float Thickness = 0.0f); static void DrawSolidQuad(const UWorld* World, const FVector& Position, const FQuat& Rotation, const FVector2D& Extents, const FColor& Color, bool bPersistent = false, float LifeTime = -1, uint8 DepthPriority = 0); + static void DrawShape(const UWorld* World, const FCollisionShape& InShape, const FVector& Location, const FQuat& Rotation, const FVector& Scale, const FColor& Color, const bool Persistent, const float LifeTime, const uint8 DepthPriority, const float Thickness); + + static void DrawPrimitiveComponent(const UPrimitiveComponent& PrimitiveComponent, const FColor& Color, const bool Persistent, const float LifeTime, const uint8 DepthPriority, const float Thickness); + + static void DrawOverlap(const UWorld* World, const FCollisionShape& Shape, const FVector& Location, const FQuat& Rotation, TArray& OverlapResults, const FCogDebugDrawOverlapParams& Settings); + + static void DrawHitResult(const UWorld* World, const FHitResult& HitResult, const FCogDebugDrawLineTraceParams& Settings); + + static void DrawHitResults(const UWorld* World, const TArray& HitResults, const FCogDebugDrawLineTraceParams& Settings); + + static void DrawLineTrace(const UWorld* World, const FVector& Start, const FVector& End, const bool HasHits, TArray& HitResults, const FCogDebugDrawLineTraceParams& Settings); + + static void DrawSweep(const UWorld* World, const FCollisionShape& Shape, const FVector& Start, const FVector& End, const FQuat& Rotation, const bool HasHits, TArray& HitResults, const FCogDebugDrawSweepParams& Settings); + }; diff --git a/Plugins/Cog/Source/CogEngine/Private/CogEngineCollisionTester.cpp b/Plugins/Cog/Source/CogEngine/Private/CogEngineCollisionTester.cpp index 7e7172a..88615c2 100644 --- a/Plugins/Cog/Source/CogEngine/Private/CogEngineCollisionTester.cpp +++ b/Plugins/Cog/Source/CogEngine/Private/CogEngineCollisionTester.cpp @@ -38,16 +38,11 @@ void ACogEngineCollisionTester::Tick(float DeltaSeconds) } //-------------------------------------------------------------------------------------------------------------------------- -void ACogEngineCollisionTester::Query() +void ACogEngineCollisionTester::Query() const { - AlreadyDrawnActors.Empty(); - AlreadyDrawnComponents.Empty(); - FVector QueryStart = StartComponent->GetComponentLocation(); FVector QueryEnd = EndComponent->GetComponentLocation(); FQuat QueryRotation = StartComponent->GetComponentQuat(); - TArray Hits; - TArray Overlaps; bool HasHits = false; static const FName TraceTag(TEXT("FCogWindow_Collision")); @@ -57,9 +52,7 @@ void ACogEngineCollisionTester::Query() const FName ProfileName = Profile != nullptr ? Profile->Name : FName(); FCollisionShape QueryShape; - - const bool bIsUsingShape = Type == ECogEngine_CollisionQueryType::Overlap || Type == ECogEngine_CollisionQueryType::Sweep; - if (bIsUsingShape) + if (Type == ECogEngine_CollisionQueryType::Overlap || Type == ECogEngine_CollisionQueryType::Sweep) { switch (Shape) { @@ -71,439 +64,235 @@ void ACogEngineCollisionTester::Query() switch (Type) { - case ECogEngine_CollisionQueryType::Overlap: - { - switch (By) - { - case ECogEngine_CollisionQueryBy::Channel: - { - HasHits = GetWorld()->OverlapMultiByChannel(Overlaps, QueryStart, QueryRotation, Channel, QueryShape, QueryParams); - break; - } + case ECogEngine_CollisionQueryType::Overlap: + { + TArray Overlaps; + switch (By) + { + case ECogEngine_CollisionQueryBy::Channel: + { + HasHits = GetWorld()->OverlapMultiByChannel(Overlaps, QueryStart, QueryRotation, Channel, QueryShape, QueryParams); + break; + } - case ECogEngine_CollisionQueryBy::ObjectType: - { - FCollisionObjectQueryParams QueryObjectParams; - QueryObjectParams.ObjectTypesToQuery = ObjectTypesToQuery; - HasHits = GetWorld()->OverlapMultiByObjectType(Overlaps, QueryStart, QueryRotation, QueryObjectParams, QueryShape, QueryParams); - break; - } + case ECogEngine_CollisionQueryBy::ObjectType: + { + FCollisionObjectQueryParams QueryObjectParams; + QueryObjectParams.ObjectTypesToQuery = ObjectTypesToQuery; + HasHits = GetWorld()->OverlapMultiByObjectType(Overlaps, QueryStart, QueryRotation, QueryObjectParams, QueryShape, QueryParams); + break; + } - case ECogEngine_CollisionQueryBy::Profile: - { - HasHits = GetWorld()->OverlapMultiByProfile(Overlaps, QueryStart, QueryRotation, ProfileName, QueryShape, QueryParams); - break; - } - } + case ECogEngine_CollisionQueryBy::Profile: + { + HasHits = GetWorld()->OverlapMultiByProfile(Overlaps, QueryStart, QueryRotation, ProfileName, QueryShape, QueryParams); + break; + } + } - break; - } + FCogDebugDrawOverlapParams DrawParams; + FCogDebug::GetDebugDrawOverlapSettings(DrawParams); + FCogDebugDrawHelper::DrawOverlap(GetWorld(), QueryShape, QueryStart, QueryRotation, Overlaps, DrawParams); + break; + } - case ECogEngine_CollisionQueryType::LineTrace: - { - switch (By) - { - 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; - } - } + case ECogEngine_CollisionQueryType::LineTrace: + { + TArray Hits; + switch (By) + { + 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; - } + break; + } - case ECogEngine_CollisionQueryBy::ObjectType: - { - FCollisionObjectQueryParams QueryObjectParams; - QueryObjectParams.ObjectTypesToQuery = ObjectTypesToQuery; + case ECogEngine_CollisionQueryBy::ObjectType: + { + FCollisionObjectQueryParams QueryObjectParams; + QueryObjectParams.ObjectTypesToQuery = ObjectTypesToQuery; - switch (Mode) - { - case ECogEngine_CollisionQueryMode::Single: - { - FHitResult Hit; - HasHits = GetWorld()->LineTraceSingleByObjectType(Hit, QueryStart, QueryEnd, QueryObjectParams, QueryParams); - if (HasHits) - { - 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; - } + switch (Mode) + { + case ECogEngine_CollisionQueryMode::Single: + { + FHitResult Hit; + HasHits = GetWorld()->LineTraceSingleByObjectType(Hit, QueryStart, QueryEnd, QueryObjectParams, QueryParams); + if (HasHits) + { + 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: - { - switch (Mode) - { - 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; - } - } - break; - } + case ECogEngine_CollisionQueryBy::Profile: + { + switch (Mode) + { + 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; + } + } - case ECogEngine_CollisionQueryType::Sweep: - { - switch (By) - { - 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; - } + FCogDebugDrawLineTraceParams DrawParams; + FCogDebug::GetDebugDrawLineTraceSettings(DrawParams); + FCogDebugDrawHelper::DrawLineTrace(GetWorld(), QueryStart, QueryEnd, HasHits, Hits, DrawParams); + break; + } - case ECogEngine_CollisionQueryBy::ObjectType: - { - FCollisionObjectQueryParams QueryObjectParams; - QueryObjectParams.ObjectTypesToQuery = ObjectTypesToQuery; + case ECogEngine_CollisionQueryType::Sweep: + { + TArray Hits; + switch (By) + { + 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; + } - switch (Mode) - { - case ECogEngine_CollisionQueryMode::Single: - { - 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::ObjectType: + { + FCollisionObjectQueryParams QueryObjectParams; + QueryObjectParams.ObjectTypesToQuery = ObjectTypesToQuery; - case ECogEngine_CollisionQueryBy::Profile: - { - switch (Mode) - { - case ECogEngine_CollisionQueryMode::Single: - { - FHitResult Hit; - HasHits = GetWorld()->SweepSingleByProfile(Hit, QueryStart, QueryEnd, QueryRotation, ProfileName, QueryShape, QueryParams); - if (HasHits) - { - Hits.Add(Hit); - } - break; - } - case ECogEngine_CollisionQueryMode::Multi: - { - HasHits = GetWorld()->SweepMultiByProfile(Hits, QueryStart, QueryEnd, QueryRotation, ProfileName, QueryShape, QueryParams); - break; - } - case ECogEngine_CollisionQueryMode::Test: - { - HasHits = GetWorld()->SweepTestByProfile(QueryStart, QueryEnd, QueryRotation, ProfileName, QueryShape, QueryParams); - break; - } - } - break; - } - } - break; - } - } + switch (Mode) + { + case ECogEngine_CollisionQueryMode::Single: + { + 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; + } - const FColor Color = HasHits ? FLinearColor(HitColor).ToFColor(true) : FLinearColor(NoHitColor).ToFColor(true); - const bool bUseTrace = Type == ECogEngine_CollisionQueryType::LineTrace || Type == ECogEngine_CollisionQueryType::Sweep; - if (bUseTrace) - { - DrawDebugDirectionalArrow( - GetWorld(), - QueryStart, - QueryEnd, - FCogDebug::Settings.ArrowSize, - Color, - false, - 0.0f, - FCogDebug::GetDebugDepthPriority(0), - FCogDebug::GetDebugThickness(0.0f)); - } + case ECogEngine_CollisionQueryBy::Profile: + { + switch (Mode) + { + case ECogEngine_CollisionQueryMode::Single: + { + FHitResult Hit; + HasHits = GetWorld()->SweepSingleByProfile(Hit, QueryStart, QueryEnd, QueryRotation, ProfileName, QueryShape, QueryParams); + if (HasHits) + { + Hits.Add(Hit); + } + break; + } + case ECogEngine_CollisionQueryMode::Multi: + { + HasHits = GetWorld()->SweepMultiByProfile(Hits, QueryStart, QueryEnd, QueryRotation, ProfileName, QueryShape, QueryParams); + break; + } + case ECogEngine_CollisionQueryMode::Test: + { + HasHits = GetWorld()->SweepTestByProfile(QueryStart, QueryEnd, QueryRotation, ProfileName, QueryShape, QueryParams); + break; + } + } + break; + } + } - if (bIsUsingShape) - { - DrawShape(QueryShape, QueryStart, QueryRotation, FVector::OneVector, Color, false); - } - - for (const FOverlapResult& Overlap : Overlaps) - { - if (DrawHitPrimitives) - { - DrawPrimitive(Overlap.GetComponent()); - } - } - - for (const FHitResult& Hit : Hits) - { - if (DrawHitLocations) - { - DrawDebugPoint( - GetWorld(), - Hit.Location, - HitPointSize, - Color, - false, - 0.0f, - FCogDebug::GetDebugDepthPriority(0)); - } - - if (DrawHitImpactPoints) - { - DrawDebugPoint( - GetWorld(), - Hit.ImpactPoint, - HitPointSize, - Color, - false, - 0.0f, - FCogDebug::GetDebugDepthPriority(0)); - } - - if (bIsUsingShape && DrawHitShapes) - { - DrawShape(QueryShape, Hit.Location, QueryRotation, FVector::OneVector, Color, false); - } - - if (DrawHitNormals) - { - DrawDebugDirectionalArrow( - GetWorld(), - Hit.Location, - Hit.Location + Hit.Normal * 20.0f, - FCogDebug::Settings.ArrowSize, - FLinearColor(NormalColor).ToFColor(true), - false, - 0.0f, - FCogDebug::GetDebugDepthPriority(0), - FCogDebug::GetDebugThickness(0.0f)); - } - - if (DrawHitImpactNormals) - { - DrawDebugDirectionalArrow( - GetWorld(), - Hit.ImpactPoint, - Hit.ImpactPoint + Hit.ImpactNormal * 20.0f, - FCogDebug::Settings.ArrowSize, - FLinearColor(ImpactNormalColor).ToFColor(true), - false, - 0.0f, - FCogDebug::GetDebugDepthPriority(0), - FCogDebug::GetDebugThickness(0.0f)); - } - - if (DrawHitPrimitives) - { - DrawPrimitive(Hit.GetComponent()); - } - } -} - -//-------------------------------------------------------------------------------------------------------------------------- -void ACogEngineCollisionTester::DrawPrimitive(const UPrimitiveComponent* PrimitiveComponent) -{ - //------------------------------------------------------- - // Don't draw same primitives multiple times (for bones) - //------------------------------------------------------- - if (AlreadyDrawnComponents.Contains(PrimitiveComponent)) - { - return; - } - - AlreadyDrawnComponents.Add(PrimitiveComponent); - - ECollisionChannel CollisionObjectType = PrimitiveComponent->GetCollisionObjectType(); - FColor Color = FColor::Green; // Channels[CollisionObjectType].Color; - - //------------------------------------------------------- - // Draw Name - //------------------------------------------------------- - if (DrawHitActorsNames) - { - const AActor* Actor = PrimitiveComponent->GetOwner(); - if (Actor != nullptr) - { - if (AlreadyDrawnActors.Contains(Actor) == false) - { - FColor TextColor = Color.WithAlpha(255); - DrawDebugString(GetWorld(), Actor->GetActorLocation(), GetNameSafe(Actor->GetClass()), nullptr, FColor::White, 0.0f, FCogDebug::Settings.TextShadow, FCogDebug::Settings.TextSize); - AlreadyDrawnActors.Add(Actor); - } - } - } - - const FVector Location = PrimitiveComponent->GetComponentLocation(); - const FQuat Rotation = PrimitiveComponent->GetComponentQuat(); - const FVector Scale = PrimitiveComponent->GetComponentScale(); - const FCollisionShape PrimitiveShape = PrimitiveComponent->GetCollisionShape(); - DrawShape(PrimitiveShape, Location, Rotation, Scale, Color, true); -} - -//-------------------------------------------------------------------------------------------------------------------------- -void ACogEngineCollisionTester::DrawShape(const FCollisionShape& InShape, const FVector& InLocation, const FQuat& InRotation, const FVector& InScale, const FColor& InColor, bool InDrawSolid) const -{ - switch (InShape.ShapeType) - { - case ECollisionShape::Box: - { - //-------------------------------------------------- - // see UBoxComponent::GetScaledBoxExtent() - //-------------------------------------------------- - const FVector HalfExtent(InShape.Box.HalfExtentX * InScale.X, InShape.Box.HalfExtentY * InScale.Y, InShape.Box.HalfExtentZ * InScale.Z); - - if (InDrawSolid) - { - DrawDebugSolidBox( - GetWorld(), - InLocation, - HalfExtent, - InRotation, - InColor, - false, - 0.0f, - FCogDebug::GetDebugDepthPriority(0)); - } - - DrawDebugBox( - GetWorld(), - InLocation, - HalfExtent, - InRotation, - InColor, - false, - 0.0f, - FCogDebug::GetDebugDepthPriority(0), - FCogDebug::GetDebugThickness(0.0f)); - - break; - } - - case ECollisionShape::Sphere: - { - //-------------------------------------------------- - // see USphereComponent::GetScaledSphereRadius() - //-------------------------------------------------- - const float RadiusScale = FMath::Min(InScale.X, FMath::Min(InScale.Y, InScale.Z)); - const float Radius = InShape.Sphere.Radius * RadiusScale; - - FCogDebugDrawHelper::DrawSphere( - GetWorld(), - InLocation, - Radius, - FCogDebug::GetCircleSegments(), - InColor, - false, - 0.0f, - FCogDebug::GetDebugDepthPriority(0), - FCogDebug::GetDebugThickness(0.0f)); - break; - } - - case ECollisionShape::Capsule: - { - //-------------------------------------------------- - // see UCapsuleComponent::GetScaledCapsuleRadius() - //-------------------------------------------------- - const float Radius = InShape.Capsule.Radius * FMath::Min(InScale.X, InScale.Y); - const float HalfHeight = InShape.Capsule.HalfHeight * UE_REAL_TO_FLOAT(InScale.Z); - - DrawDebugCapsule( - GetWorld(), - InLocation, - HalfHeight, - Radius, - InRotation, - InColor, - false, - 0.0f, - FCogDebug::GetDebugDepthPriority(0), - FCogDebug::GetDebugThickness(0.0f)); - break; - } + FCogDebugDrawSweepParams DrawParams; + FCogDebug::GetDebugDrawSweepSettings(DrawParams); + FCogDebugDrawHelper::DrawSweep(GetWorld(), QueryShape, QueryStart, QueryEnd, QueryRotation, HasHits, Hits, DrawParams); + break; + } } } diff --git a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CollisionTester.cpp b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CollisionTester.cpp index 988fc7b..12c2579 100644 --- a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CollisionTester.cpp +++ b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CollisionTester.cpp @@ -1,7 +1,6 @@ #include "CogEngineWindow_CollisionTester.h" #include "CogDebug.h" -#include "CogEngineDataAsset.h" #include "CogImGuiHelper.h" #include "CogWindowWidgets.h" #include "Components/PrimitiveComponent.h" @@ -15,8 +14,6 @@ void FCogEngineWindow_CollisionTester::Initialize() bHasMenu = true; - SetAsset(GetAsset()); - Config = GetConfig(); } @@ -34,117 +31,80 @@ void FCogEngineWindow_CollisionTester::ResetConfig() Config->Reset(); } -//-------------------------------------------------------------------------------------------------------------------------- -bool RenderCollisionProfileChannels(const UCollisionProfile& CollisionProfileChannels, int32& Channels, const TArray& ChannelsConfig) -{ - bool Result = false; - - for (const FCogCollisionChannel& ChannelConfig : ChannelsConfig) - { - const ECollisionChannel Channel = ChannelConfig.Channel.GetValue(); - ImGui::PushID(Channel); - - ImColor Color = FCogImguiHelper::ToImColor(ChannelConfig.Color); - ImGui::ColorEdit4("Color", (float*)&Color.Value, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel); - ImGui::SameLine(); - - bool IsCollisionActive = (Channels & ECC_TO_BITFIELD(Channel)) > 0; - const FName ChannelName = CollisionProfileChannels.ReturnChannelNameFromContainerIndex(Channel); - if (ImGui::Checkbox(TCHAR_TO_ANSI(*ChannelName.ToString()), &IsCollisionActive)) - { - Result = true; - - if (IsCollisionActive) - { - Channels |= ECC_TO_BITFIELD(Channel); - } - else - { - Channels &= ~ECC_TO_BITFIELD(Channel); - } - } - - ImGui::PopID(); - } - - return Result; -} - -//-------------------------------------------------------------------------------------------------------------------------- -bool RenderComboCollisionChannel(const char* Label, const UCollisionProfile& CollisionProfile, ECollisionChannel& SelectedChannel, const TArray& ChannelsConfig) -{ - const FName SelectedChannelName = CollisionProfile.ReturnChannelNameFromContainerIndex(SelectedChannel); - - bool Result = false; - if (ImGui::BeginCombo(Label, TCHAR_TO_ANSI(*SelectedChannelName.ToString()), ImGuiComboFlags_HeightLarge)) - { - for (const FCogCollisionChannel& ChannelConfig : ChannelsConfig) - { - const ECollisionChannel Channel = ChannelConfig.Channel.GetValue(); - ImGui::PushID(Channel); - - const FName ChannelName = CollisionProfile.ReturnChannelNameFromContainerIndex(Channel); - - ImColor Color = FCogImguiHelper::ToImColor(ChannelConfig.Color); - ImGui::ColorEdit4("Color", (float*)&Color.Value, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel); - ImGui::SameLine(); - - if (ImGui::Selectable(TCHAR_TO_ANSI(*ChannelName.ToString()))) - { - SelectedChannel = Channel; - Result = true; - } - - ImGui::PopID(); - } - ImGui::EndCombo(); - } - - return Result; -} - //-------------------------------------------------------------------------------------------------------------------------- void FCogEngineWindow_CollisionTester::RenderContent() { Super::RenderContent(); + ACogEngineCollisionTester* CollisionTester = Cast(GetSelection()); + //------------------------------------------------- // Menu //------------------------------------------------- if (ImGui::BeginMenuBar()) { - if (ImGui::BeginMenu("Options")) + ImGui::PushStyleColor(ImGuiCol_Button, IM_COL32(0, 0, 0, 0)); + ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0.0f, 0.0f)); + + if (ImGui::ArrowButton("SelectPrev", ImGuiDir_Left)) { - ImGui::Checkbox("Draw Hit Locations", &Config->DrawHitLocations); - ImGui::Checkbox("Draw Hit Impact Points", &Config->DrawHitImpactPoints); - ImGui::Checkbox("Draw Hit Shapes", &Config->DrawHitShapes); - ImGui::Checkbox("Draw Hit Normal", &Config->DrawHitNormals); - ImGui::Checkbox("Draw Hit Impact Normal", &Config->DrawHitImpactNormals); - ImGui::Checkbox("Draw Hit Primitives", &Config->DrawHitPrimitives); - ImGui::Checkbox("Draw Hit Actors Names", &Config->DrawHitActorsNames); + } + if (ImGui::BeginItemTooltip()) + { + ImGui::SetTooltip("Select previous collision tester"); + ImGui::EndTooltip(); + } - FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::SliderFloat("Hit Point Size", &Config->HitPointSize, 0.0f, 20.0f, "%0.f"); + ImGui::SameLine(); + if (ImGui::ArrowButton("SelectNext", ImGuiDir_Right)) + { + } + if (ImGui::BeginItemTooltip()) + { + ImGui::SetTooltip("Select next collision tester"); + ImGui::EndTooltip(); + } - ImGui::ColorEdit4("No Hit Color", (float*)&Config->NoHitColor, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); - ImGui::ColorEdit4("Hit Color", (float*)&Config->HitColor, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); - ImGui::ColorEdit4("Normal Color", (float*)&Config->NormalColor, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); - ImGui::ColorEdit4("Impact Normal Color", (float*)&Config->ImpactNormalColor, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); + ImGui::PopStyleColor(1); + ImGui::PopStyleVar(1); - ImGui::EndMenu(); + + if (ImGui::MenuItem("Spawn")) + { + const FActorSpawnParameters SpawnInfo; + const FTransform Transform = GetSelection() ? GetSelection()->GetActorTransform() : FTransform::Identity; + ACogEngineCollisionTester* Actor = GetWorld()->SpawnActor(ACogEngineCollisionTester::StaticClass(), Transform, SpawnInfo); + FCogDebug::SetSelection(GetWorld(), Actor); + } + if (ImGui::BeginItemTooltip()) + { + ImGui::SetTooltip("Spawn a new collision tester"); + ImGui::EndTooltip(); + } + + const bool Disable = CollisionTester == nullptr; + if (Disable) + { + ImGui::BeginDisabled(); + } + if (ImGui::MenuItem("Delete")) + { + GetWorld()->DestroyActor(CollisionTester); + CollisionTester = nullptr; + } + if (ImGui::BeginItemTooltip()) + { + ImGui::SetTooltip("Delete selected collision tester"); + ImGui::EndTooltip(); + } + if (Disable) + { + ImGui::EndDisabled(); } ImGui::EndMenuBar(); } - if (ImGui::Button("Spawn Collision Tester", ImVec2(-1, 0))) - { - const FActorSpawnParameters SpawnInfo; - ACogEngineCollisionTester* Actor = GetWorld()->SpawnActor(SpawnInfo); - FCogDebug::SetSelection(GetWorld(), Actor); - } - - ACogEngineCollisionTester* CollisionTester = Cast(GetSelection()); if (CollisionTester == nullptr) { ImGui::TextDisabled("Spawn or select a Collision Tester actor"); @@ -183,7 +143,7 @@ void FCogEngineWindow_CollisionTester::RenderContent() { FCogWindowWidgets::SetNextItemToShortWidth(); ECollisionChannel Channel = CollisionTester->Channel.GetValue(); - if (RenderComboCollisionChannel("Channel", *CollisionProfile, Channel, Asset->Channels)) + if (FCogWindowWidgets::ComboCollisionChannel("Channel", Channel)) { CollisionTester->Channel = Channel; } @@ -241,24 +201,24 @@ void FCogEngineWindow_CollisionTester::RenderContent() case ECogEngine_CollisionQueryShape::Sphere: { FCogWindowWidgets::SetNextItemToShortWidth(); - FCogImguiHelper::DragDouble("Sphere Radius", &CollisionTester->ShapeExtent.X, 0.1f, 0, FLT_MAX, "%.1f"); + FCogImguiHelper::DragDouble("Sphere Radius", &CollisionTester->ShapeExtent.X, 1.0f, 0, FLT_MAX, "%.1f"); break; } case ECogEngine_CollisionQueryShape::Box: { FCogWindowWidgets::SetNextItemToShortWidth(); - FCogImguiHelper::DragFVector("Box Extent", CollisionTester->ShapeExtent, 0.1f, 0, FLT_MAX, "%.1f"); + FCogImguiHelper::DragFVector("Box Extent", CollisionTester->ShapeExtent, 1.0f, 0, FLT_MAX, "%.1f"); break; } case ECogEngine_CollisionQueryShape::Capsule: { FCogWindowWidgets::SetNextItemToShortWidth(); - FCogImguiHelper::DragDouble("Capsule Radius", &CollisionTester->ShapeExtent.X, 0.1f, 0, FLT_MAX, "%.1f"); + FCogImguiHelper::DragDouble("Capsule Radius", &CollisionTester->ShapeExtent.X, 1.0f, 0, FLT_MAX, "%.1f"); FCogWindowWidgets::SetNextItemToShortWidth(); - FCogImguiHelper::DragDouble("Capsule Half Height", &CollisionTester->ShapeExtent.Z, 0.1f, 0, FLT_MAX, "%.1f"); + FCogImguiHelper::DragDouble("Capsule Half Height", &CollisionTester->ShapeExtent.Z, 1.0f, 0, FLT_MAX, "%.1f"); break; } } @@ -272,34 +232,11 @@ void FCogEngineWindow_CollisionTester::RenderContent() if (CollisionTester->By == ECogEngine_CollisionQueryBy::Profile) { ImGui::BeginDisabled(); - RenderCollisionProfileChannels(*CollisionProfile, CollisionTester->ObjectTypesToQuery, Asset->Channels); + FCogWindowWidgets::CollisionProfileChannels(CollisionTester->ObjectTypesToQuery); ImGui::EndDisabled(); } else if (CollisionTester->By == ECogEngine_CollisionQueryBy::ObjectType) { - RenderCollisionProfileChannels(*CollisionProfile, CollisionTester->ObjectTypesToQuery, Asset->Channels); - } -} - -//-------------------------------------------------------------------------------------------------------------------------- -void FCogEngineWindow_CollisionTester::SetAsset(const UCogEngineDataAsset* Value) -{ - Asset = Value; - - if (Asset == nullptr) - { - return; - } - - for (FChannel& Channel : Channels) - { - Channel.IsValid = false; - } - - for (const FCogCollisionChannel& AssetChannel : Asset->Channels) - { - FChannel& Channel = Channels[(uint8)AssetChannel.Channel]; - Channel.IsValid = true; - Channel.Color = AssetChannel.Color.ToFColor(true); + FCogWindowWidgets::CollisionProfileChannels(CollisionTester->ObjectTypesToQuery); } } diff --git a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CollisionViewer.cpp b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CollisionViewer.cpp index 1e76459..45e7e4a 100644 --- a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CollisionViewer.cpp +++ b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_CollisionViewer.cpp @@ -2,14 +2,11 @@ #include "CogDebugDrawHelper.h" #include "CogDebug.h" -#include "CogEngineDataAsset.h" +#include "CogEngineCollisionTester.h" #include "CogImguiHelper.h" -#include "CogWindowHelper.h" -#include "Components/BoxComponent.h" -#include "Components/CapsuleComponent.h" +#include "CogWindowWidgets.h" #include "Components/PrimitiveComponent.h" #include "Components/SceneComponent.h" -#include "Components/SphereComponent.h" #include "DrawDebugHelpers.h" #include "Engine/World.h" #include "GameFramework/Pawn.h" @@ -24,8 +21,6 @@ void FCogEngineWindow_CollisionViewer::Initialize() bHasMenu = true; - SetAsset(GetAsset()); - Config = GetConfig(); } @@ -34,8 +29,6 @@ void FCogEngineWindow_CollisionViewer::RenderHelp() { ImGui::Text("This window is used to inspect collisions by performing a collision query with the selected channels. " "The query can be configured in the options. " - "The displayed collision channels can be configured in the '%s' data asset. " - , TCHAR_TO_ANSI(*GetNameSafe(Asset.Get())) ); } @@ -108,11 +101,6 @@ void FCogEngineWindow_CollisionViewer::RenderContent() //------------------------------------------------- ImGui::Checkbox("Show Actors Names", &Config->ShowActorsNames); - //------------------------------------------------- - // Show Query - //------------------------------------------------- - ImGui::Checkbox("Show Query", &Config->ShowQuery); - ImGui::EndMenu(); } @@ -153,41 +141,7 @@ void FCogEngineWindow_CollisionViewer::RenderContent() } ImGui::Separator(); - //------------------------------------------------- - // Query Filtering - //------------------------------------------------- - for (int ChannelIndex = 0; ChannelIndex < (int32)ECC_MAX; ++ChannelIndex) - { - const FChannel& Channel = Channels[ChannelIndex]; - if (Channel.IsValid == false) - { - continue; - } - - ImGui::PushID(ChannelIndex); - - ImColor Color = FCogImguiHelper::ToImColor(Channel.Color); - ImGui::ColorEdit4("Color", (float*)&Color.Value, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel); - ImGui::SameLine(); - - bool IsCollisionActive = (Config->ObjectTypesToQuery & ECC_TO_BITFIELD(ChannelIndex)) > 0; - const FName ChannelName = CollisionProfile->ReturnChannelNameFromContainerIndex(ChannelIndex); - if (ImGui::Checkbox(TCHAR_TO_ANSI(*ChannelName.ToString()), &IsCollisionActive)) - { - if (IsCollisionActive) - { - Config->ObjectTypesToQuery |= ECC_TO_BITFIELD(ChannelIndex); - Config->ProfileIndex = INDEX_NONE; - } - else - { - Config->ObjectTypesToQuery &= ~ECC_TO_BITFIELD(ChannelIndex); - Config->ProfileIndex = INDEX_NONE; - } - } - - ImGui::PopID(); - } + FCogWindowWidgets::CollisionProfileChannels(Config->ObjectTypesToQuery); //------------------------------------------------- // Perform Query @@ -247,10 +201,10 @@ void FCogEngineWindow_CollisionViewer::RenderContent() FCollisionShape QueryShape; QueryShape.SetSphere(QueryRadius); - TArray QueryHits; + TArray HitResults; UWorld* World = GetWorld(); World->SweepMultiByObjectType( - QueryHits, + HitResults, QueryStart, QueryEnd, FQuat::Identity, @@ -258,153 +212,13 @@ void FCogEngineWindow_CollisionViewer::RenderContent() QueryShape, QueryParams); - if (Config->ShowQuery) - { - FCogDebugDrawHelper::DrawCapsuleCastMulti(World, QueryStart, QueryEnd, FQuat::Identity, 0.0f, QueryRadius, EDrawDebugTrace::ForOneFrame, false, QueryHits, FLinearColor::White, FLinearColor::Red, FCogDebug::GetDebugDuration(true)); - } - - TSet AlreadyDrawnActors; - TSet AlreadyDrawnComponents; - - for (const FHitResult& HitResult : QueryHits) - { - //------------------------------------------------------- - // Don't draw same primitives multiple times (for bones) - //------------------------------------------------------- - const UPrimitiveComponent* PrimitiveComponent = HitResult.GetComponent(); - if (AlreadyDrawnComponents.Contains(PrimitiveComponent)) - { - continue; - } - AlreadyDrawnComponents.Add(PrimitiveComponent); - - ECollisionChannel CollisionObjectType = PrimitiveComponent->GetCollisionObjectType(); - FColor Color = Channels[CollisionObjectType].Color; - - //------------------------------------------------------- - // Draw Name - //------------------------------------------------------- - if (Config->ShowActorsNames) - { - const AActor* Actor = HitResult.GetActor(); - if (Actor != nullptr) - { - if (AlreadyDrawnActors.Contains(Actor) == false) - { - FColor TextColor = Color.WithAlpha(255); - DrawDebugString(World, Actor->GetActorLocation(), GetNameSafe(Actor->GetClass()), nullptr, FColor::White, 0.0f, FCogDebug::Settings.TextShadow, FCogDebug::Settings.TextSize); - AlreadyDrawnActors.Add(Actor); - } - } - } - - //------------------------------------------------------- - // Draw Shape - //------------------------------------------------------- - FCollisionShape Shape = PrimitiveComponent->GetCollisionShape(); - switch (Shape.ShapeType) - { - case ECollisionShape::Box: - { - FVector Location; - FVector Extent; - FQuat Rotation; - - if (const UBoxComponent* BoxComponent = Cast(PrimitiveComponent)) - { - Location = BoxComponent->GetComponentLocation(); - Extent = BoxComponent->GetScaledBoxExtent(); - Rotation = BoxComponent->GetComponentQuat(); - } - else - { - PrimitiveComponent->Bounds.GetBox().GetCenterAndExtents(Location, Extent); - Extent += FVector::OneVector; - Rotation = FQuat::Identity; - } - - DrawDebugSolidBox( - World, - Location, - Extent, - Rotation, - Color, - false, - 0.0f, - FCogDebug::GetDebugDepthPriority(0)); - - DrawDebugBox( - World, - Location, - Extent, - Rotation, - Color, - false, - 0.0f, - FCogDebug::GetDebugDepthPriority(0), - FCogDebug::GetDebugThickness(0.0f)); - - break; - } - - case ECollisionShape::Sphere: - { - if (const USphereComponent* SphereComponent = Cast(PrimitiveComponent)) - { - FCogDebugDrawHelper::DrawSphere( - World, - SphereComponent->GetComponentLocation(), - SphereComponent->GetScaledSphereRadius(), - FCogDebug::GetCircleSegments(), - Color, - false, - 0.0f, - FCogDebug::GetDebugDepthPriority(0), - FCogDebug::GetDebugThickness(0.0f)); - } - break; - } - - case ECollisionShape::Capsule: - { - if (const UCapsuleComponent* CapsuleComponent = Cast(PrimitiveComponent)) - { - DrawDebugCapsule(World, - CapsuleComponent->GetComponentLocation(), - CapsuleComponent->GetScaledCapsuleHalfHeight(), - CapsuleComponent->GetScaledCapsuleRadius(), - CapsuleComponent->GetComponentQuat(), - Color, - false, - 0.0f, - FCogDebug::GetDebugDepthPriority(0), - FCogDebug::GetDebugThickness(0.0f)); - } - break; - } - } - } + FCogDebugDrawSweepParams DrawParams; + FCogDebug::GetDebugDrawSweepSettings(DrawParams); + DrawParams.DrawHitNormals = false; + DrawParams.DrawHitImpactNormals = false; + DrawParams.DrawHitImpactPoints = false; + DrawParams.DrawHitLocation = false; + DrawParams.DrawHitPrimitives = true; + DrawParams.DrawHitPrimitiveActorsName = Config->ShowActorsNames; + FCogDebugDrawHelper::DrawSweep(GetWorld(), QueryShape, QueryStart, QueryEnd, FQuat::Identity, false, HitResults, DrawParams); } - -//-------------------------------------------------------------------------------------------------------------------------- -void FCogEngineWindow_CollisionViewer::SetAsset(const UCogEngineDataAsset* Value) -{ - Asset = Value; - - if (Asset == nullptr) - { - return; - } - - for (FChannel& Channel : Channels) - { - Channel.IsValid = false; - } - - for (const FCogCollisionChannel& AssetChannel : Asset->Channels) - { - FChannel& Channel = Channels[(uint8)AssetChannel.Channel]; - Channel.IsValid = true; - Channel.Color = AssetChannel.Color.ToFColor(true); - } -} \ No newline at end of file diff --git a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_DebugSettings.cpp b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_DebugSettings.cpp index f1ccf3b..636f691 100644 --- a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_DebugSettings.cpp +++ b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_DebugSettings.cpp @@ -43,6 +43,13 @@ void FCogEngineWindow_DebugSettings::PreSaveConfig() Config->Data = FCogDebug::Settings; } +//-------------------------------------------------------------------------------------------------------------------------- +void RenderCollisionChannelColor(const UCollisionProfile& CollisionProfile, FColor& Color, ECollisionChannel Channel, ImGuiColorEditFlags ColorEditFlags) +{ + const FString ChannelName = CollisionProfile.ReturnChannelNameFromContainerIndex(Channel).ToString(); + FCogImguiHelper::ColorEdit4(StringCast(*ChannelName).Get(), Color, ColorEditFlags); +} + //-------------------------------------------------------------------------------------------------------------------------- void FCogEngineWindow_DebugSettings::RenderContent() { @@ -57,200 +64,210 @@ void FCogEngineWindow_DebugSettings::RenderContent() FCogDebug::Reset(); } - ImGui::Checkbox("Show Advanced Settings", &Config->bShowAdvancedSettings); - ImGui::EndMenu(); } ImGui::EndMenuBar(); } - Config->Data.bIsFilteringBySelection = FCogDebug::GetIsFilteringBySelection(); - if (ImGui::Checkbox("Filter by selection", &Config->Data.bIsFilteringBySelection)) - { - FCogDebug::SetIsFilteringBySelection(GetWorld(), Config->Data.bIsFilteringBySelection); - } - if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) - { - ImGui::SetTooltip("If checked, only show the debug of the currently selected actor. Otherwise show the debug of all actors."); - } - + constexpr ImGuiColorEditFlags ColorEditFlags = ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf; FCogDebugSettings& Settings = FCogDebug::Settings; - ImGui::Checkbox("Persistent", &Settings.Persistent); - if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) + if (ImGui::CollapsingHeader("General", ImGuiTreeNodeFlags_DefaultOpen)) { - ImGui::SetTooltip("Make debug draw always persist"); + Config->Data.bIsFilteringBySelection = FCogDebug::GetIsFilteringBySelection(); + if (ImGui::Checkbox("Filter by selection", &Config->Data.bIsFilteringBySelection)) + { + FCogDebug::SetIsFilteringBySelection(GetWorld(), Config->Data.bIsFilteringBySelection); + } + if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) + { + ImGui::SetTooltip("If checked, only show the debug of the currently selected actor. Otherwise show the debug of all actors."); + } + + ImGui::Checkbox("Persistent", &Settings.Persistent); + if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) + { + ImGui::SetTooltip("Make debug draw always persist"); + } + + ImGui::Checkbox("Text Shadow", &Settings.TextShadow); + if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) + { + ImGui::SetTooltip("Show a shadow below debug text."); + } + + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::Checkbox("Fade 2D", &Settings.Fade2D); + if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) + { + ImGui::SetTooltip("Does the 2D debug is fading out."); + } + + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragFloat("Duration", &Settings.Duration, 0.01f, 0.0f, 100.0f, "%.1f"); + if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) + { + ImGui::SetTooltip("The duration of debug elements."); + } + + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragFloat("Thickness", &Settings.Thickness, 0.05f, 0.0f, 5.0f, "%.1f"); + if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) + { + ImGui::SetTooltip("The thickness of debug lines."); + } + + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragFloat("Server Thickness", &Settings.ServerThickness, 0.05f, 0.0f, 5.0f, "%.1f"); + if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) + { + ImGui::SetTooltip("The thickness the server debug lines."); + } + + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragFloat("Server Color Mult", &Settings.ServerColorMultiplier, 0.01f, 0.0f, 1.0f, "%.1f"); + if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) + { + ImGui::SetTooltip("The color multiplier applied to the server debug lines."); + } + + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragInt("Depth Priority", &Settings.DepthPriority, 0.1f, 0, 100); + if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) + { + ImGui::SetTooltip("The depth priority of debug elements."); + } + + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragInt("Segments", &Settings.Segments, 0.1f, 4, 20.0f); + if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) + { + ImGui::SetTooltip("The number of segments used for circular shapes."); + } + + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragFloat("Axes Scale", &Settings.AxesScale, 0.1f, 0, 10.0f, "%.1f"); + if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) + { + ImGui::SetTooltip("The scaling debug axis."); + } + + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragFloat("Arrow Size", &Settings.ArrowSize, 1.0f, 0.0f, 200.0f, "%.0f"); + if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) + { + ImGui::SetTooltip("The size of debug arrows."); + } + + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragFloat("Gradient Intensity", &Settings.GradientColorIntensity, 0.01f, 0.0f, 1.0f, "%.2f"); + if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) + { + ImGui::SetTooltip("How much the debug elements color should be changed by a gradient color over time."); + } + + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragFloat("Gradient Speed", &Settings.GradientColorSpeed, 0.1f, 0.0f, 10.0f, "%.1f"); + if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) + { + ImGui::SetTooltip("The speed of the gradient color change."); + } + + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragFloat("Text Size", &Settings.TextSize, 0.1f, 0.1f, 5.0f, "%.1f"); + if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) + { + ImGui::SetTooltip("The size of the debug texts."); + } } - ImGui::Checkbox("Text Shadow", &Settings.TextShadow); - if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) + if (ImGui::CollapsingHeader("Gizmo")) { - ImGui::SetTooltip("Show a shadow below debug text."); - } + ImGui::SeparatorText("General"); - FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::Checkbox("Fade 2D", &Settings.Fade2D); - if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) - { - ImGui::SetTooltip("Does the 2D debug is fading out."); - } - - FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Duration", &Settings.Duration, 0.01f, 0.0f, 100.0f, "%.1f"); - if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) - { - ImGui::SetTooltip("The duration of debug elements."); - } - - FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Thickness", &Settings.Thickness, 0.05f, 0.0f, 5.0f, "%.1f"); - if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) - { - ImGui::SetTooltip("The thickness of debug lines."); - } - - FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Server Thickness", &Settings.ServerThickness, 0.05f, 0.0f, 5.0f, "%.1f"); - if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) - { - ImGui::SetTooltip("The thickness the server debug lines."); - } - - FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Server Color Mult", &Settings.ServerColorMultiplier, 0.01f, 0.0f, 1.0f, "%.1f"); - if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) - { - ImGui::SetTooltip("The color multiplier applied to the server debug lines."); - } - - FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragInt("Depth Priority", &Settings.DepthPriority, 0.1f, 0, 100); - if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) - { - ImGui::SetTooltip("The depth priority of debug elements."); - } - - FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragInt("Segments", &Settings.Segments, 0.1f, 4, 20.0f); - if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) - { - ImGui::SetTooltip("The number of segments used for circular shapes."); - } - - FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Axes Scale", &Settings.AxesScale, 0.1f, 0, 10.0f, "%.1f"); - if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) - { - ImGui::SetTooltip("The scaling debug axis."); - } - - FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Arrow Size", &Settings.ArrowSize, 1.0f, 0.0f, 200.0f, "%.0f"); - if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) - { - ImGui::SetTooltip("The size of debug arrows."); - } - - FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Gradient Intensity", &Settings.GradientColorIntensity, 0.01f, 0.0f, 1.0f, "%.2f"); - if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) - { - ImGui::SetTooltip("How much the debug elements color should be changed by a gradient color over time."); - } - - FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Gradient Speed", &Settings.GradientColorSpeed, 0.1f, 0.0f, 10.0f, "%.1f"); - if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) - { - ImGui::SetTooltip("The speed of the gradient color change."); - } - - FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Text Size", &Settings.TextSize, 0.1f, 0.1f, 5.0f, "%.1f"); - if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) - { - ImGui::SetTooltip("The size of the debug texts."); - } - - ImGui::SeparatorText("Gizmo"); - - ImGui::Checkbox("Gizmo Use Local Space", &Settings.GizmoUseLocalSpace); - - FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Gizmo Scale", &Settings.GizmoScale, 0.1f, 0.1f, 10.0f, "%.1f"); - if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) - { - ImGui::SetTooltip("The scale of the gizmo."); - } - - if (Config->bShowAdvancedSettings) - { - FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragInt("Gizmo Z Low", &Settings.GizmoZLow, 0.5f, 0, 1000); + ImGui::Checkbox("Use Local Space", &Settings.GizmoUseLocalSpace); FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragInt("Gizmo Z High", &Settings.GizmoZHigh, 0.5f, 0, 1000); + ImGui::DragFloat("Gizmo Scale", &Settings.GizmoScale, 0.1f, 0.1f, 10.0f, "%.1f"); + if (ImGui::IsItemHovered(ImGuiHoveredFlags_Stationary)) + { + ImGui::SetTooltip("The scale of the gizmo."); + } FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Gizmo Thickness Z Low", &Settings.GizmoThicknessZLow, 0.1f, 0.0f, 10.0f, "%.1f"); + ImGui::DragInt("Z Low", &Settings.GizmoZLow, 0.5f, 0, 1000); FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Gizmo Thickness Z High", &Settings.GizmoThicknessZHigh, 0.1f, 0.0f, 10.0f, "%.1f"); + ImGui::DragInt("Z High", &Settings.GizmoZHigh, 0.5f, 0, 1000); FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Gizmo Mouse Max Distance", &Settings.GizmoCursorSelectionThreshold, 0.1f, 0.0f, 50.0f, "%.1f"); + ImGui::DragFloat("Thickness Z Low", &Settings.GizmoThicknessZLow, 0.1f, 0.0f, 10.0f, "%.1f"); FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::Checkbox("Gizmo Translation Snap Enable", &Settings.GizmoTranslationSnapEnable); + ImGui::DragFloat("Thickness Z High", &Settings.GizmoThicknessZHigh, 0.1f, 0.0f, 10.0f, "%.1f"); FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Gizmo Translation Snap", &Settings.GizmoTranslationSnapValue, 0.1f, 0.0f, 1000.0f, "%.1f"); + ImGui::DragFloat("Mouse Max Distance", &Settings.GizmoCursorSelectionThreshold, 0.1f, 0.0f, 50.0f, "%.1f"); + + ImGui::SeparatorText("Translation"); FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Gizmo Translation Axis Length", &Settings.GizmoTranslationAxisLength, 0.1f, 0.1f, 500.0f, "%.1f"); + ImGui::Checkbox("Translation Snap Enable", &Settings.GizmoTranslationSnapEnable); FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Gizmo Translation Plane Offset", &Settings.GizmoTranslationPlaneOffset, 0.1f, 0.0f, 500.0f, "%.1f"); + ImGui::DragFloat("Translation Snap", &Settings.GizmoTranslationSnapValue, 0.1f, 0.0f, 1000.0f, "%.1f"); FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Gizmo Translation Plane Extent", &Settings.GizmoTranslationPlaneExtent, 0.1f, 0.0f, 100.0f, "%.1f"); + ImGui::DragFloat("Translation Axis Length", &Settings.GizmoTranslationAxisLength, 0.1f, 0.1f, 500.0f, "%.1f"); FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::Checkbox("Gizmo Rotation Snap Enable", &Settings.GizmoRotationSnapEnable); + ImGui::DragFloat("Translation Plane Offset", &Settings.GizmoTranslationPlaneOffset, 0.1f, 0.0f, 500.0f, "%.1f"); FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Gizmo Rotation Snap", &Settings.GizmoRotationSnapValue, 0.1f, 0.0f, 360.0f, "%.1f"); + ImGui::DragFloat("Translation Plane Extent", &Settings.GizmoTranslationPlaneExtent, 0.1f, 0.0f, 100.0f, "%.1f"); + + ImGui::SeparatorText("Rotation"); FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Gizmo Rotation Speed", &Settings.GizmoRotationSpeed, 0.01f, 0.01f, 100.0f, "%.2f"); + ImGui::Checkbox("Rotation Snap Enable", &Settings.GizmoRotationSnapEnable); FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Gizmo Rotation Radius", &Settings.GizmoRotationRadius, 0.1f, 0.1f, 500.0f, "%.1f"); + ImGui::DragFloat("Rotation Snap", &Settings.GizmoRotationSnapValue, 0.1f, 0.0f, 360.0f, "%.1f"); FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragInt("Gizmo Rotation Segments", &Settings.GizmoRotationSegments, 0.5f, 2, 12); + ImGui::DragFloat("Rotation Speed", &Settings.GizmoRotationSpeed, 0.01f, 0.01f, 100.0f, "%.2f"); FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::Checkbox("Gizmo Scale Snap Enable", &Settings.GizmoScaleSnapEnable); + ImGui::DragFloat("Rotation Radius", &Settings.GizmoRotationRadius, 0.1f, 0.1f, 500.0f, "%.1f"); FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Gizmo Scale Snap", &Settings.GizmoScaleSnapValue, 0.1f, 0.0f, 10.0f, "%.1f"); + ImGui::DragInt("Rotation Segments", &Settings.GizmoRotationSegments, 0.5f, 2, 12); + + ImGui::SeparatorText("Scale"); FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Gizmo Scale Box Offset", &Settings.GizmoScaleBoxOffset, 0.0f, 0.0f, 500.0f, "%.1f"); + ImGui::Checkbox("Scale Snap Enable", &Settings.GizmoScaleSnapEnable); FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Gizmo Scale Box Extent", &Settings.GizmoScaleBoxExtent, 0.1f, 0.0f, 100.0f, "%.1f"); + ImGui::DragFloat("Scale Snap", &Settings.GizmoScaleSnapValue, 0.1f, 0.0f, 10.0f, "%.1f"); FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Gizmo Scale Speed", &Settings.GizmoScaleSpeed, 0.01f, 0.01f, 100.0f, "%.2f"); + ImGui::DragFloat("Scale Box Offset", &Settings.GizmoScaleBoxOffset, 0.0f, 0.0f, 500.0f, "%.1f"); FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Gizmo Scale Min", &Settings.GizmoScaleMin, 0.001f, 0.001f, 1.0f, "%.3f"); + ImGui::DragFloat("Scale Box Extent", &Settings.GizmoScaleBoxExtent, 0.1f, 0.0f, 100.0f, "%.1f"); FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Gizmo Ground Raycast Length", &Settings.GizmoGroundRaycastLength, 10.0f, 0.0f, 1000000.0f, "%.0f"); + ImGui::DragFloat("Scale Speed", &Settings.GizmoScaleSpeed, 0.01f, 0.01f, 100.0f, "%.2f"); + + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragFloat("Scale Min", &Settings.GizmoScaleMin, 0.001f, 0.001f, 1.0f, "%.3f"); + + ImGui::SeparatorText("Ground Raycast"); + + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragFloat("Ground Raycast Length", &Settings.GizmoGroundRaycastLength, 10.0f, 0.0f, 1000000.0f, "%.0f"); FCogWindowWidgets::SetNextItemToShortWidth(); ECollisionChannel Channel = Settings.GizmoGroundRaycastChannel.GetValue(); @@ -260,26 +277,90 @@ void FCogEngineWindow_DebugSettings::RenderContent() } FCogWindowWidgets::SetNextItemToShortWidth(); - ImGui::DragFloat("Gizmo Ground Raycast Circle Radius", &Settings.GizmoGroundRaycastCircleRadius, 0.1f, 0.1f, 1000.0f, "%.1f"); + ImGui::DragFloat("Ground Raycast Circle Radius", &Settings.GizmoGroundRaycastCircleRadius, 0.1f, 0.1f, 1000.0f, "%.1f"); - FCogImguiHelper::ColorEdit4("Gizmo Axis Colors ZLow X", Settings.GizmoAxisColorsZLowX, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); - FCogImguiHelper::ColorEdit4("Gizmo Axis Colors ZLow Y", Settings.GizmoAxisColorsZLowY, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); - FCogImguiHelper::ColorEdit4("Gizmo Axis Colors ZLow Z", Settings.GizmoAxisColorsZLowZ, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); - FCogImguiHelper::ColorEdit4("Gizmo Axis Colors ZLow W", Settings.GizmoAxisColorsZLowW, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); + FCogImguiHelper::ColorEdit4("Ground Raycast Color", Settings.GizmoGroundRaycastColor, ColorEditFlags); + FCogImguiHelper::ColorEdit4("Ground Raycast Circle Color", Settings.GizmoGroundRaycastCircleColor, ColorEditFlags); - FCogImguiHelper::ColorEdit4("Gizmo Axis Colors ZHigh X", Settings.GizmoAxisColorsZHighX, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); - FCogImguiHelper::ColorEdit4("Gizmo Axis Colors ZHigh Y", Settings.GizmoAxisColorsZHighY, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); - FCogImguiHelper::ColorEdit4("Gizmo Axis Colors ZHigh Z", Settings.GizmoAxisColorsZHighZ, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); - FCogImguiHelper::ColorEdit4("Gizmo Axis Colors ZHigh W", Settings.GizmoAxisColorsZHighW, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); + ImGui::SeparatorText("Axis Colors"); - FCogImguiHelper::ColorEdit4("Gizmo Axis Colors Selection X", Settings.GizmoAxisColorsSelectionX, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); - FCogImguiHelper::ColorEdit4("Gizmo Axis Colors Selection Y", Settings.GizmoAxisColorsSelectionY, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); - FCogImguiHelper::ColorEdit4("Gizmo Axis Colors Selection Z", Settings.GizmoAxisColorsSelectionZ, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); - FCogImguiHelper::ColorEdit4("Gizmo Axis Colors Selection W", Settings.GizmoAxisColorsSelectionW, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); + FCogImguiHelper::ColorEdit4("Axis Colors ZLow X", Settings.GizmoAxisColorsZLowX, ColorEditFlags); + FCogImguiHelper::ColorEdit4("Axis Colors ZLow Y", Settings.GizmoAxisColorsZLowY, ColorEditFlags); + FCogImguiHelper::ColorEdit4("Axis Colors ZLow Z", Settings.GizmoAxisColorsZLowZ, ColorEditFlags); + FCogImguiHelper::ColorEdit4("Axis Colors ZLow W", Settings.GizmoAxisColorsZLowW, ColorEditFlags); - FCogImguiHelper::ColorEdit4("Gizmo Text Color", Settings.GizmoTextColor, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); + FCogImguiHelper::ColorEdit4("Axis Colors ZHigh X", Settings.GizmoAxisColorsZHighX, ColorEditFlags); + FCogImguiHelper::ColorEdit4("Axis Colors ZHigh Y", Settings.GizmoAxisColorsZHighY, ColorEditFlags); + FCogImguiHelper::ColorEdit4("Axis Colors ZHigh Z", Settings.GizmoAxisColorsZHighZ, ColorEditFlags); + FCogImguiHelper::ColorEdit4("Axis Colors ZHigh W", Settings.GizmoAxisColorsZHighW, ColorEditFlags); - FCogImguiHelper::ColorEdit4("Gizmo Ground Raycast Color", Settings.GizmoGroundRaycastColor, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); - FCogImguiHelper::ColorEdit4("Gizmo Ground Raycast Circle Color", Settings.GizmoGroundRaycastCircleColor, ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_AlphaPreviewHalf); + FCogImguiHelper::ColorEdit4("Axis Colors Selection X", Settings.GizmoAxisColorsSelectionX, ColorEditFlags); + FCogImguiHelper::ColorEdit4("Axis Colors Selection Y", Settings.GizmoAxisColorsSelectionY, ColorEditFlags); + FCogImguiHelper::ColorEdit4("Axis Colors Selection Z", Settings.GizmoAxisColorsSelectionZ, ColorEditFlags); + FCogImguiHelper::ColorEdit4("Axis Colors Selection W", Settings.GizmoAxisColorsSelectionW, ColorEditFlags); + + FCogImguiHelper::ColorEdit4("Text Color", Settings.GizmoTextColor, ColorEditFlags); + } + + if (ImGui::CollapsingHeader("Collision Channels")) + { + if (const UCollisionProfile* CollisionProfile = UCollisionProfile::Get()) + { + RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorWorldStatic, ECC_WorldStatic, ColorEditFlags); + RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorWorldDynamic, ECC_WorldDynamic, ColorEditFlags); + RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorPawn, ECC_Pawn, ColorEditFlags); + RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorVisibility, ECC_Visibility, ColorEditFlags); + RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorCamera, ECC_Camera, ColorEditFlags); + RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorPhysicsBody, ECC_PhysicsBody, ColorEditFlags); + RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorVehicle, ECC_Vehicle, 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.ChannelColorGameTraceChannel2, ECC_GameTraceChannel2, ColorEditFlags); + RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorGameTraceChannel3, ECC_GameTraceChannel3, ColorEditFlags); + RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorGameTraceChannel4, ECC_GameTraceChannel4, ColorEditFlags); + RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorGameTraceChannel5, ECC_GameTraceChannel5, ColorEditFlags); + RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorGameTraceChannel6, ECC_GameTraceChannel6, ColorEditFlags); + RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorGameTraceChannel7, ECC_GameTraceChannel7, ColorEditFlags); + RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorGameTraceChannel8, ECC_GameTraceChannel8, ColorEditFlags); + RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorGameTraceChannel9, ECC_GameTraceChannel9, ColorEditFlags); + RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorGameTraceChannel10, ECC_GameTraceChannel10, ColorEditFlags); + RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorGameTraceChannel11, ECC_GameTraceChannel11, ColorEditFlags); + RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorGameTraceChannel12, ECC_GameTraceChannel12, ColorEditFlags); + RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorGameTraceChannel13, ECC_GameTraceChannel13, ColorEditFlags); + RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorGameTraceChannel14, ECC_GameTraceChannel14, ColorEditFlags); + RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorGameTraceChannel15, ECC_GameTraceChannel15, ColorEditFlags); + RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorGameTraceChannel16, ECC_GameTraceChannel16, ColorEditFlags); + RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorGameTraceChannel17, ECC_GameTraceChannel17, ColorEditFlags); + RenderCollisionChannelColor(*CollisionProfile, Settings.ChannelColorGameTraceChannel18, ECC_GameTraceChannel18, ColorEditFlags); + } + } + + if (ImGui::CollapsingHeader("Collision Query")) + { + ImGui::Checkbox("Draw Hit Primitives", &Settings.CollisionQueryDrawHitPrimitives); + ImGui::Checkbox("Draw Hit Primitive Actors Name", &Settings.CollisionQueryDrawHitPrimitiveActorsName); + ImGui::Checkbox("Prim Hit Primitive Actors Name Shadow", &Settings.CollisionQueryHitPrimitiveActorsNameShadow); + ImGui::Checkbox("Draw Hit Shapes", &Settings.CollisionQueryDrawHitShapes); + ImGui::Checkbox("Draw Hit Location", &Settings.CollisionQueryDrawHitLocation); + ImGui::Checkbox("Draw Hit Impact Points", &Settings.CollisionQueryDrawHitImpactPoints); + ImGui::Checkbox("Draw Hit Normals", &Settings.CollisionQueryDrawHitNormals); + ImGui::Checkbox("Draw Hit Impact Normals", &Settings.CollisionQueryDrawHitImpactNormals); + + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragFloat("Primitive Actors Name Size", &Settings.CollisionQueryHitPrimitiveActorsNameSize); + + FCogWindowWidgets::SetNextItemToShortWidth(); + ImGui::DragFloat("Hit Point Size", &Settings.CollisionQueryHitPointSize); + + FCogImguiHelper::ColorEdit4("Hit Color", Settings.CollisionQueryHitColor, ColorEditFlags); + FCogImguiHelper::ColorEdit4("No Hit Color", Settings.CollisionQueryNoHitColor, ColorEditFlags); + FCogImguiHelper::ColorEdit4("Normal Color", Settings.CollisionQueryNormalColor, ColorEditFlags); + FCogImguiHelper::ColorEdit4("Impact Normal Color", Settings.CollisionQueryImpactNormalColor, ColorEditFlags); } } diff --git a/Plugins/Cog/Source/CogEngine/Public/CogEngineCollisionTester.h b/Plugins/Cog/Source/CogEngine/Public/CogEngineCollisionTester.h index 0610053..49bd5b8 100644 --- a/Plugins/Cog/Source/CogEngine/Public/CogEngineCollisionTester.h +++ b/Plugins/Cog/Source/CogEngine/Public/CogEngineCollisionTester.h @@ -4,11 +4,6 @@ #include "Engine/HitResult.h" #include "CogEngineCollisionTester.generated.h" -class UCogEngineEditAnywhere_CollisionViewer; -class UCogEngineDataAsset; -class UPrimitiveComponent; -struct FCollisionShape; - //-------------------------------------------------------------------------------------------------------------------------- UENUM() enum class ECogEngine_CollisionQueryType : uint8 @@ -52,15 +47,14 @@ class COGENGINE_API ACogEngineCollisionTester : public AActor GENERATED_BODY() public: + ACogEngineCollisionTester(const FObjectInitializer& ObjectInitializer); virtual void Tick(float DeltaSeconds) override; + virtual bool ShouldTickIfViewportsOnly() const override; - void Query(); - void DrawPrimitive(const UPrimitiveComponent* PrimitiveComponent); - void DrawShape(const FCollisionShape& Shape, const FVector& InLocation, const FQuat& InRotation, const FVector& InScale, - const FColor& InColor, bool InDrawSolid) const; + void Query() const; UPROPERTY(EditAnywhere) bool TickInEditor = false; @@ -90,7 +84,7 @@ public: int32 ProfileIndex = 0; UPROPERTY(EditAnywhere) - FVector ShapeExtent = FVector::One(); + FVector ShapeExtent = FVector(100, 100, 100); UPROPERTY(EditAnywhere) bool DrawHitLocations = true; @@ -128,10 +122,6 @@ public: UPROPERTY(EditAnywhere) FColor ImpactNormalColor = FColor::Cyan; - TSet AlreadyDrawnActors; - - TSet AlreadyDrawnComponents; - UPROPERTY(EditAnywhere) USceneComponent* StartComponent = nullptr; diff --git a/Plugins/Cog/Source/CogEngine/Public/CogEngineDataAsset.h b/Plugins/Cog/Source/CogEngine/Public/CogEngineDataAsset.h index 5fc6933..8462ebd 100644 --- a/Plugins/Cog/Source/CogEngine/Public/CogEngineDataAsset.h +++ b/Plugins/Cog/Source/CogEngine/Public/CogEngineDataAsset.h @@ -5,19 +5,6 @@ #include "Engine/EngineTypes.h" #include "CogEngineDataAsset.generated.h" -//-------------------------------------------------------------------------------------------------------------------------- -USTRUCT() -struct COGENGINE_API FCogCollisionChannel -{ - GENERATED_BODY() - - UPROPERTY(EditAnywhere) - TEnumAsByte Channel = ECC_WorldStatic; - - UPROPERTY(EditAnywhere) - FLinearColor Color = FLinearColor(0.5f, 0.5f, 0.5f, 1.0f); -}; - //-------------------------------------------------------------------------------------------------------------------------- USTRUCT() struct COGENGINE_API FCogEngineSpawnEntry @@ -59,7 +46,4 @@ public: UPROPERTY(Category = "Spawns", EditAnywhere, meta = (TitleProperty = "Name")) TArray SpawnGroups; - - UPROPERTY(Category = "Collisions", EditAnywhere, meta = (TitleProperty = "Channel")) - TArray Channels; }; diff --git a/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_CollisionTester.h b/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_CollisionTester.h index a4636cc..7eb8d03 100644 --- a/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_CollisionTester.h +++ b/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_CollisionTester.h @@ -9,7 +9,6 @@ #include "CogEngineWindow_CollisionTester.generated.h" class UCogEngineConfig_CollisionViewer; -class UCogEngineDataAsset; class UPrimitiveComponent; struct FCollisionShape; @@ -32,8 +31,6 @@ protected: virtual void RenderContent() override; - virtual void SetAsset(const UCogEngineDataAsset* Value); - struct FChannel { bool IsValid = false; @@ -42,8 +39,6 @@ protected: FChannel Channels[ECC_MAX]; - TObjectPtr Asset = nullptr; - TObjectPtr Config = nullptr; FCogDebug_Gizmo EndGizmo; @@ -96,42 +91,6 @@ public: UPROPERTY(Config) FVector ShapeExtent; - UPROPERTY(Config) - bool DrawHitLocations; - - UPROPERTY(Config) - bool DrawHitImpactPoints; - - UPROPERTY(Config) - bool DrawHitShapes; - - UPROPERTY(Config) - bool DrawHitNormals; - - UPROPERTY(Config) - bool DrawHitImpactNormals; - - UPROPERTY(Config) - bool DrawHitPrimitives; - - UPROPERTY(Config) - bool DrawHitActorsNames; - - UPROPERTY(Config) - float HitPointSize; - - UPROPERTY(Config) - FVector4f NoHitColor; - - UPROPERTY(Config) - FVector4f HitColor; - - UPROPERTY(Config) - FVector4f NormalColor; - - UPROPERTY(Config) - FVector4f ImpactNormalColor; - UCogEngineConfig_CollisionTester() { Reset(); @@ -151,17 +110,5 @@ public: ObjectTypesToQuery = 0; ProfileIndex = 0; - DrawHitLocations = true; - DrawHitImpactPoints = true; - DrawHitShapes = true; - DrawHitNormals = true; - DrawHitImpactNormals = true; - DrawHitPrimitives = true; - DrawHitActorsNames = false; - HitPointSize = 10.0f; - NoHitColor = FVector4f(1.0f, 0.0f, 0.0f, 1.0f); - HitColor = FVector4f(0.0f, 1.0f, 0.0f, 1.0f); - NormalColor = FVector4f(0.0f, 1.0f, 0.0f, 1.0f); - ImpactNormalColor = FVector4f(0.0f, 1.0f, 0.0f, 1.0f); } }; \ No newline at end of file diff --git a/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_CollisionViewer.h b/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_CollisionViewer.h index 721534e..3f28d30 100644 --- a/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_CollisionViewer.h +++ b/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_CollisionViewer.h @@ -26,18 +26,12 @@ protected: virtual void RenderContent() override; - virtual void SetAsset(const UCogEngineDataAsset* Value); - struct FChannel { bool IsValid = false; FColor Color; }; - FChannel Channels[ECC_MAX]; - - TObjectPtr Asset = nullptr; - TObjectPtr Config = nullptr; }; @@ -70,9 +64,6 @@ public: UPROPERTY(Config) bool ShowActorsNames = false; - UPROPERTY(Config) - bool ShowQuery = false; - virtual void Reset() override { Super::Reset(); @@ -84,6 +75,5 @@ public: QueryThickness = 0.0f; UseComplexCollisions = false; ShowActorsNames = false; - ShowQuery = false; } }; \ No newline at end of file diff --git a/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_DebugSettings.h b/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_DebugSettings.h index 7659803..47c705f 100644 --- a/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_DebugSettings.h +++ b/Plugins/Cog/Source/CogEngine/Public/CogEngineWindow_DebugSettings.h @@ -41,13 +41,9 @@ public: UPROPERTY(Config) FCogDebugSettings Data; - UPROPERTY(Config) - bool bShowAdvancedSettings = false; - virtual void Reset() override { Super::Reset(); Data = FCogDebugSettings(); - bShowAdvancedSettings = false; } }; \ No newline at end of file diff --git a/Plugins/Cog/Source/CogWindow/Private/CogWindowWidgets.cpp b/Plugins/Cog/Source/CogWindow/Private/CogWindowWidgets.cpp index 79897e9..387c5a6 100644 --- a/Plugins/Cog/Source/CogWindow/Private/CogWindowWidgets.cpp +++ b/Plugins/Cog/Source/CogWindow/Private/CogWindowWidgets.cpp @@ -1,5 +1,6 @@ #include "CogWindowWidgets.h" +#include "CogDebug.h" #include "CogImguiHelper.h" #include "CogImguiKeyInfo.h" #include "CogImguiInputHelper.h" @@ -616,6 +617,9 @@ bool FCogWindowWidgets::MultiChoiceButtonsFloat(TArray& Values, float& Va //-------------------------------------------------------------------------------------------------------------------------- bool FCogWindowWidgets::ComboCollisionChannel(const char* Label, ECollisionChannel& Channel) { + FColor ChannelColors[ECC_MAX]; + FCogDebug::GetDebugChannelColors(ChannelColors); + FName SelectedChannelName; const UCollisionProfile* CollisionProfile = UCollisionProfile::Get(); if (CollisionProfile != nullptr) @@ -626,12 +630,21 @@ bool FCogWindowWidgets::ComboCollisionChannel(const char* Label, ECollisionChann bool Result = false; if (ImGui::BeginCombo(Label, TCHAR_TO_ANSI(*SelectedChannelName.ToString()), ImGuiComboFlags_HeightLarge)) { - for (int32 ChannelIndex = 0; ChannelIndex < (int32)ECC_MAX; ++ChannelIndex) + for (int32 ChannelIndex = 0; ChannelIndex < (int32)ECC_OverlapAll_Deprecated; ++ChannelIndex) { + FColor Color = ChannelColors[ChannelIndex]; + if (Color == FColor::Transparent) + { + continue; + } + ImGui::PushID(ChannelIndex); const FName ChannelName = CollisionProfile->ReturnChannelNameFromContainerIndex(ChannelIndex); + FCogImguiHelper::ColorEdit4("Color", Color, ImGuiColorEditFlags_NoPicker | ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel); + ImGui::SameLine(); + if (ChannelName.IsValid()) { if (ImGui::Selectable(TCHAR_TO_ANSI(*ChannelName.ToString()))) @@ -650,10 +663,13 @@ bool FCogWindowWidgets::ComboCollisionChannel(const char* Label, ECollisionChann } //-------------------------------------------------------------------------------------------------------------------------- -bool FCogWindowWidgets::CollisionProfileChannel(const UCollisionProfile& CollisionProfile, const int32 ChannelIndex, int32& Channels) +bool FCogWindowWidgets::CollisionProfileChannel(const UCollisionProfile& CollisionProfile, const int32 ChannelIndex, FColor& ChannelColor, int32& Channels) { bool Result = false; + FCogImguiHelper::ColorEdit4("Color", ChannelColor, ImGuiColorEditFlags_NoPicker | ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel); + ImGui::SameLine(); + bool IsCollisionActive = (Channels & ECC_TO_BITFIELD(ChannelIndex)) > 0; const FName ChannelName = CollisionProfile.ReturnChannelNameFromContainerIndex(ChannelIndex); if (ImGui::Checkbox(TCHAR_TO_ANSI(*ChannelName.ToString()), &IsCollisionActive)) @@ -674,14 +690,29 @@ bool FCogWindowWidgets::CollisionProfileChannel(const UCollisionProfile& Collisi } //-------------------------------------------------------------------------------------------------------------------------- -bool FCogWindowWidgets::CollisionProfileChannels(const UCollisionProfile& CollisionProfile, int32& Channels) +bool FCogWindowWidgets::CollisionProfileChannels(int32& Channels) { + 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 < (int32)ECC_MAX; ++ChannelIndex) + for (int32 ChannelIndex = 0; ChannelIndex < (int32)ECC_OverlapAll_Deprecated; ++ChannelIndex) { + FColor Color = ChannelColors[ChannelIndex]; + if (Color == FColor::Transparent) + { + continue; + } + ImGui::PushID(ChannelIndex); - Result |= CollisionProfileChannel(CollisionProfile, ChannelIndex, Channels); + Result |= CollisionProfileChannel(*CollisionProfile, ChannelIndex, Color, Channels); ImGui::PopID(); } diff --git a/Plugins/Cog/Source/CogWindow/Public/CogWindowWidgets.h b/Plugins/Cog/Source/CogWindow/Public/CogWindowWidgets.h index f15622a..29a333c 100644 --- a/Plugins/Cog/Source/CogWindow/Public/CogWindowWidgets.h +++ b/Plugins/Cog/Source/CogWindow/Public/CogWindowWidgets.h @@ -82,9 +82,9 @@ public: static bool ComboCollisionChannel(const char* Label, ECollisionChannel& Channel); - static bool CollisionProfileChannel(const UCollisionProfile& CollisionProfile, int32 ChannelIndex, int32& Channels); + static bool CollisionProfileChannel(const UCollisionProfile& CollisionProfile, int32 ChannelIndex, FColor& ChannelColor, int32& Channels); - static bool CollisionProfileChannels(const UCollisionProfile& CollisionProfile, int32& Channels); + static bool CollisionProfileChannels(int32& Channels); }; From 0f130f7dff878ee89dafa16ae4ef5b073aff5c3d Mon Sep 17 00:00:00 2001 From: Arnaud Jamin Date: Wed, 3 Jan 2024 19:20:12 -0500 Subject: [PATCH 8/8] Fix bad refactor --- .../Cog/Source/CogEngine/CogEngine.Build.cs | 82 +++++++++---------- .../Private/CogEngineWindow_Plots.cpp | 2 +- Source/CogSample/CogSampleCharacter.cpp | 2 +- Source/CogSample/CogSampleGameplayAbility.cpp | 4 +- 4 files changed, 45 insertions(+), 45 deletions(-) diff --git a/Plugins/Cog/Source/CogEngine/CogEngine.Build.cs b/Plugins/Cog/Source/CogEngine/CogEngine.Build.cs index 38b9ffa..9fc456b 100644 --- a/Plugins/Cog/Source/CogEngine/CogEngine.Build.cs +++ b/Plugins/Cog/Source/CogEngine/CogEngine.Build.cs @@ -2,53 +2,53 @@ using UnrealBuildTool; public class CogEngine : ModuleRules { - public CogEngine(ReadOnlyTargetRules Target) : base(Target) - { - PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs; - - PublicIncludePaths.AddRange( - new string[] - { - } - ); - - - PrivateIncludePaths.AddRange( - new string[] - { - } - ); - - - PublicDependencyModuleNames.AddRange( - new string[] - { + public CogEngine(ReadOnlyTargetRules Target) : base(Target) + { + PCHUsage = ModuleRules.PCHUsageMode.UseExplicitOrSharedPCHs; + + PublicIncludePaths.AddRange( + new string[] + { + } + ); + + + PrivateIncludePaths.AddRange( + new string[] + { + } + ); + + + PublicDependencyModuleNames.AddRange( + new string[] + { "CogDebug", } - ); - - - PrivateDependencyModuleNames.AddRange( - new string[] - { - "CogCommon", + ); + + + PrivateDependencyModuleNames.AddRange( + new string[] + { + "CogCommon", "CogImgui", "CogWindow", - "Core", + "Core", "CoreUObject", - "Engine", + "Engine", "InputCore", "NetCore", - "Slate", - "SlateCore", + "Slate", + "SlateCore", } - ); - - - DynamicallyLoadedModuleNames.AddRange( - new string[] - { - } - ); - } + ); + + + DynamicallyLoadedModuleNames.AddRange( + new string[] + { + } + ); + } } diff --git a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Plots.cpp b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Plots.cpp index f0749b1..2db6f41 100644 --- a/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Plots.cpp +++ b/Plugins/Cog/Source/CogEngine/Private/CogEngineWindow_Plots.cpp @@ -82,7 +82,7 @@ void FCogEngineWindow_Plots::RenderMenu() { if (ImGui::BeginMenu("Options")) { - if (ImGui::MenuItem("Clear Settings")) + if (ImGui::MenuItem("Clear Data")) { FCogDebugPlot::Clear(); } diff --git a/Source/CogSample/CogSampleCharacter.cpp b/Source/CogSample/CogSampleCharacter.cpp index db0627f..1f1fe62 100644 --- a/Source/CogSample/CogSampleCharacter.cpp +++ b/Source/CogSample/CogSampleCharacter.cpp @@ -677,7 +677,7 @@ void ACogSampleCharacter::OnGhostTagNewOrRemoved(const FGameplayTag InTag, int32 void ACogSampleCharacter::OnScaleAttributeChanged(const FOnAttributeChangeData& Data) { //---------------------------------------------------------------------------------- - // 'Settings.NewValue' is not used because it seems to only corresponds to the changes + // 'Data.NewValue' is not used because it seems to only corresponds to the changes // of the BaseValue which do not account for the temporary modifiers. //---------------------------------------------------------------------------------- diff --git a/Source/CogSample/CogSampleGameplayAbility.cpp b/Source/CogSample/CogSampleGameplayAbility.cpp index c238d36..d1c43f8 100644 --- a/Source/CogSample/CogSampleGameplayAbility.cpp +++ b/Source/CogSample/CogSampleGameplayAbility.cpp @@ -197,8 +197,8 @@ bool UCogSampleGameplayAbility::IsCostGameplayEffectIsZero(const UGameplayEffect const float CostValue = ModSpec.GetEvaluatedMagnitude(); //---------------------------------------------------------------------------------------------- - // The Cost in the Settings is positive, but UCogSampleModifierCalculation_Cost negates it. - // Therefore a cost less than zero is an actual cost, and a cost of 0 or greater can be ignored + // The Cost in the Data is positive, but UCogSampleModifierCalculation_Cost negates it. + // Therefore, a cost less than zero is an actual cost, and a cost of 0 or greater can be ignored //---------------------------------------------------------------------------------------------- if (CostValue < 0) {