1 #include "OrbitTest.hpp"
3 #include "../assert.hpp"
6 #include "world/Orbit.hpp"
8 CPPUNIT_TEST_SUITE_REGISTRATION(blobs::test::world::OrbitTest);
10 using blobs::world::Orbit;
17 void OrbitTest::setUp() {
20 void OrbitTest::tearDown() {
24 void OrbitTest::testSMA() {
26 orbit.SemiMajorAxis(1.0);
27 CPPUNIT_ASSERT_DOUBLES_EQUAL_MESSAGE(
28 "wrong semi-major axis on orbit",
29 1.0, orbit.SemiMajorAxis(), std::numeric_limits<double>::epsilon()
32 // reference direction is +X, so at t=0, the body should be
33 // at (sma,0,0) relative to its parent
34 glm::vec4 pos(orbit.Matrix(0.0) * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f));
36 "wrong position at t=0",
37 glm::vec3(1.0f, 0.0f, 0.0f),
38 glm::vec3(pos) / pos.w
41 // at 90° position should be (0,0,sma) since the zero inclination
42 // reference plane is XZ and rotates counter-clockwise
43 pos = orbit.Matrix(PI_0p5) * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
45 "wrong position at t=90°",
46 glm::vec3(0.0f, 0.0f, -1.0f),
47 glm::vec3(pos) / pos.w
50 // at 180° position should be (-sma,0,0)
51 pos = orbit.Matrix(PI) * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
53 "wrong position at t=180°",
54 glm::vec3(-1.0f, 0.0f, 0.0f),
55 glm::vec3(pos) / pos.w
58 // at 270° position should be (0,0,-sma)
59 pos = orbit.Matrix(PI_1p5) * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
61 "wrong position at t=270°",
62 glm::vec3(0.0f, 0.0f, 1.0f),
63 glm::vec3(pos) / pos.w
66 // at 360° position should be (sma,0,0), the initial position
67 pos = orbit.Matrix(PI_2p0) * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
69 "wrong position at t=360°",
70 glm::vec3(1.0f, 0.0f, 0.0f),
71 glm::vec3(pos) / pos.w