mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 07:03:25 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c3202a3bc3 | ||
|
|
39ab9d065d | ||
|
|
ed372a1c78 |
@@ -8,6 +8,7 @@ include(CMakePackageConfigHelpers)
|
||||
option(OMATH_BUILD_TESTS "Build unit tests" ON)
|
||||
option(OMATH_THREAT_WARNING_AS_ERROR "Set highest level of warnings and force compiler to treat them as errors" ON)
|
||||
option(OMATH_BUILD_AS_SHARED_LIBRARY "Build Omath as .so or .dll" OFF)
|
||||
option(OMATH_USE_AVX2 "Omath will use AVX2 to boost performance" ON)
|
||||
|
||||
|
||||
if (OMATH_BUILD_AS_SHARED_LIBRARY)
|
||||
@@ -24,9 +25,15 @@ set_target_properties(omath PROPERTIES
|
||||
CXX_STANDARD 23
|
||||
CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
|
||||
target_compile_options(omath PRIVATE -mavx2 -mfma)
|
||||
endif()
|
||||
|
||||
target_compile_features(omath PUBLIC cxx_std_23)
|
||||
|
||||
if (OMATH_USE_AVX2)
|
||||
target_compile_definitions(omath PUBLIC OMATH_USE_AVX2)
|
||||
endif()
|
||||
|
||||
add_subdirectory(source)
|
||||
|
||||
|
||||
@@ -2,13 +2,15 @@
|
||||
// Created by Vlad on 2/23/2025.
|
||||
//
|
||||
#include "omath/projectile_prediction/ProjPredEngineAVX2.hpp"
|
||||
|
||||
#include "source_location"
|
||||
|
||||
namespace omath::projectile_prediction
|
||||
{
|
||||
std::optional<Vector3<float>> ProjPredEngineAVX2::MaybeCalculateAimPoint(const Projectile& projectile,
|
||||
const Target& target) const
|
||||
std::optional<Vector3<float>>
|
||||
ProjPredEngineAVX2::MaybeCalculateAimPoint([[maybe_unused]] const Projectile& projectile,
|
||||
[[maybe_unused]] const Target& target) const
|
||||
{
|
||||
#ifdef OMATH_USE_AVX2
|
||||
const float bulletGravity = m_gravityConstant * projectile.m_gravityScale;
|
||||
const float v0 = projectile.m_launchSpeed;
|
||||
const float v0Sqr = v0 * v0;
|
||||
@@ -31,8 +33,8 @@ namespace omath::projectile_prediction
|
||||
_mm256_fmadd_ps(_mm256_set1_ps(target.m_velocity.y), times, _mm256_set1_ps(target.m_origin.y));
|
||||
const __m256 timesSq = _mm256_mul_ps(times, times);
|
||||
const __m256 targetZ = _mm256_fmadd_ps(_mm256_set1_ps(target.m_velocity.z), times,
|
||||
_mm256_fnmadd_ps(_mm256_set1_ps(0.5f * m_gravityConstant), timesSq,
|
||||
_mm256_set1_ps(target.m_origin.z)));
|
||||
_mm256_fnmadd_ps(_mm256_set1_ps(0.5f * m_gravityConstant), timesSq,
|
||||
_mm256_set1_ps(target.m_origin.z)));
|
||||
|
||||
const __m256 deltaX = _mm256_sub_ps(targetX, _mm256_set1_ps(projOrigin.x));
|
||||
const __m256 deltaY = _mm256_sub_ps(targetY, _mm256_set1_ps(projOrigin.y));
|
||||
@@ -110,8 +112,9 @@ namespace omath::projectile_prediction
|
||||
m_maximumSimulationTime(simulationTimeStep)
|
||||
{
|
||||
}
|
||||
std::optional<float> ProjPredEngineAVX2::CalculatePitch(const Vector3<float>& projOrigin, const Vector3<float>& targetPos,
|
||||
const float bulletGravity, const float v0, const float time)
|
||||
std::optional<float> ProjPredEngineAVX2::CalculatePitch(const Vector3<float>& projOrigin,
|
||||
const Vector3<float>& targetPos, const float bulletGravity,
|
||||
const float v0, const float time)
|
||||
{
|
||||
if (time <= 0.0f)
|
||||
return std::nullopt;
|
||||
@@ -134,5 +137,9 @@ namespace omath::projectile_prediction
|
||||
const float d = std::sqrt(dSqr);
|
||||
const float tanTheta = term / d;
|
||||
return angles::RadiansToDegrees(std::atan(tanTheta));
|
||||
#else
|
||||
throw std::runtime_error(
|
||||
std::format("{} AVX2 feature is not enabled!", std::source_location::current().function_name()));
|
||||
#endif
|
||||
}
|
||||
} // namespace omath::projectile_prediction
|
||||
|
||||
Reference in New Issue
Block a user