Skip to content

Commit

Permalink
Reverted 447 (erincatto#655)
Browse files Browse the repository at this point in the history
The old interpolation method was better.
Modified unit tests to ensure this doesn't change.
https://fgiesen.wordpress.com/2012/08/15/linear-interpolation-past-present-and-future/
  • Loading branch information
erincatto authored Oct 12, 2020
1 parent e772b71 commit ee4e1c7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
5 changes: 3 additions & 2 deletions include/box2d/b2_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -681,10 +681,11 @@ inline bool b2IsPowerOfTwo(uint32 x)
return result;
}

// https://fgiesen.wordpress.com/2012/08/15/linear-interpolation-past-present-and-future/
inline void b2Sweep::GetTransform(b2Transform* xf, float beta) const
{
xf->p = c0 + beta * (c - c0);
float angle = a0 + beta * (a - a0);
xf->p = (1.0f - beta) * c0 + beta * c;
float angle = (1.0f - beta) * a0 + beta * a;
xf->q.Set(angle);

// Shift to origin
Expand Down
18 changes: 13 additions & 5 deletions unit-test/math_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,24 @@ DOCTEST_TEST_CASE("math test")
// From issue #447
b2Sweep sweep;
sweep.localCenter.SetZero();
sweep.c0.Set(3.0f, 4.0f);
sweep.c.Set(3.0f, 4.0f);
sweep.a0 = 0.0f;
sweep.a = 0.0f;
sweep.c0.Set(-2.0f, 4.0f);
sweep.c.Set(3.0f, 8.0f);
sweep.a0 = 0.5f;
sweep.a = 5.0f;
sweep.alpha0 = 0.0f;

b2Transform transform;
sweep.GetTransform(&transform, 0.6f);

sweep.GetTransform(&transform, 0.0f);
DOCTEST_REQUIRE_EQ(transform.p.x, sweep.c0.x);
DOCTEST_REQUIRE_EQ(transform.p.y, sweep.c0.y);
DOCTEST_REQUIRE_EQ(transform.q.c, cosf(sweep.a0));
DOCTEST_REQUIRE_EQ(transform.q.s, sinf(sweep.a0));

sweep.GetTransform(&transform, 1.0f);
DOCTEST_REQUIRE_EQ(transform.p.x, sweep.c.x);
DOCTEST_REQUIRE_EQ(transform.p.y, sweep.c.y);
DOCTEST_REQUIRE_EQ(transform.q.c, cosf(sweep.a));
DOCTEST_REQUIRE_EQ(transform.q.s, sinf(sweep.a));
}
}

0 comments on commit ee4e1c7

Please sign in to comment.