]> git.localhorst.tv Git - blobs.git/blob - tst/world/OrbitTest.cpp
more orbits and stuff
[blobs.git] / tst / world / OrbitTest.cpp
1 #include "OrbitTest.hpp"
2
3 #include "../assert.hpp"
4
5 #include "const.hpp"
6 #include "world/Orbit.hpp"
7
8 CPPUNIT_TEST_SUITE_REGISTRATION(blobs::test::world::OrbitTest);
9
10 using blobs::world::Orbit;
11
12
13 namespace blobs {
14 namespace test {
15 namespace world {
16
17 void OrbitTest::setUp() {
18 }
19
20 void OrbitTest::tearDown() {
21 }
22
23
24 void OrbitTest::testSMA() {
25         Orbit orbit;
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()
30         );
31
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));
35         AssertEqual(
36                 "wrong position at t=0",
37                 glm::vec3(1.0f, 0.0f, 0.0f),
38                 glm::vec3(pos) / pos.w
39         );
40
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);
44         AssertEqual(
45                 "wrong position at t=90°",
46                 glm::vec3(0.0f, 0.0f, -1.0f),
47                 glm::vec3(pos) / pos.w
48         );
49
50         // at 180° position should be (-sma,0,0)
51         pos = orbit.Matrix(PI) * glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
52         AssertEqual(
53                 "wrong position at t=180°",
54                 glm::vec3(-1.0f, 0.0f, 0.0f),
55                 glm::vec3(pos) / pos.w
56         );
57
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);
60         AssertEqual(
61                 "wrong position at t=270°",
62                 glm::vec3(0.0f, 0.0f, 1.0f),
63                 glm::vec3(pos) / pos.w
64         );
65
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);
68         AssertEqual(
69                 "wrong position at t=360°",
70                 glm::vec3(1.0f, 0.0f, 0.0f),
71                 glm::vec3(pos) / pos.w
72         );
73 }
74
75 }
76 }
77 }