sceneNodeAnimator.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. // Copyright (C) 2008-2012 Colin MacDonald
  2. // No rights reserved: this software is in the public domain.
  3. #include "testUtils.h"
  4. using namespace irr;
  5. using namespace core;
  6. using namespace scene;
  7. /** Test functionality of the ISceneNodeAnimator implementations. */
  8. bool sceneNodeAnimator(void)
  9. {
  10. IrrlichtDevice * device = irr::createDevice(video::EDT_NULL, dimension2d<u32>(160, 120));
  11. assert_log(device);
  12. if(!device)
  13. return false;
  14. ISceneManager * smgr = device->getSceneManager();
  15. // Test the hasFinished() method.
  16. ISceneNodeAnimatorCollisionResponse* collisionResponseAnimator
  17. = smgr->createCollisionResponseAnimator(0, 0);
  18. ISceneNodeAnimator* deleteAnimator = smgr->createDeleteAnimator(1);
  19. ISceneNodeAnimator* flyCircleAnimator = smgr->createFlyCircleAnimator();
  20. ISceneNodeAnimator* flyStraightAnimator
  21. = smgr->createFlyStraightAnimator(vector3df(0, 0, 0), vector3df(0, 0, 0), 1, false);
  22. ISceneNodeAnimator* flyStraightAnimatorLooping
  23. = smgr->createFlyStraightAnimator(vector3df(0, 0, 0), vector3df(0, 0, 0), 1, true);
  24. ISceneNodeAnimator* rotationAnimator = smgr->createRotationAnimator(vector3df(0, 0, 0));
  25. array<vector3df> points;
  26. points.push_back(vector3df(0, 0, 0));
  27. points.push_back(vector3df(0, 0, 0));
  28. ISceneNodeAnimator* followSplineAnimator = smgr->createFollowSplineAnimator(0, points, 1000.f);
  29. array<video::ITexture*> textures;
  30. textures.push_back(0);
  31. textures.push_back(0);
  32. ISceneNodeAnimator* textureAnimator = smgr->createTextureAnimator(textures, 1, false);
  33. ISceneNodeAnimator* textureAnimatorLooping = smgr->createTextureAnimator(textures, 1, true);
  34. bool result = true;
  35. ISceneNode * deletedNode = smgr->addEmptySceneNode();
  36. deletedNode->addAnimator(deleteAnimator);
  37. ISceneNode * testNode = smgr->addEmptySceneNode();
  38. testNode->addAnimator(collisionResponseAnimator);
  39. testNode->addAnimator(deleteAnimator);
  40. testNode->addAnimator(flyCircleAnimator);
  41. testNode->addAnimator(flyStraightAnimator);
  42. testNode->addAnimator(flyStraightAnimatorLooping);
  43. testNode->addAnimator(rotationAnimator);
  44. testNode->addAnimator(followSplineAnimator);
  45. testNode->addAnimator(textureAnimator);
  46. testNode->addAnimator(textureAnimatorLooping);
  47. result &= !collisionResponseAnimator->hasFinished();
  48. result &= !deleteAnimator->hasFinished();
  49. result &= !flyCircleAnimator->hasFinished();
  50. result &= !flyStraightAnimator->hasFinished();
  51. result &= !flyStraightAnimatorLooping->hasFinished();
  52. result &= !rotationAnimator->hasFinished();
  53. result &= !followSplineAnimator->hasFinished();
  54. result &= !textureAnimator->hasFinished();
  55. result &= !textureAnimatorLooping->hasFinished();
  56. device->run();
  57. device->sleep(10);
  58. device->run();
  59. smgr->drawAll();
  60. // These animators don't have an endpoint.
  61. result &= !collisionResponseAnimator->hasFinished();
  62. result &= !flyCircleAnimator->hasFinished();
  63. result &= !rotationAnimator->hasFinished();
  64. result &= !followSplineAnimator->hasFinished();
  65. // These animators are looping and so can't finish.
  66. result &= !flyStraightAnimatorLooping->hasFinished();
  67. result &= !textureAnimatorLooping->hasFinished();
  68. // These have an endpoint and have reached it.
  69. result &= deleteAnimator->hasFinished();
  70. result &= flyStraightAnimator->hasFinished();
  71. result &= textureAnimator->hasFinished();
  72. collisionResponseAnimator->drop();
  73. deleteAnimator->drop();
  74. flyCircleAnimator->drop();
  75. flyStraightAnimator->drop();
  76. flyStraightAnimatorLooping->drop();
  77. rotationAnimator->drop();
  78. followSplineAnimator->drop();
  79. textureAnimator->drop();
  80. textureAnimatorLooping->drop();
  81. device->closeDevice();
  82. device->run();
  83. device->drop();
  84. if(!result)
  85. {
  86. logTestString("One or more animators has a bad hasFinished() state\n.");
  87. assert_log(false);
  88. }
  89. return result;
  90. }