CDefaultSceneNodeAnimatorFactory.cpp 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. // Copyright (C) 2002-2012 Nikolaus Gebhardt
  2. // This file is part of the "Irrlicht Engine".
  3. // For conditions of distribution and use, see copyright notice in irrlicht.h
  4. #include "CDefaultSceneNodeAnimatorFactory.h"
  5. #include "CSceneNodeAnimatorCameraFPS.h"
  6. #include "CSceneNodeAnimatorCameraMaya.h"
  7. #include "ICursorControl.h"
  8. #include "ISceneNodeAnimatorCollisionResponse.h"
  9. #include "ISceneManager.h"
  10. namespace irr
  11. {
  12. namespace scene
  13. {
  14. //! Names for scene node types
  15. const c8* const SceneNodeAnimatorTypeNames[] =
  16. {
  17. "flyCircle",
  18. "flyStraight",
  19. "followSpline",
  20. "rotation",
  21. "texture",
  22. "deletion",
  23. "collisionResponse",
  24. "cameraFPS",
  25. "cameraMaya",
  26. 0
  27. };
  28. CDefaultSceneNodeAnimatorFactory::CDefaultSceneNodeAnimatorFactory(ISceneManager* mgr, gui::ICursorControl* crs)
  29. : Manager(mgr), CursorControl(crs)
  30. {
  31. #ifdef _DEBUG
  32. setDebugName("CDefaultSceneNodeAnimatorFactory");
  33. #endif
  34. // don't grab the scene manager here to prevent cyclic references
  35. if (CursorControl)
  36. CursorControl->grab();
  37. }
  38. CDefaultSceneNodeAnimatorFactory::~CDefaultSceneNodeAnimatorFactory()
  39. {
  40. if (CursorControl)
  41. CursorControl->drop();
  42. }
  43. //! creates a scene node animator based on its type id
  44. ISceneNodeAnimator* CDefaultSceneNodeAnimatorFactory::createSceneNodeAnimator(ESCENE_NODE_ANIMATOR_TYPE type, ISceneNode* target)
  45. {
  46. scene::ISceneNodeAnimator* anim = 0;
  47. switch(type)
  48. {
  49. case ESNAT_FLY_CIRCLE:
  50. anim = Manager->createFlyCircleAnimator(core::vector3df(0,0,0), 10);
  51. break;
  52. case ESNAT_FLY_STRAIGHT:
  53. anim = Manager->createFlyStraightAnimator(core::vector3df(0,0,0), core::vector3df(100,100,100), 10000, true );
  54. break;
  55. case ESNAT_FOLLOW_SPLINE:
  56. {
  57. core::array<core::vector3df> points;
  58. points.push_back(core::vector3df(0,0,0));
  59. points.push_back(core::vector3df(10,5,10));
  60. anim = Manager->createFollowSplineAnimator(0, points);
  61. }
  62. break;
  63. case ESNAT_ROTATION:
  64. anim = Manager->createRotationAnimator(core::vector3df(0.3f,0,0));
  65. break;
  66. case ESNAT_TEXTURE:
  67. {
  68. core::array<video::ITexture*> textures;
  69. anim = Manager->createTextureAnimator(textures, 250);
  70. }
  71. break;
  72. case ESNAT_DELETION:
  73. anim = Manager->createDeleteAnimator(5000);
  74. break;
  75. case ESNAT_COLLISION_RESPONSE:
  76. anim = Manager->createCollisionResponseAnimator(0, target);
  77. break;
  78. case ESNAT_CAMERA_FPS:
  79. anim = new CSceneNodeAnimatorCameraFPS(CursorControl);
  80. break;
  81. case ESNAT_CAMERA_MAYA:
  82. anim = new CSceneNodeAnimatorCameraMaya(CursorControl);
  83. break;
  84. default:
  85. break;
  86. }
  87. if (anim && target)
  88. target->addAnimator(anim);
  89. return anim;
  90. }
  91. //! creates a scene node animator based on its type name
  92. ISceneNodeAnimator* CDefaultSceneNodeAnimatorFactory::createSceneNodeAnimator(const c8* typeName, ISceneNode* target)
  93. {
  94. return createSceneNodeAnimator( getTypeFromName(typeName), target );
  95. }
  96. //! returns amount of scene node animator types this factory is able to create
  97. u32 CDefaultSceneNodeAnimatorFactory::getCreatableSceneNodeAnimatorTypeCount() const
  98. {
  99. return ESNAT_COUNT;
  100. }
  101. //! returns type of a createable scene node animator type
  102. ESCENE_NODE_ANIMATOR_TYPE CDefaultSceneNodeAnimatorFactory::getCreateableSceneNodeAnimatorType(u32 idx) const
  103. {
  104. if (idx<ESNAT_COUNT)
  105. return (ESCENE_NODE_ANIMATOR_TYPE)idx;
  106. else
  107. return ESNAT_UNKNOWN;
  108. }
  109. //! returns type name of a createable scene node animator type
  110. const c8* CDefaultSceneNodeAnimatorFactory::getCreateableSceneNodeAnimatorTypeName(u32 idx) const
  111. {
  112. if (idx<ESNAT_COUNT)
  113. return SceneNodeAnimatorTypeNames[idx];
  114. else
  115. return 0;
  116. }
  117. //! returns type name of a createable scene node animator type
  118. const c8* CDefaultSceneNodeAnimatorFactory::getCreateableSceneNodeAnimatorTypeName(ESCENE_NODE_ANIMATOR_TYPE type) const
  119. {
  120. // for this factory: index == type
  121. if (type<ESNAT_COUNT)
  122. return SceneNodeAnimatorTypeNames[type];
  123. else
  124. return 0;
  125. }
  126. ESCENE_NODE_ANIMATOR_TYPE CDefaultSceneNodeAnimatorFactory::getTypeFromName(const c8* name) const
  127. {
  128. for ( u32 i=0; SceneNodeAnimatorTypeNames[i]; ++i)
  129. if (!strcmp(name, SceneNodeAnimatorTypeNames[i]) )
  130. return (ESCENE_NODE_ANIMATOR_TYPE)i;
  131. return ESNAT_UNKNOWN;
  132. }
  133. } // end namespace scene
  134. } // end namespace irr