CCActionCamera.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /****************************************************************************
  2. Copyright (c) 2008-2010 Ricardo Quesada
  3. Copyright (c) 2010-2012 cocos2d-x.org
  4. Copyright (c) 2011 Zynga Inc.
  5. Copyright (c) 2013-2017 Chukong Technologies Inc.
  6. http://www.cocos2d-x.org
  7. Permission is hereby granted, free of charge, to any person obtaining a copy
  8. of this software and associated documentation files (the "Software"), to deal
  9. in the Software without restriction, including without limitation the rights
  10. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. copies of the Software, and to permit persons to whom the Software is
  12. furnished to do so, subject to the following conditions:
  13. The above copyright notice and this permission notice shall be included in
  14. all copies or substantial portions of the Software.
  15. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. THE SOFTWARE.
  22. ****************************************************************************/
  23. #ifndef __CCCAMERA_ACTION_H__
  24. #define __CCCAMERA_ACTION_H__
  25. #include "2d/CCActionInterval.h"
  26. #include "math/CCMath.h"
  27. NS_CC_BEGIN
  28. class Camera;
  29. /**
  30. * @addtogroup actions
  31. * @{
  32. */
  33. /**
  34. *@brief Base class for Camera actions.
  35. *@ingroup Actions
  36. */
  37. class CC_DLL ActionCamera : public ActionInterval
  38. {
  39. public:
  40. /**
  41. * @js ctor
  42. * @lua new
  43. */
  44. ActionCamera();
  45. /**
  46. * @js NA
  47. * @lua NA
  48. */
  49. virtual ~ActionCamera(){};
  50. // Overrides
  51. virtual void startWithTarget(Node *target) override;
  52. virtual ActionCamera * reverse() const override;
  53. virtual ActionCamera *clone() const override;
  54. /* Sets the Eye value of the Camera.
  55. *
  56. * @param eye The Eye value of the Camera.
  57. * @js NA
  58. */
  59. void setEye(const Vec3 &eye);
  60. void setEye(float x, float y, float z);
  61. /* Returns the Eye value of the Camera.
  62. *
  63. * @return The Eye value of the Camera.
  64. * @js NA
  65. */
  66. const Vec3& getEye() const { return _eye; }
  67. /* Sets the Center value of the Camera.
  68. *
  69. * @param center The Center value of the Camera.
  70. * @js NA
  71. */
  72. void setCenter(const Vec3 &center);
  73. /* Returns the Center value of the Camera.
  74. *
  75. * @return The Center value of the Camera.
  76. * @js NA
  77. */
  78. const Vec3& getCenter() const { return _center; }
  79. /* Sets the Up value of the Camera.
  80. *
  81. * @param up The Up value of the Camera.
  82. * @js NA
  83. */
  84. void setUp(const Vec3 &up);
  85. /* Returns the Up value of the Camera.
  86. *
  87. * @return The Up value of the Camera.
  88. * @js NA
  89. */
  90. const Vec3& getUp() const { return _up; }
  91. protected:
  92. void restore();
  93. void updateTransform();
  94. Vec3 _center;
  95. Vec3 _eye;
  96. Vec3 _up;
  97. };
  98. /** @class OrbitCamera
  99. *
  100. * @brief OrbitCamera action.
  101. * Orbits the camera around the center of the screen using spherical coordinates.
  102. * @ingroup Actions
  103. */
  104. class CC_DLL OrbitCamera : public ActionCamera
  105. {
  106. public:
  107. /** Creates a OrbitCamera action with radius, delta-radius, z, deltaZ, x, deltaX.
  108. *
  109. * @param t Duration in seconds.
  110. * @param radius The start radius.
  111. * @param deltaRadius The delta radius.
  112. * @param angleZ The start angle in Z.
  113. * @param deltaAngleZ The delta angle in Z.
  114. * @param angleX The start angle in X.
  115. * @param deltaAngleX The delta angle in X.
  116. * @return An OrbitCamera.
  117. */
  118. static OrbitCamera* create(float t, float radius, float deltaRadius, float angleZ, float deltaAngleZ, float angleX, float deltaAngleX);
  119. /** Positions the camera according to spherical coordinates.
  120. *
  121. * @param r The spherical radius.
  122. * @param zenith The spherical zenith.
  123. * @param azimuth The spherical azimuth.
  124. */
  125. void sphericalRadius(float *r, float *zenith, float *azimuth);
  126. // Overrides
  127. OrbitCamera *clone() const override;
  128. virtual void startWithTarget(Node *target) override;
  129. virtual void update(float time) override;
  130. CC_CONSTRUCTOR_ACCESS:
  131. /**
  132. * @js ctor
  133. */
  134. OrbitCamera();
  135. /**
  136. * @js NA
  137. * @lua NA
  138. */
  139. virtual ~OrbitCamera();
  140. /** Initializes a OrbitCamera action with radius, delta-radius, z, deltaZ, x, deltaX. */
  141. bool initWithDuration(float t, float radius, float deltaRadius, float angleZ, float deltaAngleZ, float angleX, float deltaAngleX);
  142. protected:
  143. float _radius;
  144. float _deltaRadius;
  145. float _angleZ;
  146. float _deltaAngleZ;
  147. float _angleX;
  148. float _deltaAngleX;
  149. float _radZ;
  150. float _radDeltaZ;
  151. float _radX;
  152. float _radDeltaX;
  153. };
  154. // end of actions group
  155. /// @}
  156. NS_CC_END
  157. #endif //__CCCAMERA_ACTION_H__