64 lines
1.7 KiB
C++
64 lines
1.7 KiB
C++
// Copyright 2020 Mookie. All Rights Reserved.
|
|
|
|
#include "EBBullet.h"
|
|
#include "EBBarrel.h"
|
|
#include "Engine/World.h"
|
|
#include "Engine/Engine.h"
|
|
#include "PhysicalMaterials/PhysicalMaterial.h"
|
|
#include "DrawDebugHelpers.h"
|
|
|
|
void AEBBullet::CreateDebugImpactWidget(FVector Location, bool bRicochet, bool bPenetration, FVector ImpactVelocity, float PenetrationDepth, UPhysicalMaterial* Material)
|
|
{
|
|
UEBBarrel* Barrel = GetFiringBarrel();
|
|
if (!Barrel || !Barrel->DebugImpactInfo)
|
|
{
|
|
return;
|
|
}
|
|
|
|
UWorld* World = GetWorld();
|
|
if (!World)
|
|
{
|
|
return;
|
|
}
|
|
|
|
FString ImpactType;
|
|
if (bRicochet)
|
|
{
|
|
ImpactType = TEXT("RICOCHET");
|
|
}
|
|
else if (bPenetration)
|
|
{
|
|
ImpactType = TEXT("PENETRATION");
|
|
}
|
|
else
|
|
{
|
|
ImpactType = TEXT("STOPPED");
|
|
}
|
|
|
|
FString MaterialName = Material ? Material->GetName() : TEXT("Unknown");
|
|
|
|
float VelocityMPS = ImpactVelocity.Size();
|
|
float VelocityKMH = VelocityMPS * 0.036f; // Convert cm/s to km/h
|
|
|
|
FString DebugInfo = FString::Printf(TEXT(
|
|
"Impact: %s | Material: %s | Velocity: %.1f m/s (%.1f km/h) | Mass: %.3f kg | Diameter: %.2f cm | Energy: %.1f J | Penetration: %.2f cm"
|
|
),
|
|
*ImpactType,
|
|
*MaterialName,
|
|
VelocityMPS / 100.0f, // Convert cm/s to m/s for display
|
|
VelocityKMH,
|
|
GetEffectiveMass(),
|
|
GetEffectiveDiameter(),
|
|
0.5f * GetEffectiveMass() * FMath::Pow(VelocityMPS / 100.0f, 2.0f), // Kinetic energy in Joules
|
|
PenetrationDepth
|
|
);
|
|
|
|
// Use simple on-screen debug message instead of UMG widget
|
|
if (GEngine)
|
|
{
|
|
GEngine->AddOnScreenDebugMessage(-1, 10.0f, FColor::Yellow, DebugInfo);
|
|
}
|
|
|
|
// Also draw debug text in world space
|
|
DrawDebugString(World, Location + FVector(0, 0, 50), DebugInfo, nullptr, FColor::Yellow, 10.0f, false, 1.2f);
|
|
} |