]> git.lizzy.rs Git - irrlicht.git/blob - tests/projectionMatrix.cpp
Fix include install location
[irrlicht.git] / tests / projectionMatrix.cpp
1 // Copyright (C) 2008-2012 Christian Stehno, Colin MacDonald\r
2 // No rights reserved: this software is in the public domain.\r
3 \r
4 #include "testUtils.h"\r
5 \r
6 using namespace irr;\r
7 using namespace core;\r
8 using namespace scene;\r
9 using namespace video;\r
10 using namespace io;\r
11 using namespace gui;\r
12 \r
13 //! Tests projection matrices\r
14 static bool runTestWithDriver(E_DRIVER_TYPE driverType)\r
15 {\r
16         IrrlichtDevice *device = createDevice( driverType, dimension2d<u32>(160, 120), 32);\r
17         if (!device)\r
18                 return true; // Treat a failure to create a driver as benign; this saves a lot of #ifdefs\r
19 \r
20         IVideoDriver* driver = device->getVideoDriver();\r
21 \r
22         stabilizeScreenBackground(driver);\r
23 \r
24         logTestString("Testing driver %ls\n", driver->getName());\r
25 \r
26         bool result = true;\r
27 \r
28         driver->beginScene(video::ECBF_COLOR, SColor(255,0,0,0));\r
29                         \r
30         SMaterial mat;\r
31         mat.MaterialType = EMT_SOLID;\r
32         mat.Lighting = false;\r
33         mat.ZBuffer = false;\r
34         mat.ZWriteEnable = video::EZW_OFF;\r
35         mat.Thickness = 1;\r
36 \r
37         driver->setMaterial(mat);\r
38 \r
39         core::dimension2d<f32> dims(driver->getCurrentRenderTargetSize());\r
40         //apply custom projection, no offset\r
41         core::matrix4 pmtx = matrix4().buildProjectionMatrixOrthoLH(dims.Width, dims.Height, 0, 100);\r
42         driver->setTransform(ETS_PROJECTION, pmtx);\r
43         driver->setTransform(ETS_VIEW, matrix4());\r
44         driver->setTransform(ETS_WORLD, matrix4());\r
45 \r
46         //the red cross appears at center\r
47         for (u32 i=0; i<10; ++i)\r
48         {\r
49                 driver->draw3DLine(vector3df(0.f+i,-50.f,1.f), vector3df(0.f+i,50.f,1.f), SColor(255,255,0,0));\r
50                 driver->draw3DLine(vector3df(-50.f,0.f+i,1.f), vector3df(50.f,0.f+i,1.f), SColor(255,255,0,0));\r
51         }\r
52 \r
53         //apply custom projection, offset to right-top\r
54         pmtx.setTranslation(vector3df(0.7f, 0.7f, 0.f));\r
55         driver->setTransform(ETS_PROJECTION, pmtx);\r
56         driver->setTransform(ETS_VIEW, matrix4());\r
57         driver->setTransform(ETS_WORLD, matrix4());\r
58 \r
59         //The green cross must be in right-top corner. But for OpenGL driver it is in left-top corner\r
60         for (u32 i=0; i<10; ++i)\r
61         {\r
62                 driver->draw3DLine(vector3df(0.f+i,-50,1), vector3df(0.f+i,50,1), SColor(255,0,255,0));\r
63                 driver->draw3DLine(vector3df(-50,0.f+i,1), vector3df(50,0.f+i,1), SColor(255,0,255,0));\r
64         }\r
65 \r
66         driver->endScene();\r
67 \r
68         result = takeScreenshotAndCompareAgainstReference(driver, "-projMat.png", 98.71f);\r
69 \r
70         device->closeDevice();\r
71         device->run();\r
72         device->drop();\r
73 \r
74         return result;\r
75 }\r
76 \r
77 \r
78 bool projectionMatrix(void)\r
79 {\r
80         bool result = true;\r
81 \r
82         // TODO: Seems that software driver does not handle this projection matrix\r
83         TestWithAllDrivers(runTestWithDriver);\r
84 \r
85         return result;\r
86 }\r