Files
BallisticsDocs/Source/EasyBallistics/Public/EBUnitConversions.h
T
2025-07-04 01:09:56 -07:00

168 lines
5.9 KiB
C++

// Copyright 2016 Mookie. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
/**
* Centralized unit conversion utilities for EasyBallistics
* This class ensures consistent unit conversions throughout the plugin
*/
class EASYBALLISTICS_API FEBUnitConversions
{
public:
// === VELOCITY CONVERSIONS ===
/** Convert feet per second to meters per second */
static float FPSToMPS(float FPS) { return FPS * 0.3048f; }
/** Convert meters per second to feet per second */
static float MPSToFPS(float MPS) { return MPS / 0.3048f; }
/** Convert centimeters per second (Unreal units) to meters per second */
static float CMPSToMPS(float CMPS) { return CMPS / 100.0f; }
/** Convert meters per second to centimeters per second (Unreal units) */
static float MPSToCMPS(float MPS) { return MPS * 100.0f; }
/** Convert centimeters per second to kilometers per hour */
static float CMPSToKMH(float CMPS) { return (CMPS / 100.0f) * 3.6f; }
/** Convert feet per second to centimeters per second (Unreal units) */
static float FPSToCMPS(float FPS) { return FPS * 30.48f; }
/** Convert centimeters per second (Unreal units) to feet per second */
static float CMPSToFPS(float CMPS) { return CMPS / 30.48f; }
// === DISTANCE CONVERSIONS ===
/** Convert inches to centimeters */
static float InchesToCM(float Inches) { return Inches * 2.54f; }
/** Convert centimeters to inches */
static float CMToInches(float CM) { return CM / 2.54f; }
/** Convert meters to centimeters */
static float MetersToCM(float Meters) { return Meters * 100.0f; }
/** Convert centimeters to meters */
static float CMToMeters(float CM) { return CM / 100.0f; }
/** Alias for CMToMeters for compatibility */
static float CMToM(float CM) { return CMToMeters(CM); }
/** Convert feet to meters */
static float FeetToMeters(float Feet) { return Feet * 0.3048f; }
/** Convert meters to feet */
static float MetersToFeet(float Meters) { return Meters / 0.3048f; }
// === MASS CONVERSIONS ===
/** Convert grains to kilograms */
static float GrainsToKG(float Grains) { return Grains * 0.0647989f / 1000.0f; }
/** Convert kilograms to grains */
static float KGToGrains(float KG) { return KG * 1000.0f / 0.0647989f; }
/** Convert grains to grams */
static float GrainsToGrams(float Grains) { return Grains * 0.0647989f; }
/** Convert grams to grains */
static float GrainsToGrains(float Grams) { return Grams / 0.0647989f; }
// === DENSITY CONVERSIONS ===
/** Convert g/cm³ to kg/m³ */
static float GPerCM3ToKGPerM3(float GPerCM3) { return GPerCM3 * 1000.0f; }
/** Convert kg/m³ to g/cm³ */
static float KGPerM3ToGPerCM3(float KGPerM3) { return KGPerM3 / 1000.0f; }
// === PRESSURE CONVERSIONS ===
/** Convert MPa to Pa */
static float MPaToPa(float MPa) { return MPa * 1000000.0f; }
/** Convert Pa to MPa */
static float PaToMPa(float Pa) { return Pa / 1000000.0f; }
/** Convert PSI to MPa */
static float PSIToMPa(float PSI) { return PSI * 0.00689476f; }
/** Convert MPa to PSI */
static float MPaToPSI(float MPa) { return MPa / 0.00689476f; }
// === ENERGY CONVERSIONS ===
/** Convert foot-pounds to Joules */
static float FtLbsToJoules(float FtLbs) { return FtLbs * 1.35582f; }
/** Convert Joules to foot-pounds */
static float JoulesToFtLbs(float Joules) { return Joules / 1.35582f; }
// === ANGLE CONVERSIONS ===
/** Convert degrees to radians */
static float DegreesToRadians(float Degrees) { return Degrees * PI / 180.0f; }
/** Convert radians to degrees */
static float RadiansToDegrees(float Radians) { return Radians * 180.0f / PI; }
// === AREA CONVERSIONS ===
/** Convert square centimeters to square meters */
static float CM2ToM2(float CM2) { return CM2 * 0.0001f; }
/** Convert square meters to square centimeters */
static float M2ToCM2(float M2) { return M2 * 10000.0f; }
/** Convert square inches to square centimeters */
static float Inch2ToCM2(float Inch2) { return Inch2 * 6.4516f; }
/** Convert square centimeters to square inches */
static float CM2ToInch2(float CM2) { return CM2 / 6.4516f; }
// === HELPER FUNCTIONS ===
/** Calculate kinetic energy in Joules from mass (kg) and velocity (m/s) */
static float CalculateKineticEnergyJoules(float MassKG, float VelocityMPS)
{
return 0.5f * MassKG * VelocityMPS * VelocityMPS;
}
/** Calculate sectional density in kg/m² from mass (kg) and diameter (m) */
static float CalculateSectionalDensityKGPerM2(float MassKG, float DiameterM)
{
float RadiusM = DiameterM / 2.0f;
float CrossSectionM2 = PI * RadiusM * RadiusM;
return MassKG / CrossSectionM2;
}
/** Calculate cross-sectional area in m² from diameter in m */
static float CalculateCrossSectionM2(float DiameterM)
{
float RadiusM = DiameterM / 2.0f;
return PI * RadiusM * RadiusM;
}
// === VALIDATION FUNCTIONS ===
/** Validate that a velocity value is reasonable for ballistics (returns true if valid) */
static bool IsValidBallisticVelocity(float VelocityMPS)
{
return VelocityMPS >= 0.0f && VelocityMPS <= 2000.0f; // 0 to 2000 m/s is reasonable range
}
/** Validate that a mass value is reasonable for bullets (returns true if valid) */
static bool IsValidBulletMass(float MassKG)
{
return MassKG >= 0.001f && MassKG <= 0.1f; // 1g to 100g is reasonable range
}
/** Validate that a diameter value is reasonable for bullets (returns true if valid) */
static bool IsValidBulletDiameter(float DiameterCM)
{
return DiameterCM >= 0.1f && DiameterCM <= 5.0f; // 1mm to 50mm is reasonable range
}
};