terrainSceneNode.cpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #include "testUtils.h"
  2. using namespace irr;
  3. using namespace core;
  4. namespace
  5. {
  6. // test camera changes with terrain scene node recalculation
  7. bool terrainRecalc(void)
  8. {
  9. IrrlichtDevice *device =
  10. createDevice(video::EDT_BURNINGSVIDEO, dimension2du(160, 120), 32);
  11. if (!device)
  12. return true;
  13. video::IVideoDriver* driver = device->getVideoDriver();
  14. scene::ISceneManager* smgr = device->getSceneManager();
  15. scene::ITerrainSceneNode* terrain = smgr->addTerrainSceneNode(
  16. "../media/terrain-heightmap.bmp");
  17. terrain->setScale(core::vector3df(40.f, .1f, 40.f));
  18. terrain->setMaterialFlag(video::EMF_LIGHTING, false);
  19. terrain->setMaterialTexture(0, driver->getTexture("../media/terrain-texture.jpg"));
  20. terrain->setDebugDataVisible(scene::EDS_FULL);
  21. scene::ICameraSceneNode* camera = smgr->addCameraSceneNode();
  22. const core::vector3df center(terrain->getBoundingBox().getCenter());
  23. camera->setTarget(center);
  24. // yes, Y is intentionally being set to X here
  25. const core::vector3df above (center.X, center.X, center.Z);
  26. camera->setPosition (above);
  27. camera->setUpVector(vector3df(1.f, 0.f, 0.f));
  28. camera->setFarValue(above.Y);
  29. device->run();
  30. smgr->drawAll();
  31. // This shouldn't cause a recalc
  32. camera->setUpVector(vector3df(1.f, 0.f, .01f).normalize());
  33. device->run();
  34. driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(255,100,101,140));
  35. smgr->drawAll();
  36. driver->endScene();
  37. // Note that this has to be a slightly fuzzier than usual compare to satisfy multiple OpenGL environments
  38. bool result = takeScreenshotAndCompareAgainstReference(driver, "-terrainSceneNode-1.png", 97.98f);
  39. if(!result)
  40. {
  41. logTestString("Small camera up rotation caused bad recalc.\n");
  42. }
  43. // This is big enough to cause a recalc
  44. camera->setUpVector(vector3df(1.f, 0.f, .1f).normalize());
  45. device->run();
  46. driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(255,100,101,140));
  47. smgr->drawAll();
  48. driver->endScene();
  49. result &= takeScreenshotAndCompareAgainstReference(driver, "-terrainSceneNode-2.png", 98.38f);
  50. if(!result)
  51. {
  52. logTestString("Large camera up rotation caused bad recalc.\n");
  53. }
  54. device->closeDevice();
  55. device->run();
  56. device->drop();
  57. return result;
  58. }
  59. bool terrainGaps()
  60. {
  61. IrrlichtDevice* device = createDevice(video::EDT_BURNINGSVIDEO, dimension2d<u32>(160, 120));
  62. if (!device)
  63. return true;
  64. video::IVideoDriver * irrVideo = device->getVideoDriver();
  65. scene::ISceneManager* irrScene = device->getSceneManager();
  66. // Add camera
  67. scene::ICameraSceneNode* camera = irrScene->addCameraSceneNode();
  68. camera->setPosition(vector3df(20000, 500, 12800));
  69. camera->setTarget(vector3df(16800, 0, 12800));
  70. camera->setFarValue(42000.0f);
  71. // Add terrain scene node
  72. for (u32 i = 0; i < 2; i++)
  73. {
  74. const char* name="media/ter1.png";
  75. scene::ITerrainSceneNode* terrain = irrScene->addTerrainSceneNode(
  76. name, 0, -1,
  77. vector3df((f32)(256*50), 0.f, (f32)(i*256*50)),// position 12800(==imgsize*scale)
  78. vector3df(0.f, 0.f, 0.f), // rotation
  79. vector3df(50.f, 15.0f, 50.f) // scale 50 15 50
  80. );
  81. terrain->setMaterialFlag(video::EMF_LIGHTING, false);
  82. terrain->setMaterialFlag(video::EMF_WIREFRAME, !terrain->getMaterial(0).Wireframe);
  83. }
  84. irrVideo->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(0,150,150,150));
  85. irrScene->drawAll();
  86. irrVideo->endScene();
  87. bool result = takeScreenshotAndCompareAgainstReference(irrVideo, "-terrainGap.png");
  88. device->closeDevice();
  89. device->run();
  90. device->drop();
  91. return result;
  92. }
  93. }
  94. bool terrainSceneNode()
  95. {
  96. bool result = terrainRecalc();
  97. result &= terrainGaps();
  98. return result;
  99. }