CCPUSimpleSpline.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /****************************************************************************
  2. Copyright (C) 2013 Henry van Merode. All rights reserved.
  3. Copyright (c) 2015-2017 Chukong Technologies Inc.
  4. http://www.cocos2d-x.org
  5. Permission is hereby granted, free of charge, to any person obtaining a copy
  6. of this software and associated documentation files (the "Software"), to deal
  7. in the Software without restriction, including without limitation the rights
  8. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. copies of the Software, and to permit persons to whom the Software is
  10. furnished to do so, subject to the following conditions:
  11. The above copyright notice and this permission notice shall be included in
  12. all copies or substantial portions of the Software.
  13. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. THE SOFTWARE.
  20. ****************************************************************************/
  21. #ifndef __CC_PU_PARTICLE_3D_SIMPLE_SPLINE_H__
  22. #define __CC_PU_PARTICLE_3D_SIMPLE_SPLINE_H__
  23. #include "base/CCRef.h"
  24. #include "math/CCMath.h"
  25. #include <vector>
  26. NS_CC_BEGIN
  27. class PUSimpleSpline
  28. {
  29. public:
  30. PUSimpleSpline();
  31. ~PUSimpleSpline();
  32. /** Adds a control point to the end of the spline. */
  33. void addPoint(const Vec3& p);
  34. /** Gets the detail of one of the control points of the spline. */
  35. const Vec3& getPoint(unsigned short index) const;
  36. /** Gets the number of control points in the spline. */
  37. unsigned short getNumPoints(void) const;
  38. /** Clears all the points in the spline. */
  39. void clear(void);
  40. /** Updates a single point in the spline.
  41. @remarks
  42. This point must already exist in the spline.
  43. */
  44. void updatePoint(unsigned short index, const Vec3& value);
  45. /** Returns an interpolated point based on a parametric value over the whole series.
  46. @remarks
  47. Given a t value between 0 and 1 representing the parametric distance along the
  48. whole length of the spline, this method returns an interpolated point.
  49. @param t Parametric value.
  50. */
  51. Vec3 interpolate(float t) const;
  52. /** Interpolates a single segment of the spline given a parametric value.
  53. @param fromIndex The point index to treat as t=0. fromIndex + 1 is deemed to be t=1
  54. @param t Parametric value
  55. */
  56. Vec3 interpolate(unsigned int fromIndex, float t) const;
  57. /** Tells the spline whether it should automatically calculate tangents on demand
  58. as points are added.
  59. @remarks
  60. The spline calculates tangents at each point automatically based on the input points.
  61. Normally it does this every time a point changes. However, if you have a lot of points
  62. to add in one go, you probably don't want to incur this overhead and would prefer to
  63. defer the calculation until you are finished setting all the points. You can do this
  64. by calling this method with a parameter of 'false'. Just remember to manually call
  65. the recalcTangents method when you are done.
  66. @param autoCalc If true, tangents are calculated for you whenever a point changes. If false,
  67. you must call reclacTangents to recalculate them when it best suits.
  68. */
  69. void setAutoCalculate(bool autoCalc);
  70. /** Recalculates the tangents associated with this spline.
  71. @remarks
  72. If you tell the spline not to update on demand by calling setAutoCalculate(false)
  73. then you must call this after completing your updates to the spline points.
  74. */
  75. void recalcTangents(void);
  76. protected:
  77. bool _autoCalc;
  78. std::vector<Vec3> _points;
  79. std::vector<Vec3> _tangents;
  80. /// Matrix of coefficients
  81. Mat4 _coeffs;
  82. };
  83. NS_CC_END
  84. #endif