VGearsAFile.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * Copyright (C) 2022 The V-Gears Team
  3. *
  4. * This file is part of V-Gears
  5. *
  6. * V-Gears is free software: you can redistribute it and/or modify it under
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, version 3.0 (GPLv3) of the License.
  9. *
  10. * V-Gears is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #include <boost/test/unit_test.hpp>
  16. #include <OgreAnimation.h>
  17. #include <OgreAnimationTrack.h>
  18. #include <OgreKeyFrame.h>
  19. #include <OgreSkeleton.h>
  20. #include "data/VGearsAFile.h"
  21. BOOST_AUTO_TEST_CASE(TestVGearsAFile){
  22. VGears::AFile animation(nullptr, "animation", 0, "test", true);
  23. VGears::AFile::Frame first_frame;
  24. first_frame.root_rotation = Ogre::Vector3::ZERO;
  25. first_frame.root_translation = Ogre::Vector3(2.0f, 3.0f, 4.0f);
  26. animation.GetFrames().push_back(first_frame);
  27. VGears::AFile::Frame last_frame;
  28. last_frame.root_rotation = Ogre::Vector3::ZERO;
  29. last_frame.root_translation = Ogre::Vector3(-1.0f, 5.0f, -6.0f);
  30. animation.GetFrames().push_back(last_frame);
  31. Ogre::SkeletonPtr skeleton(new Ogre::Skeleton(nullptr, "skeleton", 0, "test", true));
  32. skeleton->createBone("root");
  33. animation.AddTo(skeleton, "jump", true);
  34. Ogre::NodeAnimationTrack* track = skeleton->getAnimation("jump")->getNodeTrack(0);
  35. BOOST_CHECK(track->getNodeKeyFrame(0)->getTranslate() == Ogre::Vector3(2.0f, 3.0f, -4.0f));
  36. BOOST_CHECK(track->getNodeKeyFrame(1)->getTranslate() == Ogre::Vector3(-1.0f, 5.0f, 6.0f));
  37. animation.AddTo(skeleton, "unmodified");
  38. track = skeleton->getAnimation("unmodified")->getNodeTrack(0);
  39. BOOST_CHECK(track->getNodeKeyFrame(0)->getTranslate() == first_frame.root_translation);
  40. BOOST_CHECK(track->getNodeKeyFrame(1)->getTranslate() == last_frame.root_translation);
  41. const Ogre::AxisAlignedBox bounds = animation.GetRootTranslationBounds(true);
  42. BOOST_CHECK(bounds.getMinimum() == Ogre::Vector3(-1.0f, 0.0f, -4.0f));
  43. BOOST_CHECK(bounds.getMaximum() == Ogre::Vector3(2.0f, 5.0f, 6.0f));
  44. const Ogre::AxisAlignedBox original_bounds = animation.GetRootTranslationBounds();
  45. BOOST_CHECK(original_bounds.getMinimum() == Ogre::Vector3(-1.0f, 0.0f, -6.0f));
  46. BOOST_CHECK(original_bounds.getMaximum() == Ogre::Vector3(2.0f, 5.0f, 4.0f));
  47. }