projectionMatrix.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. using namespace core;
  6. using namespace scene;
  7. using namespace video;
  8. using namespace io;
  9. using namespace gui;
  10. //! Tests projection matrices
  11. static bool runTestWithDriver(E_DRIVER_TYPE driverType)
  12. {
  13. IrrlichtDevice *device = createDevice( driverType, dimension2d<u32>(160, 120), 32);
  14. if (!device)
  15. return true; // Treat a failure to create a driver as benign; this saves a lot of #ifdefs
  16. IVideoDriver* driver = device->getVideoDriver();
  17. stabilizeScreenBackground(driver);
  18. logTestString("Testing driver %ls\n", driver->getName());
  19. bool result = true;
  20. driver->beginScene(video::ECBF_COLOR, SColor(255,0,0,0));
  21. SMaterial mat;
  22. mat.MaterialType = EMT_SOLID;
  23. mat.Lighting = false;
  24. mat.ZBuffer = false;
  25. mat.ZWriteEnable = video::EZW_OFF;
  26. mat.Thickness = 1;
  27. driver->setMaterial(mat);
  28. core::dimension2d<f32> dims(driver->getCurrentRenderTargetSize());
  29. //apply custom projection, no offset
  30. core::matrix4 pmtx = matrix4().buildProjectionMatrixOrthoLH(dims.Width, dims.Height, 0, 100);
  31. driver->setTransform(ETS_PROJECTION, pmtx);
  32. driver->setTransform(ETS_VIEW, matrix4());
  33. driver->setTransform(ETS_WORLD, matrix4());
  34. //the red cross appears at center
  35. for (u32 i=0; i<10; ++i)
  36. {
  37. driver->draw3DLine(vector3df(0.f+i,-50.f,1.f), vector3df(0.f+i,50.f,1.f), SColor(255,255,0,0));
  38. driver->draw3DLine(vector3df(-50.f,0.f+i,1.f), vector3df(50.f,0.f+i,1.f), SColor(255,255,0,0));
  39. }
  40. //apply custom projection, offset to right-top
  41. pmtx.setTranslation(vector3df(0.7f, 0.7f, 0.f));
  42. driver->setTransform(ETS_PROJECTION, pmtx);
  43. driver->setTransform(ETS_VIEW, matrix4());
  44. driver->setTransform(ETS_WORLD, matrix4());
  45. //The green cross must be in right-top corner. But for OpenGL driver it is in left-top corner
  46. for (u32 i=0; i<10; ++i)
  47. {
  48. driver->draw3DLine(vector3df(0.f+i,-50,1), vector3df(0.f+i,50,1), SColor(255,0,255,0));
  49. driver->draw3DLine(vector3df(-50,0.f+i,1), vector3df(50,0.f+i,1), SColor(255,0,255,0));
  50. }
  51. driver->endScene();
  52. result = takeScreenshotAndCompareAgainstReference(driver, "-projMat.png", 98.71f);
  53. device->closeDevice();
  54. device->run();
  55. device->drop();
  56. return result;
  57. }
  58. bool projectionMatrix(void)
  59. {
  60. bool result = true;
  61. // TODO: Seems that software driver does not handle this projection matrix
  62. TestWithAllDrivers(runTestWithDriver);
  63. return result;
  64. }