ISceneNodeAnimatorCollisionResponse.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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. #ifndef IRR_I_SCENE_NODE_ANIMATOR_COLLISION_RESPONSE_H_INCLUDED
  5. #define IRR_I_SCENE_NODE_ANIMATOR_COLLISION_RESPONSE_H_INCLUDED
  6. #include "ISceneNode.h"
  7. namespace irr
  8. {
  9. namespace scene
  10. {
  11. class ISceneNodeAnimatorCollisionResponse;
  12. //! Callback interface for catching events of collisions.
  13. /** Implement this interface and use
  14. ISceneNodeAnimatorCollisionResponse::setCollisionCallback to be able to
  15. be notified if a collision has occurred.
  16. **/
  17. class ICollisionCallback : public virtual IReferenceCounted
  18. {
  19. public:
  20. //! Will be called when a collision occurs.
  21. /** See ISceneNodeAnimatorCollisionResponse::setCollisionCallback for more information.
  22. \param animator: Collision response animator in which the collision occurred. You can call
  23. this animator's methods to find the node, collisionPoint and/or collision triangle.
  24. \retval true if the collision was handled in the animator. The animator's target
  25. node will *not* be stopped at the collision point, but will instead move fully
  26. to the location that triggered the collision check.
  27. \retval false if the collision was not handled in the animator. The animator's
  28. target node will be moved to the collision position.
  29. */
  30. virtual bool onCollision(const ISceneNodeAnimatorCollisionResponse& animator) = 0;
  31. };
  32. //! Special scene node animator for doing automatic collision detection and response.
  33. /** This scene node animator can be attached to any single scene node
  34. and will then prevent it from moving through specified collision geometry
  35. (e.g. walls and floors of the) world, as well as having it fall under gravity.
  36. This animator provides a simple implementation of first person shooter cameras.
  37. Attach it to a camera, and the camera will behave as the player control in a
  38. first person shooter game: The camera stops and slides at walls, walks up stairs,
  39. falls down if there is no floor under it, and so on.
  40. The animator will treat any change in the position of its target scene
  41. node as movement, including a setPosition(), as movement. If you want to
  42. teleport the target scene node manually to a location without it being effected
  43. by collision geometry, then call setTargetNode(node) after calling node->setPosition().
  44. */
  45. class ISceneNodeAnimatorCollisionResponse : public ISceneNodeAnimator
  46. {
  47. public:
  48. //! Destructor
  49. virtual ~ISceneNodeAnimatorCollisionResponse() {}
  50. //! Check if the attached scene node is falling.
  51. /** Falling means that there is no blocking wall from the scene
  52. node in the direction of the gravity. The implementation of
  53. this method is very fast, no collision detection is done when
  54. invoking it.
  55. \return True if the scene node is falling, false if not. */
  56. virtual bool isFalling() const = 0;
  57. //! Sets the radius of the ellipsoid for collision detection and response.
  58. /** If you have a scene node, and you are unsure about how big
  59. the radius should be, you could use the following code to
  60. determine it:
  61. \code
  62. core::aabbox<f32> box = yourSceneNode->getBoundingBox();
  63. core::vector3df radius = box.MaxEdge - box.getCenter();
  64. \endcode
  65. \param radius: New radius of the ellipsoid. */
  66. virtual void setEllipsoidRadius(const core::vector3df& radius) = 0;
  67. //! Returns the radius of the ellipsoid for collision detection and response.
  68. /** \return Radius of the ellipsoid. */
  69. virtual core::vector3df getEllipsoidRadius() const = 0;
  70. //! Sets the gravity of the environment.
  71. /** A good example value would be core::vector3df(0,-100.0f,0)
  72. for letting gravity affect all object to fall down. For bigger
  73. gravity, make increase the length of the vector. You can
  74. disable gravity by setting it to core::vector3df(0,0,0);
  75. \param gravity: New gravity vector. */
  76. virtual void setGravity(const core::vector3df& gravity) = 0;
  77. //! Get current vector of gravity.
  78. //! \return Gravity vector. */
  79. virtual core::vector3df getGravity() const = 0;
  80. //! 'Jump' the animator, by adding a jump speed opposite to its gravity
  81. /** \param jumpSpeed The initial speed of the jump; the velocity will be opposite
  82. to this animator's gravity vector. */
  83. virtual void jump(f32 jumpSpeed) = 0;
  84. //! Should the Target react on collision ( default = true )
  85. virtual void setAnimateTarget ( bool enable ) = 0;
  86. virtual bool getAnimateTarget () const = 0;
  87. //! Set translation of the collision ellipsoid.
  88. /** By default, the ellipsoid for collision detection is
  89. created around the center of the scene node, which means that
  90. the ellipsoid surrounds it completely. If this is not what you
  91. want, you may specify a translation for the ellipsoid.
  92. \param translation: Translation of the ellipsoid relative
  93. to the position of the scene node. */
  94. virtual void setEllipsoidTranslation(const core::vector3df &translation) = 0;
  95. //! Get the translation of the ellipsoid for collision detection.
  96. /** See
  97. ISceneNodeAnimatorCollisionResponse::setEllipsoidTranslation()
  98. for more details.
  99. \return Translation of the ellipsoid relative to the position
  100. of the scene node. */
  101. virtual core::vector3df getEllipsoidTranslation() const = 0;
  102. //! Sets a triangle selector holding all triangles of the world with which the scene node may collide.
  103. /** \param newWorld: New triangle selector containing triangles
  104. to let the scene node collide with. */
  105. virtual void setWorld(ITriangleSelector* newWorld) = 0;
  106. //! Get the current triangle selector containing all triangles for collision detection.
  107. virtual ITriangleSelector* getWorld() const = 0;
  108. //! Set the single node that this animator will act on.
  109. /** \param node The new target node. Setting this will force the animator to update
  110. its last target position for the node, allowing setPosition() to teleport
  111. the node through collision geometry. */
  112. virtual void setTargetNode(ISceneNode * node) = 0;
  113. //! Gets the single node that this animator is acting on.
  114. /** \return The node that this animator is acting on. */
  115. virtual ISceneNode* getTargetNode(void) const = 0;
  116. //! Returns true if a collision occurred during the last animateNode()
  117. virtual bool collisionOccurred() const = 0;
  118. //! Returns the last point of collision.
  119. virtual const core::vector3df & getCollisionPoint() const = 0;
  120. //! Returns the last triangle that caused a collision
  121. virtual const core::triangle3df & getCollisionTriangle() const = 0;
  122. //! Returns the position that the target node will be moved to, unless the collision is consumed in a callback.
  123. /**
  124. If you have a collision callback registered, and it consumes the collision, then the
  125. node will ignore the collision and will not stop at this position. Instead, it will
  126. move fully to the position that caused the collision to occur. */
  127. virtual const core::vector3df & getCollisionResultPosition(void) const = 0;
  128. //! Returns the node that was collided with.
  129. virtual ISceneNode* getCollisionNode(void) const = 0;
  130. //! Sets a callback interface which will be called if a collision occurs.
  131. /** \param callback: collision callback handler that will be called when a collision
  132. occurs. Set this to 0 to disable the callback.
  133. */
  134. virtual void setCollisionCallback(ICollisionCallback* callback) = 0;
  135. };
  136. } // end namespace scene
  137. } // end namespace irr
  138. #endif