~baltix/+junk/irrlicht-test

« back to all changes in this revision

Viewing changes to tests/md2Animation.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 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 MD2 animations.
 
14
/** At the moment, this just verifies that the last frame of the animation produces the expected bitmap. */
 
15
bool md2Animation(void)
 
16
{
 
17
        // Use EDT_BURNINGSVIDEO since it is not dependent on (e.g.) OpenGL driver versions.
 
18
        IrrlichtDevice *device = createDevice( EDT_BURNINGSVIDEO, dimension2d<u32>(160, 120), 32);
 
19
        assert(device);
 
20
        if (!device)
 
21
                return false;
 
22
 
 
23
        IVideoDriver* driver = device->getVideoDriver();
 
24
        ISceneManager * smgr = device->getSceneManager();
 
25
 
 
26
        IAnimatedMesh* mesh = smgr->getMesh("../media/sydney.md2");
 
27
        IAnimatedMeshSceneNode* node;
 
28
        assert(mesh);
 
29
 
 
30
        bool result = (mesh != 0);
 
31
        if(mesh)
 
32
        {
 
33
                node = smgr->addAnimatedMeshSceneNode(mesh);
 
34
                assert(node);
 
35
 
 
36
                if(node)
 
37
                {
 
38
                        node->setPosition(vector3df(20, 0, 30));
 
39
                        node->setMaterialFlag(EMF_LIGHTING, false);
 
40
                        node->setMaterialTexture(0, driver->getTexture("../media/sydney.bmp"));
 
41
                        node->setLoopMode(false);
 
42
 
 
43
                        (void)smgr->addCameraSceneNode();
 
44
 
 
45
                        // Just jump to the last frame since that's all we're interested in.
 
46
                        node->setMD2Animation(EMAT_DEATH_FALLBACK);
 
47
                        node->setCurrentFrame((f32)(node->getEndFrame()));
 
48
                        node->setAnimationSpeed(0);
 
49
                        device->run();
 
50
                        driver->beginScene(true, true, SColor(255, 255, 255, 0));
 
51
                        smgr->drawAll();
 
52
                        driver->endScene();
 
53
                        if (mesh->getBoundingBox() != mesh->getMesh(node->getEndFrame())->getBoundingBox())
 
54
                        {
 
55
                                logTestString("bbox of md2 mesh not updated.\n");
 
56
                                result = false;
 
57
                        }
 
58
                        //TODO: Does not yet work, not sure if this is correct or not
 
59
#if 0
 
60
                        if (node->getBoundingBox() != mesh->getMesh(node->getFrameNr())->getBoundingBox())
 
61
                        {
 
62
                                logTestString("bbox of md2 scene node not updated.\n");
 
63
                                result = false;
 
64
                        }
 
65
#endif
 
66
                        if (node->getTransformedBoundingBox() == core::aabbox3df())
 
67
                        {
 
68
                                logTestString("md2 node returns empty bbox.\n");
 
69
                                result = false;
 
70
                        }
 
71
                }
 
72
        }
 
73
 
 
74
        result &= takeScreenshotAndCompareAgainstReference(driver, "-md2Animation.png");
 
75
        device->closeDevice();
 
76
        device->run();
 
77
        device->drop();
 
78
 
 
79
        return result;
 
80
}
 
81