]> git.mxchange.org Git - simgear.git/blob - simgear/scene/model/animation_test.cxx
Make return type from loadPagedModel explicit.
[simgear.git] / simgear / scene / model / animation_test.cxx
1 #include "animation.hxx"
2
3 #include <cstring>
4 #include <iostream>
5
6 #define VERIFY_CLOSE(a, b) \
7   if( norm((a) - (b)) > 1e-5 ) \
8   { \
9     std::cerr << "line " << __LINE__ << ": failed: "\
10               << #a << " != " << #b\
11               << " [" << (a) << " != " << (b) << "]" << std::endl; \
12     return 1; \
13   }
14
15 #define VERIFY(a) \
16   if( !(a) ) \
17   { \
18     std::cerr << "failed: line " << __LINE__ << ": " << #a << std::endl; \
19     return 1; \
20   }
21
22 struct AnimationTest:
23   public SGAnimation
24 {
25   AnimationTest(const SGPropertyNode* n):
26     SGAnimation(n, 0)
27   {}
28
29   void readConfig()
30   {
31     readRotationCenterAndAxis(center, axis);
32   }
33
34   SGVec3d center,
35           axis;
36 };
37
38 int main(int argc, char* argv[])
39 {
40   SGPropertyNode_ptr config = new SGPropertyNode;
41   AnimationTest anim(config);
42
43   SGVec3d v1(1, 2, 3),
44           v2(-1, 4, 0);
45   config->setDoubleValue("axis/x1-m", v1.x());
46   config->setDoubleValue("axis/y1-m", v1.y());
47   config->setDoubleValue("axis/z1-m", v1.z());
48   config->setDoubleValue("axis/x2-m", v2.x());
49   config->setDoubleValue("axis/y2-m", v2.y());
50   config->setDoubleValue("axis/z2-m", v2.z());
51   anim.readConfig();
52
53   VERIFY_CLOSE(anim.center, (v1 + v2) * 0.5)
54   VERIFY_CLOSE(anim.axis, normalize(v2 - v1))
55
56   config->removeChild("axis", 0, false);
57   config->setDoubleValue("center/x-m", v1.x());
58   config->setDoubleValue("center/y-m", v1.y());
59   config->setDoubleValue("center/z-m", v1.z());
60   config->setDoubleValue("axis/x", v2.x());
61   config->setDoubleValue("axis/y", v2.y());
62   config->setDoubleValue("axis/z", v2.z());
63   anim.readConfig();
64
65   VERIFY_CLOSE(anim.center, v1)
66   VERIFY_CLOSE(anim.axis, normalize(v2))
67
68   return 0;
69 }