~baltix/+junk/irrlicht-test

« back to all changes in this revision

Viewing changes to tests/projectionMatrix.cpp

  • Committer: Mantas Kriaučiūnas
  • Date: 2011-07-18 13:06:25 UTC
  • Revision ID: mantas@akl.lt-20110718130625-c5pvifp61e7kj1ol
Included whole irrlicht SVN libraries to work around launchpad recipe issue with quilt, see https://answers.launchpad.net/launchpad/+question/165193

Show diffs side-by-side

added added

removed removed

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