b3dAnimation.cpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. // Tests B3D animations.
  6. bool b3dAnimation(void)
  7. {
  8. // Use EDT_BURNINGSVIDEO since it is not dependent on (e.g.) OpenGL driver versions.
  9. IrrlichtDevice *device = createDevice(video::EDT_BURNINGSVIDEO, core::dimension2d<u32>(160, 120), 32);
  10. assert_log(device);
  11. if (!device)
  12. return false;
  13. video::IVideoDriver* driver = device->getVideoDriver();
  14. scene::ISceneManager * smgr = device->getSceneManager();
  15. scene::ISkinnedMesh* mesh = (scene::ISkinnedMesh*)smgr->getMesh("../media/ninja.b3d");
  16. assert_log(mesh);
  17. bool result = false;
  18. if (!mesh)
  19. return false;
  20. scene::IAnimatedMeshSceneNode* node1 = smgr->addAnimatedMeshSceneNode(mesh);
  21. assert_log(node1);
  22. /** Verify that two skinned animated mesh scene nodes can use different frames of the skinned mesh */
  23. if(node1)
  24. {
  25. node1->setPosition(core::vector3df(-3, -3, 10));
  26. node1->setMaterialFlag(video::EMF_LIGHTING, false);
  27. node1->setAnimationSpeed(0.f);
  28. node1->setCurrentFrame(10.f);
  29. node1->setDebugDataVisible(irr::scene::EDS_BBOX_BUFFERS);
  30. }
  31. scene::IAnimatedMeshSceneNode* node2 = smgr->addAnimatedMeshSceneNode(mesh);
  32. assert_log(node2);
  33. if(node2)
  34. {
  35. node2->setPosition(core::vector3df(3, -3, 10));
  36. node2->setMaterialFlag(video::EMF_LIGHTING, false);
  37. node2->setAnimationSpeed(0.f);
  38. node2->setCurrentFrame(62.f);
  39. node2->setDebugDataVisible(scene::EDS_BBOX_BUFFERS);
  40. }
  41. (void)smgr->addCameraSceneNode();
  42. // Just jump to the last frame since that's all we're interested in.
  43. device->run();
  44. driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(255, 60, 60, 60));
  45. smgr->drawAll();
  46. driver->endScene();
  47. result = takeScreenshotAndCompareAgainstReference(driver, "-b3dAnimation.png");
  48. if (node2)
  49. node2->remove();
  50. /** Now test if bones are correctly positioned. */
  51. node1->setDebugDataVisible(scene::EDS_SKELETON);
  52. node1->setPosition(core::vector3df(1,-5,8));
  53. node1->setRotation(core::vector3df(0,180,0));
  54. node1->updateAbsolutePosition();
  55. for (u32 i=0; i<node1->getJointCount(); ++i)
  56. {
  57. smgr->addCubeSceneNode(1.f,0,-1,node1->getJointNode(i)->getAbsolutePosition());
  58. // smgr->addCubeSceneNode(1.f,node1->getJointNode(i));
  59. }
  60. // Simple render call
  61. device->run();
  62. driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(255, 60, 60, 60));
  63. smgr->drawAll();
  64. driver->endScene();
  65. result &= takeScreenshotAndCompareAgainstReference(driver, "-b3dJointPosition.png");
  66. device->closeDevice();
  67. device->run();
  68. device->drop();
  69. return result;
  70. }