Skip to content

Commit

Permalink
Changes to address #560
Browse files Browse the repository at this point in the history
  • Loading branch information
louis-langholtz committed Jan 21, 2024
1 parent 6df26ed commit 41a4981
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 20 deletions.
10 changes: 3 additions & 7 deletions Library/include/playrho/d2/Body.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,14 +451,10 @@ class Body
static FlagsType GetFlags(const BodyConf& bd) noexcept;

/// Transformation for body origin.
/// @note Also availble from <code>GetTransform1(m_sweep)</code>.
/// @note <code>m_xf.p == m_sweep.pos1.linear && m_xf.q ==
/// UnitVec::Get(m_sweep.pos1.angular)</code>.
/// @note This is a cache of the result of <code>GetTransform1(m_sweep)</code>.
Transformation m_xf;

/// @brief Sweep motion for CCD.
/// @note <code>m_sweep.pos1.linear == m_xf.p && UnitVec::Get(m_sweep.pos1.angular) ==
/// m_xf.q</code>.
Sweep m_sweep;

FlagsType m_flags = 0u; ///< Flags.
Expand Down Expand Up @@ -671,7 +667,7 @@ inline void Body::SetSweep(const Sweep& value) noexcept
{
assert(((m_flags & Body::e_velocityFlag) != 0) || value.pos0 == value.pos1);
m_sweep = value;
m_xf = GetTransform1(value);
m_xf = GetTransform1(m_sweep);
}

inline void Body::SetPosition0(const Position& value) noexcept
Expand All @@ -684,7 +680,7 @@ inline void Body::SetPosition1(const Position& value) noexcept
{
assert(((m_flags & Body::e_velocityFlag) != 0) || m_sweep.pos1 == value);
m_sweep.pos1 = value;
m_xf = ::playrho::d2::GetTransformation(value, m_sweep.localCenter);
m_xf = GetTransform1(m_sweep);
}

inline void Body::ResetAlpha0() noexcept
Expand Down
8 changes: 5 additions & 3 deletions Library/include/playrho/d2/Transformation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
// IWYU pragma: begin_exports

#include <playrho/Vector2.hpp>

#include <playrho/d2/UnitVec.hpp>

// IWYU pragma: end_exports

namespace playrho {
namespace d2 {
namespace playrho::d2 {

struct BodyConf;

Expand Down Expand Up @@ -79,7 +79,9 @@ constexpr UnitVec GetDirection(const Transformation& value) noexcept
return value.q;
}

} // namespace d2
} // namespace playrho::d2

namespace playrho {

/// @brief Determines if the given value is valid.
/// @relatedalso d2::Transformation
Expand Down
2 changes: 1 addition & 1 deletion Library/source/playrho/d2/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ Body::FlagsType Body::GetFlags(const BodyConf& bd) noexcept
}

Body::Body(const BodyConf& bd)
: m_xf{::playrho::d2::GetTransformation(bd)},
: m_xf{GetTransform1(bd.sweep)},
m_sweep{bd.sweep},
m_flags{GetFlags(bd)},
m_invMass{(bd.type == playrho::BodyType::Dynamic)
Expand Down
3 changes: 2 additions & 1 deletion Library/source/playrho/d2/BodyConf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ BodyConf GetBodyConf(const Body& body)

Transformation GetTransformation(const BodyConf& conf) noexcept
{
return {conf.sweep.pos0.linear, UnitVec::Get(conf.sweep.pos0.angular)};
// This must match what GetTransformation(Body{}) returns
return GetTransform1(conf.sweep);
}

} // namespace playrho::d2
16 changes: 8 additions & 8 deletions UnitTests/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,14 +139,14 @@ TEST(Body, InvMassOnConstruction)

TEST(Body, TransformationOnConstruction)
{
EXPECT_EQ(
Body(BodyConf{}.UseLocation(Length2{10_m, 12_m}).UseAngle(90_deg)).GetTransformation(),
::playrho::d2::GetTransformation(
BodyConf{}.UseLocation(Length2{10_m, 12_m}).UseAngle(90_deg)));
EXPECT_EQ(
Body(BodyConf{}.UseLocation(Length2{4_m, -3_m}).UseAngle(-32_deg)).GetTransformation(),
::playrho::d2::GetTransformation(
BodyConf{}.UseLocation(Length2{4_m, -3_m}).UseAngle(-32_deg)));
{
const auto conf = BodyConf{}.UseLocation(Length2{10_m, 12_m}).UseAngle(90_deg);
EXPECT_EQ(Body(conf).GetTransformation(), GetTransform1(conf.sweep));
}
{
const auto conf = BodyConf{}.UseLocation(Length2{4_m, -3_m}).UseAngle(-32_deg);
EXPECT_EQ(Body(conf).GetTransformation(), GetTransform1(conf.sweep));
}
}

TEST(Body, VelocityOnConstruction)
Expand Down

0 comments on commit 41a4981

Please sign in to comment.