md2Animation.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // Copyright (C) 2008-2012 Colin MacDonald
  2. // No rights reserved: this software is in the public domain.
  3. #include "testUtils.h"
  4. using namespace irr;
  5. using namespace core;
  6. namespace
  7. {
  8. // Tests MD2 animations.
  9. /** At the moment, this just verifies that the last frame of the animation produces the expected bitmap. */
  10. bool testLastFrame()
  11. {
  12. // Use EDT_BURNINGSVIDEO since it is not dependent on (e.g.) OpenGL driver versions.
  13. IrrlichtDevice *device = createDevice(video::EDT_BURNINGSVIDEO, dimension2d<u32>(160, 120), 32);
  14. if (!device)
  15. return false;
  16. video::IVideoDriver* driver = device->getVideoDriver();
  17. scene::ISceneManager * smgr = device->getSceneManager();
  18. scene::IAnimatedMesh* mesh = smgr->getMesh("./media/sydney.md2");
  19. bool result = (mesh != 0);
  20. if (mesh)
  21. {
  22. scene::IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode(mesh);
  23. if (node)
  24. {
  25. node->setPosition(vector3df(20, 0, 30));
  26. node->setMaterialFlag(video::EMF_LIGHTING, false);
  27. node->setMaterialTexture(0, driver->getTexture("./media/sydney.bmp"));
  28. node->setLoopMode(false);
  29. (void)smgr->addCameraSceneNode();
  30. // Just jump to the last frame since that's all we're interested in.
  31. node->setMD2Animation(scene::EMAT_DEATH_FALLBACK);
  32. node->setCurrentFrame((f32)(node->getEndFrame()));
  33. node->setAnimationSpeed(0);
  34. device->run();
  35. driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(255, 255, 255, 0));
  36. smgr->drawAll();
  37. driver->endScene();
  38. if (mesh->getBoundingBox() != mesh->getMesh(node->getEndFrame())->getBoundingBox())
  39. {
  40. logTestString("bbox of md2 mesh not updated.\n");
  41. result = false;
  42. }
  43. //TODO: Does not yet work, not sure if this is correct or not
  44. #if 0
  45. if (node->getBoundingBox() != mesh->getMesh(node->getFrameNr())->getBoundingBox())
  46. {
  47. logTestString("bbox of md2 scene node not updated.\n");
  48. result = false;
  49. }
  50. #endif
  51. if (node->getTransformedBoundingBox() == core::aabbox3df())
  52. {
  53. logTestString("md2 node returns empty bbox.\n");
  54. result = false;
  55. }
  56. }
  57. }
  58. result &= takeScreenshotAndCompareAgainstReference(driver, "-md2Animation.png");
  59. device->closeDevice();
  60. device->run();
  61. device->drop();
  62. return result;
  63. }
  64. // Tests MD2 normals.
  65. bool testNormals()
  66. {
  67. // Use EDT_BURNINGSVIDEO since it is not dependent on (e.g.) OpenGL driver versions.
  68. IrrlichtDevice *device = createDevice(video::EDT_BURNINGSVIDEO, dimension2d<u32>(160, 120), 32);
  69. if (!device)
  70. return false;
  71. video::IVideoDriver* driver = device->getVideoDriver();
  72. scene::ISceneManager * smgr = device->getSceneManager();
  73. scene::IAnimatedMesh* mesh = smgr->getMesh("./media/sydney.md2");
  74. bool result = (mesh != 0);
  75. if (mesh)
  76. {
  77. scene::IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode(mesh);
  78. if (node)
  79. {
  80. node->setPosition(vector3df(20, 0, 30));
  81. node->setMaterialFlag(video::EMF_LIGHTING, false);
  82. node->setDebugDataVisible(scene::EDS_NORMALS);
  83. node->setMaterialTexture(0, driver->getTexture("./media/sydney.bmp"));
  84. node->setLoopMode(false);
  85. (void)smgr->addCameraSceneNode();
  86. node->setMD2Animation(scene::EMAT_STAND);
  87. node->setAnimationSpeed(0);
  88. device->run();
  89. driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(255, 255, 255, 0));
  90. smgr->drawAll();
  91. driver->endScene();
  92. }
  93. }
  94. result &= takeScreenshotAndCompareAgainstReference(driver, "-md2Normals.png");
  95. device->closeDevice();
  96. device->run();
  97. device->drop();
  98. return result;
  99. }
  100. }
  101. // test md2 features
  102. bool md2Animation(void)
  103. {
  104. bool result = testLastFrame();
  105. result &= testNormals();
  106. return result;
  107. }