Skip to content

Commit

Permalink
Changes related to handling larger scales and better understanding of…
Browse files Browse the repository at this point in the history
… numerical limitations.
  • Loading branch information
louis-langholtz committed Nov 27, 2017
1 parent 5d8b043 commit 46df3fd
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 21 deletions.
21 changes: 7 additions & 14 deletions PlayRho/Common/Fixed.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -761,6 +761,13 @@ namespace playrho
{
return Abs(x - y) <= Fixed<BT, FB>{0, static_cast<std::uint32_t>(ulp)};
}

/// @brief Gets an invalid value.
template <typename BT, unsigned int FB>
constexpr Fixed<BT, FB> GetInvalid() noexcept
{
return Fixed<BT, FB>::GetNaN();
}

/// @brief Output stream operator.
template <typename BT, unsigned int FB>
Expand Down Expand Up @@ -853,13 +860,6 @@ namespace playrho
const auto result = lhs.Compare(rhs);
return result == Fixed32::CmpResult::GreaterThan;
}

/// @brief Gets an invalid value.
template <>
constexpr Fixed32 GetInvalid() noexcept
{
return Fixed32::GetNaN();
}

/// @brief Gets the specialized name for the Fixed32 type.
/// @details Provides an interface to a specialized function for getting C-style
Expand Down Expand Up @@ -951,13 +951,6 @@ namespace playrho
template<> struct Wider<Fixed32> {
using type = Fixed64; ///< Wider type.
};

/// @brief Gets an invalid value.
template <>
constexpr Fixed64 GetInvalid() noexcept
{
return Fixed64::GetNaN();
}

/// @brief Gets the specialized name for the Fixed64 type.
/// @details Provides an interface to a specialized function for getting C-style
Expand Down
3 changes: 2 additions & 1 deletion PlayRho/Common/Math.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,8 @@ AlmostEqual(T x, T y, int ulp = 2)
/// @note Modulo via std::fmod appears slower than via std::trunc.
/// @sa ModuloViaTrunc
template <typename T>
inline auto ModuloViaFmod(T dividend, T divisor) noexcept
inline typename std::enable_if<std::is_floating_point<T>::value, T>::type
ModuloViaFmod(T dividend, T divisor) noexcept
{
// Note: modulo via std::fmod appears slower than via std::trunc.
return static_cast<T>(std::fmod(dividend, divisor));
Expand Down
6 changes: 2 additions & 4 deletions PlayRho/Dynamics/StepConf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,9 @@ class StepConf

/// @brief Target depth.
/// @details Target depth of overlap for calculating the TOI for CCD elligible bodies.
/// @note Must be greater than 0.
/// @note Must not be subnormal.
/// @note Must be less than twice the world's minimum vertex radius.
/// @note Recommend value that's less than twice the world's minimum vertex radius.
/// @note Used in the TOI phase of step processing.
Positive<Length> targetDepth = DefaultLinearSlop * Real{3};
Length targetDepth = DefaultLinearSlop * Real{3};

/// @brief Tolerance.
/// @details The acceptable plus or minus tolerance from the target depth for TOI calculations.
Expand Down
3 changes: 3 additions & 0 deletions PlayRho/Dynamics/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1387,6 +1387,9 @@ World::UpdateContactsData World::UpdateContactTOIs(const StepConf& conf)
// Compute the TOI for this contact (one or both bodies are active and impenetrable).
// Computes the time of impact in interval [0, 1]
const auto output = CalcToi(c, toiConf);
assert((output.state == TOIOutput::State::e_touching)
|| (output.state == TOIOutput::State::e_separated)
|| (output.state == TOIOutput::State::e_overlapped));

// Use Min function to handle floating point imprecision which possibly otherwise
// could provide a TOI that's greater than 1.
Expand Down
10 changes: 8 additions & 2 deletions Testbed/Tests/SolarSystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ class SolarSystem: public Test
os << " km (" << minName << "), to ";
os << static_cast<float>(Real{maxRadius / 1_km});
os << " km (" << maxName << ").";
if (std::is_same<Real, float>::value)
{
os << "\n\n";
os << "Note: recompile with playrho::Real set to use double (or bigger)";
os << " for collisions to work better at these scales.";
}

auto conf = Test::Conf{};
conf.description = os.str();
Expand All @@ -93,7 +99,7 @@ class SolarSystem: public Test
conf.neededSettings |= (1u << NeedDrawLabelsField);
conf.neededSettings |= (1u << NeedMaxTranslation);
conf.neededSettings |= (1u << NeedDeltaTime);
conf.settings.linearSlop = 1000.0f; // minRadius / 1000_m;
conf.settings.linearSlop = 200 * 1000.0f; // 200_km;
conf.settings.cameraZoom = 2.2e11f;
conf.settings.drawLabels = true;
conf.settings.maxTranslation = std::numeric_limits<float>::infinity();
Expand All @@ -106,7 +112,7 @@ class SolarSystem: public Test
SolarSystem(): Test(GetTestConf())
{
m_world.SetGravity(LinearAcceleration2{});
const auto DynamicBD = BodyDef{}.UseType(BodyType::Dynamic);
const auto DynamicBD = BodyDef{}.UseType(BodyType::Dynamic).UseBullet(true);
for (auto& sso: SolarSystemBodies)
{
const auto p = sso.orbitalPeriod;
Expand Down

0 comments on commit 46df3fd

Please sign in to comment.