testGeometryCreator.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. using namespace scene;
  7. using namespace video;
  8. /** Tests that the geometry creator does what it says it does. */
  9. bool testGeometryCreator(void)
  10. {
  11. IrrlichtDevice *device = createDevice(video::EDT_BURNINGSVIDEO,
  12. core::dimension2du(160,120), 32);
  13. if (!device)
  14. return false;
  15. IVideoDriver* driver = device->getVideoDriver();
  16. ISceneManager* smgr = device->getSceneManager();
  17. (void)smgr->addCameraSceneNode(0, vector3df(0, 0, -50));
  18. const IGeometryCreator * geom = smgr->getGeometryCreator();
  19. ITexture * wall = driver->getTexture("../media/wall.bmp");
  20. SMaterial material;
  21. material.Lighting = false;
  22. material.TextureLayer[0].Texture = wall;
  23. irr::scene::IMesh * meshHill = geom->createHillPlaneMesh(dimension2df(10, 5), dimension2du(5, 5),
  24. &material, 10, dimension2df(2, 2), dimension2df(3, 3) );
  25. IMeshSceneNode * node = smgr->addMeshSceneNode(meshHill, 0, -1,
  26. vector3df(0, 10, 0), vector3df(-60, 0, 0));
  27. meshHill->drop();
  28. irr::scene::IMesh * meshArrow = geom->createArrowMesh(4, 8, 10, 6, 3, 6,
  29. SColor(255, 255, 0, 0), SColor(255, 0, 255, 0));
  30. node = smgr->addMeshSceneNode(meshArrow, 0, -1, vector3df(-10, -20, 0));
  31. node->setMaterialFlag(video::EMF_LIGHTING, false);
  32. meshArrow->drop();
  33. irr::scene::IMesh * meshCone = geom->createConeMesh(5.f, 10.f, 16);
  34. node = smgr->addMeshSceneNode(meshCone, 0, -1, vector3df(-35, -20, 0));
  35. node->setMaterialFlag(video::EMF_LIGHTING, false);
  36. node->setMaterialTexture(0, wall);
  37. meshCone->drop();
  38. irr::scene::IMesh * meshCube = geom->createCubeMesh();
  39. node = smgr->addMeshSceneNode(meshCube, 0, -1, vector3df(-20, -20, 0));
  40. node->setMaterialFlag(video::EMF_LIGHTING, false);
  41. node->setMaterialTexture(0, wall);
  42. meshCube->drop();
  43. irr::scene::IMesh * meshCylinder = geom->createCylinderMesh(3, 10, 16);
  44. node = smgr->addMeshSceneNode(meshCylinder, 0, -1, vector3df(0, -20, 10), core::vector3df(45,0,0));
  45. node->setMaterialFlag(video::EMF_LIGHTING, false);
  46. node->setMaterialTexture(0, wall);
  47. meshCylinder->drop();
  48. irr::scene::IMesh * meshSphere = geom->createSphereMesh();
  49. node = smgr->addMeshSceneNode(meshSphere, 0, -1, vector3df(10, -15, 0));
  50. node->setMaterialFlag(video::EMF_LIGHTING, false);
  51. node->setMaterialTexture(0, wall);
  52. meshSphere->drop();
  53. irr::scene::IMesh * meshVolumeLight = geom->createVolumeLightMesh();
  54. node = smgr->addMeshSceneNode(meshVolumeLight, 0, -1, vector3df(20, -20, -10));
  55. node->setMaterialFlag(video::EMF_LIGHTING, false);
  56. node->setMaterialTexture(0, wall);
  57. node->setScale(core::vector3df(4.f,4.f,4.f));
  58. meshVolumeLight->drop();
  59. bool result = false;
  60. device->run();
  61. if (driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(0, 80, 80, 80)))
  62. {
  63. smgr->drawAll();
  64. driver->endScene();
  65. result = takeScreenshotAndCompareAgainstReference(driver, "-testGeometryCreator.png", 99.989f);
  66. }
  67. smgr->clear();
  68. driver->setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT, true);
  69. // add camera
  70. scene::ICameraSceneNode* camera = smgr->addCameraSceneNodeFPS(0,100.0f,2.0f);
  71. camera->setPosition(core::vector3df(2000.0f,5000.f,0.0f));
  72. camera->setTarget(core::vector3df(0.0f,0.0f,0.0f));
  73. camera->setFarValue(20000.0f);
  74. device->getCursorControl()->setVisible(false); // disable mouse cursor
  75. video::IImage* colorMapImage = driver->createImageFromFile("../media/terrain-texture.jpg");
  76. video::IImage* heightMapImage = driver->createImageFromFile("../media/terrain-heightmap.bmp");
  77. scene::IAnimatedMesh* terrain = smgr->addTerrainMesh("TerrainMeshName",
  78. colorMapImage, heightMapImage,
  79. core::dimension2d<f32>(40, 40), // size of a pixel
  80. 8*40); // maximum height
  81. colorMapImage->drop();
  82. colorMapImage = 0;
  83. heightMapImage->drop();
  84. heightMapImage = 0;
  85. scene::IAnimatedMeshSceneNode* anode = smgr->addAnimatedMeshSceneNode(terrain);
  86. if (anode)
  87. {
  88. anode->setMaterialFlag(video::EMF_LIGHTING, false);
  89. anode->setPosition(core::vector3df(-5000,0,-5000));
  90. }
  91. driver->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(0));
  92. smgr->drawAll();
  93. driver->endScene();
  94. // This screenshot shows some mipmap problems, but this seems to be
  95. // no fault of the mesh
  96. result &= takeScreenshotAndCompareAgainstReference(driver, "-testTerrainMesh.png", 99.989f);
  97. device->closeDevice();
  98. device->run();
  99. device->drop();
  100. return result;
  101. }