CCActionCamera.h 5.0 KB

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