aboutsummaryrefslogtreecommitdiff
path: root/tests/md2Animation.cpp
blob: 3fac32bc9fa93e2d4075433ed9123bb28c29a89b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// Copyright (C) 2008-2011 Colin MacDonald
// No rights reserved: this software is in the public domain.

#include "testUtils.h"

using namespace irr;
using namespace core;

namespace
{
// Tests MD2 animations.
/** At the moment, this just verifies that the last frame of the animation produces the expected bitmap. */
bool testLastFrame()
{
	// Use EDT_BURNINGSVIDEO since it is not dependent on (e.g.) OpenGL driver versions.
	IrrlichtDevice *device = createDevice(video::EDT_BURNINGSVIDEO, dimension2d<u32>(160, 120), 32);
	if (!device)
		return false;

	video::IVideoDriver* driver = device->getVideoDriver();
	scene::ISceneManager * smgr = device->getSceneManager();

	scene::IAnimatedMesh* mesh = smgr->getMesh("../media/sydney.md2");

	bool result = (mesh != 0);
	if (mesh)
	{
		scene::IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode(mesh);

		if (node)
		{
			node->setPosition(vector3df(20, 0, 30));
			node->setMaterialFlag(video::EMF_LIGHTING, false);
			node->setMaterialTexture(0, driver->getTexture("../media/sydney.bmp"));
			node->setLoopMode(false);

			(void)smgr->addCameraSceneNode();

			// Just jump to the last frame since that's all we're interested in.
			node->setMD2Animation(scene::EMAT_DEATH_FALLBACK);
			node->setCurrentFrame((f32)(node->getEndFrame()));
			node->setAnimationSpeed(0);
			device->run();
			driver->beginScene(true, true, video::SColor(255, 255, 255, 0));
			smgr->drawAll();
			driver->endScene();
			if (mesh->getBoundingBox() != mesh->getMesh(node->getEndFrame())->getBoundingBox())
			{
				logTestString("bbox of md2 mesh not updated.\n");
				result = false;
			}
			//TODO: Does not yet work, not sure if this is correct or not
#if 0
			if (node->getBoundingBox() != mesh->getMesh(node->getFrameNr())->getBoundingBox())
			{
				logTestString("bbox of md2 scene node not updated.\n");
				result = false;
			}
#endif
			if (node->getTransformedBoundingBox() == core::aabbox3df())
			{
				logTestString("md2 node returns empty bbox.\n");
				result = false;
			}
		}
	}

	result &= takeScreenshotAndCompareAgainstReference(driver, "-md2Animation.png");
	device->closeDevice();
	device->run();
	device->drop();

	return result;
}

// Tests MD2 normals.
bool testNormals()
{
	// Use EDT_BURNINGSVIDEO since it is not dependent on (e.g.) OpenGL driver versions.
	IrrlichtDevice *device = createDevice(video::EDT_BURNINGSVIDEO, dimension2d<u32>(160, 120), 32);
	if (!device)
		return false;

	video::IVideoDriver* driver = device->getVideoDriver();
	scene::ISceneManager * smgr = device->getSceneManager();

	scene::IAnimatedMesh* mesh = smgr->getMesh("../media/sydney.md2");

	bool result = (mesh != 0);
	if (mesh)
	{
		scene::IAnimatedMeshSceneNode* node = smgr->addAnimatedMeshSceneNode(mesh);
		if (node)
		{
			node->setPosition(vector3df(20, 0, 30));
			node->setMaterialFlag(video::EMF_LIGHTING, false);
			node->setDebugDataVisible(scene::EDS_NORMALS);
			node->setMaterialTexture(0, driver->getTexture("../media/sydney.bmp"));
			node->setLoopMode(false);

			(void)smgr->addCameraSceneNode();

			node->setMD2Animation(scene::EMAT_STAND);
			node->setAnimationSpeed(0);
			device->run();
			driver->beginScene(true, true, video::SColor(255, 255, 255, 0));
			smgr->drawAll();
			driver->endScene();
		}
	}

	result &= takeScreenshotAndCompareAgainstReference(driver, "-md2Normals.png");
	device->closeDevice();
	device->run();
	device->drop();

	return result;
}

}

// test md2 features
bool md2Animation(void)
{
	bool result = testLastFrame();
	result &= testNormals();
	return result;
}