orthoCam.cpp 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. // Copyright (C) 2008-2012 Christian Stehno, Colin MacDonald
  2. // No rights reserved: this software is in the public domain.
  3. #include "testUtils.h"
  4. using namespace irr;
  5. static bool testOrthoCam(video::E_DRIVER_TYPE driverType)
  6. {
  7. IrrlichtDevice *device = createDevice (driverType, core::dimension2d<u32>(160,120));
  8. if (!device)
  9. return true; // No error if device does not exist
  10. stabilizeScreenBackground(device->getVideoDriver());
  11. scene::ICameraSceneNode* cam = device->getSceneManager()->addCameraSceneNode();
  12. cam->setPosition(core::vector3df(500,200,-500));
  13. cam->setTarget(core::vector3df());
  14. cam->setProjectionMatrix(core::matrix4().buildProjectionMatrixOrthoLH(240,180,0.9f,2000.f,driverType != video::EDT_OPENGL), true);
  15. device->getSceneManager()->addAnimatedMeshSceneNode(device->getSceneManager()->addHillPlaneMesh("plane", core::dimension2df(32,32), core::dimension2du(16,16)));//->setMaterialFlag(video::EMF_WIREFRAME, true);
  16. device->getSceneManager()->addCubeSceneNode(20.f)->setPosition(core::vector3df(50,20,50));
  17. device->getSceneManager()->addCubeSceneNode(20.f)->setPosition(core::vector3df(50,20,-50));
  18. device->getSceneManager()->addCubeSceneNode(20.f)->setPosition(core::vector3df(50,50,0));
  19. device->getSceneManager()->addCubeSceneNode(20.f)->setPosition(core::vector3df(-50,10,0));
  20. device->getSceneManager()->addCubeSceneNode(20.f)->setPosition(core::vector3df(100,10,-100));
  21. device->getSceneManager()->addCubeSceneNode(20.f)->setPosition(core::vector3df(150,10,0));
  22. scene::IAnimatedMeshSceneNode* node = device->getSceneManager()->addAnimatedMeshSceneNode(device->getSceneManager()->getMesh("../media/ninja.b3d"), 0, -1, core::vector3df(-50,2,-50), core::vector3df(),core::vector3df(5,5,5));
  23. node->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, true);
  24. node->setAnimationSpeed(0.f);
  25. scene::ILightSceneNode* light = device->getSceneManager()->addLightSceneNode(0, core::vector3df(0,100,0));
  26. light->setLightType(video::ELT_POINT);
  27. light->setRadius(500.f);
  28. light->getLightData().DiffuseColor.set(0,1,1);
  29. device->getVideoDriver()->beginScene(video::ECBF_COLOR | video::ECBF_DEPTH, video::SColor(0,0,0,0));
  30. device->getSceneManager()->drawAll();
  31. device->getVideoDriver()->endScene();
  32. const bool result = takeScreenshotAndCompareAgainstReference(device->getVideoDriver(), "-orthoCam.png", 99.91f);
  33. device->closeDevice();
  34. device->run();
  35. device->drop();
  36. return result;
  37. }
  38. static bool testOrthoStencil(video::E_DRIVER_TYPE driverType)
  39. {
  40. IrrlichtDevice *device = createDevice (driverType, core::dimension2d<u32>(160,120), 16, false, true);
  41. if (!device)
  42. return true; // No error if device does not exist
  43. stabilizeScreenBackground(device->getVideoDriver());
  44. scene::ICameraSceneNode* cam = device->getSceneManager()->addCameraSceneNode();
  45. cam->setPosition(core::vector3df(300,250,-300));
  46. cam->setTarget(core::vector3df(0,20,0));
  47. cam->setProjectionMatrix(core::matrix4().buildProjectionMatrixOrthoLH(120,90,0.9f,5000.f,driverType != video::EDT_OPENGL), true);
  48. device->getSceneManager()->addAnimatedMeshSceneNode(device->getSceneManager()->addHillPlaneMesh("plane", core::dimension2df(32,32), core::dimension2du(16,16)));//->setMaterialFlag(video::EMF_WIREFRAME, true);
  49. scene::IAnimatedMeshSceneNode* node = device->getSceneManager()->addAnimatedMeshSceneNode(device->getSceneManager()->getMesh("../media/ninja.b3d"), 0, -1, core::vector3df(0,2,0), core::vector3df(),core::vector3df(5,5,5));
  50. node->setMaterialFlag(video::EMF_NORMALIZE_NORMALS, true);
  51. node->addShadowVolumeSceneNode();
  52. node->setAnimationSpeed(0.f);
  53. scene::ILightSceneNode* light = device->getSceneManager()->addLightSceneNode(0, core::vector3df(100,150,100));
  54. light->setLightType(video::ELT_POINT);
  55. light->setRadius(500.f);
  56. light->getLightData().DiffuseColor.set(0,1,1);
  57. device->getVideoDriver()->beginScene(video::ECBF_ALL, video::SColor(0,0,0,0));
  58. device->getSceneManager()->drawAll();
  59. device->getVideoDriver()->endScene();
  60. const bool result = takeScreenshotAndCompareAgainstReference(device->getVideoDriver(), "-orthoStencil.png", 99.91f);
  61. device->closeDevice();
  62. device->run();
  63. device->drop();
  64. return result;
  65. }
  66. bool orthoCam(void)
  67. {
  68. bool passed = true;
  69. passed &= testOrthoCam(video::EDT_OPENGL);
  70. // no lights in sw renderer
  71. // passed &= testOrthoCam(video::EDT_SOFTWARE);
  72. passed &= testOrthoCam(video::EDT_BURNINGSVIDEO);
  73. passed &= testOrthoCam(video::EDT_DIRECT3D9);
  74. // TODO: not sure if burnings could work? Currently it doesn't.
  75. passed &= testOrthoStencil(video::EDT_OPENGL);
  76. passed &= testOrthoStencil(video::EDT_DIRECT3D9);
  77. return passed;
  78. }