Actually SVN add the new unit test files for collisionResponseAnimator and sceneCollisionManager...
git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@1959 dfc29bdd-3216-0410-991c-e03cc46cb475master
parent
340b984ced
commit
96b28d9162
|
@ -0,0 +1,106 @@
|
|||
// Copyright (C) 2008 Colin MacDonald
|
||||
// No rights reserved: this software is in the public domain.
|
||||
|
||||
#include "testUtils.h"
|
||||
#include "irrlicht.h"
|
||||
#include <assert.h>
|
||||
|
||||
using namespace irr;
|
||||
using namespace core;
|
||||
using namespace scene;
|
||||
using namespace video;
|
||||
|
||||
|
||||
/** Test that collision response animator will reset itself when removed from a
|
||||
scene node, so that the scene node can then be moved without the animator
|
||||
jumping it back again. */
|
||||
bool collisionResponseAnimator(void)
|
||||
{
|
||||
IrrlichtDevice * device = irr::createDevice(video::EDT_NULL);
|
||||
assert(device);
|
||||
if(!device)
|
||||
return false;
|
||||
|
||||
ISceneManager * smgr = device->getSceneManager();
|
||||
|
||||
// Create 2 nodes to the left of a "wall"
|
||||
ISceneNode * testNode1 = smgr->addEmptySceneNode();
|
||||
ISceneNode * testNode2 = smgr->addEmptySceneNode();
|
||||
testNode1->setPosition(vector3df(-50, 0,0));
|
||||
testNode2->setPosition(vector3df(-50, 0,0));
|
||||
|
||||
// Create a "wall" node, and collision response animators for each test node.
|
||||
IMeshSceneNode * wallNode = smgr->addCubeSceneNode(10.f);
|
||||
|
||||
ITriangleSelector * wallSelector = smgr->createTriangleSelectorFromBoundingBox(wallNode);
|
||||
ISceneNodeAnimatorCollisionResponse * collisionAnimator1 =
|
||||
smgr->createCollisionResponseAnimator(wallSelector,
|
||||
testNode1,
|
||||
vector3df(10,10,10),
|
||||
vector3df(0, 0, 0));
|
||||
testNode1->addAnimator(collisionAnimator1);
|
||||
collisionAnimator1->drop();
|
||||
collisionAnimator1 = 0;
|
||||
|
||||
ISceneNodeAnimatorCollisionResponse * collisionAnimator2 =
|
||||
smgr->createCollisionResponseAnimator(wallSelector,
|
||||
testNode2,
|
||||
vector3df(10,10,10),
|
||||
vector3df(0, 0, 0));
|
||||
testNode2->addAnimator(collisionAnimator2);
|
||||
|
||||
wallSelector->drop();
|
||||
// Don't drop() collisionAnimator2 since we're going to use it.
|
||||
|
||||
// Get the system in a good state
|
||||
device->run();
|
||||
smgr->drawAll();
|
||||
|
||||
// Try to move both nodes to the right of the wall.
|
||||
// This one should be stopped by its animator.
|
||||
testNode1->setPosition(vector3df(50, 0,0));
|
||||
|
||||
// Whereas this one, by forcing the animator to update its target node, should be
|
||||
// able to pass through the wall. (In <=1.6 it was stopped by the wall even if
|
||||
// the animator was removed and later re-added);
|
||||
testNode2->setPosition(vector3df(50, 0,0));
|
||||
collisionAnimator2->setTargetNode(testNode2);
|
||||
collisionAnimator2->drop(); // We're done using this now.
|
||||
|
||||
device->run();
|
||||
smgr->drawAll();
|
||||
|
||||
bool result = true;
|
||||
|
||||
if(testNode1->getAbsolutePosition().X > -15.f)
|
||||
{
|
||||
logTestString("collisionResponseAnimator test node 1 wasn't stopped from moving.\n");
|
||||
assert(false);
|
||||
result = false;
|
||||
}
|
||||
|
||||
if(testNode2->getAbsolutePosition().X < 50.f)
|
||||
{
|
||||
logTestString("collisionResponseAnimator test node 2 was stopped from moving.\n");
|
||||
assert(false);
|
||||
result = false;
|
||||
}
|
||||
|
||||
// Now try to move the second node back through the wall again. Now it should be
|
||||
// stopped by the wall.
|
||||
testNode2->setPosition(vector3df(-50, 0, 0));
|
||||
device->run();
|
||||
smgr->drawAll();
|
||||
|
||||
if(testNode2->getAbsolutePosition().X < 15.f)
|
||||
{
|
||||
logTestString("collisionResponseAnimator test node 2 wasn't stopped from moving.\n");
|
||||
assert(false);
|
||||
result = false;
|
||||
}
|
||||
|
||||
device->drop();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,84 @@
|
|||
// Copyright (C) 2008 Colin MacDonald
|
||||
// No rights reserved: this software is in the public domain.
|
||||
|
||||
#include "testUtils.h"
|
||||
#include "irrlicht.h"
|
||||
#include <assert.h>
|
||||
|
||||
using namespace irr;
|
||||
using namespace core;
|
||||
using namespace scene;
|
||||
using namespace video;
|
||||
|
||||
|
||||
/** Test functionality of the sceneCollisionManager */
|
||||
bool sceneCollisionManager(void)
|
||||
{
|
||||
IrrlichtDevice * device = irr::createDevice(video::EDT_NULL);
|
||||
assert(device);
|
||||
if(!device)
|
||||
return false;
|
||||
|
||||
ISceneManager * smgr = device->getSceneManager();
|
||||
ISceneCollisionManager * collMgr = smgr->getSceneCollisionManager();
|
||||
|
||||
IMeshSceneNode * cubeNode = smgr->addCubeSceneNode(10.f);
|
||||
ITriangleSelector * cubeSelector = smgr->createTriangleSelectorFromBoundingBox(cubeNode);
|
||||
|
||||
triangle3df triOut;
|
||||
vector3df hitPosition;
|
||||
bool falling;
|
||||
|
||||
vector3df resultPosition =
|
||||
collMgr->getCollisionResultPosition(cubeSelector,
|
||||
vector3df(0, 50, 0),
|
||||
vector3df(10, 20, 10),
|
||||
vector3df(0, -100, 0),
|
||||
triOut,
|
||||
hitPosition,
|
||||
falling);
|
||||
|
||||
bool result = true;
|
||||
if(!equals(resultPosition.Y, 25.f, 0.01f))
|
||||
{
|
||||
logTestString("Unexpected collision response position\n");
|
||||
assert(false);
|
||||
result = false;
|
||||
}
|
||||
|
||||
if(!equals(hitPosition.Y, 5.f, 0.01f))
|
||||
{
|
||||
logTestString("Unexpected collision position\n");
|
||||
assert(false);
|
||||
result = false;
|
||||
}
|
||||
|
||||
resultPosition =
|
||||
collMgr->getCollisionResultPosition(cubeSelector,
|
||||
vector3df(-20, 0, 0),
|
||||
vector3df(10, 20, 10),
|
||||
vector3df(100, 0, 0),
|
||||
triOut,
|
||||
hitPosition,
|
||||
falling);
|
||||
|
||||
if(!equals(resultPosition.X, -15.f, 0.01f))
|
||||
{
|
||||
logTestString("Unexpected collision response position\n");
|
||||
assert(false);
|
||||
result = false;
|
||||
}
|
||||
|
||||
if(!equals(hitPosition.X, -5.f, 0.01f))
|
||||
{
|
||||
logTestString("Unexpected collision position\n");
|
||||
assert(false);
|
||||
result = false;
|
||||
}
|
||||
|
||||
cubeSelector->drop();
|
||||
device->drop();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue