meshTransform.cpp 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. // Copyright (C) 2009-2012 Christian Stehno
  2. // No rights reserved: this software is in the public domain.
  3. #include "testUtils.h"
  4. using namespace irr;
  5. using namespace core;
  6. using namespace scene;
  7. using namespace video;
  8. using namespace io;
  9. using namespace gui;
  10. // Tests mesh transformations via mesh manipulator.
  11. bool meshTransform(void)
  12. {
  13. // Use EDT_BURNINGSVIDEO since it is not dependent on (e.g.) OpenGL driver versions.
  14. IrrlichtDevice *device = createDevice(EDT_BURNINGSVIDEO, dimension2d<u32>(160, 120), 32);
  15. assert_log(device);
  16. if (!device)
  17. return false;
  18. IVideoDriver* driver = device->getVideoDriver();
  19. ISceneManager * smgr = device->getSceneManager();
  20. IMeshSceneNode* node1 = smgr->addCubeSceneNode(50);
  21. IAnimatedMesh* amesh = smgr->getMesh("../media/sydney.md2");
  22. IAnimatedMesh* smesh = smgr->getMesh("../media/ninja.b3d");
  23. assert_log(node1 && amesh && smesh);
  24. bool result = false;
  25. if (!node1 || !amesh || !smesh)
  26. return false;
  27. // node1->setPosition(core::vector3df(-60,0,150));
  28. node1->setDebugDataVisible(scene::EDS_BBOX_ALL);
  29. IMeshSceneNode* node2 = smgr->addMeshSceneNode(amesh->getMesh(10));
  30. assert_log(node2);
  31. if (!node2)
  32. return false;
  33. // node2->setPosition(core::vector3df(30,10,150));
  34. node2->setDebugDataVisible(scene::EDS_BBOX_ALL);
  35. node2->setMaterialFlag(EMF_LIGHTING, false);
  36. IMeshSceneNode* node3 = smgr->addMeshSceneNode(smesh->getMesh(10));
  37. assert_log(node3);
  38. if (!node3)
  39. return false;
  40. // node3->setPosition(core::vector3df(10,0,0));
  41. node3->setDebugDataVisible(scene::EDS_BBOX_ALL);
  42. node3->setMaterialFlag(EMF_LIGHTING, false);
  43. smgr->addCameraSceneNode()->setPosition(core::vector3df(0,0,-20));
  44. // Just jump to the last frame since that's all we're interested in.
  45. device->run();
  46. driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, SColor(255, 60, 60, 60));
  47. smgr->drawAll();
  48. driver->endScene();
  49. core::matrix4 mat;
  50. mat.setTranslation(core::vector3df(-60,0,150));
  51. driver->getMeshManipulator()->transform(node1->getMesh(), mat);
  52. mat.setTranslation(core::vector3df(30,10,150));
  53. driver->getMeshManipulator()->transform(node2->getMesh(), mat);
  54. mat.setTranslation(core::vector3df(10,0,0));
  55. driver->getMeshManipulator()->transform(node3->getMesh(), mat);
  56. // Just jump to the last frame since that's all we're interested in.
  57. device->run();
  58. driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, SColor(255, 60, 60, 60));
  59. smgr->drawAll();
  60. driver->endScene();
  61. result = takeScreenshotAndCompareAgainstReference(driver, "-meshTransform.png");
  62. device->closeDevice();
  63. device->run();
  64. device->drop();
  65. return result;
  66. }