-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix camera/rendering + apparent physical bias (#16)
* Introduce verlet.h (Verlet integration) To investigate velocity bias issue. Integrator does not seem to be cause of problem. Why: Both Yoshida and Verlet have same problem. * WIP: Add routine to test circle-rectangle collision I'm doing this because Raylib's built-in routine for collision detection seems to be erroneous. (Additionally, it's never performed well. In my 1,000 particle test runs, circle testing has been one of the more consistent bottlenecks despite the O(n^2) vs. O(n) time complexities [n = number of particles]. According to my inexpert reading of the profiler's reports, because of the time the CPU spends in converting between integers and floating-points as part of the implementation detail of the routine, which may be causing certain unknown effects that propagate outward.) Or, more precisely, disk-rectangle collision (two-dimensional figures), which means that, if one figure is contained in the other, they are said to be colliding (intersecting). (As opposed to the one-dimensional case where it would be considered not intersecting because no point of intersection is created on the respective curves.) Remaining: 1. At least one affirmative case. 2. Coverage of every branch. 3. Rotated version of each test. Later, I will compute the branch coverage for all tests. * Remove hypot from disk-rectangle intersection detection The hypot calls were estimated to be O(n) where n is the number of particles in the previous implementation. I will add in the tests soon when I find the time to do it. * Revise disk and (area) rectangle testing routine * Fix "flickering near boundaries" issue The erroneous "CheckCollisionCircleRec" (Raylib) routine was replaced with a custom routine. * circle.h: Remove unintended math function calls The signbit calls were observed to be calling a system function that would extract the sign bit from the floating-point number. * demo: Remove collision bias Refresh the Halton disk at every frame to remove statistical bias when particles are partially colliding * Fix last remaining camera issue I ignored the screen offset, which is now taken into account. * Table.h: Revert to Yoshida integration Verlet integration was only used for exposition of a problem.
- Loading branch information
1 parent
dbe77ae
commit 89ba006
Showing
12 changed files
with
190 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#ifndef GRASS_VERLET_H | ||
#define GRASS_VERLET_H | ||
|
||
#include <complex> | ||
|
||
namespace dyn { | ||
|
||
template <typename F = float> struct Verlet { | ||
std::complex<F> y0, y1; | ||
|
||
template <typename A> void step(F h, A y2) { | ||
auto a = y2(y0); | ||
y0 += h * y1 + h * h * F(0.5) * a; | ||
auto b = y2(y0); | ||
y1 += h * F(0.5) * (a + b); | ||
} | ||
}; | ||
|
||
} // namespace dyn | ||
|
||
#endif // GRASS_VERLET_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#include "gtest/gtest.h" | ||
|
||
#include <complex> | ||
|
||
#include <circle.h> | ||
|
||
/// @brief See `CircleTest0.png` for reference. | ||
class CircleTest0 : public testing::Test { | ||
protected: | ||
// xy, r; rectangles (2 corners) | ||
dyn::Circle<float> const circle{0, 2.4f}; | ||
std::complex<float> const less_less{-4.0f, -4.0f}; | ||
std::complex<float> const greater_greater{-2.0f, -2.0f}; | ||
}; | ||
|
||
TEST_F(CircleTest0, Disjoint0) { | ||
ASSERT_FALSE(dyn::disk_arrect_isct(circle, less_less, greater_greater)); | ||
} | ||
|
||
class CircleTest1 : public testing::Test { | ||
protected: | ||
dyn::Circle<float> const circle{0, 2.0f}; | ||
std::complex<float> const less_less{-5.0f, 1.0f}, | ||
greater_greater{-1.0f, 5.0f}; | ||
}; | ||
|
||
TEST_F(CircleTest1, In0) { | ||
ASSERT_TRUE(dyn::disk_arrect_isct(circle, less_less, greater_greater)); | ||
} | ||
|
||
class CircleTest2 : public testing::Test { | ||
protected: | ||
dyn::Circle<float> const circle{0, 3.0f}; | ||
std::complex<float> const less_less{0.6f, 2.7f}, greater_greater{1.8f, 3.6f}; | ||
}; | ||
|
||
TEST_F(CircleTest2, In0) { | ||
ASSERT_TRUE(dyn::disk_arrect_isct(circle, less_less, greater_greater)); | ||
} | ||
|
||
class CircleTest3 : public testing::Test { | ||
protected: | ||
dyn::Circle<float> const circle{0, 4.0f}; | ||
std::complex<float> const c{-2.0f, -2.0f}, e{0, -1.0f}, l{-2.0f, -5.0f}, | ||
n{5.0f, 3.0f}, s{7.0f, 2.0f}, u{9.0f, 3.0f}; | ||
}; | ||
|
||
TEST_F(CircleTest3, In0) { | ||
ASSERT_TRUE(dyn::disk_arrect_isct(circle, c, e)); | ||
} | ||
|
||
TEST_F(CircleTest3, In1) { | ||
ASSERT_TRUE(dyn::disk_arrect_isct(circle, l, n)); | ||
} | ||
|
||
TEST_F(CircleTest3, Out0) { | ||
ASSERT_FALSE(dyn::disk_arrect_isct(circle, s, u)); | ||
} |